| Conditions | 13 |
| Paths | 432 |
| Total Lines | 73 |
| Code Lines | 46 |
| 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 |
||
| 111 | public function buildModelCriteria() |
||
| 112 | { |
||
| 113 | $query = DealerQuery::create(); |
||
| 114 | |||
| 115 | // manage translations |
||
| 116 | $this->configureI18nProcessing( |
||
| 117 | $query, |
||
| 118 | [ |
||
| 119 | 'TITLE', |
||
| 120 | 'DESCRIPTION' |
||
| 121 | ], |
||
| 122 | null, |
||
| 123 | 'ID', |
||
| 124 | $this->getForceReturn() |
||
| 125 | ); |
||
| 126 | |||
| 127 | if ($id = $this->getId()) { |
||
| 128 | $query->filterById($id); |
||
| 129 | } |
||
| 130 | |||
| 131 | if ($country_id = $this->getCountryId()) { |
||
| 132 | $query->filterByCountryId($country_id); |
||
| 133 | } |
||
| 134 | |||
| 135 | if ($city = $this->getCity()) { |
||
| 136 | $query->filterByCity($city); |
||
| 137 | } |
||
| 138 | |||
| 139 | if($content = $this->getContentId()){ |
||
| 140 | if(is_array($content)){ |
||
| 141 | $content = implode(",", $content); |
||
| 142 | } |
||
| 143 | $contentJoin = new Join(DealerTableMap::ID,DealerContentTableMap::DEALER_ID,Criteria::LEFT_JOIN); |
||
| 144 | $query |
||
| 145 | ->addJoinObject($contentJoin) |
||
| 146 | ->where(DealerContentTableMap::CONTENT_ID." ".Criteria::IN." (".$content.")"); |
||
| 147 | ; |
||
| 148 | |||
| 149 | } |
||
| 150 | |||
| 151 | if($folder = $this->getFolderId()){ |
||
| 152 | if(is_array($folder)){ |
||
| 153 | $folder = implode(",", $folder); |
||
| 154 | } |
||
| 155 | $contentJoin = new Join(DealerTableMap::ID,DealerFolderTableMap::DEALER_ID,Criteria::LEFT_JOIN); |
||
| 156 | $query |
||
| 157 | ->addJoinObject($contentJoin) |
||
| 158 | ->where(DealerFolderTableMap::FOLDER_ID." ".Criteria::IN." (".$folder.")"); |
||
| 159 | ; |
||
| 160 | |||
| 161 | } |
||
| 162 | |||
| 163 | foreach ($this->getOrder() as $order) { |
||
| 164 | switch ($order) { |
||
| 165 | case 'id' : |
||
|
|
|||
| 166 | $query->orderById(); |
||
| 167 | break; |
||
| 168 | case 'id-reverse' : |
||
| 169 | $query->orderById(Criteria::DESC); |
||
| 170 | break; |
||
| 171 | case 'date' : |
||
| 172 | $query->orderByCreatedAt(); |
||
| 173 | break; |
||
| 174 | case 'date-reverse' : |
||
| 175 | $query->orderByCreatedAt(Criteria::DESC); |
||
| 176 | break; |
||
| 177 | default: |
||
| 178 | break; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | return $query; |
||
| 183 | } |
||
| 184 | |||
| 240 | } |
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.