| Conditions | 21 |
| Paths | > 20000 |
| Total Lines | 110 |
| 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 |
||
| 130 | public function buildModelCriteria() |
||
| 131 | { |
||
| 132 | $query = DealerQuery::create(); |
||
| 133 | |||
| 134 | // manage translations |
||
| 135 | $this->configureI18nProcessing( |
||
| 136 | $query, |
||
| 137 | [ |
||
| 138 | 'TITLE', |
||
| 139 | 'DESCRIPTION', |
||
| 140 | 'ACCESS', |
||
| 141 | 'BIG_DESCRIPTION', |
||
| 142 | 'HARD_OPEN_HOUR' |
||
| 143 | ], |
||
| 144 | null, |
||
| 145 | 'ID', |
||
| 146 | $this->getForceReturn() |
||
| 147 | ); |
||
| 148 | |||
| 149 | if (null != $id = $this->getId()) { |
||
| 150 | $query->filterById($id); |
||
| 151 | } |
||
| 152 | |||
| 153 | if (null != $country_id = $this->getCountryId()) { |
||
| 154 | $query->filterByCountryId($country_id); |
||
| 155 | } |
||
| 156 | |||
| 157 | if (null != $city = $this->getCity()) { |
||
| 158 | $query->filterByCity($city); |
||
| 159 | } |
||
| 160 | |||
| 161 | if (null != $visible = $this->getVisible()) { |
||
| 162 | $query->filterByVisible($visible); |
||
| 163 | } |
||
| 164 | |||
| 165 | if ($content = $this->getContentId()) { |
||
| 166 | if (is_array($content)) { |
||
| 167 | $content = implode(",", $content); |
||
| 168 | } |
||
| 169 | $contentJoin = new Join(DealerTableMap::ID, DealerContentTableMap::DEALER_ID, Criteria::LEFT_JOIN); |
||
| 170 | $query |
||
| 171 | ->addJoinObject($contentJoin) |
||
| 172 | ->where(DealerContentTableMap::CONTENT_ID." ".Criteria::IN." (".$content.")"); |
||
| 173 | ; |
||
| 174 | } |
||
| 175 | |||
| 176 | if ($folder = $this->getFolderId()) { |
||
| 177 | if (is_array($folder)) { |
||
| 178 | $folder = implode(",", $folder); |
||
| 179 | } |
||
| 180 | $contentJoin = new Join(DealerTableMap::ID, DealerFolderTableMap::DEALER_ID, Criteria::LEFT_JOIN); |
||
| 181 | $query |
||
| 182 | ->addJoinObject($contentJoin) |
||
| 183 | ->where(DealerFolderTableMap::FOLDER_ID." ".Criteria::IN." (".$folder.")"); |
||
| 184 | ; |
||
| 185 | } |
||
| 186 | |||
| 187 | if ($brand = $this->getBrandId()) { |
||
| 188 | if (is_array($brand)) { |
||
| 189 | $brand = implode(",", $brand); |
||
| 190 | } |
||
| 191 | $contentJoin = new Join(DealerTableMap::ID, DealerBrandTableMap::DEALER_ID, Criteria::LEFT_JOIN); |
||
| 192 | $query |
||
| 193 | ->addJoinObject($contentJoin) |
||
| 194 | ->where(DealerBrandTableMap::BRAND_ID." ".Criteria::IN." (".$brand.")"); |
||
| 195 | ; |
||
| 196 | } |
||
| 197 | |||
| 198 | if ($product = $this->getProductId()) { |
||
| 199 | if (is_array($product)) { |
||
| 200 | $product = implode(",", $product); |
||
| 201 | } |
||
| 202 | $contentJoin = new Join(DealerTableMap::ID, DealerProductTableMap::DEALER_ID, Criteria::LEFT_JOIN); |
||
| 203 | $query |
||
| 204 | ->addJoinObject($contentJoin) |
||
| 205 | ->where(DealerProductTableMap::PRODUCT_ID." ".Criteria::IN." (".$product.")"); |
||
| 206 | ; |
||
| 207 | } |
||
| 208 | |||
| 209 | if ($this->getBackendContext() === true) { |
||
| 210 | $query =$this->getAdminDealer($query); |
||
| 211 | } |
||
| 212 | |||
| 213 | foreach ($this->getOrder() as $order) { |
||
| 214 | switch ($order) { |
||
| 215 | case 'id' : |
||
| 216 | $query->orderById(); |
||
| 217 | break; |
||
| 218 | case 'id-reverse' : |
||
| 219 | $query->orderById(Criteria::DESC); |
||
| 220 | break; |
||
| 221 | case 'date' : |
||
| 222 | $query->orderByCreatedAt(); |
||
| 223 | break; |
||
| 224 | case 'date-reverse' : |
||
| 225 | $query->orderByCreatedAt(Criteria::DESC); |
||
| 226 | break; |
||
| 227 | case 'title' : |
||
| 228 | $query->useDealerI18nQuery()->orderByTitle()->endUse(); |
||
| 229 | break; |
||
| 230 | case 'title-reverse' : |
||
| 231 | $query->useDealerI18nQuery()->orderByTitle(Criteria::DESC)->endUse(); |
||
| 232 | break; |
||
| 233 | default: |
||
| 234 | break; |
||
| 235 | } |
||
| 236 | } |
||
| 237 | |||
| 238 | return $query; |
||
| 239 | } |
||
| 240 | |||
| 326 |