Conditions | 11 |
Paths | 11 |
Total Lines | 35 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 1 |
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 |
||
66 | public static function fromTypeToTypeUtilInterface(string $fieldName, Type $type): TypeUtilInterface |
||
67 | { |
||
68 | if ($type instanceof Types\Boolean) { |
||
69 | return new Boolean($fieldName); |
||
70 | } |
||
71 | if ($type instanceof Types\Float_) { |
||
72 | return new FloatingPoint($fieldName); |
||
73 | } |
||
74 | if ($type instanceof Types\Array_) { |
||
75 | return new PrimitiveArray($fieldName); |
||
76 | } |
||
77 | if ($type instanceof Types\Object_) { |
||
78 | $className = $type->getFqsen(); |
||
79 | return new AnotherValueObject($fieldName, $className); |
||
80 | } |
||
81 | if ($type instanceof Types\Integer) { |
||
82 | return new Integer($fieldName); |
||
83 | } |
||
84 | if ($type instanceof Types\String_) { |
||
85 | return new StringLiteral($fieldName); |
||
86 | } |
||
87 | if ($type instanceof Types\Mixed_) { |
||
88 | return new MixedTypehint($fieldName); |
||
89 | } |
||
90 | if ($type instanceof Types\Null_) { |
||
91 | return new NullObject(); |
||
92 | } |
||
93 | if ($type instanceof Types\Compound) { |
||
94 | $compoundTypes = []; |
||
95 | foreach ($type as $compoundItemType) { |
||
96 | $compoundTypes[] = self::fromTypeToTypeUtilInterface($fieldName, $compoundItemType); |
||
97 | } |
||
98 | return new Compound($fieldName, ...$compoundTypes); |
||
99 | } |
||
100 | throw new UnimplementedPhpDocBlockException($fieldName, $type); |
||
101 | } |
||
103 |