Conditions | 11 |
Paths | 10 |
Total Lines | 38 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Tests | 21 |
CRAP Score | 11 |
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 |
||
33 | 65 | public static function matchOptionArg($option, $arg, $equals) |
|
34 | { |
||
35 | 65 | $optLen = strlen($option); |
|
36 | 65 | if (0 === $optLen) { |
|
37 | 12 | return false; |
|
38 | } |
||
39 | |||
40 | 53 | $argLen = strlen($arg); |
|
41 | 53 | if ($argLen < 2) { |
|
42 | 4 | return false; |
|
43 | } |
||
44 | |||
45 | 49 | if ('--' === $arg) { |
|
46 | 4 | return false; |
|
47 | } |
||
48 | |||
49 | 45 | if ('-' !== $arg[0]) { |
|
50 | 4 | return false; |
|
51 | } |
||
52 | |||
53 | 41 | if ((1 !== $optLen) !== ('-' === $arg[1])) { |
|
54 | 4 | return false; |
|
55 | } |
||
56 | |||
57 | 37 | $buffer = substr($arg, 1 === $optLen ? 1 : 2); |
|
58 | |||
59 | 37 | if ($equals && false !== $posEquals = strpos($buffer, '=')) { |
|
60 | 15 | if (0 === $posEquals) { |
|
61 | 2 | return false; |
|
62 | } |
||
63 | 13 | $buffer = substr($buffer, 0, $posEquals); |
|
64 | } |
||
65 | |||
66 | 35 | if (1 === $optLen) { |
|
67 | 22 | return false !== strpos($buffer, $option); |
|
68 | } |
||
69 | |||
70 | 13 | return $buffer === $option; |
|
71 | } |
||
111 |