Completed
Push — master ( ba40ee...261a9c )
by Tobias
02:47
created

FormTypeInvalidMessage::enterNode()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 8.2964

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 15
cts 18
cp 0.8333
rs 8.1475
c 0
b 0
f 0
cc 8
nc 8
nop 1
crap 8.2964
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\Symfony;
13
14
use PhpParser\Node;
15
use PhpParser\NodeVisitor;
16
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
17
18
/**
19
 * @author Tobias Nyholm <[email protected]>
20
 */
21
final class FormTypeInvalidMessage extends BasePHPVisitor implements NodeVisitor
22
{
23
    use FormTrait;
24
25 3
    public function enterNode(Node $node)
26
    {
27 3
        if (!$this->isFormType($node)) {
28 3
            return;
29
        }
30
31 3
        if (!$node instanceof Node\Expr\Array_) {
32 3
            return;
33
        }
34
35 3
        foreach ($node->items as $item) {
36 3
            if (!$item->key instanceof Node\Scalar\String_) {
37 1
                continue;
38
            }
39
40 3
            if ('invalid_message' !== $item->key->value) {
41 3
                continue;
42
            }
43
44 2
            if (!$item->value instanceof Node\Scalar\String_) {
45
                $this->addError($item, 'Form label is not a scalar string');
46
47
                continue;
48
            }
49
50 2
            $label = $item->value->value;
51 2
            if (empty($label)) {
52
                continue;
53
            }
54
55 2
            $this->addLocation($label, $node->getAttribute('startLine'), $node, ['domain' => 'validators']);
56
        }
57 3
    }
58
59 3
    public function leaveNode(Node $node)
60
    {
61 3
    }
62
63 3
    public function beforeTraverse(array $nodes)
64
    {
65 3
    }
66
67 3
    public function afterTraverse(array $nodes)
68
    {
69 3
    }
70
}
71