These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | if ('translation_domain' === $item->key->value) { |
|
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 ($helpNode->value instanceof Node\Scalar\String_) { |
|
53 | 1 | $line = $helpNode->value->getAttribute('startLine'); |
|
54 | 1 | View Code Duplication | if (null !== $location = $this->getLocation($helpNode->value->value, $line, $helpNode, ['domain' => $domain])) { |
0 ignored issues
–
show
|
|||
55 | 1 | $this->lateCollect($location); |
|
56 | } |
||
57 | } else { |
||
58 | 1 | $this->addError($helpNode, 'Form help is not a scalar string'); |
|
59 | } |
||
60 | 2 | } |
|
61 | } |
||
62 |
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.