Upgrade php-cs-fixer to 3.x and fix CS

main
Jordi Boggiano 3 years ago
parent c65d09dff7
commit 44b69ba77f
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

2
.gitignore vendored

@ -9,4 +9,4 @@ phpunit.xml
.vagrant
Vagrantfile
.idea
.php_cs.cache
.php-cs-fixer.cache

@ -18,10 +18,8 @@ $finder = PhpCsFixer\Finder::create()
->notPath('Fixtures')
;
return PhpCsFixer\Config::create()
->setUsingCache(true)
->setRiskyAllowed(true)
->setRules(array(
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR2' => true,
'array_syntax' => array('syntax' => 'long'),
'binary_operator_spaces' => true,
@ -29,31 +27,42 @@ return PhpCsFixer\Config::create()
'cast_spaces' => array('space' => 'single'),
'header_comment' => array('header' => $header),
'include' => true,
'class_attributes_separation' => array('elements' => array('method')),
'class_attributes_separation' => array('elements' => array('method' => 'one', 'trait_import' => 'none')),
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unused_imports' => true,
'no_whitespace_in_blank_line' => true,
'object_operator_without_whitespace' => true,
'phpdoc_align' => true,
//'phpdoc_align' => true,
'phpdoc_indent' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
'phpdoc_order' => true,
//'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'psr0' => true,
'psr_autoloading' => true,
'single_blank_line_before_namespace' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'unary_operator_spaces' => true,
))
// imports
'no_unused_imports' => true,
'fully_qualified_strict_types' => true,
'single_line_after_imports' => true,
'fully_qualified_strict_types' => true,
//'global_namespace_import' => ['import_classes' => true],
'no_leading_import_slash' => true,
'single_import_per_statement' => true,
])
->setUsingCache(true)
->setRiskyAllowed(true)
->setFinder($finder)
;

@ -1,5 +1,15 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
@ -118,6 +128,7 @@ class PhpFileCleaner
&& \preg_match($type['pattern'], $this->contents, $match, 0, $this->index - 1)
) {
$clean .= $match[0];
return $clean;
}
}
@ -222,6 +233,7 @@ class PhpFileCleaner
&& $this->match($delimiterPattern)
) {
$this->index += $delimiterLength;
return;
}
break;

@ -138,6 +138,7 @@ EOT
$process = new ProcessExecutor($this->getIO());
if (Platform::isWindows()) {
$process->execute('start "web" explorer ' . $url, $output);
return;
}

@ -13,7 +13,6 @@
namespace Composer\Command;
use Composer\Json\JsonFile;
use Composer\Package\BasePackage;
use Composer\Package\CompletePackageInterface;
use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;

@ -113,6 +113,7 @@ EOT
if ($input->getOption('update-keys')) {
$this->fetchKeys($io, $config);
return 0;
}

