| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 43 | public function providesRequestsWithASuspiciousUserAgentHeader(): array |
||
| 44 | { |
||
| 45 | $requestFactory = $this->getRequestFactory(); |
||
| 46 | |||
| 47 | return [ |
||
| 48 | // OK |
||
| 49 | [ |
||
| 50 | false, |
||
| 51 | $requestFactory->createWithHeaders(['User-Agent' => 'Something']), |
||
| 52 | ], |
||
| 53 | // [NEW] OK (at least one alpha) |
||
| 54 | [ |
||
| 55 | false, |
||
| 56 | $requestFactory->createWithHeaders(['User-Agent' => 'a']), |
||
| 57 | ], |
||
| 58 | // [NEW] OK (at least one alpha) |
||
| 59 | [ |
||
| 60 | false, |
||
| 61 | $requestFactory->createWithHeaders(['User-Agent' => 'a1']), |
||
| 62 | ], |
||
| 63 | |||
| 64 | // Suspicious (blank) |
||
| 65 | [ |
||
| 66 | true, |
||
| 67 | $requestFactory->createWithHeaders(['User-Agent' => '']), |
||
| 68 | ], |
||
| 69 | // Suspicious (non-existent) |
||
| 70 | [ |
||
| 71 | true, |
||
| 72 | $requestFactory->createWithHeaders([]), |
||
| 73 | ], |
||
| 74 | // Suspicious (only whitespace) |
||
| 75 | [ |
||
| 76 | true, |
||
| 77 | $requestFactory->createWithHeaders(['User-Agent' => ' ']), |
||
| 78 | ], |
||
| 79 | // Suspicious (only whitespace) |
||
| 80 | [ |
||
| 81 | true, |
||
| 82 | $requestFactory->createWithHeaders(['User-Agent' => ' ']), |
||
| 83 | ], |
||
| 84 | // Suspicious (dash) |
||
| 85 | [ |
||
| 86 | true, |
||
| 87 | $requestFactory->createWithHeaders(['User-Agent' => '-']), |
||
| 88 | ], |
||
| 89 | // Suspicious (dash) |
||
| 90 | [ |
||
| 91 | true, |
||
| 92 | $requestFactory->createWithHeaders(['User-Agent' => ' - ']), |
||
| 93 | ], |
||
| 94 | |||
| 95 | // [NEW] Suspicious (just numbers) |
||
| 96 | [ |
||
| 97 | true, |
||
| 98 | $requestFactory->createWithHeaders(['User-Agent' => '1']), |
||
| 99 | ], |
||
| 100 | // [NEW] Suspicious (no alpha) |
||
| 101 | [ |
||
| 102 | true, |
||
| 103 | $requestFactory->createWithHeaders(['User-Agent' => '!@£123']), |
||
| 104 | ], |
||
| 119 |