From 80d71ccb3f007a04b35896a4451e2250c8d2d827 Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Fri, 11 Sep 2020 23:51:55 +0200 Subject: [PATCH] Merged isset, unset and str_replace calls --- src/Composer/Command/InitCommand.php | 2 +- src/Composer/Command/SelfUpdateCommand.php | 2 +- src/Composer/Compiler.php | 11 ++++++++--- src/Composer/DependencyResolver/PoolBuilder.php | 6 ++---- src/Composer/DependencyResolver/Problem.php | 2 +- src/Composer/DependencyResolver/Request.php | 3 +-- .../DependencyResolver/RuleSetIterator.php | 3 +-- src/Composer/Package/Loader/ArrayLoader.php | 5 ++--- src/Composer/Repository/Vcs/SvnDriver.php | 6 +++--- src/Composer/Util/Bitbucket.php | 3 +-- src/Composer/Util/ConfigValidator.php | 2 +- src/Composer/Util/Http/CurlDownloader.php | 2 +- tests/Composer/Test/InstallerTest.php | 5 +---- tests/Composer/Test/Json/ComposerSchemaTest.php | 3 +-- tests/Composer/Test/Util/RemoteFilesystemTest.php | 5 ++++- .../Test/Util/StreamContextFactoryTest.php | 14 ++------------ 16 files changed, 31 insertions(+), 43 deletions(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 8071b9003..fd9cd76ed 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -277,7 +277,7 @@ EOT $author_email = $git['user.email']; } - if (isset($author_name) && isset($author_email)) { + if (isset($author_name, $author_email)) { $author = sprintf('%s <%s>', $author_name, $author_email); } } diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 38a1abdc6..e6d4ed4eb 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -124,7 +124,7 @@ EOT if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) { $composeUser = posix_getpwuid(posix_geteuid()); $homeOwner = posix_getpwuid(fileowner($home)); - if (isset($composeUser['name']) && isset($homeOwner['name']) && $composeUser['name'] !== $homeOwner['name']) { + if (isset($composeUser['name'], $homeOwner['name']) && $composeUser['name'] !== $homeOwner['name']) { $io->writeError('You are running composer as "'.$composeUser['name'].'", while "'.$home.'" is owned by "'.$homeOwner['name'].'"'); } } diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index 240870a1c..2e4a4ece6 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -199,9 +199,14 @@ class Compiler } if ($path === 'src/Composer/Composer.php') { - $content = str_replace('@package_version@', $this->version, $content); - $content = str_replace('@package_branch_alias_version@', $this->branchAliasVersion, $content); - $content = str_replace('@release_date@', $this->versionDate->format('Y-m-d H:i:s'), $content); + $content = strtr( + $content, + array( + '@package_version@' => $this->version, + '@package_branch_alias_version@' => $this->branchAliasVersion, + '@release_date@' => $this->versionDate->format('Y-m-d H:i:s') + ) + ); $content = preg_replace('{SOURCE_VERSION = \'[^\']+\';}', 'SOURCE_VERSION = \'\';', $content); } diff --git a/src/Composer/DependencyResolver/PoolBuilder.php b/src/Composer/DependencyResolver/PoolBuilder.php index 6812a622d..15995a9cd 100644 --- a/src/Composer/DependencyResolver/PoolBuilder.php +++ b/src/Composer/DependencyResolver/PoolBuilder.php @@ -399,7 +399,7 @@ class PoolBuilder if ($propagateUpdate && $request->getUpdateAllowTransitiveDependencies()) { foreach ($package->getReplaces() as $link) { $replace = $link->getTarget(); - if (isset($this->loadedPackages[$replace]) && isset($this->skippedLoad[$replace])) { + if (isset($this->loadedPackages[$replace], $this->skippedLoad[$replace])) { if ($request->getUpdateAllowTransitiveRootDependencies() || !$this->isRootRequire($request, $this->skippedLoad[$replace])) { $this->unfixPackage($request, $replace); $this->markPackageNameForLoading($request, $replace, $link->getConstraint()); @@ -488,9 +488,7 @@ class PoolBuilder $this->unfixPackage($request, $this->skippedLoad[$name]); } - unset($this->skippedLoad[$name]); - unset($this->loadedPackages[$name]); - unset($this->maxExtendedReqs[$name]); + unset($this->skippedLoad[$name], $this->loadedPackages[$name], $this->maxExtendedReqs[$name]); } private function removeLoadedPackage(Request $request, PackageInterface $package, $index) diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index 9d4405330..1ddd16268 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -331,7 +331,7 @@ class Problem } foreach ($prepared as $name => $package) { // remove the implicit default branch alias to avoid cruft in the display - if (isset($package['versions'][VersionParser::DEFAULT_BRANCH_ALIAS]) && isset($hasDefaultBranch[$name])) { + if (isset($package['versions'][VersionParser::DEFAULT_BRANCH_ALIAS], $hasDefaultBranch[$name])) { unset($package['versions'][VersionParser::DEFAULT_BRANCH_ALIAS]); } diff --git a/src/Composer/DependencyResolver/Request.php b/src/Composer/DependencyResolver/Request.php index 32da89a13..c0f30ed0e 100644 --- a/src/Composer/DependencyResolver/Request.php +++ b/src/Composer/DependencyResolver/Request.php @@ -82,8 +82,7 @@ class Request public function unfixPackage(PackageInterface $package) { - unset($this->fixedPackages[spl_object_hash($package)]); - unset($this->unlockables[spl_object_hash($package)]); + unset($this->fixedPackages[spl_object_hash($package)], $this->unlockables[spl_object_hash($package)]); } public function setUpdateAllowList($updateAllowList, $updateAllowTransitiveDependencies) diff --git a/src/Composer/DependencyResolver/RuleSetIterator.php b/src/Composer/DependencyResolver/RuleSetIterator.php index 1c95218da..50d72dc93 100644 --- a/src/Composer/DependencyResolver/RuleSetIterator.php +++ b/src/Composer/DependencyResolver/RuleSetIterator.php @@ -88,7 +88,6 @@ class RuleSetIterator implements \Iterator public function valid() { - return isset($this->rules[$this->currentType]) - && isset($this->rules[$this->currentType][$this->currentOffset]); + return isset($this->rules[$this->currentType], $this->rules[$this->currentType][$this->currentOffset]); } } diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 7f137bf46..6a9b1dcde 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -129,7 +129,7 @@ class ArrayLoader implements LoaderInterface } if (isset($config['source'])) { - if (!isset($config['source']['type']) || !isset($config['source']['url']) || !isset($config['source']['reference'])) { + if (!isset($config['source']['type'], $config['source']['url'], $config['source']['reference'])) { throw new \UnexpectedValueException(sprintf( "Package %s's source key should be specified as {\"type\": ..., \"url\": ..., \"reference\": ...},\n%s given.", $config['name'], @@ -145,8 +145,7 @@ class ArrayLoader implements LoaderInterface } if (isset($config['dist'])) { - if (!isset($config['dist']['type']) - || !isset($config['dist']['url'])) { + if (!isset($config['dist']['type'], $config['dist']['url'])) { throw new \UnexpectedValueException(sprintf( "Package %s's dist key should be specified as ". "{\"type\": ..., \"url\": ..., \"reference\": ..., \"shasum\": ...},\n%s given.", diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index b91f2f603..779b460df 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -225,7 +225,7 @@ class SvnDriver extends VcsDriver foreach ($this->process->splitLines($output) as $line) { $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { - if (isset($match[1]) && isset($match[2]) && $match[2] !== './') { + if (isset($match[1], $match[2]) && $match[2] !== './') { $this->tags[rtrim($match[2], '/')] = $this->buildIdentifier( '/' . $this->tagsPath . '/' . $match[2], $match[1] @@ -259,7 +259,7 @@ class SvnDriver extends VcsDriver foreach ($this->process->splitLines($output) as $line) { $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { - if (isset($match[1]) && isset($match[2]) && $match[2] === './') { + if (isset($match[1], $match[2]) && $match[2] === './') { $this->branches['trunk'] = $this->buildIdentifier( '/' . $this->trunkPath, $match[1] @@ -278,7 +278,7 @@ class SvnDriver extends VcsDriver foreach ($this->process->splitLines(trim($output)) as $line) { $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { - if (isset($match[1]) && isset($match[2]) && $match[2] !== './') { + if (isset($match[1], $match[2]) && $match[2] !== './') { $this->branches[rtrim($match[2], '/')] = $this->buildIdentifier( '/' . $this->branchesPath . '/' . $match[2], $match[1] diff --git a/src/Composer/Util/Bitbucket.php b/src/Composer/Util/Bitbucket.php index 11b7f9dd9..d75310cf7 100644 --- a/src/Composer/Util/Bitbucket.php +++ b/src/Composer/Util/Bitbucket.php @@ -236,8 +236,7 @@ class Bitbucket $authConfig = $this->config->get('bitbucket-oauth'); if ( - !isset($authConfig[$originUrl]['access-token']) - || !isset($authConfig[$originUrl]['access-token-expiration']) + !isset($authConfig[$originUrl]['access-token'], $authConfig[$originUrl]['access-token-expiration']) || time() > $authConfig[$originUrl]['access-token-expiration'] ) { return false; diff --git a/src/Composer/Util/ConfigValidator.php b/src/Composer/Util/ConfigValidator.php index aae5879b3..4e332c2e5 100644 --- a/src/Composer/Util/ConfigValidator.php +++ b/src/Composer/Util/ConfigValidator.php @@ -132,7 +132,7 @@ class ConfigValidator } // check for require-dev overrides - if (isset($manifest['require']) && isset($manifest['require-dev'])) { + if (isset($manifest['require'], $manifest['require-dev'])) { $requireOverrides = array_intersect_key($manifest['require'], $manifest['require-dev']); if (!empty($requireOverrides)) { diff --git a/src/Composer/Util/Http/CurlDownloader.php b/src/Composer/Util/Http/CurlDownloader.php index 92b3bd0ff..94b8038e5 100644 --- a/src/Composer/Util/Http/CurlDownloader.php +++ b/src/Composer/Util/Http/CurlDownloader.php @@ -220,7 +220,7 @@ class CurlDownloader public function abortRequest($id) { - if (isset($this->jobs[$id]) && isset($this->jobs[$id]['handle'])) { + if (isset($this->jobs[$id], $this->jobs[$id]['handle'])) { $job = $this->jobs[$id]; curl_multi_remove_handle($this->multiHandle, $job['handle']); curl_close($job['handle']); diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 0be8af711..031b2eb08 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -347,10 +347,7 @@ class InstallerTest extends TestCase $output = str_replace("\r", '', $io->getOutput()); $this->assertEquals($expectResult, $result, $output . stream_get_contents($appOutput)); if ($expectLock && isset($actualLock)) { - unset($actualLock['hash']); - unset($actualLock['content-hash']); - unset($actualLock['_readme']); - unset($actualLock['plugin-api-version']); + unset($actualLock['hash'], $actualLock['content-hash'], $actualLock['_readme'], $actualLock['plugin-api-version']); $this->assertEquals($expectLock, $actualLock); } diff --git a/tests/Composer/Test/Json/ComposerSchemaTest.php b/tests/Composer/Test/Json/ComposerSchemaTest.php index 9a7902dad..c5ea2e70b 100644 --- a/tests/Composer/Test/Json/ComposerSchemaTest.php +++ b/tests/Composer/Test/Json/ComposerSchemaTest.php @@ -120,8 +120,7 @@ class ComposerSchemaTest extends TestCase // remove justinrainbow/json-schema 3.0/5.2 props so it works with all versions foreach ($errors as &$err) { - unset($err['pointer']); - unset($err['context']); + unset($err['pointer'], $err['context']); } return $errors; diff --git a/tests/Composer/Test/Util/RemoteFilesystemTest.php b/tests/Composer/Test/Util/RemoteFilesystemTest.php index b6b062b12..f51dd1942 100644 --- a/tests/Composer/Test/Util/RemoteFilesystemTest.php +++ b/tests/Composer/Test/Util/RemoteFilesystemTest.php @@ -82,7 +82,10 @@ class RemoteFilesystemTest extends TestCase )); $res = $this->callGetOptionsForUrl($io, array('https://example.org', array()), $streamOptions); - $this->assertTrue(isset($res['ssl']) && isset($res['ssl']['allow_self_signed']) && true === $res['ssl']['allow_self_signed'], 'getOptions must return an array with a allow_self_signed set to true'); + $this->assertTrue( + isset($res['ssl'], $res['ssl']['allow_self_signed']) && true === $res['ssl']['allow_self_signed'], + 'getOptions must return an array with a allow_self_signed set to true' + ); } public function testGetOptionsForUrlWithCallOptionsKeepsHeader() diff --git a/tests/Composer/Test/Util/StreamContextFactoryTest.php b/tests/Composer/Test/Util/StreamContextFactoryTest.php index bd4935cf2..a3bb3941f 100644 --- a/tests/Composer/Test/Util/StreamContextFactoryTest.php +++ b/tests/Composer/Test/Util/StreamContextFactoryTest.php @@ -19,22 +19,12 @@ class StreamContextFactoryTest extends TestCase { protected function setUp() { - unset($_SERVER['HTTP_PROXY']); - unset($_SERVER['http_proxy']); - unset($_SERVER['HTTPS_PROXY']); - unset($_SERVER['https_proxy']); - unset($_SERVER['NO_PROXY']); - unset($_SERVER['no_proxy']); + unset($_SERVER['HTTP_PROXY'], $_SERVER['http_proxy'], $_SERVER['HTTPS_PROXY'], $_SERVER['https_proxy'], $_SERVER['NO_PROXY'], $_SERVER['no_proxy']); } protected function tearDown() { - unset($_SERVER['HTTP_PROXY']); - unset($_SERVER['http_proxy']); - unset($_SERVER['HTTPS_PROXY']); - unset($_SERVER['https_proxy']); - unset($_SERVER['NO_PROXY']); - unset($_SERVER['no_proxy']); + unset($_SERVER['HTTP_PROXY'], $_SERVER['http_proxy'], $_SERVER['HTTPS_PROXY'], $_SERVER['https_proxy'], $_SERVER['NO_PROXY'], $_SERVER['no_proxy']); } /**