Passed
Push — master ( c2a6de...b42a4e )
by Shinji
01:35
created

TargetProcessSettings::fromConsoleInput()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 15
rs 9.9666
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-profiler 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 PhpProfiler\Command\Inspector\Settings;
15
16
use PhpProfiler\Command\CommandSettingsException;
17
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
19
class TargetProcessSettings
20
{
21
    public int $pid;
22
23
    /**
24
     * GetTraceSettings constructor.
25
     * @param int $pid
26
     */
27
    public function __construct(int $pid)
28
    {
29
        $this->pid = $pid;
30
    }
31
32
    /**
33
     * @param InputInterface $input
34
     * @return self
35
     * @throws CommandSettingsException
36
     */
37
    public static function fromConsoleInput(InputInterface $input): self
38
    {
39
        $pid = $input->getOption('pid');
40
        if (is_null($pid)) {
41
            throw TargetProcessSettingsException::create(
42
                TargetProcessSettingsException::PID_NOT_SPECIFIED
43
            );
44
        }
45
        $pid = filter_var($pid, FILTER_VALIDATE_INT);
46
        if ($pid === false) {
47
            throw TargetProcessSettingsException::create(
48
                TargetProcessSettingsException::PID_NOT_SPECIFIED
49
            );
50
        }
51
        return new self($pid);
52
    }
53
}
54