@ -58,7 +58,6 @@ class LockTransaction extends Transaction
parent::__construct($this->presentMap, $this->resultPackages['all']);
}
// TODO make this a bit prettier instead of the two text indexes?
/**
* @return void

@ -22,7 +22,6 @@ use Composer\Package\PackageInterface;
use Composer\Package\Version\StabilityFilter;
use Composer\Plugin\PluginEvents;
use Composer\Plugin\PrePoolCreateEvent;
use Composer\Repository\LockArrayRepository;
use Composer\Repository\PlatformRepository;
use Composer\Repository\RepositoryInterface;
use Composer\Repository\RootPackageRepository;

@ -20,7 +20,6 @@ use Composer\Package\Version\VersionGuesser;
use Composer\Package\RootPackageInterface;
use Composer\Repository\RepositoryManager;
use Composer\Repository\RepositoryFactory;
use Composer\Repository\WritableRepositoryInterface;
use Composer\Util\Filesystem;
use Composer\Util\Platform;
use Composer\Util\ProcessExecutor;

@ -22,8 +22,6 @@ use Composer\Package\BasePackage;
use Composer\Package\AliasPackage;
use Composer\Package\CompleteAliasPackage;
use Composer\Package\CompletePackage;
use Composer\Package\CompletePackageInterface;
use Composer\Package\PackageInterface;
use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Package\Version\StabilityFilter;

@ -13,9 +13,7 @@
namespace Composer\Util;
use Composer\IO\IOInterface;
use Composer\Util\Platform;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessUtils;
use Symfony\Component\Process\Exception\RuntimeException;
use React\Promise\Promise;
use React\Promise\PromiseInterface;

@ -255,13 +255,13 @@ class ClassMapGeneratorTest extends TestCase
public function testCreateMapDoesNotHitRegexBacktraceLimit()
{
$expected = array(
'Foo\\StripNoise' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/StripNoise.php',
'Foo\\VeryLongHeredoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongHeredoc.php',
'Foo\\StripNoise' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/StripNoise.php',
'Foo\\VeryLongHeredoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongHeredoc.php',
'Foo\\ClassAfterLongHereDoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongHeredoc.php',
'Foo\\VeryLongPHP73Heredoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongPHP73Heredoc.php',
'Foo\\VeryLongPHP73Nowdoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongPHP73Nowdoc.php',
'Foo\\ClassAfterLongNowDoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongPHP73Nowdoc.php',
'Foo\\VeryLongNowdoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongNowdoc.php',
'Foo\\VeryLongPHP73Heredoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongPHP73Heredoc.php',
'Foo\\VeryLongPHP73Nowdoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongPHP73Nowdoc.php',
'Foo\\ClassAfterLongNowDoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongPHP73Nowdoc.php',
'Foo\\VeryLongNowdoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongNowdoc.php',
);
ini_set('pcre.backtrack_limit', '30000');

@ -200,7 +200,7 @@ class SolverTest extends TestCase
*
* This is not something that can happen with packages on e.g. Packagist, but custom installers with custom repositories might do something like this;
* in fact, some PaaSes do the exact thing above, installing binary builds of PHP and extensions as Composer packages with a custom installer in a separate step before the "userland" `composer install`.
*
*
* If version selectors are sufficiently permissive (e.g. "ourcustom/php":"*", "ourcustom/ext-foobar":"*"), then it may happen that the Solver won't pick the highest possible PHP version, as it has already settled on an "ext-foobar" (they're all the same version to the Solver, it doesn't know about the different requirements in each of the otherwise identical packages) if that was listed in "require" before "php".
* That's "unfixable", and not even broken, behavior (what if the "ext-foobar" has higher versions for the lower "PHP"? who wins then? any combination of the packages is "correct"), but it shouldn't randomly change.
* This test asserts this behavior to prevent regressions.

@ -151,12 +151,14 @@ class GitDownloaderTest extends TestCase
$process = new ProcessExecutorMock;
$process->expects(array(
array('cmd' => $this->winCompat(sprintf("git clone --mirror -- 'https://example.com/composer/composer' '%s'", $cachePath)), 'callback' => function () use ($cachePath) { @mkdir($cachePath, 0777, true); }),
array('cmd' => $this->winCompat(sprintf("git clone --mirror -- 'https://example.com/composer/composer' '%s'", $cachePath)), 'callback' => function () use ($cachePath) {
@mkdir($cachePath, 0777, true);
}),
array('cmd' => 'git rev-parse --git-dir', 'stdout' => '.'),
$this->winCompat('git rev-parse --quiet --verify \'1234567890123456789012345678901234567890^{commit}\''),
$this->winCompat(sprintf("git clone --no-checkout '%1\$s' 'composerPath' --dissociate --reference '%1\$s' && cd 'composerPath' && git remote set-url origin -- 'https://example.com/composer/composer' && git remote add composer -- 'https://example.com/composer/composer'", $cachePath)),
'git branch -r',
$this->winCompat("(git checkout 'master' -- || git checkout -B 'master' 'composer/master' --) && git reset --hard '1234567890123456789012345678901234567890' --")
$this->winCompat("(git checkout 'master' -- || git checkout -B 'master' 'composer/master' --) && git reset --hard '1234567890123456789012345678901234567890' --"),
), true);
$downloader = $this->getDownloaderMock(null, $config, $process);

@ -65,7 +65,9 @@ class NullIOTest extends TestCase
{
$io = new NullIO();
$this->assertEquals('foo', $io->askAndValidate('question', function ($x) { return true; }, null, 'foo'));
$this->assertEquals('foo', $io->askAndValidate('question', function ($x) {
return true;
}, null, 'foo'));
}
public function testSelect()

@ -75,10 +75,10 @@ class InstallerTest extends TestCase
switch ($key) {
case 'vendor-dir':
return 'foo';
case 'lock';
case 'notify-on-install';
case 'lock':
case 'notify-on-install':
return true;
case 'platform';
case 'platform':
return array();
}

@ -91,7 +91,6 @@ class ComposerSchemaTest extends TestCase
}
/**
*
* @param string $json
* @return mixed
*/

