| Conditions | 11 |
| Paths | 11 |
| Total Lines | 23 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 26 | public function invoke(?int $type = null, ?string $customType = null): string |
||
| 27 | { |
||
| 28 | switch (true) { |
||
| 29 | case TypeInterface::CUSTOM === $type: |
||
| 30 | return sprintf('$this->createMock(%s::class)', $customType); |
||
| 31 | case TypeInterface::OBJECT === $type: |
||
| 32 | return '$this->createMock(\\DateTime::class)'; |
||
| 33 | case TypeInterface::BOOL === $type: |
||
| 34 | return 'true'; |
||
| 35 | case TypeInterface::INT === $type: |
||
| 36 | return '42'; |
||
| 37 | case TypeInterface::FLOAT === $type: |
||
| 38 | return '42.42'; |
||
| 39 | case TypeInterface::ARRAY === $type: |
||
| 40 | case TypeInterface::ITERABLE === $type: |
||
| 41 | return '["a", "strings", "array"]'; |
||
| 42 | case TypeInterface::CALLABLE === $type: |
||
| 43 | return 'function(): void {/* A callable */}'; |
||
| 44 | case TypeInterface::STRING === $type: |
||
| 45 | case TypeInterface::MIXED === $type: |
||
| 46 | return '"a string to test"'; |
||
| 47 | default: |
||
| 48 | return '/** @todo Insert a value matching type here */'; |
||
| 49 | } |
||
| 52 |