Conditions | 10 |
Paths | 3 |
Total Lines | 37 |
Code Lines | 24 |
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 |
||
69 | function split_enclosed($delimiter, $open, $close, $string) |
||
70 | { |
||
71 | $string = trim($string); |
||
1 ignored issue
–
show
|
|||
72 | if(strlen($string) === 0) { |
||
73 | return []; |
||
74 | } |
||
75 | |||
76 | $chars = str_split($string); |
||
77 | |||
78 | $result = array_reduce($chars, function($acc, $c) use($delimiter, $open, $close) { |
||
79 | if($acc === false) { |
||
80 | return $acc; |
||
81 | } |
||
82 | |||
83 | switch($c) { |
||
84 | case $delimiter: |
||
85 | if($acc[2] === 0) { |
||
86 | return strlen(trim($acc[1])) === 0 ? |
||
87 | false : |
||
88 | [array_merge($acc[0], [trim($acc[1])]), '', 0]; |
||
89 | } |
||
90 | break; |
||
91 | case $open: |
||
92 | return [$acc[0], $acc[1].$c, $acc[2] + 1]; |
||
93 | case $close: |
||
94 | return [$acc[0], $acc[1].$c, $acc[2] - 1]; |
||
95 | } |
||
96 | |||
97 | return [$acc[0], $acc[1].$c, $acc[2]]; |
||
98 | }, [[], '', 0]); |
||
99 | |||
100 | if($result === false || strlen(trim($result[1])) === 0) { |
||
101 | return false; |
||
102 | } |
||
103 | |||
104 | return array_merge($result[0], [trim($result[1])]); |
||
105 | } |
||
106 | |||
107 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.