TemplateSettingsFromConsoleInput   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 36
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setOptions() 0 8 1
A createSettings() 0 13 3
A __construct() 0 3 1
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\TemplatedTraceFormatterSettings;
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 PhpProfiler\Inspector\Settings\InspectorSettingsException;
19
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...
20
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...
21
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...
22
23
use function is_null;
24
25
final class TemplateSettingsFromConsoleInput
26
{
27
    public function __construct(
28
        private Config $config
29
    ) {
30
    }
31
32
    /** @codeCoverageIgnore */
33
    public function setOptions(Command $command): void
34
    {
35
        $command
36
            ->addOption(
37
                'template',
38
                't',
39
                InputOption::VALUE_OPTIONAL,
40
                'template name (phpspy|phpspy_with_opcode|json_lines) (default: phpspy)'
41
            )
42
        ;
43
    }
44
45
    /**
46
     * @throws InspectorSettingsException
47
     */
48
    public function createSettings(InputInterface $input): TemplateSettings
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 TemplateSettingsException::create(
55
                    TemplateSettingsException::TEMPLATE_NOT_SPECIFIED
56
                );
57
            }
58
        }
59
60
        return new TemplateSettings($template);
61
    }
62
}
63