|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the reliforp/reli-prof package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) sji <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Reli\Inspector\Settings\TargetProcessSettings; |
|
15
|
|
|
|
|
16
|
|
|
use PhpCast\NullableCast; |
|
|
|
|
|
|
17
|
|
|
use Reli\Inspector\Settings\InspectorSettingsException; |
|
18
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
|
|
19
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
|
|
|
|
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
|
|
21
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
use function filter_var; |
|
24
|
|
|
use function is_null; |
|
25
|
|
|
|
|
26
|
|
|
use const FILTER_VALIDATE_INT; |
|
27
|
|
|
|
|
28
|
|
|
final class TargetProcessSettingsFromConsoleInput |
|
29
|
|
|
{ |
|
30
|
|
|
/** @codeCoverageIgnore */ |
|
31
|
|
|
public function setOptions(Command $command): void |
|
32
|
|
|
{ |
|
33
|
|
|
$command |
|
34
|
|
|
->addOption( |
|
35
|
|
|
'pid', |
|
36
|
|
|
'p', |
|
37
|
|
|
InputOption::VALUE_REQUIRED, |
|
38
|
|
|
'process id' |
|
39
|
|
|
) |
|
40
|
|
|
->addArgument( |
|
41
|
|
|
'cmd', |
|
42
|
|
|
InputArgument::OPTIONAL, |
|
43
|
|
|
'command to execute as a target: either pid (via -p/--pid) or cmd must be specified' |
|
44
|
|
|
) |
|
45
|
|
|
->addArgument( |
|
46
|
|
|
'args', |
|
47
|
|
|
InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
48
|
|
|
'command line arguments for cmd', |
|
49
|
|
|
) |
|
50
|
|
|
; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @throws InspectorSettingsException |
|
55
|
|
|
*/ |
|
56
|
|
|
public function createSettings(InputInterface $input): TargetProcessSettings |
|
57
|
|
|
{ |
|
58
|
|
|
$pid = NullableCast::toString($input->getOption('pid')); |
|
59
|
|
|
$command = NullableCast::toString($input->getArgument('cmd')); |
|
60
|
|
|
if (is_null($pid) and is_null($command)) { |
|
61
|
|
|
throw TargetProcessSettingsException::create( |
|
62
|
|
|
TargetProcessSettingsException::TARGET_NOT_SPECIFIED |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
if (!is_null($pid)) { |
|
66
|
|
|
$pid = filter_var($pid, FILTER_VALIDATE_INT); |
|
67
|
|
|
if ($pid === false) { |
|
68
|
|
|
throw TargetProcessSettingsException::create( |
|
69
|
|
|
TargetProcessSettingsException::TARGET_NOT_SPECIFIED |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
return new TargetProcessSettings($pid); |
|
73
|
|
|
} |
|
74
|
|
|
/** @var list<string> $args */ |
|
75
|
|
|
$args = $input->getArgument('args'); |
|
76
|
|
|
return new TargetProcessSettings(null, $command, $args); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths