Passed
Push — add-option-to-change-output ( 0c1513 )
by Shinji
03:29
created

OutputSettingsFromConsoleInput::setOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 14
rs 9.9
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\OutputSettings;
15
16
use Noodlehaus\Config;
0 ignored issues
show
Bug introduced by
The type Noodlehaus\Config 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...
17
use PhpCast\NullableCast;
0 ignored issues
show
Bug introduced by
The type PhpCast\NullableCast 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\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...
19
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...
20
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...
21
22
final class OutputSettingsFromConsoleInput
23
{
24
    public function __construct(
25
        private Config $config
26
    ) {
27
    }
28
29
    /** @codeCoverageIgnore */
30
    public function setOptions(Command $command): void
31
    {
32
        $command
33
            ->addOption(
34
                'template',
35
                't',
36
                InputOption::VALUE_OPTIONAL,
37
                'template name (phpspy|phpspy_with_opcode|json_lines) (default: phpspy)'
38
            )
39
            ->addOption(
40
                'output',
41
                'o',
42
                InputOption::VALUE_REQUIRED,
43
                'path to write output from this tool (default: stdout)'
44
            )
45
        ;
46
    }
47
48
    public function createSettings(InputInterface $input): OutputSettings
49
    {
50
        $template = NullableCast::toString($input->getOption('template'));
51
        if (is_null($template)) {
52
            $template = NullableCast::toString($this->config->get('output.template.default'));
53
            if (is_null($template)) {
54
                throw OutputSettingsException::create(
55
                    OutputSettingsException::TEMPLATE_NOT_SPECIFIED
56
                );
57
            }
58
        }
59
60
        $output_path = $input->getOption('output');
61
        if (!is_null($output_path) and !is_string($output_path)) {
62
            throw OutputSettingsException::create(
63
                OutputSettingsException::OUTPUT_IS_NOT_STRING
64
            );
65
        }
66
67
        return new OutputSettings(
68
            $template,
69
            $output_path,
70
        );
71
    }
72
}
73