Conditions | 1 |
Paths | 1 |
Total Lines | 196 |
Code Lines | 141 |
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 |
||
113 | public function providerForTestGetPermissionsCriterion() |
||
114 | { |
||
115 | $criterionMock = $this |
||
116 | ->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\Query\\Criterion') |
||
117 | ->disableOriginalConstructor() |
||
118 | ->getMock(); |
||
119 | $limitationMock = $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\User\\Limitation'); |
||
120 | $limitationMock |
||
121 | ->expects($this->any()) |
||
122 | ->method('getIdentifier') |
||
123 | ->will($this->returnValue('limitationIdentifier')); |
||
124 | |||
125 | $policy1 = new Policy(array('limitations' => array($limitationMock))); |
||
126 | $policy2 = new Policy(array('limitations' => array($limitationMock, $limitationMock))); |
||
127 | |||
128 | return array( |
||
129 | array( |
||
130 | $criterionMock, |
||
131 | 1, |
||
132 | array( |
||
133 | array( |
||
134 | 'limitation' => null, |
||
135 | 'policies' => array($policy1), |
||
136 | ), |
||
137 | ), |
||
138 | $criterionMock, |
||
139 | ), |
||
140 | array( |
||
141 | $criterionMock, |
||
142 | 2, |
||
143 | array( |
||
144 | array( |
||
145 | 'limitation' => null, |
||
146 | 'policies' => array($policy1, $policy1), |
||
147 | ), |
||
148 | ), |
||
149 | new Criterion\LogicalOr(array($criterionMock, $criterionMock)), |
||
150 | ), |
||
151 | array( |
||
152 | $criterionMock, |
||
153 | 1, |
||
154 | array( |
||
155 | array( |
||
156 | 'limitation' => null, |
||
157 | 'policies' => array(new Policy(array('limitations' => '*')), $policy1), |
||
158 | ), |
||
159 | ), |
||
160 | $criterionMock, |
||
161 | ), |
||
162 | array( |
||
163 | $criterionMock, |
||
164 | 1, |
||
165 | array( |
||
166 | array( |
||
167 | 'limitation' => null, |
||
168 | 'policies' => array(new Policy(array('limitations' => array())), $policy1), |
||
169 | ), |
||
170 | ), |
||
171 | $criterionMock, |
||
172 | ), |
||
173 | array( |
||
174 | $criterionMock, |
||
175 | 2, |
||
176 | array( |
||
177 | array( |
||
178 | 'limitation' => null, |
||
179 | 'policies' => array($policy2), |
||
180 | ), |
||
181 | ), |
||
182 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
||
183 | ), |
||
184 | array( |
||
185 | $criterionMock, |
||
186 | 3, |
||
187 | array( |
||
188 | array( |
||
189 | 'limitation' => null, |
||
190 | 'policies' => array($policy1, $policy2), |
||
191 | ), |
||
192 | ), |
||
193 | new Criterion\LogicalOr( |
||
194 | array( |
||
195 | $criterionMock, |
||
196 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
||
197 | ) |
||
198 | ), |
||
199 | ), |
||
200 | array( |
||
201 | $criterionMock, |
||
202 | 2, |
||
203 | array( |
||
204 | array( |
||
205 | 'limitation' => null, |
||
206 | 'policies' => array($policy1), |
||
207 | ), |
||
208 | array( |
||
209 | 'limitation' => null, |
||
210 | 'policies' => array($policy1), |
||
211 | ), |
||
212 | ), |
||
213 | new Criterion\LogicalOr(array($criterionMock, $criterionMock)), |
||
214 | ), |
||
215 | array( |
||
216 | $criterionMock, |
||
217 | 3, |
||
218 | array( |
||
219 | array( |
||
220 | 'limitation' => null, |
||
221 | 'policies' => array($policy1), |
||
222 | ), |
||
223 | array( |
||
224 | 'limitation' => null, |
||
225 | 'policies' => array($policy1, $policy1), |
||
226 | ), |
||
227 | ), |
||
228 | new Criterion\LogicalOr(array($criterionMock, $criterionMock, $criterionMock)), |
||
229 | ), |
||
230 | array( |
||
231 | $criterionMock, |
||
232 | 3, |
||
233 | array( |
||
234 | array( |
||
235 | 'limitation' => null, |
||
236 | 'policies' => array($policy2), |
||
237 | ), |
||
238 | array( |
||
239 | 'limitation' => null, |
||
240 | 'policies' => array($policy1), |
||
241 | ), |
||
242 | ), |
||
243 | new Criterion\LogicalOr( |
||
244 | array( |
||
245 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
||
246 | $criterionMock, |
||
247 | ) |
||
248 | ), |
||
249 | ), |
||
250 | array( |
||
251 | $criterionMock, |
||
252 | 2, |
||
253 | array( |
||
254 | array( |
||
255 | 'limitation' => $limitationMock, |
||
256 | 'policies' => array($policy1), |
||
257 | ), |
||
258 | ), |
||
259 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
||
260 | ), |
||
261 | array( |
||
262 | $criterionMock, |
||
263 | 4, |
||
264 | array( |
||
265 | array( |
||
266 | 'limitation' => $limitationMock, |
||
267 | 'policies' => array($policy1), |
||
268 | ), |
||
269 | array( |
||
270 | 'limitation' => $limitationMock, |
||
271 | 'policies' => array($policy1), |
||
272 | ), |
||
273 | ), |
||
274 | new Criterion\LogicalOr( |
||
275 | array( |
||
276 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
||
277 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
||
278 | ) |
||
279 | ), |
||
280 | ), |
||
281 | array( |
||
282 | $criterionMock, |
||
283 | 1, |
||
284 | array( |
||
285 | array( |
||
286 | 'limitation' => $limitationMock, |
||
287 | 'policies' => array(new Policy(array('limitations' => '*'))), |
||
288 | ), |
||
289 | ), |
||
290 | $criterionMock, |
||
291 | ), |
||
292 | array( |
||
293 | $criterionMock, |
||
294 | 2, |
||
295 | array( |
||
296 | array( |
||
297 | 'limitation' => $limitationMock, |
||
298 | 'policies' => array(new Policy(array('limitations' => '*'))), |
||
299 | ), |
||
300 | array( |
||
301 | 'limitation' => $limitationMock, |
||
302 | 'policies' => array(new Policy(array('limitations' => '*'))), |
||
303 | ), |
||
304 | ), |
||
305 | new Criterion\LogicalOr(array($criterionMock, $criterionMock)), |
||
306 | ), |
||
307 | ); |
||
308 | } |
||
309 | |||
420 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.