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