Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed lock file being used when lock:false is in config #10726

Merged
merged 1 commit into from Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/06-config.md
Expand Up @@ -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

Expand Down
121 changes: 13 additions & 108 deletions phpstan/baseline.neon
Expand Up @@ -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

-
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

-
Expand Down Expand Up @@ -2440,23 +2430,13 @@ 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
path: ../src/Composer/Compiler.php

-
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

Expand Down Expand Up @@ -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\\<int, 10\\|20\\> 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\\<string, string\\|null\\>\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -3871,20 +3841,25 @@ parameters:
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\\<string\\>, key\\: string\\}\\.$#"
count: 1
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 &&, Composer\\\\IO\\\\IOInterface\\|null given on the left side\\.$#"
count: 3
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
Expand Down Expand Up @@ -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

-
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -5225,11 +5190,6 @@ parameters:
count: 2
path: ../src/Composer/Repository/ComposerRepository.php

-
message: "#^Method Composer\\\\Repository\\\\ComposerRepository\\:\\:getProviderNames\\(\\) should return array\\<string\\> but returns array\\<int, int\\|string\\>\\.$#"
count: 1
path: ../src/Composer/Repository/ComposerRepository.php

-
message: "#^Method Composer\\\\Repository\\\\ComposerRepository\\:\\:getProviders\\(\\) should return array\\<string, array\\{name\\: string, description\\: string, type\\: string\\}\\> but returns array\\<int\\|string, array\\{name\\: mixed, description\\: mixed, type\\: mixed\\}\\>\\.$#"
count: 1
Expand Down Expand Up @@ -5342,19 +5302,14 @@ parameters:

-
message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#"
count: 13
count: 12
path: ../src/Composer/Repository/ComposerRepository.php

-
message: "#^Only booleans are allowed in \\|\\|, string\\|null given on the right side\\.$#"
count: 1
path: ../src/Composer/Repository/ComposerRepository.php

-
message: "#^Parameter \\#1 \\$input of function array_keys expects array, array\\<string, array\\<string, string\\>\\>\\|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
Expand Down Expand Up @@ -6265,11 +6220,6 @@ parameters:
count: 1
path: ../src/Composer/SelfUpdate/Keys.php

-
message: "#^Only booleans are allowed in a negated boolean, array\\<string, array\\<int, array\\<string, int\\|string\\>\\>\\> given\\.$#"
count: 1
path: ../src/Composer/SelfUpdate/Versions.php

-
message: "#^Only booleans are allowed in an if condition, string given\\.$#"
count: 1
Expand Down Expand Up @@ -6915,11 +6865,6 @@ parameters:
count: 1
path: ../src/Composer/Util/HttpDownloader.php

-
message: "#^Binary operation \"\\.\" between non\\-empty\\-string and non\\-empty\\-array\\<array\\{versions\\: string, message\\: string\\}\\>\\|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
Expand Down Expand Up @@ -7615,11 +7560,6 @@ parameters:
count: 3
path: ../tests/Composer/Test/AllFunctionalTest.php

-
message: "#^Method Composer\\\\Test\\\\AllFunctionalTest\\:\\:getTestFiles\\(\\) should return array\\<string, array\\<string\\>\\> but returns array\\<string, array\\<int, string\\|false\\>\\>\\.$#"
count: 1
path: ../tests/Composer/Test/AllFunctionalTest.php

-
message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#"
count: 1
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/Composer/Factory.php
Expand Up @@ -442,8 +442,11 @@ public function createComposer(IOInterface $io, $localConfig = null, $disablePlu
// init locker if possible
if ($fullLoad && isset($composerFile)) {
$lockFile = self::getLockFile($composerFile);
if (!$config->get('lock') && file_exists($lockFile)) {
$io->writeError('<warning>'.$lockFile.' is present but ignored as the "lock" config option is disabled.</warning>');
}

$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);
}

Expand Down
12 changes: 12 additions & 0 deletions src/Composer/Util/Platform.php
Expand Up @@ -249,4 +249,16 @@ private static function isVirtualBoxGuest()

return self::$isVirtualBoxGuest;
}

/**
* @return 'NUL'|'/dev/null'
*/
public static function getDevNull()
{
if (self::isWindows()) {
return 'NUL';
}

return '/dev/null';
}
}