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

LoopSettings::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
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\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 LoopSettings
20
{
21
    private const SLEEP_NANO_SECONDS_DEFAULT = 1000 * 1000 * 10;
22
    private const CANCEL_KEY_DEFAULT = 'q';
23
24
    public int $sleep_nano_seconds;
25
    public string $cancel_key;
26
27
    /**
28
     * TraceLoopSettings constructor.
29
     * @param int $sleep_nano_seconds
30
     * @param string $cancel_key
31
     */
32
    public function __construct(int $sleep_nano_seconds, string $cancel_key)
33
    {
34
        $this->sleep_nano_seconds = $sleep_nano_seconds;
35
        $this->cancel_key = $cancel_key;
36
    }
37
38
    /**
39
     * @param InputInterface $input
40
     * @return self
41
     * @throws CommandSettingsException
42
     */
43
    public static function fromConsoleInput(InputInterface $input): self
44
    {
45
        $sleep_nano_seconds = $input->getOption('sleep-ns');
46
        if (is_null($sleep_nano_seconds)) {
47
            $sleep_nano_seconds = self::SLEEP_NANO_SECONDS_DEFAULT;
48
        }
49
        $sleep_nano_seconds = filter_var($sleep_nano_seconds, FILTER_VALIDATE_INT);
50
        if ($sleep_nano_seconds === false) {
51
            throw LoopSettingsException::create(LoopSettingsException::ERRPR_SLEEP_NS_IS_NOT_INTEGER);
52
        }
53
54
        return new self($sleep_nano_seconds, self::CANCEL_KEY_DEFAULT);
55
    }
56
}
57