ItemLabel   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 33
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B enterNode() 0 30 8
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[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
namespace Translation\Extractor\Visitor\Php\Knp\Menu;
13
14
use PhpParser\Node;
15
use PhpParser\NodeVisitor;
16
17
/**
18
 * This class extracts knp menu item labels:
19
 *     - $menu->addChild('foo')
20
 *     - $menu['foo']->setLabel('bar').
21
 */
22
final class ItemLabel extends AbstractKnpMenuVisitor implements NodeVisitor
23
{
24 2
    public function enterNode(Node $node): ?Node
25
    {
26 2
        if (!$this->isKnpMenuBuildingMethod($node)) {
27 2
            return null;
28
        }
29
30 2
        parent::enterNode($node);
31
32 2
        if (!$node instanceof Node\Expr\MethodCall) {
33 2
            return null;
34
        }
35
36 2
        if (!\is_string($node->name) && !$node->name instanceof Node\Identifier) {
37
            return null;
38
        }
39
40 2
        $methodName = (string) $node->name;
41 2
        if (!\in_array($methodName, ['addChild', 'setLabel'], true)) {
42 2
            return null;
43
        }
44
45 2
        if (null !== $label = $this->getStringArgument($node, 0)) {
46 2
            $line = $node->getAttribute('startLine');
47 2
            if (null !== $location = $this->getLocation($label, $line, $node)) {
48 2
                $this->lateCollect($location);
49
            }
50
        }
51
52 2
        return null;
53
    }
54
}
55