From c8aea719b145ca78a79a60913db5c312883e8ace Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 18 Dec 2017 16:02:48 +0100 Subject: [PATCH] CS fixes --- .php_cs | 4 +-- .../Command/CheckPlatformReqsCommand.php | 17 +++++++--- src/Composer/Command/InitCommand.php | 14 ++++---- src/Composer/Compiler.php | 2 +- src/Composer/Installer.php | 4 +-- .../Repository/FilesystemRepository.php | 2 +- src/Composer/Repository/Vcs/FossilDriver.php | 2 +- src/Composer/Repository/Vcs/GitDriver.php | 1 + src/Composer/Repository/Vcs/GitLabDriver.php | 2 +- src/Composer/Util/Filesystem.php | 5 +-- src/Composer/Util/Perforce.php | 1 + src/Composer/Util/ProcessExecutor.php | 1 + src/Composer/Util/RemoteFilesystem.php | 1 + src/Composer/XdebugHandler.php | 2 +- tests/Composer/Test/IO/ConsoleIOTest.php | 2 +- .../Test/Json/JsonManipulatorTest.php | 2 -- .../Test/Repository/Vcs/GitLabDriverTest.php | 33 ++++++++++--------- tests/Composer/Test/Util/FilesystemTest.php | 2 +- .../Test/Util/RemoteFilesystemTest.php | 2 +- 19 files changed, 56 insertions(+), 43 deletions(-) diff --git a/.php_cs b/.php_cs index 8f2a14b9b..7755b4f70 100644 --- a/.php_cs +++ b/.php_cs @@ -12,10 +12,10 @@ EOF; $finder = PhpCsFixer\Finder::create() ->files() - ->name('*.php') - ->exclude('Fixtures') ->in(__DIR__.'/src') ->in(__DIR__.'/tests') + ->name('*.php') + ->notPath('Fixtures') ; return PhpCsFixer\Config::create() diff --git a/src/Composer/Command/CheckPlatformReqsCommand.php b/src/Composer/Command/CheckPlatformReqsCommand.php index 51be758b4..7da5edaa5 100644 --- a/src/Composer/Command/CheckPlatformReqsCommand.php +++ b/src/Composer/Command/CheckPlatformReqsCommand.php @@ -1,11 +1,20 @@ + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Composer\Command; use Composer\Package\Link; use Composer\Package\PackageInterface; use Composer\Semver\Constraint\Constraint; -use Composer\Semver\Constraint\MultiConstraint; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -115,17 +124,17 @@ EOT protected function printTable(OutputInterface $output, $results) { $table = array(); - $rows = array(); + $rows = array(); foreach ($results as $result) { /** * @var Link|null $link */ list($platformPackage, $version, $link, $status) = $result; - $rows[] = array( + $rows[] = array( $platformPackage, $version, $link ? sprintf('%s %s %s (%s)', $link->getSource(), $link->getDescription(), $link->getTarget(), $link->getPrettyConstraint()) : '', - $status + $status, ); } $table = array_merge($rows, $table); diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 63e628170..b84c8dde0 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -191,7 +191,7 @@ EOT $name = basename($cwd); $name = preg_replace('{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}', '\\1\\3-\\2\\4', $name); $name = strtolower($name); - if ( !empty($_SERVER['COMPOSER_DEFAULT_VENDOR']) ) { + if (!empty($_SERVER['COMPOSER_DEFAULT_VENDOR'])) { $name = $_SERVER['COMPOSER_DEFAULT_VENDOR'] . '/' . $name; } elseif (isset($git['github.user'])) { $name = $git['github.user'] . '/' . $name; @@ -242,15 +242,15 @@ EOT $input->setOption('description', $description); if (null === $author = $input->getOption('author')) { - if ( !empty($_SERVER['COMPOSER_DEFAULT_AUTHOR']) ) { + if (!empty($_SERVER['COMPOSER_DEFAULT_AUTHOR'])) { $author_name = $_SERVER['COMPOSER_DEFAULT_AUTHOR']; - } elseif ( isset($git['user.name']) ) { + } elseif (isset($git['user.name'])) { $author_name = $git['user.name']; } - if ( !empty($_SERVER['COMPOSER_DEFAULT_EMAIL']) ) { + if (!empty($_SERVER['COMPOSER_DEFAULT_EMAIL'])) { $author_email = $_SERVER['COMPOSER_DEFAULT_EMAIL']; - } elseif ( isset($git['user.email']) ) { + } elseif (isset($git['user.email'])) { $author_email = $git['user.email']; } @@ -306,7 +306,7 @@ EOT $input->setOption('type', $type); if (null === $license = $input->getOption('license')) { - if ( !empty($_SERVER['COMPOSER_DEFAULT_LICENSE']) ) { + if (!empty($_SERVER['COMPOSER_DEFAULT_LICENSE'])) { $license = $_SERVER['COMPOSER_DEFAULT_LICENSE']; } } @@ -423,7 +423,7 @@ EOT $abandoned = sprintf('Abandoned. %s.', $replacement); } - $choices[] = sprintf(' %5s %s %s',"[$position]", $foundPackage['name'], $abandoned); + $choices[] = sprintf(' %5s %s %s', "[$position]", $foundPackage['name'], $abandoned); if ($foundPackage['name'] === $package) { $exactMatch = true; break; diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index 6fccb8e96..34eca8be2 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -165,7 +165,7 @@ class Compiler } /** - * @param \SplFileInfo $file + * @param \SplFileInfo $file * @return string */ private function getRelativeFilePath($file) diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index f88f3a70c..dbdcb048d 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -767,7 +767,7 @@ class Installer // is this a plugin or a dependency of a plugin? if ($isPlugin || count(array_intersect($package->getNames(), $pluginRequires))) { // get the package's requires, but filter out any platform requirements or 'composer-plugin-api' - $requires = array_filter(array_keys($package->getRequires()), function($req) { + $requires = array_filter(array_keys($package->getRequires()), function ($req) { return $req !== 'composer-plugin-api' && !preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $req); }); @@ -1207,7 +1207,7 @@ class Installer if (preg_match('{^https?://(?:(?:www\.)?bitbucket\.org|(api\.)?github\.com)/}i', $package->getDistUrl())) { $package->setDistReference($reference); $package->setDistUrl(preg_replace('{(?<=/)[a-f0-9]{40}(?=/|$)}i', $reference, $package->getDistUrl())); - } else if ($package->getDistReference()) { // update the dist reference if there was one, but if none was provided ignore it + } elseif ($package->getDistReference()) { // update the dist reference if there was one, but if none was provided ignore it $package->setDistReference($reference); } } diff --git a/src/Composer/Repository/FilesystemRepository.php b/src/Composer/Repository/FilesystemRepository.php index a057abae3..bde55aad3 100644 --- a/src/Composer/Repository/FilesystemRepository.php +++ b/src/Composer/Repository/FilesystemRepository.php @@ -83,7 +83,7 @@ class FilesystemRepository extends WritableArrayRepository $data[] = $dumper->dump($package); } - usort($data, function($a, $b) { + usort($data, function ($a, $b) { return strcmp($a['name'], $b['name']); }); diff --git a/src/Composer/Repository/Vcs/FossilDriver.php b/src/Composer/Repository/Vcs/FossilDriver.php index 3874e56c5..7af97ad3e 100644 --- a/src/Composer/Repository/Vcs/FossilDriver.php +++ b/src/Composer/Repository/Vcs/FossilDriver.php @@ -162,7 +162,7 @@ class FossilDriver extends VcsDriver { $this->process->execute('fossil finfo -b -n 1 composer.json', $output, $this->checkoutDir); list($ckout, $date, $message) = explode(' ', trim($output), 3); - + return new \DateTime($date, new \DateTimeZone('UTC')); } diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index 6cb8be91a..0269f4721 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -216,6 +216,7 @@ class GitDriver extends VcsDriver } $process = new ProcessExecutor($io); + return $process->execute('git ls-remote --heads ' . ProcessExecutor::escape($url), $output) === 0; } } diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index fb2b7437e..dcaf646ec 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -261,6 +261,7 @@ class GitLabDriver extends VcsDriver { $domainName = $this->originUrl; $portNumber = (true === is_numeric($this->portNumber)) ? sprintf(':%s', $this->portNumber) : ''; + return $this->scheme.'://'.$domainName.$portNumber.'/api/v4/projects/'.$this->urlEncodeAll($this->namespace).'%2F'.$this->urlEncodeAll($this->repository); } @@ -449,7 +450,6 @@ class GitLabDriver extends VcsDriver */ public static function supports(IOInterface $io, Config $config, $url, $deep = false) { - if (!preg_match(self::URL_REGEX, $url, $match)) { return false; } diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 04b767ec3..39c953a50 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -264,7 +264,8 @@ class Filesystem * @param $target * @return bool */ - public function copy($source, $target) { + public function copy($source, $target) + { if (!is_dir($source)) { return copy($source, $target); } @@ -273,7 +274,7 @@ class Filesystem $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST); $this->ensureDirectoryExists($target); - $result=true; + $result = true; foreach ($ri as $file) { $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName(); if ($file->isDir()) { diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 3058d870b..13c07d6fd 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -117,6 +117,7 @@ class Perforce protected function executeCommand($command) { $this->commandResult = ''; + return $this->process->execute($command, $this->commandResult); } diff --git a/src/Composer/Util/ProcessExecutor.php b/src/Composer/Util/ProcessExecutor.php index 408aa9eae..5e40470b0 100644 --- a/src/Composer/Util/ProcessExecutor.php +++ b/src/Composer/Util/ProcessExecutor.php @@ -134,6 +134,7 @@ class ProcessExecutor if (method_exists('Symfony\Component\Process\ProcessUtils', 'escapeArgument')) { return ProcessUtils::escapeArgument($argument); } + return self::escapeArgument($argument); } diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index 8f25fe2dc..6bc1505dd 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -1013,6 +1013,7 @@ class RemoteFilesystem // Path for a public download follows this pattern /{user}/{repo}/downloads/{whatever} // {@link https://blog.bitbucket.org/2009/04/12/new-feature-downloads/} $pathParts = explode('/', $path); + return count($pathParts) >= 4 && $pathParts[3] == 'downloads'; } } diff --git a/src/Composer/XdebugHandler.php b/src/Composer/XdebugHandler.php index e9d719abf..7031e6ff8 100644 --- a/src/Composer/XdebugHandler.php +++ b/src/Composer/XdebugHandler.php @@ -203,7 +203,7 @@ class XdebugHandler * Returns true if the restart environment variables were set * * @param bool $additional Whether there were additional inis - * @param array $iniPaths Locations reported by the current process + * @param array $iniPaths Locations reported by the current process * * @return bool */ diff --git a/tests/Composer/Test/IO/ConsoleIOTest.php b/tests/Composer/Test/IO/ConsoleIOTest.php index 183012b63..c02a2eae5 100644 --- a/tests/Composer/Test/IO/ConsoleIOTest.php +++ b/tests/Composer/Test/IO/ConsoleIOTest.php @@ -219,7 +219,7 @@ class ConsoleIOTest extends TestCase ; $validator = function ($value) { - return true; + return true; }; $consoleIO = new ConsoleIO($inputMock, $outputMock, $setMock); $consoleIO->askAndValidate('Why?', $validator, 10, 'default'); diff --git a/tests/Composer/Test/Json/JsonManipulatorTest.php b/tests/Composer/Test/Json/JsonManipulatorTest.php index 35a69bf5b..e66e9aac2 100644 --- a/tests/Composer/Test/Json/JsonManipulatorTest.php +++ b/tests/Composer/Test/Json/JsonManipulatorTest.php @@ -111,7 +111,6 @@ class JsonManipulatorTest extends TestCase ', ), - array( '{ "require": @@ -2360,6 +2359,5 @@ class JsonManipulatorTest extends TestCase } } ', $manipulator->getContents()); - } } diff --git a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php index 081425005..ced826672 100644 --- a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php @@ -143,13 +143,13 @@ JSON; return $driver; } - /** - * @dataProvider getInitializeUrls - */ - public function testInitializePublicProjectAsAnonymous($url, $apiUrl) - { - // @link http://doc.gitlab.com/ce/api/projects.html#get-single-project - $projectData = <<assertEquals($expected, $driver->getTags(), 'Tags are cached'); } - public function testGetPaginatedRefs() { + public function testGetPaginatedRefs() + { $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'); $apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/branches?per_page=100'; @@ -319,15 +320,15 @@ JSON; "name" => "mymaster", "commit" => array( "id" => "97eda36b5c1dd953a3792865c222d4e85e5f302e", - "committed_date" => "2013-01-03T21:04:07.000+01:00" - ) + "committed_date" => "2013-01-03T21:04:07.000+01:00", + ), ), array( "name" => "staging", "commit" => array( "id" => "502cffe49f136443f2059803f2e7192d1ac066cd", - "committed_date" => "2013-03-09T16:35:23.000+01:00" - ) + "committed_date" => "2013-03-09T16:35:23.000+01:00", + ), ), ); @@ -336,8 +337,8 @@ JSON; "name" => "stagingdupe", "commit" => array( "id" => "502cffe49f136443f2059803f2e7192d1ac066cd", - "committed_date" => "2013-03-09T16:35:23.000+01:00" - ) + "committed_date" => "2013-03-09T16:35:23.000+01:00", + ), ); } @@ -349,7 +350,7 @@ JSON; ->shouldBeCalledTimes(1) ; - $this->remoteFilesystem + $this->remoteFilesystem ->getContents('gitlab.com', "http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=2&per_page=20", false, array()) ->willReturn($branchData) ->shouldBeCalledTimes(1) @@ -372,8 +373,8 @@ JSON; $this->assertEquals($expected, $driver->getBranches()); $this->assertEquals($expected, $driver->getBranches(), 'Branches are cached'); - } + public function testGetBranches() { $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'); diff --git a/tests/Composer/Test/Util/FilesystemTest.php b/tests/Composer/Test/Util/FilesystemTest.php index 53b1e4929..ef3ab5bbe 100644 --- a/tests/Composer/Test/Util/FilesystemTest.php +++ b/tests/Composer/Test/Util/FilesystemTest.php @@ -324,7 +324,7 @@ class FilesystemTest extends TestCase $fs = new Filesystem(); $result1 = $fs->copy($this->workingDir . '/foo', $this->workingDir . '/foop'); - $this->assertTrue($result1,'Copying directory failed.'); + $this->assertTrue($result1, 'Copying directory failed.'); $this->assertTrue(is_dir($this->workingDir . '/foop'), 'Not a directory: ' . $this->workingDir . '/foop'); $this->assertTrue(is_dir($this->workingDir . '/foop/bar'), 'Not a directory: ' . $this->workingDir . '/foop/bar'); $this->assertTrue(is_dir($this->workingDir . '/foop/baz'), 'Not a directory: ' . $this->workingDir . '/foop/baz'); diff --git a/tests/Composer/Test/Util/RemoteFilesystemTest.php b/tests/Composer/Test/Util/RemoteFilesystemTest.php index 286e4b521..066a9275f 100644 --- a/tests/Composer/Test/Util/RemoteFilesystemTest.php +++ b/tests/Composer/Test/Util/RemoteFilesystemTest.php @@ -252,7 +252,7 @@ class RemoteFilesystemTest extends TestCase $io ->expects($this->any()) ->method('hasAuthentication') - ->will($this->returnCallback(function($arg) use (&$domains) { + ->will($this->returnCallback(function ($arg) use (&$domains) { $domains[] = $arg; // first time is called with bitbucket.org, then it redirects to bbuseruploads.s3.amazonaws.com so next time we have no auth configured return $arg === 'bitbucket.org';