TypeNameReducer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 4 1
A reduce() 0 6 1
A getChunks() 0 6 2
1
<?php
2
/**
3
 * This file is part of Properties 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 Serafim\Properties\Reducers;
11
12
use Railt\Parser\Ast\RuleInterface;
13
14
/**
15
 * Class TypeNameReducer
16
 */
17
class TypeNameReducer implements ReducerInterface
18
{
19
    /**
20
     * @param RuleInterface $rule
21
     * @return bool
22
     */
23
    public function match(RuleInterface $rule): bool
24
    {
25
        return $rule->getName() === 'Type';
26
    }
27
28
    /**
29
     * @param RuleInterface $rule
30
     * @return string
31
     */
32
    public function reduce(RuleInterface $rule): string
33
    {
34
        $chunks = \iterator_to_array($this->getChunks($rule));
35
36
        return \implode('\\', $chunks);
37
    }
38
39
    /**
40
     * @param RuleInterface $rule
41
     * @return \Traversable|string[]
42
     */
43
    private function getChunks(RuleInterface $rule): \Traversable
44
    {
45
        foreach ($rule->getChildren() as $child) {
46
            yield $child->getValue();
47
        }
48
    }
49
}
50