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

FormTypeHelp::enterNode()   C

Complexity

Conditions 12
Paths 32

Size

Total Lines 44

Duplication

Lines 11
Ratio 25 %

Code Coverage

Tests 21
CRAP Score 13.0239

Importance

Changes 0
Metric Value
dl 11
loc 44
ccs 21
cts 26
cp 0.8077
rs 6.9666
c 0
b 0
f 0
cc 12
nc 32
nop 1
crap 13.0239

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
17
final class FormTypeHelp extends AbstractFormType implements NodeVisitor
18
{
19
    use FormTrait;
20
21 3
    public function enterNode(Node $node)
22
    {
23 3
        if (!$this->isFormType($node)) {
24 3
            return;
25
        }
26 2
        parent::enterNode($node);
27
28 2
        if (!$node instanceof Node\Expr\Array_) {
29 2
            return;
30
        }
31
32 2
        $helpNode = null;
33 2
        $domain = null;
34 2
        foreach ($node->items as $item) {
35 2
            if (!$item->key instanceof Node\Scalar\String_) {
36
                continue;
37
            }
38 2 View Code Duplication
            if ('translation_domain' === $item->key->value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
                // Try to find translation domain
40
                if ($item->value instanceof Node\Scalar\String_) {
41
                    $domain = $item->value->value;
42
                }
43 2
            } elseif ('help' === $item->key->value) {
44 2
                $helpNode = $item;
45
            }
46
        }
47
48 2
        if (null === $helpNode) {
49
            return;
50
        }
51
52 2
        if ($this->isKnownNode($helpNode)) {
53
            return;
54
        }
55
56 2
        if ($helpNode->value instanceof Node\Scalar\String_) {
57 1
            $line = $helpNode->value->getAttribute('startLine');
58 1 View Code Duplication
            if (null !== $location = $this->getLocation($helpNode->value->value, $line, $helpNode, ['domain' => $domain])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59 1
                $this->lateCollect($location);
60
            }
61
        } else {
62 1
            $this->addError($helpNode, 'Form help is not a scalar string');
63
        }
64 2
    }
65
}
66