Test Failed
Push — master ( b7ab7b...94ee03 )
by Kirill
02:59
created

SimpleNamingStrategy::formatArgument()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 6
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Naming;
11
12
use Railt\SDL\Frontend\Invocation\ArgumentInterface;
13
use Railt\SDL\Frontend\Invocation\TypeInvocation;
14
use Railt\SDL\IR\TypeNameInterface;
15
16
/**
17
 * Class SimpleNamingStrategy
18
 */
19
class SimpleNamingStrategy extends Strategy
20
{
21
    /**
22
     * PrettyNamingStrategy constructor.
23
     */
24
    public function __construct()
25
    {
26
        parent::__construct(\Closure::fromCallable([$this, 'format']));
27
    }
28
29
    /**
30
     * @param TypeNameInterface $name
31
     * @param iterable|ArgumentInterface[] $arguments
32
     * @return string
33
     */
34
    protected function format(TypeNameInterface $name, iterable $arguments): string
35
    {
36
        return $this->formatName($name) . $this->formatArguments($arguments);
37
    }
38
39
    /**
40
     * @param iterable|ArgumentInterface[] $arguments
41
     * @return string
42
     */
43
    protected function formatArguments(iterable $arguments): string
44
    {
45
        $result = [];
46
47
        foreach ($arguments as $argument) {
48
            $result[] = $this->formatArgument($argument);
49
        }
50
51
        if (\count($result)) {
52
            return 'Of' . \implode('And', $result);
53
        }
54
55
        return '';
56
    }
57
58
    /**
59
     * @param ArgumentInterface $argument
60
     * @return string
61
     */
62
    protected function formatArgument(ArgumentInterface $argument): string
63
    {
64
        $value = $argument->getValue();
65
        $suffix = $value instanceof TypeInvocation ? $this->formatType($value) : $this->formatArgument($value);
0 ignored issues
show
Bug introduced by
The class Railt\SDL\Frontend\Invocation\TypeInvocation does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
66
67
        return \ucfirst($argument->getName()) . $suffix;
68
    }
69
70
    /**
71
     * @param TypeInvocation $type
72
     * @return string
73
     */
74
    protected function formatType(TypeInvocation $type): string
75
    {
76
        return $this->formatName($type->getTypeName()) . $this->formatArguments($type->getArguments());
77
    }
78
79
    /**
80
     * @param TypeNameInterface $name
81
     * @return string
82
     */
83
    protected function formatName(TypeNameInterface $name): string
84
    {
85
        $from = TypeNameInterface::NAMESPACE_SEPARATOR;
86
87
        return \str_replace($from, '_', $name->getFullyQualifiedName());
88
    }
89
}
90