From bb0edce0950bfc0eea1b464405991a5e8b7e257d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 13 Apr 2022 14:52:13 +0200 Subject: [PATCH] Fixed lock file being used when lock:false is in config, refs #10715 (#10726) --- doc/06-config.md | 2 +- phpstan/baseline.neon | 123 ++++----------------------------- src/Composer/Factory.php | 5 +- src/Composer/Util/Platform.php | 12 ++++ 4 files changed, 31 insertions(+), 111 deletions(-) diff --git a/doc/06-config.md b/doc/06-config.md index 636cf9555..d89aa062d 100644 --- a/doc/06-config.md +++ b/doc/06-config.md @@ -396,7 +396,7 @@ in the Composer home, cache, and data directories. ## lock Defaults to `true`. If set to `false`, Composer will not create a `composer.lock` -file. +file and will ignore it if one is present. ## platform-check diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index e8bb60c5c..ad57bc557 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -127,7 +127,7 @@ parameters: - message: "#^Parameter \\#1 \\$str of function strtr expects string, string\\|false given\\.$#" - count: 3 + count: 2 path: ../src/Composer/Autoload/AutoloadGenerator.php - @@ -605,11 +605,6 @@ parameters: count: 2 path: ../src/Composer/Command/ConfigCommand.php - - - message: "#^Parameter \\#1 \\$path of function dirname expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Command/ConfigCommand.php - - message: "#^Parameter \\#1 \\$path of function realpath expects string, string\\|false given\\.$#" count: 1 @@ -1070,11 +1065,6 @@ parameters: count: 1 path: ../src/Composer/Command/InitCommand.php - - - message: "#^Only booleans are allowed in a negated boolean, true\\|null given\\.$#" - count: 1 - path: ../src/Composer/Command/InitCommand.php - - message: "#^Only booleans are allowed in a ternary operator condition, Composer\\\\Composer\\|null given\\.$#" count: 1 @@ -1662,7 +1652,7 @@ parameters: - message: "#^Only booleans are allowed in &&, string\\|null given on the left side\\.$#" - count: 2 + count: 1 path: ../src/Composer/Command/SelfUpdateCommand.php - @@ -2440,11 +2430,6 @@ parameters: count: 1 path: ../src/Composer/Compiler.php - - - message: "#^Parameter \\#1 \\$haystack of function strpos expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Compiler.php - - message: "#^Parameter \\#1 \\$source of method Composer\\\\Compiler\\:\\:stripWhitespace\\(\\) expects string, string\\|false given\\.$#" count: 1 @@ -2452,11 +2437,6 @@ parameters: - message: "#^Parameter \\#1 \\$str of function strtr expects string, string\\|false given\\.$#" - count: 2 - path: ../src/Composer/Compiler.php - - - - message: "#^Parameter \\#1 \\$str of function substr_replace expects array\\|string, string\\|false given\\.$#" count: 1 path: ../src/Composer/Compiler.php @@ -3505,16 +3485,6 @@ parameters: count: 1 path: ../src/Composer/Downloader/PathDownloader.php - - - message: "#^Call to function in_array\\(\\) with arguments 20, non\\-empty\\-array\\ and true will always evaluate to true\\.$#" - count: 1 - path: ../src/Composer/Downloader/PathDownloader.php - - - - message: "#^Else branch is unreachable because previous condition is always true\\.$#" - count: 1 - path: ../src/Composer/Downloader/PathDownloader.php - - message: "#^Only booleans are allowed in an if condition, array\\\\|null given\\.$#" count: 1 @@ -3870,21 +3840,26 @@ parameters: count: 3 path: ../src/Composer/Factory.php - - - message: "#^Offset 'line' does not exist on array\\{text\\?\\: string, token\\?\\: string, line\\?\\: int, loc\\?\\: array\\{first_line\\: int, first_column\\: int, last_line\\: int, last_column\\: int\\}, expected\\?\\: array\\, key\\: string\\}\\.$#" - count: 1 - path: ../src/Composer/Factory.php - - message: "#^Only booleans are allowed in &&, Composer\\\\IO\\\\IOInterface\\|null given on the left side\\.$#" count: 3 path: ../src/Composer/Factory.php + - + message: "#^Only booleans are allowed in a negated boolean, mixed given\\.$#" + count: 1 + path: ../src/Composer/Factory.php + - message: "#^Only booleans are allowed in a negated boolean, string\\|false given\\.$#" count: 3 path: ../src/Composer/Factory.php + - + message: "#^Only booleans are allowed in a ternary operator condition, mixed given\\.$#" + count: 1 + path: ../src/Composer/Factory.php + - message: "#^Only booleans are allowed in an if condition, Composer\\\\IO\\\\IOInterface\\|null given\\.$#" count: 1 @@ -4480,14 +4455,9 @@ parameters: count: 1 path: ../src/Composer/Package/Archiver/ArchivableFilesFinder.php - - - message: "#^Parameter \\#1 \\$haystack of function strpos expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Package/Archiver/ArchivableFilesFinder.php - - message: "#^Parameter \\#1 \\$path of method Composer\\\\Util\\\\Filesystem\\:\\:normalizePath\\(\\) expects string, string\\|false given\\.$#" - count: 2 + count: 1 path: ../src/Composer/Package/Archiver/ArchivableFilesFinder.php - @@ -5185,11 +5155,6 @@ parameters: count: 1 path: ../src/Composer/Repository/ArtifactRepository.php - - - message: "#^Parameter \\#1 \\$filename of function sha1_file expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Repository/ArtifactRepository.php - - message: "#^Anonymous function uses \\$this assigned to variable \\$repo\\. Use \\$this directly in the function body\\.$#" count: 3 @@ -5225,11 +5190,6 @@ parameters: count: 2 path: ../src/Composer/Repository/ComposerRepository.php - - - message: "#^Method Composer\\\\Repository\\\\ComposerRepository\\:\\:getProviderNames\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: ../src/Composer/Repository/ComposerRepository.php - - message: "#^Method Composer\\\\Repository\\\\ComposerRepository\\:\\:getProviders\\(\\) should return array\\ but returns array\\\\.$#" count: 1 @@ -5342,7 +5302,7 @@ parameters: - message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#" - count: 13 + count: 12 path: ../src/Composer/Repository/ComposerRepository.php - @@ -5350,11 +5310,6 @@ parameters: count: 1 path: ../src/Composer/Repository/ComposerRepository.php - - - message: "#^Parameter \\#1 \\$input of function array_keys expects array, array\\\\>\\|null given\\.$#" - count: 1 - path: ../src/Composer/Repository/ComposerRepository.php - - message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#" count: 3 @@ -6265,11 +6220,6 @@ parameters: count: 1 path: ../src/Composer/SelfUpdate/Keys.php - - - message: "#^Only booleans are allowed in a negated boolean, array\\\\>\\> given\\.$#" - count: 1 - path: ../src/Composer/SelfUpdate/Versions.php - - message: "#^Only booleans are allowed in an if condition, string given\\.$#" count: 1 @@ -6915,11 +6865,6 @@ parameters: count: 1 path: ../src/Composer/Util/HttpDownloader.php - - - message: "#^Binary operation \"\\.\" between non\\-empty\\-string and non\\-empty\\-array\\\\|non\\-empty\\-string results in an error\\.$#" - count: 1 - path: ../src/Composer/Util/HttpDownloader.php - - message: "#^Cannot call method abortRequest\\(\\) on Composer\\\\Util\\\\Http\\\\CurlDownloader\\|null\\.$#" count: 1 @@ -7615,11 +7560,6 @@ parameters: count: 3 path: ../tests/Composer/Test/AllFunctionalTest.php - - - message: "#^Method Composer\\\\Test\\\\AllFunctionalTest\\:\\:getTestFiles\\(\\) should return array\\\\> but returns array\\\\>\\.$#" - count: 1 - path: ../tests/Composer/Test/AllFunctionalTest.php - - message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#" count: 1 @@ -7695,31 +7635,11 @@ parameters: count: 2 path: ../tests/Composer/Test/Autoload/AutoloadGeneratorTest.php - - - message: "#^Parameter \\#1 \\$expected of static method Composer\\\\Test\\\\Autoload\\\\AutoloadGeneratorTest\\:\\:assertEqualsNormalized\\(\\) expects string, string\\|false given\\.$#" - count: 1 - path: ../tests/Composer/Test/Autoload/AutoloadGeneratorTest.php - - message: "#^Parameter \\#1 \\$new_include_path of function set_include_path expects string, string\\|false given\\.$#" count: 2 path: ../tests/Composer/Test/Autoload/AutoloadGeneratorTest.php - - - message: "#^Parameter \\#2 \\$actual of static method Composer\\\\Test\\\\Autoload\\\\AutoloadGeneratorTest\\:\\:assertEqualsNormalized\\(\\) expects string, string\\|false given\\.$#" - count: 1 - path: ../tests/Composer/Test/Autoload/AutoloadGeneratorTest.php - - - - message: "#^Parameter \\#2 \\$haystack of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\) expects string, string\\|false given\\.$#" - count: 8 - path: ../tests/Composer/Test/Autoload/AutoloadGeneratorTest.php - - - - message: "#^Parameter \\#2 \\$haystack of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringNotContainsString\\(\\) expects string, string\\|false given\\.$#" - count: 3 - path: ../tests/Composer/Test/Autoload/AutoloadGeneratorTest.php - - message: "#^Property Composer\\\\Test\\\\Autoload\\\\AutoloadGeneratorTest\\:\\:\\$origDir \\(string\\) does not accept string\\|false\\.$#" count: 1 @@ -7835,11 +7755,6 @@ parameters: count: 1 path: ../tests/Composer/Test/DependencyResolver/PoolBuilderTest.php - - - message: "#^Parameter \\#1 \\$filename of function file_get_contents expects string, string\\|false given\\.$#" - count: 1 - path: ../tests/Composer/Test/DependencyResolver/PoolBuilderTest.php - - message: "#^Parameter \\#2 \\$fixturesDir of method Composer\\\\Test\\\\DependencyResolver\\\\PoolBuilderTest\\:\\:readTestFile\\(\\) expects string, string\\|false given\\.$#" count: 1 @@ -7875,11 +7790,6 @@ parameters: count: 1 path: ../tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php - - - message: "#^Parameter \\#1 \\$filename of function file_get_contents expects string, string\\|false given\\.$#" - count: 1 - path: ../tests/Composer/Test/DependencyResolver/PoolOptimizerTest.php - - message: "#^Parameter \\#2 \\$fixturesDir of method Composer\\\\Test\\\\DependencyResolver\\\\PoolOptimizerTest\\:\\:readTestFile\\(\\) expects string, string\\|false given\\.$#" count: 1 @@ -8208,11 +8118,6 @@ parameters: count: 1 path: ../tests/Composer/Test/InstallerTest.php - - - message: "#^Parameter \\#1 \\$filename of function file_get_contents expects string, string\\|false given\\.$#" - count: 1 - path: ../tests/Composer/Test/InstallerTest.php - - message: "#^Parameter \\#1 \\$fp of function fseek expects resource, resource\\|false given\\.$#" count: 1 diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index ee0b07f3e..9288da19b 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -442,8 +442,11 @@ class Factory // init locker if possible if ($fullLoad && isset($composerFile)) { $lockFile = self::getLockFile($composerFile); + if (!$config->get('lock') && file_exists($lockFile)) { + $io->writeError(''.$lockFile.' is present but ignored as the "lock" config option is disabled.'); + } - $locker = new Package\Locker($io, new JsonFile($lockFile, null, $io), $im, file_get_contents($composerFile), $process); + $locker = new Package\Locker($io, new JsonFile($config->get('lock') ? $lockFile : Platform::getDevNull(), null, $io), $im, file_get_contents($composerFile), $process); $composer->setLocker($locker); } diff --git a/src/Composer/Util/Platform.php b/src/Composer/Util/Platform.php index 756c11506..e65c64534 100644 --- a/src/Composer/Util/Platform.php +++ b/src/Composer/Util/Platform.php @@ -249,4 +249,16 @@ class Platform return self::$isVirtualBoxGuest; } + + /** + * @return 'NUL'|'/dev/null' + */ + public static function getDevNull() + { + if (self::isWindows()) { + return 'NUL'; + } + + return '/dev/null'; + } }