Conditions | 16 |
Paths | 140 |
Total Lines | 63 |
Code Lines | 27 |
Lines | 14 |
Ratio | 22.22 % |
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 declare(strict_types=1); |
||
121 | protected function compareStringStructure(array $initial, array $compared): int |
||
122 | { |
||
123 | $maxStructureSize = max(count($initial), count($compared)); |
||
124 | |||
125 | // Make structures same size preserving previous existing structure value |
||
126 | for ($i = 1; $i < $maxStructureSize; $i++) { |
||
127 | if (!array_key_exists($i, $initial)) { |
||
128 | $initial[$i] = $initial[$i - 1]; |
||
129 | } |
||
130 | if (!array_key_exists($i, $compared)) { |
||
131 | $compared[$i] = $compared[$i - 1]; |
||
132 | } |
||
133 | } |
||
134 | |||
135 | // Iterate every structure group |
||
136 | for ($i = 0; $i < $maxStructureSize; $i++) { |
||
137 | // If initial structure has NPCG than it has higher priority |
||
138 | if ($initial[$i][0] > $compared[$i][0]) { |
||
139 | return -1; |
||
140 | } |
||
141 | |||
142 | // If compared structure has NPCG than it has higher priority |
||
143 | if ($initial[$i][0] < $compared[$i][0]) { |
||
144 | return 1; |
||
145 | } |
||
146 | |||
147 | // Compare NOT starting NPCG length |
||
148 | if ($i > 0 && $initial[$i][0] === 1) { |
||
149 | if ($initial[$i][1] > $compared[$i][1]) { |
||
150 | return -1; |
||
151 | } |
||
152 | |||
153 | if ($initial[$i][1] < $compared[$i][1]) { |
||
154 | return 1; |
||
155 | } |
||
156 | } |
||
157 | |||
158 | // They are equal continue to next structure group comparison |
||
159 | } |
||
160 | |||
161 | // If both structures are equal compare lengths of NPCG |
||
162 | View Code Duplication | for ($i = 0; $i < $maxStructureSize; $i++) { |
|
|
|||
163 | // If current CG is NPCG |
||
164 | if ($initial[$i][0] === 1) { |
||
165 | if ($initial[$i][1] > $compared[$i][1]) { |
||
166 | return 1; |
||
167 | } |
||
168 | |||
169 | if ($initial[$i][1] < $compared[$i][1]) { |
||
170 | return -1; |
||
171 | } |
||
172 | } |
||
173 | |||
174 | // Current NPCG character groups have equal length - continue |
||
175 | } |
||
176 | |||
177 | $return = $this->compareStructureLengths($maxStructureSize, $initial, $compared, self::G_FIXED); |
||
178 | if ($return === 0) { |
||
179 | $return = $this->compareStructureLengths($maxStructureSize, $initial, $compared, self::G_VARIABLE); |
||
180 | } |
||
181 | |||
182 | return $return; |
||
183 | } |
||
184 | |||
221 |
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.