Conditions | 7 |
Paths | 8 |
Total Lines | 55 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
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 |
||
46 | public function __construct(string $snippetKey, ?string $filterType, string $paramKey, array $originalParams, string $originalFilter) |
||
47 | { |
||
48 | $this->snippetKey = $snippetKey; |
||
49 | $this->filterType = $filterType; |
||
50 | |||
51 | $this->paramKey = $paramKey; |
||
52 | |||
53 | $this->originalParams = $originalParams; |
||
54 | $this->originalFilter = $originalFilter; |
||
55 | |||
56 | $this->processedParams = $originalParams; |
||
57 | $this->processedFilter = $originalFilter; |
||
58 | |||
59 | switch ($filterType) { |
||
60 | case 'like': |
||
61 | $newValue = '%'.$this->getOriginalParamValue().'%'; |
||
62 | $this->replaceParamValue($newValue); |
||
63 | |||
64 | break; |
||
65 | case 'string_any': |
||
66 | $newValue = '{'.implode(', ', array_map('strval', $this->getOriginalParamValue())).'}'; |
||
67 | $this->replaceParamValue($newValue); |
||
68 | |||
69 | break; |
||
70 | case 'numeric_any': |
||
71 | $newValue = '{'.implode(', ', array_map('intval', $this->getOriginalParamValue())).'}::integer'; |
||
72 | $this->replaceParamValue($newValue); |
||
73 | |||
74 | break; |
||
75 | case 'in': |
||
76 | $newFilter = ''; |
||
77 | $newParams = []; |
||
78 | |||
79 | $i = 0; |
||
80 | |||
81 | foreach ($this->getOriginalParamValue() as $value) { |
||
82 | $newFilter .= ':'.$paramKey.'_'.$i.','; |
||
83 | $newParams[$paramKey.'_'.$i] = $value; |
||
84 | |||
85 | ++$i; |
||
86 | } |
||
87 | |||
88 | if (strlen($newFilter) > 0) { |
||
89 | $newFilter = substr($newFilter, 0, strlen($newFilter) - 1); |
||
90 | } |
||
91 | |||
92 | $this->removeParams([$this->getParamKey()]); |
||
93 | |||
94 | $processedParams = array_merge($this->processedParams, $newParams); |
||
95 | $processedFilter = str_replace(':'.$paramKey, $newFilter, $originalFilter); |
||
96 | |||
97 | $this->setProcessedParams($processedParams); |
||
98 | $this->setProcessedFilter($processedFilter); |
||
99 | |||
100 | break; |
||
101 | } |
||
211 |