Passed
Pull Request — master (#9)
by Shinji
02:03
created

TargetProcessSettings::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 1
dl 0
loc 3
c 0
b 0
f 0
cc 1
rs 10
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\Inspector\Settings;
15
16
use PhpProfiler\Inspector\Settings\InspectorSettingsException;
17
use PhpProfiler\Lib\PhpInternals\ZendTypeReader;
18
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...
19
20
final class TargetProcessSettings
21
{
22
    public int $pid;
23
24
    /**
25
     * GetTraceSettings constructor.
26
     * @param int $pid
27
     */
28
    public function __construct(int $pid)
29
    {
30
        $this->pid = $pid;
31
    }
32
33
    /**
34
     * @param InputInterface $input
35
     * @return self
36
     * @throws InspectorSettingsException
37
     */
38
    public static function fromConsoleInput(InputInterface $input): self
39
    {
40
        $pid = $input->getOption('pid');
41
        if (is_null($pid)) {
42
            throw TargetProcessInspectorSettingsException::create(
43
                TargetProcessInspectorSettingsException::PID_NOT_SPECIFIED
44
            );
45
        }
46
        $pid = filter_var($pid, FILTER_VALIDATE_INT);
47
        if ($pid === false) {
48
            throw TargetProcessInspectorSettingsException::create(
49
                TargetProcessInspectorSettingsException::PID_NOT_SPECIFIED
50
            );
51
        }
52
53
        return new self($pid);
54
    }
55
}
56