@ -370,10 +370,9 @@ class JsonFileTest extends TestCase
}
/**
*
* @param string $json
* @param mixed $data
* @param integer|null $options
* @param int|null $options
* @return void
*/
private function assertJsonFormat($json, $data, $options = null)

@ -21,7 +21,6 @@ use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
use React\Promise\PromiseInterface;
class InstallationManagerMock extends InstallationManager
{

@ -45,7 +45,7 @@ class ProcessExecutorMock extends ProcessExecutor
* @param array<string|array{cmd: string, return?: int, stdout?: string, stderr?: string, callback?: callable}> $expectations
* @param bool $strict set to true if you want to provide *all* expected commands, and not just a subset you are interested in testing
* @param array{return: int, stdout?: string, stderr?: string} $defaultHandler default command handler for undefined commands if not in strict mode
*
*
* @return void
*/
public function expects(array $expectations, $strict = false, array $defaultHandler = array('return' => 0, 'stdout' => '', 'stderr' => ''))
@ -100,7 +100,6 @@ class ProcessExecutorMock extends ProcessExecutor
}
/**
*
* @param string $command
* @param string $cwd
* @param bool $tty

@ -16,7 +16,6 @@ use Composer\IO\NullIO;
use Composer\Factory;
use Composer\Package\Archiver\ArchiveManager;
use Composer\Package\CompletePackage;
use Composer\Package\PackageInterface;
use Composer\Util\Loop;
use Composer\Test\Mock\FactoryMock;
use Composer\Util\ProcessExecutor;

@ -82,7 +82,6 @@ class RootPackageLoaderTest extends TestCase
$this->assertEquals("1.0.0.0", $package->getVersion());
$this->assertEquals(RootPackage::DEFAULT_PRETTY_VERSION, $package->getPrettyVersion());
}
public function testPrettyVersionForRootPackageInVersionBranch()
@ -150,7 +149,7 @@ class RootPackageLoaderTest extends TestCase
$process->expects(array(
array(
'cmd' => 'git branch -a --no-color --no-abbrev -v',
'stdout' => "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n"
'stdout' => "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n",
),
), true);

@ -66,7 +66,7 @@ class VersionGuesserTest extends TestCase
$process->expects(array(
array(
'cmd' => 'git branch -a --no-color --no-abbrev -v',
'stdout' => "* master $commitHash Commit message\n(no branch) $anotherCommitHash Commit message\n"
'stdout' => "* master $commitHash Commit message\n(no branch) $anotherCommitHash Commit message\n",
),
), true);
@ -94,7 +94,7 @@ class VersionGuesserTest extends TestCase
array(
'cmd' => 'git branch -a --no-color --no-abbrev -v',
// Assumption here is that arbitrary would be the default branch
'stdout' => " arbitrary $commitHash Commit message\n* current $anotherCommitHash Another message\n"
'stdout' => " arbitrary $commitHash Commit message\n* current $anotherCommitHash Another message\n",
),
), true);
@ -118,11 +118,11 @@ class VersionGuesserTest extends TestCase
$process->expects(array(
array(
'cmd' => 'git branch -a --no-color --no-abbrev -v',
'stdout' => " arbitrary $commitHash Commit message\n* feature $anotherCommitHash Another message\n"
'stdout' => " arbitrary $commitHash Commit message\n* feature $anotherCommitHash Another message\n",
),
array(
'cmd' => 'git rev-list arbitrary..feature',
'stdout' => "$anotherCommitHash\n"
'stdout' => "$anotherCommitHash\n",
),
), true);
@ -245,7 +245,6 @@ class VersionGuesserTest extends TestCase
{
$commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
$process = new ProcessExecutorMock;
$process->expects(array(
array(

@ -249,7 +249,7 @@ class PluginInstallerTest extends TestCase
/**
* @param string $newPluginApiVersion
* @param CompletePackage[] $plugins
*
*
* @return void
*/
private function setPluginApiVersionWithPlugins($newPluginApiVersion, array $plugins = array())
@ -407,7 +407,7 @@ class PluginInstallerTest extends TestCase
* @dataProvider invalidImplementationClassNames
* @param callable $invalidImplementationClassNames
* @param string $expect
*
*
* @return void
*/
public function testQueryingWithInvalidCapabilityClassNameThrows($invalidImplementationClassNames, $expect = 'UnexpectedValueException')
@ -441,7 +441,7 @@ class PluginInstallerTest extends TestCase
->will($this->returnCallback(function () {
return array();
}));
/** @phpstan-ignore-next-line */
$this->assertNull($this->pm->getPluginCapability($plugin, $capabilityApi));
}
@ -449,7 +449,7 @@ class PluginInstallerTest extends TestCase
/**
* @dataProvider nonExistingOrInvalidImplementationClassTypes
* @param callable $wrongImplementationClassTypes
*
*
* @return void
*/
public function testQueryingWithNonExistingOrWrongCapabilityClassTypesThrows($wrongImplementationClassTypes)

