Conditions | 1 |
Paths | 1 |
Total Lines | 154 |
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 |
||
96 | public function getFiltersMultiple() |
||
97 | { |
||
98 | return [ |
||
99 | [[ |
||
100 | 'choiceType' => ChoiceType::TYPE_NOT_CONTAINS, |
||
101 | 'value' => 'somevalue', |
||
102 | 'qbNodeCount' => 6, |
||
103 | 'assertPaths' => [ |
||
104 | 'where.constraint.constraint[0].constraint.operand_dynamic' => [ |
||
105 | 'getAlias' => 'a', |
||
106 | 'getField' => 'somefield', |
||
107 | ], |
||
108 | 'where.constraint.constraint[0].constraint.operand_static' => [ |
||
109 | 'getValue' => '%somevalue%', |
||
110 | ], |
||
111 | ], |
||
112 | ]], |
||
113 | [[ |
||
114 | 'choiceType' => ChoiceType::TYPE_NOT_CONTAINS, |
||
115 | 'value' => ['somevalue', 'somevalue'], |
||
116 | 'qbNodeCount' => 10, |
||
117 | 'assertPaths' => [ |
||
118 | 'where.constraint.constraint.constraint.operand_dynamic' => [ |
||
119 | 'getAlias' => 'a', |
||
120 | 'getField' => 'somefield', |
||
121 | ], |
||
122 | 'where.constraint.constraint.constraint.operand_static' => [ |
||
123 | 'getValue' => '%somevalue%', |
||
124 | ], |
||
125 | 'where.constraint.constraint[1].constraint.operand_dynamic' => [ |
||
126 | 'getAlias' => 'a', |
||
127 | 'getField' => 'somefield', |
||
128 | ], |
||
129 | 'where.constraint.constraint[1].constraint.operand_static' => [ |
||
130 | 'getValue' => '%somevalue%', |
||
131 | ], |
||
132 | ], |
||
133 | ]], |
||
134 | [[ |
||
135 | 'choiceType' => ChoiceType::TYPE_CONTAINS, |
||
136 | 'value' => 'somevalue', |
||
137 | 'qbNodeCount' => 5, |
||
138 | 'assertPaths' => [ |
||
139 | 'where.constraint.constraint.operand_dynamic' => [ |
||
140 | 'getAlias' => 'a', |
||
141 | 'getField' => 'somefield', |
||
142 | ], |
||
143 | 'where.constraint.constraint.operand_static' => [ |
||
144 | 'getValue' => '%somevalue%', |
||
145 | ], |
||
146 | 'where.constraint.constraint.operand_static' => [ |
||
147 | 'getValue' => '%somevalue%', |
||
148 | ], |
||
149 | ], |
||
150 | ]], |
||
151 | [[ |
||
152 | 'choiceType' => ChoiceType::TYPE_CONTAINS, |
||
153 | 'value' => ['somevalue', 'somevalue'], |
||
154 | 'qbNodeCount' => 8, |
||
155 | 'assertPaths' => [ |
||
156 | 'where.constraint.constraint.operand_dynamic' => [ |
||
157 | 'getAlias' => 'a', |
||
158 | 'getField' => 'somefield', |
||
159 | ], |
||
160 | 'where.constraint.constraint.operand_static' => [ |
||
161 | 'getValue' => '%somevalue%', |
||
162 | ], |
||
163 | 'where.constraint.constraint[1].operand_dynamic' => [ |
||
164 | 'getAlias' => 'a', |
||
165 | 'getField' => 'somefield', |
||
166 | ], |
||
167 | 'where.constraint.constraint[1].operand_static' => [ |
||
168 | 'getValue' => '%somevalue%', |
||
169 | ], |
||
170 | ], |
||
171 | ]], |
||
172 | [[ |
||
173 | 'choiceType' => ChoiceType::TYPE_CONTAINS, |
||
174 | 'value' => 'somevalue', |
||
175 | 'qbNodeCount' => 5, |
||
176 | 'assertPaths' => [ |
||
177 | 'where.constraint.constraint.operand_dynamic' => [ |
||
178 | 'getAlias' => 'a', |
||
179 | 'getField' => 'somefield', |
||
180 | ], |
||
181 | 'where.constraint.constraint.operand_static' => [ |
||
182 | 'getValue' => '%somevalue%', |
||
183 | ], |
||
184 | 'where.constraint.constraint.operand_static' => [ |
||
185 | 'getValue' => '%somevalue%', |
||
186 | ], |
||
187 | ], |
||
188 | ]], |
||
189 | [[ |
||
190 | 'choiceType' => ChoiceType::TYPE_CONTAINS, |
||
191 | 'value' => ['somevalue', 'somevalue'], |
||
192 | 'qbNodeCount' => 8, |
||
193 | 'assertPaths' => [ |
||
194 | 'where.constraint.constraint.operand_dynamic' => [ |
||
195 | 'getAlias' => 'a', |
||
196 | 'getField' => 'somefield', |
||
197 | ], |
||
198 | 'where.constraint.constraint.operand_static' => [ |
||
199 | 'getValue' => '%somevalue%', |
||
200 | ], |
||
201 | 'where.constraint.constraint[1].operand_dynamic' => [ |
||
202 | 'getAlias' => 'a', |
||
203 | 'getField' => 'somefield', |
||
204 | ], |
||
205 | 'where.constraint.constraint[1].operand_static' => [ |
||
206 | 'getValue' => '%somevalue%', |
||
207 | ], |
||
208 | ], |
||
209 | ]], |
||
210 | [[ |
||
211 | 'choiceType' => ChoiceType::TYPE_EQUAL, |
||
212 | 'value' => 'somevalue', |
||
213 | 'qbNodeCount' => 5, |
||
214 | 'assertPaths' => [ |
||
215 | 'where.constraint.constraint.operand_dynamic' => [ |
||
216 | 'getAlias' => 'a', |
||
217 | 'getField' => 'somefield', |
||
218 | ], |
||
219 | 'where.constraint.constraint.operand_static' => [ |
||
220 | 'getValue' => 'somevalue', |
||
221 | ], |
||
222 | 'where.constraint.constraint.operand_static' => [ |
||
223 | 'getValue' => 'somevalue', |
||
224 | ], |
||
225 | ], |
||
226 | ]], |
||
227 | [[ |
||
228 | 'choiceType' => ChoiceType::TYPE_EQUAL, |
||
229 | 'value' => ['somevalue', 'somevalue'], |
||
230 | 'qbNodeCount' => 8, |
||
231 | 'assertPaths' => [ |
||
232 | 'where.constraint.constraint.operand_dynamic' => [ |
||
233 | 'getAlias' => 'a', |
||
234 | 'getField' => 'somefield', |
||
235 | ], |
||
236 | 'where.constraint.constraint.operand_static' => [ |
||
237 | 'getValue' => 'somevalue', |
||
238 | ], |
||
239 | 'where.constraint.constraint[1].operand_dynamic' => [ |
||
240 | 'getAlias' => 'a', |
||
241 | 'getField' => 'somefield', |
||
242 | ], |
||
243 | 'where.constraint.constraint[1].operand_static' => [ |
||
244 | 'getValue' => 'somevalue', |
||
245 | ], |
||
246 | ], |
||
247 | ]], |
||
248 | ]; |
||
249 | } |
||
250 | |||
286 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: