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