Conditions | 18 |
Paths | 17 |
Total Lines | 36 |
Code Lines | 32 |
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 |
||
53 | public static function castAttribute($type, $value) |
||
54 | { |
||
55 | if (is_null($value)) { |
||
56 | return $value; |
||
57 | } |
||
58 | |||
59 | switch ($type) { |
||
60 | case 'int': |
||
61 | case 'integer': |
||
62 | return (int)$value; |
||
63 | case 'real': |
||
64 | case 'float': |
||
65 | case 'double': |
||
66 | return (float)$value; |
||
67 | case 'string': |
||
68 | return (string)$value; |
||
69 | case 'bool': |
||
70 | case 'boolean': |
||
71 | return (bool)$value; |
||
72 | case 'object': |
||
73 | return (new static)->fromJson($value, true); |
||
74 | case 'array': |
||
75 | case 'json': |
||
76 | return (new static)->fromJson($value); |
||
77 | case 'collection': |
||
78 | return collect(is_array($value) ? $value : (new static)->fromJson($value)); |
||
79 | case 'date': |
||
80 | return (new static)->asDate($value); |
||
81 | case 'datetime': |
||
82 | return (new static)->asDateTime($value); |
||
83 | case 'bytes': |
||
84 | return static::formatBytes($value); |
||
85 | break; |
||
|
|||
86 | default: |
||
87 | return $value; |
||
88 | break; |
||
89 | } |
||
154 | } |
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.