Conditions | 18 |
Paths | 216 |
Total Lines | 47 |
Code Lines | 25 |
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 |
||
54 | protected function parseCriteria(array $criteria) |
||
55 | { |
||
56 | if (isset($criteria['blood_group_alternatives']) && $criteria['blood_group_alternatives']) { |
||
57 | if (isset($criteria['blood_group']) && is_string($criteria['blood_group'])) { |
||
58 | $criteria['blood_group'] = $this->findCompatibleRedBloodCellGroup($criteria['blood_group']); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | unset($criteria['blood_group_alternatives']); // Remove the alternative blood-groups criteria. |
||
63 | |||
64 | if (isset($criteria['blood_group']) && 'any' === $criteria['blood_group']) { |
||
65 | unset($criteria['blood_group']); // Remove the blood-group criteria. |
||
66 | } |
||
67 | |||
68 | if (isset($criteria['district']) && -1 == $criteria['district']) { |
||
69 | unset($criteria['district']); // Remove the district criteria. |
||
70 | } |
||
71 | |||
72 | if (isset($criteria['city']) && empty($criteria['district'])) { |
||
73 | $districts = []; |
||
74 | |||
75 | if ($criteria['city'] instanceof City) { |
||
76 | $districts = $criteria['city']->get('districts'); |
||
77 | } elseif (EBB\isValidID($criteria['city'])) { |
||
|
|||
78 | $em = $this->getEntityManager(); |
||
79 | $city = $em->find('Entities:City', $criteria['city']); |
||
80 | if (! empty($city)) { |
||
81 | $districts = $city->get('districts'); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | if (! empty($districts)) { |
||
86 | $criteria['district'] = []; |
||
87 | |||
88 | foreach ($districts as $district) { |
||
89 | $criteria['district'][] = (int) $district->get('id'); |
||
90 | } |
||
91 | } |
||
92 | } |
||
93 | |||
94 | unset($criteria['city']); // Remove the city criteria in any condition. |
||
95 | |||
96 | if (isset($criteria['status']) && 'any' === $criteria['status']) { |
||
97 | unset($criteria['status']); // Remove the status criteria. |
||
98 | } |
||
99 | |||
100 | return $criteria; |
||
101 | } |
||
144 |