Conditions | 17 |
Paths | 3888 |
Total Lines | 98 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
Bugs | 0 | Features | 7 |
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 |
||
120 | public function buildModelCriteria() |
||
121 | { |
||
122 | $query = DealerQuery::create(); |
||
123 | |||
124 | // manage translations |
||
125 | $this->configureI18nProcessing( |
||
126 | $query, |
||
127 | [ |
||
128 | 'TITLE', |
||
129 | 'DESCRIPTION', |
||
130 | 'ACCESS' |
||
131 | ], |
||
132 | null, |
||
133 | 'ID', |
||
134 | $this->getForceReturn() |
||
135 | ); |
||
136 | |||
137 | if ($id = $this->getId()) { |
||
138 | $query->filterById($id); |
||
139 | } |
||
140 | |||
141 | if ($country_id = $this->getCountryId()) { |
||
142 | $query->filterByCountryId($country_id); |
||
143 | } |
||
144 | |||
145 | if ($city = $this->getCity()) { |
||
146 | $query->filterByCity($city); |
||
147 | } |
||
148 | |||
149 | if($content = $this->getContentId()){ |
||
150 | if(is_array($content)){ |
||
151 | $content = implode(",", $content); |
||
152 | } |
||
153 | $contentJoin = new Join(DealerTableMap::ID,DealerContentTableMap::DEALER_ID,Criteria::LEFT_JOIN); |
||
154 | $query |
||
155 | ->addJoinObject($contentJoin) |
||
156 | ->where(DealerContentTableMap::CONTENT_ID." ".Criteria::IN." (".$content.")"); |
||
157 | ; |
||
158 | |||
159 | } |
||
160 | |||
161 | if($folder = $this->getFolderId()){ |
||
162 | if(is_array($folder)){ |
||
163 | $folder = implode(",", $folder); |
||
164 | } |
||
165 | $contentJoin = new Join(DealerTableMap::ID,DealerFolderTableMap::DEALER_ID,Criteria::LEFT_JOIN); |
||
166 | $query |
||
167 | ->addJoinObject($contentJoin) |
||
168 | ->where(DealerFolderTableMap::FOLDER_ID." ".Criteria::IN." (".$folder.")"); |
||
169 | ; |
||
170 | |||
171 | } |
||
172 | |||
173 | if($brand = $this->getBrandId()){ |
||
174 | if(is_array($brand)){ |
||
175 | $brand = implode(",", $brand); |
||
176 | } |
||
177 | $contentJoin = new Join(DealerTableMap::ID,DealerBrandTableMap::DEALER_ID,Criteria::LEFT_JOIN); |
||
178 | $query |
||
179 | ->addJoinObject($contentJoin) |
||
180 | ->where(DealerBrandTableMap::BRAND_ID." ".Criteria::IN." (".$brand.")"); |
||
181 | ; |
||
182 | |||
183 | } |
||
184 | |||
185 | if($product = $this->getProductId()){ |
||
186 | if(is_array($product)){ |
||
187 | $product = implode(",", $product); |
||
188 | } |
||
189 | $contentJoin = new Join(DealerTableMap::ID,DealerProductTableMap::DEALER_ID,Criteria::LEFT_JOIN); |
||
190 | $query |
||
191 | ->addJoinObject($contentJoin) |
||
192 | ->where(DealerProductTableMap::PRODUCT_ID." ".Criteria::IN." (".$product.")"); |
||
193 | ; |
||
194 | |||
195 | } |
||
196 | |||
197 | foreach ($this->getOrder() as $order) { |
||
198 | switch ($order) { |
||
199 | case 'id' : |
||
|
|||
200 | $query->orderById(); |
||
201 | break; |
||
202 | case 'id-reverse' : |
||
203 | $query->orderById(Criteria::DESC); |
||
204 | break; |
||
205 | case 'date' : |
||
206 | $query->orderByCreatedAt(); |
||
207 | break; |
||
208 | case 'date-reverse' : |
||
209 | $query->orderByCreatedAt(Criteria::DESC); |
||
210 | break; |
||
211 | default: |
||
212 | break; |
||
213 | } |
||
214 | } |
||
215 | |||
216 | return $query; |
||
217 | } |
||
218 | |||
274 | } |
As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.