Conditions | 11 |
Paths | 12 |
Total Lines | 39 |
Code Lines | 22 |
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 declare(strict_types=1); |
||
27 | public function build(string $definition, bool $with_literal) |
||
28 | { |
||
29 | if (is_numeric($definition)) { |
||
30 | if (false !== strpos($definition, '.')) { |
||
31 | return (float)$definition; |
||
32 | } |
||
33 | |||
34 | return (int)$definition; |
||
35 | } |
||
36 | |||
37 | switch (strtolower($definition)) { |
||
38 | case 'null': |
||
39 | return null; |
||
40 | case 'true': |
||
41 | return true; |
||
42 | case 'false': |
||
43 | return false; |
||
44 | } |
||
45 | |||
46 | if ($this->wrappedWith($definition, '[', ']')) { |
||
47 | return []; |
||
48 | } |
||
49 | |||
50 | if ($this->wrappedWith($definition, '{', '}')) { |
||
51 | return []; |
||
52 | } |
||
53 | |||
54 | foreach (['"', "'"] as $quote) { |
||
55 | if ($this->wrappedWith($definition, $quote, $quote)) { |
||
56 | return trim($definition, $quote); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | if (!$with_literal) { |
||
61 | throw new ArgumentValueBuilderException("Unknown value format '{$definition}'"); |
||
62 | } |
||
63 | |||
64 | return $definition; |
||
65 | } |
||
66 | |||
76 |