@@ -83,7 +83,8 @@ public function __construct(
8383 QueryBuilderInterface $ hasPriceBetweenQueryBuilder ,
8484 string $ optionPropertyPrefix ,
8585 string $ attributePropertyPrefix
86- ) {
86+ )
87+ {
8788 $ this ->isEnabledQueryBuilder = $ isEnabledQueryBuilder ;
8889 $ this ->hasChannelQueryBuilder = $ hasChannelQueryBuilder ;
8990 $ this ->containsNameQueryBuilder = $ containsNameQueryBuilder ;
@@ -105,17 +106,14 @@ public function buildQuery(array $data): AbstractQuery
105106 $ boolQuery ->addMust ($ this ->isEnabledQueryBuilder ->buildQuery ($ data ));
106107 $ boolQuery ->addMust ($ this ->hasChannelQueryBuilder ->buildQuery ($ data ));
107108
108- if ($ nameQuery = $ this ->containsNameQueryBuilder ->buildQuery ($ data )) {
109- $ boolQuery ->addMust ($ nameQuery );
110- }
109+ $ nameQuery = $ this ->containsNameQueryBuilder ->buildQuery ($ data );
110+ $ this ->addMustIfNotNull ($ nameQuery , $ boolQuery );
111111
112- if ($ taxonQuery = $ this ->hasTaxonQueryBuilder ->buildQuery ($ data )) {
113- $ boolQuery ->addMust ($ taxonQuery );
114- }
112+ $ taxonQuery = $ this ->hasTaxonQueryBuilder ->buildQuery ($ data );
113+ $ this ->addMustIfNotNull ($ taxonQuery , $ boolQuery );
115114
116- if ($ priceQuery = $ this ->hasPriceBetweenQueryBuilder ->buildQuery ($ data )) {
117- $ boolQuery ->addMust ($ priceQuery );
118- }
115+ $ priceQuery = $ this ->hasPriceBetweenQueryBuilder ->buildQuery ($ data );
116+ $ this ->addMustIfNotNull ($ priceQuery , $ boolQuery );
119117
120118 $ this ->resolveOptionQuery ($ boolQuery , $ data );
121119 $ this ->resolveAttributeQuery ($ boolQuery , $ data );
@@ -152,4 +150,14 @@ private function resolveAttributeQuery(BoolQuery $boolQuery, array $data): void
152150 }
153151 }
154152 }
153+
154+ /**
155+ * @param AbstractQuery|null $query
156+ * @param BoolQuery $boolQuery
157+ */
158+ private function addMustIfNotNull (?AbstractQuery $ query , BoolQuery $ boolQuery ): void {
159+ if (null !== $ query ) {
160+ $ boolQuery ->addMust ($ query );
161+ }
162+ }
155163}
0 commit comments