| Conditions | 13 |
| Paths | 12 |
| Total Lines | 41 |
| Code Lines | 34 |
| 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 |
||
| 17 | public function createType($type): CastInterface |
||
| 18 | { |
||
| 19 | $result = null; |
||
| 20 | if ($type instanceof \Closure) { |
||
| 21 | $result = new TypeClosure($type); |
||
| 22 | } elseif (\in_array($type, Cast::TYPES, true)) { |
||
| 23 | switch ($type) { |
||
| 24 | case Cast::INT: |
||
| 25 | $result = new TypeInt(); |
||
| 26 | break; |
||
| 27 | case Cast::BOOL: |
||
| 28 | $result = new TypeBool(); |
||
| 29 | break; |
||
| 30 | case Cast::FLOAT: |
||
| 31 | $result = new TypeFloat(); |
||
| 32 | break; |
||
| 33 | case Cast::STRING: |
||
| 34 | $result = new TypeString(); |
||
| 35 | break; |
||
| 36 | case Cast::BINARY: |
||
| 37 | $result = new TypeBinary(); |
||
| 38 | break; |
||
| 39 | case Cast::OBJECT: |
||
| 40 | $result = new TypeObject(); |
||
| 41 | break; |
||
| 42 | case Cast::UNSET: |
||
| 43 | $result = new TypeUnset(); |
||
| 44 | break; |
||
| 45 | case Cast::ARRAY: |
||
| 46 | $result = new TypeArray(); |
||
| 47 | break; |
||
| 48 | } |
||
| 49 | } elseif ($type instanceof CastInterface) { |
||
| 50 | $result = $type; |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($result === null) { |
||
| 54 | throw new Exception('Type not found'); |
||
| 55 | } |
||
| 56 | |||
| 57 | return $result; |
||
| 58 | } |
||
| 86 |