Conditions | 12 |
Paths | 32 |
Total Lines | 44 |
Lines | 11 |
Ratio | 25 % |
Tests | 21 |
CRAP Score | 13.0239 |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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) { |
|
|||
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])) { |
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 |
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.