forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessHelper.php
More file actions
81 lines (67 loc) · 1.87 KB
/
Copy pathProcessHelper.php
File metadata and controls
81 lines (67 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php declare(strict_types = 1);
namespace PHPStan\Process;
use PHPStan\Command\AnalyseCommand;
use Symfony\Component\Console\Input\InputInterface;
class ProcessHelper
{
/**
* @param string $mainScript
* @param string $commandName
* @param string|null $projectConfigFile
* @param string[] $additionalItems
* @param InputInterface $input
* @return string
*/
public static function getWorkerCommand(
string $mainScript,
string $commandName,
?string $projectConfigFile,
array $additionalItems,
InputInterface $input
): string
{
$processCommandArray = [
escapeshellarg(PHP_BINARY),
];
if ($input->getOption('memory-limit') === null) {
$processCommandArray[] = '-d';
$processCommandArray[] = 'memory_limit=' . ini_get('memory_limit');
}
foreach ([$mainScript, $commandName] as $arg) {
$processCommandArray[] = escapeshellarg($arg);
}
if ($projectConfigFile !== null) {
$processCommandArray[] = '--configuration';
$processCommandArray[] = escapeshellarg($projectConfigFile);
}
$options = [
'paths-file',
AnalyseCommand::OPTION_LEVEL,
'autoload-file',
'memory-limit',
'xdebug',
];
foreach ($options as $optionName) {
/** @var bool|string|null $optionValue */
$optionValue = $input->getOption($optionName);
if (is_bool($optionValue)) {
if ($optionValue === true) {
$processCommandArray[] = sprintf('--%s', $optionName);
}
continue;
}
if ($optionValue === null) {
continue;
}
$processCommandArray[] = sprintf('--%s=%s', $optionName, escapeshellarg($optionValue));
}
$processCommandArray = array_merge($processCommandArray, $additionalItems);
$processCommandArray[] = '--';
/** @var string[] $paths */
$paths = $input->getArgument('paths');
foreach ($paths as $path) {
$processCommandArray[] = escapeshellarg($path);
}
return implode(' ', $processCommandArray);
}
}