Conditions | 13 |
Paths | 8 |
Total Lines | 56 |
Code Lines | 34 |
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 |
||
55 | public function query($index, array $filters = null, |
||
56 | array $queries = null, array $fieldWeights = null, |
||
57 | $limit = 20, $offset = 0 |
||
58 | ) { |
||
59 | $sphinxClient = $this->getSphinxClient(); |
||
60 | $sphinxClient->SetLimits($offset, $limit); |
||
61 | if (null !== $filters) { |
||
62 | foreach ($filters as $filter) { |
||
63 | if (!isset($filter['key'])) { |
||
64 | // Filtro existe mas sem key |
||
65 | } |
||
66 | if ( |
||
67 | array_key_exists('min', $filter) && |
||
68 | array_key_exists('max', $filter) |
||
69 | ) { |
||
70 | $sphinxClient->SetFilterRange( |
||
71 | $filter['key'], |
||
72 | (integer) $filter['min'], |
||
73 | (integer) $filter['max'] |
||
74 | ); |
||
75 | } else { |
||
76 | if (!isset($filter['values']) || !is_array($filter['values'])) { |
||
77 | //Filtro existe mas sem valor; |
||
78 | } |
||
79 | $sphinxClient->SetFilter( |
||
80 | $filter['key'], |
||
81 | $filter['values'] |
||
82 | ); |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | if (null !== $queries) { |
||
87 | foreach ($queries as $key => $queryInfo) { |
||
88 | $query = $this->implodeQueryValues($queryInfo); |
||
89 | |||
90 | if (array_key_exists('countableAttributes', $queryInfo)) { |
||
91 | $array = $queryInfo['countableAttributes']; |
||
92 | if (!is_array($array)) { |
||
93 | $array = [$array]; |
||
94 | } |
||
95 | |||
96 | $sphinxClient->addFacetedQuery($query, $index, $array); |
||
97 | } else { |
||
98 | $sphinxClient->AddQuery($query, $index); |
||
99 | } |
||
100 | } |
||
101 | } |
||
102 | |||
103 | if (null !== $fieldWeights) { |
||
104 | $sphinxClient->SetFieldWeights($fieldWeights); |
||
105 | } |
||
106 | |||
107 | $result = $this->getResult($sphinxClient); |
||
108 | |||
109 | return $result; |
||
110 | } |
||
111 | |||
227 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.