10000 Stop relying on OS to find executables on Windows, and migrate most P… · composer/composer@3dc279c · GitHub
[go: up one dir, main page]

Skip to content

Commit 3dc279c

Browse files
Stop relying on OS to find executables on Windows, and migrate most Process calls to array syntax (#12180)
Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>
1 parent 5a75d32 commit 3dc279c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+715
-585
lines changed

composer.lock

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan/baseline.neon

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,6 @@ parameters:
300300
count: 1
301301
path: ../src/Composer/Command/CreateProjectCommand.php
302302

303-
-
304-
message: "#^Parameter \\#3 \\$existingRepos of static method Composer\\\\Repository\\\\RepositoryFactory\\:\\:generateRepositoryName\\(\\) expects array\\<string, mixed\\>, array\\<int\\|string, mixed\\> given\\.$#"
305-
count: 1
306-
path: ../src/Composer/Command/CreateProjectCommand.php
307-
308303
-
309304
message: "#^Variable method call on Composer\\\\Package\\\\RootPackageInterface\\.$#"
310305
count: 1
@@ -495,11 +490,6 @@ parameters:
495490
count: 2
496491
path: ../src/Composer/Command/LicensesCommand.php
497492

498-
-
499-
message: "#^Only booleans are allowed in a negated boolean, array\\<int, Composer\\\\Package\\\\PackageInterface\\> given\\.$#"
500-
count: 1
501-
path: ../src/Composer/Command/ReinstallCommand.php
502-
503493
-
504494
message: "#^Foreach overwrites \\$type with its key variable\\.$#"
505495
count: 1
@@ -955,11 +945,6 @@ parameters:
955945
count: 1
956946
path: ../src/Composer/Config.php
957947

958-
-
959-
message: "#^Only booleans are allowed in a ternary operator condition, string\\|null given\\.$#"
960-
count: 1
961-
path: ../src/Composer/Config.php
962-
963948
-
964949
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
965950
count: 1
@@ -1160,11 +1145,6 @@ parameters:
11601145
count: 1
11611146
path: ../src/Composer/Downloader/FileDownloader.php
11621147

1163-
-
1164-
message: "#^Parameter \\#3 \\$cwd of method Composer\\\\Util\\\\ProcessExecutor\\:\\:execute\\(\\) expects string\\|null, string\\|false given\\.$#"
1165-
count: 5
1166-
path: ../src/Composer/Downloader/FossilDownloader.php
1167-
11681148
-
11691149
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
11701150
count: 5
@@ -1367,7 +1347,7 @@ parameters:
13671347

13681348
-
13691349
message: "#^Only booleans are allowed in a negated boolean, array\\<int, array\\<int, string\\>\\> given\\.$#"
1370-
count: 3
1350+
count: 2
13711351
path: ../src/Composer/Downloader/ZipDownloader.php
13721352

13731353
-
@@ -2330,11 +2310,6 @@ parameters:
23302310
count: 2
23312311
path: ../src/Composer/Question/StrictConfirmationQuestion.php
23322312

2333-
-
2334-
message: "#^Method Composer\\\\Repository\\\\ArrayRepository\\:\\:getProviders\\(\\) should return array\\<string, array\\{name\\: string, description\\: string, type\\: string\\}\\> but returns array\\<string, array\\{name\\: string, description\\: string\\|null, type\\: string\\}\\>\\.$#"
2335-
count: 1
2336-
path: ../src/Composer/Repository/ArrayRepository.php
2337-
23382313
-
23392314
message: "#^Only booleans are allowed in a negated boolean, Composer\\\\Semver\\\\Constraint\\\\ConstraintInterface\\|null given\\.$#"
23402315
count: 1
@@ -2381,7 +2356,7 @@ parameters:
23812356
path: ../src/Composer/Repository/ComposerRepository.php
23822357

23832358
-
2384-
message: "#^Method Composer\\\\Repository\\\\ComposerRepository\\:\\:getProviders\\(\\) should return array\\<string, array\\{name\\: string, description\\: string|null, type\\: string\\}\\> but returns array\\<int\\|string, array\\{name\\: mixed, description\\: mixed, type\\: mixed\\}\\>\\.$#"
2359+
message: "#^Method Composer\\\\Repository\\\\ComposerRepository\\:\\:getProviders\\(\\) should return array\\<string, array\\{name\\: string, description\\: string\\|null, type\\: string\\}\\> but returns array\\<int\\|string, array\\{name\\: mixed, description\\: mixed, type\\: mixed\\}\\>\\.$#"
23852360
count: 1
23862361
path: ../src/Composer/Repository/ComposerRepository.php
23872362

@@ -2496,7 +2471,7 @@ parameters:
24962471
path: ../src/Composer/Repository/CompositeRepository.php
24972472

24982473
-
2499-
message: "#^Only booleans are allowed in a ternary operator condition, array\\<int, array\\<string, array\\<string, string|null\\>\\>\\> given\\.$#"
2474+
message: "#^Only booleans are allowed in a ternary operator condition, array\\<int, array\\<string, array\\<string, string\\|null\\>\\>\\> given\\.$#"
25002475
count: 1
25012476
path: ../src/Composer/Repository/CompositeRepository.php
25022477

@@ -2714,7 +2689,7 @@ parameters:
27142689
path: ../src/Composer/Repository/RepositorySet.php
27152690

27162691
-
2717-
message: "#^Only booleans are allowed in an if condition, array\\<string, array\\<string, string|null\\>\\> given\\.$#"
2692+
message: "#^Only booleans are allowed in an if condition, array\\<string, array\\<string, string\\|null\\>\\> given\\.$#"
27182693
count: 1
27192694
path: ../src/Composer/Repository/RepositorySet.php
27202695

@@ -2723,21 +2698,6 @@ parameters:
27232698
count: 1
27242699
path: ../src/Composer/Repository/RepositorySet.php
27252700

2726-
-
2727-
message: "#^Only booleans are allowed in a negated boolean, string given\\.$#"
2728-
count: 1
2729-
path: ../src/Composer/Repository/Vcs/FossilDriver.php
2730-
2731-
-
2732-
message: "#^Parameter \\#1 \\$file of method Composer\\\\Util\\\\Filesystem\\:\\:remove\\(\\) expects string, string\\|null given\\.$#"
2733-
count: 1
2734-
path: ../src/Composer/Repository/Vcs/FossilDriver.php
2735-
2736-
-
2737-
message: "#^Parameter \\#1 \\$filename of function is_file expects string, string\\|null given\\.$#"
2738-
count: 1
2739-
path: ../src/Composer/Repository/Vcs/FossilDriver.php
2740-
27412701
-
27422702
message: "#^Call to function array_search\\(\\) requires parameter \\#3 to be set\\.$#"
27432703
count: 2
@@ -3968,11 +3928,6 @@ parameters:
39683928
count: 1
39693929
path: ../src/Composer/Util/Svn.php
39703930

3971-
-
3972-
message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#"
3973-
count: 1
3974-
path: ../src/Composer/Util/Svn.php
3975-
39763931
-
39773932
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
39783933
count: 1
@@ -4341,6 +4296,11 @@ parameters:
43414296
count: 2
43424297
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php
43434298

4299+
-
4300+
message: "#^Property Composer\\\\Test\\\\Mock\\\\ProcessExecutorMock\\:\\:\\$expectations \\(array\\<array\\{cmd\\: list\\<string\\>\\|string, return\\: int, stdout\\: string, stderr\\: string, callback\\: \\(callable\\(\\)\\: mixed\\)\\|null\\}\\>\\|null\\) does not accept array\\<non\\-empty\\-array\\<'callback'\\|'cmd'\\|'return'\\|'stderr'\\|'stdout'\\|int\\<0, max\\>, non\\-empty\\-list\\<non\\-empty\\-list\\<string\\>\\|\\(callable\\(\\)\\: mixed\\)\\|int\\|string\\>\\|\\(callable\\(\\)\\: mixed\\)\\|int\\|string\\|null\\>\\>\\.$#"
4301+
count: 1
4302+
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php
4303+
43444304
-
43454305
message: "#^Composer\\\\Test\\\\Mock\\\\VersionGuesserMock\\:\\:__construct\\(\\) does not call parent constructor from Composer\\\\Package\\\\Version\\\\VersionGuesser\\.$#"
43464306
count: 1
@@ -4486,9 +4446,14 @@ parameters:
44864446
count: 1
44874447
path: ../tests/Composer/Test/TestCase.php
44884448

4449+
-
4450+
message: "#^Cannot access an offset on array\\<int, array\\<string, array\\<int, string\\>\\|int\\|string\\>\\>\\|false\\.$#"
4451+
count: 2
4452+
path: ../tests/Composer/Test/Util/GitTest.php
4453+
44894454
-
44904455
message: "#^Cannot access an offset on array\\<int, array\\<string, int\\|string\\>\\>\\|false\\.$#"
4491-
count: 3
4456+
count: 1
44924457
path: ../tests/Composer/Test/Util/GitTest.php
44934458

44944459
-

src/Composer/Command/DiagnoseCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ private function checkGit(): string
302302
return '<comment>proc_open is not available, git cannot be used</comment>';
303303
}
304304

