Conditions | 5 |
Paths | 2 |
Total Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Tests | 25 |
CRAP Score | 5 |
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 |
||
145 | 7 | private function createFunctionAliasStatements(array $whitelistedFunctions, bool $hasNamespacedFunctions): array |
|
146 | { |
||
147 | 7 | $statements = array_map( |
|
148 | function (array $node) use ($hasNamespacedFunctions): string { |
||
149 | /** |
||
150 | * @var string |
||
151 | * @var string $alias |
||
152 | */ |
||
153 | 3 | [$original, $alias] = $node; |
|
2 ignored issues
–
show
|
|||
154 | |||
155 | 3 | $original = new FullyQualified($original); |
|
1 ignored issue
–
show
|
|||
156 | 3 | $alias = new FullyQualified($alias); |
|
1 ignored issue
–
show
|
|||
157 | |||
158 | 3 | if ($hasNamespacedFunctions) { |
|
159 | 2 | $namespace = $original->slice(0, -1); |
|
160 | |||
161 | 2 | return sprintf( |
|
162 | <<<'PHP' |
||
163 | 2 | namespace %s{ |
|
164 | if (!function_exists('%s')) { |
||
165 | function %s() { |
||
166 | return \%s(...func_get_args()); |
||
167 | } |
||
168 | } |
||
169 | } |
||
170 | PHP |
||
171 | , |
||
172 | 2 | null === $namespace ? '' : $namespace->toString().' ', |
|
173 | 2 | $original->toString(), |
|
174 | 2 | null === $namespace ? $original->toString() : $original->slice(1)->toString(), |
|
175 | 2 | $alias->toString() |
|
176 | ); |
||
177 | } |
||
178 | |||
179 | 1 | return sprintf( |
|
180 | <<<'PHP' |
||
181 | 1 | if (!function_exists('%1$s')) { |
|
182 | function %1$s() { |
||
183 | return \%2$s(...func_get_args()); |
||
184 | } |
||
185 | } |
||
186 | PHP |
||
187 | , |
||
188 | 1 | $original, |
|
189 | 1 | $alias |
|
190 | ); |
||
191 | 7 | }, |
|
192 | 7 | $whitelistedFunctions |
|
193 | ); |
||
194 | |||
195 | 7 | if ([] === $statements) { |
|
196 | 4 | return $statements; |
|
197 | } |
||
198 | |||
199 | 3 | array_unshift( |
|
200 | 3 | $statements, |
|
201 | <<<'EOF' |
||
202 | 3 | // Functions whitelisting. For more information see: |
|
203 | // https://github.com/humbug/php-scoper/blob/master/README.md#functions-whitelisting |
||
204 | EOF |
||
205 | ); |
||
206 | |||
207 | 3 | return $statements; |
|
208 | } |
||
209 | |||
237 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.