Completed
Push — master ( 8009cb...0bf5b8 )
by Olivier
03:52 queued 11s
created

LinkTitle   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 35
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B enterNode() 0 32 9
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 link titles:
19
 *     - $menu['foo']->setLinkAttribute('title', 'my.title').
20
 */
21
final class LinkTitle extends AbstractKnpMenuVisitor implements NodeVisitor
22
{
23 2
    public function enterNode(Node $node): ?Node
24
    {
25 2
        if (!$this->isKnpMenuBuildingMethod($node)) {
26 2
            return null;
27
        }
28
29 2
        parent::enterNode($node);
30
31 2
        if (!$node instanceof Node\Expr\MethodCall) {
32 2
            return null;
33
        }
34
35 2
        if (!\is_string($node->name) && !$node->name instanceof Node\Identifier) {
36
            return null;
37
        }
38
39 2
        $methodName = (string) $node->name;
40 2
        if ('setLinkAttribute' !== $methodName) {
41 2
            return null;
42
        }
43
44 2
        $attributeKey = $this->getStringArgument($node, 0);
45 2
        $attributeValue = $this->getStringArgument($node, 1);
46 2
        if ('title' === $attributeKey && null !== $attributeValue) {
47 2
            $line = $node->getAttribute('startLine');
48 2
            if (null !== $location = $this->getLocation($attributeValue, $line, $node)) {
49 2
                $this->lateCollect($location);
50
            }
51
        }
52
53 2
        return null;
54
    }
55
}
56