Passed
Pull Request — master (#13)
by Shinji
01:23
created

GetTraceSettingsFromConsoleInput::setOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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\GetTraceSettings;
15
16
use PhpProfiler\Inspector\Settings\InspectorSettingsException;
17
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command 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
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
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputOption 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...
20
21
final class GetTraceSettingsFromConsoleInput
22
{
23
    public function setOptions(Command $command): void
24
    {
25
        $command
26
            ->addOption(
27
                'depth',
28
                'd',
29
                InputOption::VALUE_OPTIONAL,
30
                'max depth'
31
            )
32
        ;
33
    }
34
35
    /**
36
     * @param InputInterface $input
37
     * @return GetTraceSettings
38
     * @throws InspectorSettingsException
39
     */
40
    public function fromConsoleInput(InputInterface $input): GetTraceSettings
41
    {
42
        $depth = $input->getOption('depth');
43
        if (is_null($depth)) {
44
            $depth = PHP_INT_MAX;
45
        }
46
        $depth = filter_var($depth, FILTER_VALIDATE_INT);
47
        if ($depth === false) {
48
            throw GetTraceSettingsException::create(GetTraceSettingsException::DEPTH_IS_NOT_INTEGER);
49
        }
50
        return new GetTraceSettings($depth);
51
    }
52
}
53