305-
$this->process->execute('git config color.ui', $output);
305+
$this->process->execute(['git', 'config', 'color.ui'], $output);
306306
if (strtolower(trim($output)) === 'always') {
307307
return '<comment>Your git color.ui setting is set to always, this is known to create issues. Use "git config --global color.ui true" to set it correctly.</comment>';
308308
}

src/Composer/Command/HomeCommand.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,20 @@ private function handlePackage(CompletePackageInterface $package, bool $showHome
122122
*/
123123
private function openBrowser(string $url): void
124124
{
125-
$url = ProcessExecutor::escape($url);
126-
127125
$process = new ProcessExecutor($this->getIO());
128126
if (Platform::isWindows()) {
129-
$process->execute('start "web" explorer ' . $url, $output);
127+
$process->execute(['start', '"web"', 'explorer', $url], $output);
130128

131129
return;
132130
}
133131

134-
$linux = $process->execute('which xdg-open', $output);
135-
$osx = $process->execute('which open', $output);
132+
$linux = $process->execute(['which', 'xdg-open'], $output);
133+
$osx = $process->execute(['which', 'open'], $output);
136134

137135
if (0 === $linux) {
138-
$process->execute('xdg-open ' . $url, $output);
136+
$process->execute(['xdg-open', $url], $output);
139137
} elseif (0 === $osx) {
140-
$process->execute('open ' . $url, $output);
138+
$process->execute(['open', $url], $output);
141139
} else {
142140
$this->getIO()->writeError('No suitable browser opening command found, open yourself: ' . $url);
143141
}

src/Composer/Command/InitCommand.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\Component\Console\Input\ArrayInput;
2828
use Symfony\Component\Console\Input\InputInterface;
2929
use Composer\Console\Input\InputOption;
30+
use Composer\Util\ProcessExecutor;
3031
use Symfony\Component\Console\Output\OutputInterface;
3132
use Symfony\Component\Process\ExecutableFinder;
3233
use Symfony\Component\Process\Process;
@@ -535,15 +536,11 @@ protected function getGitConfig(): array
535536
return $this->gitConfig;
536537
}
537538

538-
$finder = new ExecutableFinder();
539-
$gitBin = $finder->find('git');
539+
$process = new ProcessExecutor($this->getIO());
540540

541-
$cmd = new Process([$gitBin, 'config', '-l']);
542-
$cmd->run();
543-
544-
if ($cmd->isSuccessful()) {
541+
if (0 === $process->execute(['git', 'config', '-l'], $output)) {
545542
$this->gitConfig = [];
546-
Preg::matchAllStrictGroups('{^([^=]+)=(.*)$}m', $cmd->getOutput(), $matches);
543+
Preg::matchAllStrictGroups('{^([^=]+)=(.*)$}m', $output, $matches);
547544
foreach ($matches[1] as $key => $match) {
548545
$this->gitConfig[$match] = $matches[2][$key];
549546
}

0 commit comments

Comments
 (0)
0