Passed
Pull Request — master (#9)
by Shinji
01:33
created

TargetProcessSettings   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 34
c 0
b 0
f 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fromConsoleInput() 0 16 3
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\Command\CommandSettingsException;
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 CommandSettingsException
37
     */
38
    public static function fromConsoleInput(InputInterface $input): self
39
    {
40
        $pid = $input->getOption('pid');
41
        if (is_null($pid)) {
42
            throw TargetProcessSettingsException::create(
43
                TargetProcessSettingsException::PID_NOT_SPECIFIED
44
            );
45
        }
46
        $pid = filter_var($pid, FILTER_VALIDATE_INT);
47
        if ($pid === false) {
48
            throw TargetProcessSettingsException::create(
49
                TargetProcessSettingsException::PID_NOT_SPECIFIED
50
            );
51
        }
52
53
        return new self($pid);
54
    }
55
}
56