| Conditions | 6 |
| Paths | 6 |
| Total Lines | 52 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 50 | public function buildModelCriteria() |
||
| 51 | { |
||
| 52 | $localequery = LangQuery::create()->findOneById($this->getLang()); |
||
| 53 | $locale = $localequery->getLocale(); |
||
| 54 | $cat = ucfirst($this->getCategorie()); |
||
| 55 | $objectQuery = null; |
||
| 56 | $urlJoin = null; |
||
| 57 | |||
| 58 | switch ($cat) { |
||
| 59 | case 'Product': |
||
| 60 | $objectQuery = ProductQuery::create(); |
||
| 61 | $urlJoin = new Join(ProductTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN); |
||
| 62 | break; |
||
| 63 | case 'Brand': |
||
| 64 | $objectQuery = BrandQuery::create(); |
||
| 65 | $urlJoin = new Join(BrandTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN); |
||
| 66 | break; |
||
| 67 | case 'Category': |
||
| 68 | $objectQuery = CategoryQuery::create(); |
||
| 69 | $urlJoin = new Join(CategoryTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN); |
||
| 70 | break; |
||
| 71 | case 'Folder': |
||
| 72 | $objectQuery = FolderQuery::create(); |
||
| 73 | $urlJoin = new Join(FolderTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN); |
||
| 74 | break; |
||
| 75 | case 'Content': |
||
| 76 | $objectQuery = ContentQuery::create(); |
||
| 77 | $urlJoin = new Join(ContentTableMap::ID, RewritingUrlTableMap::VIEW_ID, Criteria::LEFT_JOIN); |
||
| 78 | break; |
||
| 79 | } |
||
| 80 | |||
| 81 | $query = $objectQuery |
||
| 82 | ->joinWithI18n($locale) |
||
| 83 | ->addJoinObject($urlJoin, 'url_rewriting_join') |
||
| 84 | ->addJoinCondition( |
||
| 85 | 'url_rewriting_join', |
||
| 86 | RewritingUrlTableMap::VIEW . ' = ?', |
||
| 87 | strtolower($cat), |
||
| 88 | null, |
||
| 89 | \PDO::PARAM_STR |
||
| 90 | ) |
||
| 91 | ->addJoinCondition( |
||
| 92 | 'url_rewriting_join', |
||
| 93 | RewritingUrlTableMap::VIEW_LOCALE . ' = ?', |
||
| 94 | $locale, |
||
| 95 | null, |
||
| 96 | \PDO::PARAM_STR |
||
| 97 | ) |
||
| 98 | ->where('ISNULL(rewriting_url.id)') |
||
| 99 | ; |
||
| 100 | return $query; |
||
| 101 | } |
||
| 102 | |||
| 118 | } |