Conditions | 3 |
Paths | 4 |
Total Lines | 61 |
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 |
||
68 | public function createShopListQueryBuilder( |
||
69 | ChannelInterface $channel, |
||
70 | TaxonInterface $taxon, |
||
71 | string $locale, |
||
72 | array $sorting = [], |
||
73 | bool $includeAllDescendants = false |
||
74 | ): QueryBuilder { |
||
75 | $queryBuilder = $this->createQueryBuilder('o') |
||
76 | ->addSelect('translation') |
||
77 | ->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale') |
||
78 | ->innerJoin('o.productTaxons', 'productTaxon'); |
||
79 | |||
80 | if ($includeAllDescendants) { |
||
81 | $queryBuilder |
||
82 | ->innerJoin('productTaxon.taxon', 'taxon') |
||
83 | ->andWhere('taxon.left >= :taxonLeft') |
||
84 | ->andWhere('taxon.right <= :taxonRight') |
||
85 | ->andWhere('taxon.root = :taxonRoot') |
||
86 | ->setParameter('taxonLeft', $taxon->getLeft()) |
||
87 | ->setParameter('taxonRight', $taxon->getRight()) |
||
88 | ->setParameter('taxonRoot', $taxon->getRoot()) |
||
89 | ; |
||
90 | } else { |
||
91 | $queryBuilder |
||
92 | ->andWhere('productTaxon.taxon = :taxon') |
||
93 | ->setParameter('taxon', $taxon) |
||
94 | ; |
||
95 | } |
||
96 | |||
97 | $queryBuilder |
||
98 | ->andWhere(':channel MEMBER OF o.channels') |
||
99 | ->andWhere('o.enabled = true') |
||
100 | ->setParameter('locale', $locale) |
||
101 | ->setParameter('channel', $channel) |
||
102 | ; |
||
103 | |||
104 | // Grid hack, we do not need to join these if we don't sort by price |
||
105 | if (isset($sorting['price'])) { |
||
106 | // Another hack, the subquery to get the first position variant |
||
107 | $subQuery = $this->createQueryBuilder('m') |
||
108 | ->select('min(v.position)') |
||
109 | ->innerJoin('m.variants', 'v') |
||
110 | ->andWhere('m.id = :product_id') |
||
111 | ; |
||
112 | |||
113 | $queryBuilder |
||
114 | ->innerJoin('o.variants', 'variant') |
||
115 | ->innerJoin('variant.channelPricings', 'channelPricing') |
||
116 | ->andWhere('channelPricing.channelCode = :channelCode') |
||
117 | ->andWhere( |
||
118 | $queryBuilder->expr()->in( |
||
119 | 'variant.position', |
||
120 | str_replace(':product_id', 'o.id', $subQuery->getDQL()) |
||
121 | ) |
||
122 | ) |
||
123 | ->setParameter('channelCode', $channel->getCode()) |
||
124 | ; |
||
125 | } |
||
126 | |||
127 | return $queryBuilder; |
||
128 | } |
||
129 | |||
193 |