Conditions | 12 |
Paths | 12 |
Total Lines | 26 |
Code Lines | 23 |
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 |
||
38 | public function invoke(?int $type = null, ?string $customType = null): string |
||
39 | { |
||
40 | switch (true) { |
||
41 | case TypeInterface::CUSTOM === $type: |
||
42 | if ($customType === null) { |
||
43 | throw new Exception('Custom type must have a custom class to mock'); |
||
44 | } |
||
45 | return sprintf('$this->createMock(%s::class)', $customType); |
||
46 | case TypeInterface::OBJECT === $type: |
||
47 | return '$this->createMock(\\DateTime::class)'; |
||
48 | case TypeInterface::BOOL === $type: |
||
49 | return 'true'; |
||
50 | case TypeInterface::INT === $type: |
||
51 | return '42'; |
||
52 | case TypeInterface::FLOAT === $type: |
||
53 | return '42.42'; |
||
54 | case TypeInterface::ARRAY === $type: |
||
55 | case TypeInterface::ITERABLE === $type: |
||
56 | return '["a", "strings", "array"]'; |
||
57 | case TypeInterface::CALLABLE === $type: |
||
58 | return 'function(): void {/* A callable */}'; |
||
59 | case TypeInterface::STRING === $type: |
||
60 | case TypeInterface::MIXED === $type: |
||
61 | return '"a string to test"'; |
||
62 | default: |
||
63 | return '/** @todo Insert a value with a correct type here */'; |
||
64 | } |
||
67 |