SpeedscopeConverterSettingsFromConsoleInput   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createSettings() 0 5 1
A setOptions() 0 9 1
A utf8ErrorHandlingTypeFromString() 0 8 1
1
<?php
2
3
/**
4
 * This file is part of the reliforp/reli-prof 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 Reli\Converter\Speedscope\Settings;
15
16
use PhpCast\Cast;
0 ignored issues
show
Bug introduced by
The type PhpCast\Cast 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 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 SpeedscopeConverterSettingsFromConsoleInput
22
{
23
    /** @codeCoverageIgnore */
24
    public function setOptions(Command $command): void
25
    {
26
        $command
27
            ->addOption(
28
                'utf8-errors',
29
                null,
30
                InputOption::VALUE_REQUIRED,
31
                'utf8 error handling type (ignore|substitute|fail)',
32
                'ignore'
33
            );
34
        ;
35
    }
36
37
    public function createSettings(InputInterface $input): SpeedscopeConverterSettings
38
    {
39
        return new SpeedscopeConverterSettings(
40
            $this->utf8ErrorHandlingTypeFromString(
41
                Cast::toString($input->getOption('utf8-errors'))
42
            ),
43
        );
44
    }
45
46
    private function utf8ErrorHandlingTypeFromString(string $input): Utf8ErrorHandlingType
47
    {
48
        return match ($input) {
49
            'substitute' => Utf8ErrorHandlingType::Substitute,
50
            'ignore' => Utf8ErrorHandlingType::Ignore,
51
            'fail' => Utf8ErrorHandlingType::Fail,
52
            default => throw SpeedscopeConverterSettingsException::create(
53
                SpeedscopeConverterSettingsException::UNSUPPORTED_UTF8_ERROR_HANDLING
54
            ),
55
        };
56
    }
57
}
58