Conditions | 7 |
Paths | 8 |
Total Lines | 53 |
Code Lines | 36 |
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 |
||
41 | public function __construct(string $snippetKey, ?string $filterType = null, string $paramKey, array $originalParams, string $originalFilter) |
||
42 | { |
||
43 | $this->snippetKey = $snippetKey; |
||
44 | $this->filterType = $filterType; |
||
45 | |||
46 | $this->paramKey = $paramKey; |
||
47 | |||
48 | $this->originalParams = $originalParams; |
||
49 | $this->originalFilter = $originalFilter; |
||
50 | |||
51 | $this->processedParams = $originalParams; |
||
|
|||
52 | $this->processedFilter = $originalFilter; |
||
53 | |||
54 | switch ($filterType) { |
||
55 | case 'like': |
||
56 | $newValue = '%'.$this->getOriginalParamValue().'%'; |
||
57 | $this->replaceParamValue($newValue); |
||
58 | break; |
||
59 | case 'string_any': |
||
60 | $newValue = '{'.implode(', ', array_map('strval', $this->getOriginalParamValue())).'}'; |
||
61 | $this->replaceParamValue($newValue); |
||
62 | break; |
||
63 | case 'numeric_any': |
||
64 | $newValue = '{'.implode(', ', array_map('intval', $this->getOriginalParamValue())).'}'; |
||
65 | $this->replaceParamValue($newValue); |
||
66 | break; |
||
67 | case 'in': |
||
68 | |||
69 | $newFilter = ''; |
||
70 | $newParams = []; |
||
71 | |||
72 | $i = 0; |
||
73 | |||
74 | foreach ($this->getOriginalParamValue() as $value) { |
||
75 | $newFilter .= ':'.$paramKey.'_'.$i.','; |
||
76 | $newParams[$paramKey.'_'.$i] = $value; |
||
77 | |||
78 | ++$i; |
||
79 | } |
||
80 | |||
81 | if (strlen($newFilter) > 0) { |
||
82 | $newFilter = substr($newFilter, 0, strlen($newFilter) - 1); |
||
83 | } |
||
84 | |||
85 | $this->removeParams([$this->getParamKey()]); |
||
86 | |||
87 | $processedParams = array_merge($this->processedParams, $newParams); |
||
88 | $processedFilter = str_replace(':'.$paramKey, $newFilter, $originalFilter); |
||
89 | |||
90 | $this->setProcessedParams($processedParams); |
||
91 | $this->setProcessedFilter($processedFilter); |
||
92 | |||
93 | break; |
||
94 | } |
||
206 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..