Conditions | 21 |
Paths | 8 |
Total Lines | 83 |
Code Lines | 34 |
Lines | 7 |
Ratio | 8.43 % |
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 |
||
47 | public function enterNode(Node $node) |
||
48 | { |
||
49 | // |
||
50 | // For use statements |
||
51 | // |
||
52 | if ($node instanceof UseUse |
||
53 | && $node->hasAttribute('parent') |
||
54 | && false === ($node->getAttribute('parent') instanceof GroupUse) |
||
55 | && ( |
||
56 | // Is not a whitelisted use statement of the global namespace |
||
57 | (1 === count($node->name->parts) && false === ($this->whitelister)($node->name->getFirst())) |
||
58 | // Is not from the Composer namespace |
||
59 | || 'Composer' === $node->name->getFirst() |
||
60 | // Is not a whitelisted class |
||
61 | || ($node->getAttribute('parent') instanceof Use_ |
||
62 | && Use_::TYPE_NORMAL === $node->getAttribute('parent')->type |
||
63 | && in_array((string) $node->name, $this->whitelist) |
||
64 | ) |
||
65 | ) |
||
66 | ) { |
||
67 | $node->setAttribute('phpscoper_ignore', true); |
||
68 | |||
69 | return $node; |
||
70 | } elseif (false === ($node instanceof FullyQualified) || false === $node->isFullyQualified()) { |
||
71 | return $node; |
||
72 | } |
||
73 | |||
74 | /** @var FullyQualified $node */ |
||
75 | |||
76 | // Is a fully qualified call from the global namespace which is not whitelisted |
||
77 | View Code Duplication | if (1 === count($node->parts) |
|
|
|||
78 | && (false === ($this->whitelister)($node->getFirst())) |
||
79 | ) { |
||
80 | $node->setAttribute('phpscoper_ignore', true); |
||
81 | |||
82 | return $node; |
||
83 | } |
||
84 | |||
85 | if (false === $node->hasAttribute('parent')) { |
||
86 | return $node; |
||
87 | } |
||
88 | |||
89 | $parentNode = $node->getAttribute('parent'); |
||
90 | |||
91 | // Is a static method call of a whitelisted class |
||
92 | if ($parentNode instanceof StaticCall |
||
93 | && in_array((string) $parentNode->class, $this->whitelist) |
||
94 | ) { |
||
95 | $node->setAttribute('phpscoper_ignore', true); |
||
96 | |||
97 | return $node; |
||
98 | } |
||
99 | |||
100 | // // Is a method call of a whitelisted class |
||
101 | // if ($parentNode instanceof FuncCall |
||
102 | // && $parentNode->name instanceof Name |
||
103 | // && in_array((string) $parentNode->name->slice(0, -1), $this->whitelist) |
||
104 | // ) { |
||
105 | // $node->setAttribute('phpscoper_ignore', true); |
||
106 | // |
||
107 | // return $node; |
||
108 | // } |
||
109 | |||
110 | // Is a new instance of a whitelisted class |
||
111 | if ($parentNode instanceof New_ |
||
112 | && in_array((string) $parentNode->class->toString(), $this->whitelist) |
||
113 | ) { |
||
114 | $node->setAttribute('phpscoper_ignore', true); |
||
115 | |||
116 | return $node; |
||
117 | } |
||
118 | |||
119 | // Is a constant call of a whitelisted class |
||
120 | if ($parentNode instanceof ClassConstFetch |
||
121 | && in_array((string) $node, $this->whitelist) |
||
122 | ) { |
||
123 | $node->setAttribute('phpscoper_ignore', true); |
||
124 | |||
125 | return $node; |
||
126 | } |
||
127 | |||
128 | return $node; |
||
129 | } |
||
130 | } |
||
131 |
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.