Conditions | 13 |
Paths | 192 |
Total Lines | 53 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 4 |
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 buildModelCriteria() |
||
114 | { |
||
115 | $query = DealerShedulesQuery::create(); |
||
116 | |||
117 | if ($id = $this->getId()) { |
||
118 | $query->filterById($id); |
||
119 | } |
||
120 | |||
121 | if ($day = $this->getDay()) { |
||
122 | $query->filterByDay($day); |
||
123 | } |
||
124 | |||
125 | if ($dealer_id = $this->getDealerId()) { |
||
126 | $query->filterByDealerId($dealer_id); |
||
127 | } |
||
128 | |||
129 | if ($this->getDefaultPeriod()) { |
||
130 | $query->filterByPeriodNull(); |
||
131 | } else { |
||
132 | $query->filterByPeriodNotNull(); |
||
133 | if($this->getHidePast()) |
||
134 | $query->filterByPeriodEnd(new \DateTime(),Criteria::GREATER_THAN); |
||
135 | } |
||
136 | |||
137 | $query->filterByClosed($this->getClosed()); |
||
138 | |||
139 | foreach ($this->getOrder() as $order) { |
||
140 | switch ($order) { |
||
141 | case 'id': |
||
142 | $query->orderById(); |
||
143 | break; |
||
144 | case 'id-reverse': |
||
145 | $query->orderById(Criteria::DESC); |
||
146 | break; |
||
147 | case 'day': |
||
148 | $query->orderByDay(); |
||
149 | break; |
||
150 | case 'day-reverse': |
||
151 | $query->orderByDay(Criteria::DESC); |
||
152 | break; |
||
153 | case 'begin': |
||
154 | $query->orderByBegin(); |
||
155 | break; |
||
156 | case 'begin-reverse': |
||
157 | $query->orderByBegin(Criteria::DESC); |
||
158 | break; |
||
159 | default: |
||
160 | break; |
||
161 | } |
||
162 | } |
||
163 | |||
164 | return $query; |
||
165 | } |
||
166 | |||
179 | } |