@ -13,7 +13,6 @@
namespace Composer\Test\Repository;
use Composer\Package\Link;
use Composer\Package\Package;
use Composer\Package\PackageInterface;
use Composer\Repository\PlatformRepository;
use Composer\Test\TestCase;

@ -20,7 +20,6 @@ use Composer\Util\Http\Response;
use Composer\Test\Mock\ProcessExecutorMock;
use Composer\Config;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Process\Process;
class GitHubDriverTest extends TestCase
{

@ -188,6 +188,7 @@ abstract class TestCase extends PolyfillTestCase
$cmd = preg_replace_callback("/('[^']*')/", function ($m) {
// Double-quotes are used only when needed
$char = (strpbrk($m[1], " \t^&|<>()") !== false || $m[1] === "''") ? '"' : '';
return str_replace("'", $char, $m[1]);
}, $cmd);
}

@ -16,8 +16,6 @@ use Composer\Downloader\TransportException;
use Composer\Util\GitHub;
use Composer\Util\Http\Response;
use Composer\Test\TestCase;
use RecursiveArrayIterator;
use RecursiveIteratorIterator;
/**
* @author Rob Bast <rob.bast@gmail.com>

@ -86,7 +86,6 @@ class GitTest extends TestCase
$this->mockConfig('https');
$this->process->expects(array(
array('cmd' => 'git command', 'return' => 1),
array('cmd' => 'git --version', 'return' => 0),

@ -155,70 +155,70 @@ class ProcessExecutorTest extends TestCase
{
return array(
// empty argument - must be quoted
'empty' => array('', '""', "''"),
'empty' => array('', '""', "''"),
// null argument - must be quoted
'empty null' => array(null, '""', "''"),
'empty null' => array(null, '""', "''"),
// false argument - must be quoted
'empty false' => array(false, '""', "''"),
'empty false' => array(false, '""', "''"),
// unix single-quote must be escaped
'unix-sq' => array("a'bc", "a'bc", "'a'\\''bc'"),
'unix-sq' => array("a'bc", "a'bc", "'a'\\''bc'"),
// new lines must be replaced
'new lines' => array("a\nb\nc", '"a b c"', "'a\nb\nc'"),
'new lines' => array("a\nb\nc", '"a b c"', "'a\nb\nc'"),
// whitespace <space> must be quoted
'ws space' => array('a b c', '"a b c"', "'a b c'"),
'ws space' => array('a b c', '"a b c"', "'a b c'"),
// whitespace <tab> must be quoted
'ws tab' => array("a\tb\tc", "\"a\tb\tc\"", "'a\tb\tc'"),
'ws tab' => array("a\tb\tc", "\"a\tb\tc\"", "'a\tb\tc'"),
// no whitespace must not be quoted
'no-ws' => array('abc', 'abc', "'abc'"),
'no-ws' => array('abc', 'abc', "'abc'"),
// double-quotes must be backslash-escaped
'dq' => array('a"bc', 'a\^"bc', "'a\"bc'"),
'dq' => array('a"bc', 'a\^"bc', "'a\"bc'"),
// double-quotes must be backslash-escaped with preceeding backslashes doubled
'dq-bslash' => array('a\\"bc', 'a\\\\\^"bc', "'a\\\"bc'"),
'dq-bslash' => array('a\\"bc', 'a\\\\\^"bc', "'a\\\"bc'"),
// backslashes not preceeding a double-quote are treated as literal
'bslash' => array('ab\\\\c\\', 'ab\\\\c\\', "'ab\\\\c\\'"),
'bslash' => array('ab\\\\c\\', 'ab\\\\c\\', "'ab\\\\c\\'"),
// trailing backslashes must be doubled up when the argument is quoted
'bslash dq' => array('a b c\\\\', '"a b c\\\\\\\\"', "'a b c\\\\'"),
'bslash dq' => array('a b c\\\\', '"a b c\\\\\\\\"', "'a b c\\\\'"),
// meta: outer double-quotes must be caret-escaped as well
'meta dq' => array('a "b" c', '^"a \^"b\^" c^"', "'a \"b\" c'"),
'meta dq' => array('a "b" c', '^"a \^"b\^" c^"', "'a \"b\" c'"),
// meta: percent expansion must be caret-escaped
'meta-pc1' => array('%path%', '^%path^%', "'%path%'"),
'meta-pc1' => array('%path%', '^%path^%', "'%path%'"),
// meta: expansion must have two percent characters
'meta-pc2' => array('%path', '%path', "'%path'"),
'meta-pc2' => array('%path', '%path', "'%path'"),
// meta: expansion must have have two surrounding percent characters
'meta-pc3' => array('%%path', '%%path', "'%%path'"),
'meta-pc3' => array('%%path', '%%path', "'%%path'"),
// meta: bang expansion must be double caret-escaped
'meta-bang1' => array('!path!', '^^!path^^!', "'!path!'"),
'meta-bang1' => array('!path!', '^^!path^^!', "'!path!'"),
// meta: bang expansion must have two bang characters
'meta-bang2' => array('!path', '!path', "'!path'"),
'meta-bang2' => array('!path', '!path', "'!path'"),
// meta: bang expansion must have two surrounding ang characters
'meta-bang3' => array('!!path', '!!path', "'!!path'"),
'meta-bang3' => array('!!path', '!!path', "'!!path'"),
// meta: caret-escaping must escape all other meta chars (triggered by double-quote)
'meta-all-dq' => array('<>"&|()^', '^<^>\^"^&^|^(^)^^', "'<>\"&|()^'"),
'meta-all-dq' => array('<>"&|()^', '^<^>\^"^&^|^(^)^^', "'<>\"&|()^'"),
// other meta: no caret-escaping when whitespace in argument
'other meta' => array('<> &| ()^', '"<> &| ()^"', "'<> &| ()^'"),
'other meta' => array('<> &| ()^', '"<> &| ()^"', "'<> &| ()^'"),
// other meta: quote escape chars when no whitespace in argument
'other-meta' => array('<>&|()^', '"<>&|()^"', "'<>&|()^'"),
'other-meta' => array('<>&|()^', '"<>&|()^"', "'<>&|()^'"),
);
}
}

Loading…
Cancel
Save