@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | //The alias has to be uniq for each subquery, so generate a random one |
54 | 54 | $this->alias = uniqid('param_', false); |
55 | 55 | |
56 | - $this->value_text = new TextConstraint($this->alias . '.value_text'); |
|
57 | - $this->value = new ParameterValueConstraint($this->alias ); |
|
56 | + $this->value_text = new TextConstraint($this->alias.'.value_text'); |
|
57 | + $this->value = new ParameterValueConstraint($this->alias); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public function isEnabled(): bool |
@@ -69,26 +69,26 @@ discard block |
||
69 | 69 | |
70 | 70 | |
71 | 71 | |
72 | - $subqb->select('COUNT(' . $this->alias . ')') |
|
72 | + $subqb->select('COUNT('.$this->alias.')') |
|
73 | 73 | ->from(PartParameter::class, $this->alias) |
74 | - ->where($this->alias . '.element = part'); |
|
74 | + ->where($this->alias.'.element = part'); |
|
75 | 75 | |
76 | 76 | if (!empty($this->name)) { |
77 | 77 | $paramName = $this->generateParameterIdentifier('params.name'); |
78 | - $subqb->andWhere($this->alias . '.name = :' . $paramName); |
|
79 | - $queryBuilder->setParameter($paramName, $this->name); |
|
78 | + $subqb->andWhere($this->alias.'.name = :'.$paramName); |
|
79 | + $queryBuilder->setParameter($paramName, $this->name); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | if (!empty($this->symbol)) { |
83 | 83 | $paramName = $this->generateParameterIdentifier('params.symbol'); |
84 | - $subqb->andWhere($this->alias . '.symbol = :' . $paramName); |
|
85 | - $queryBuilder->setParameter($paramName, $this->symbol); |
|
84 | + $subqb->andWhere($this->alias.'.symbol = :'.$paramName); |
|
85 | + $queryBuilder->setParameter($paramName, $this->symbol); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | if (!empty($this->unit)) { |
89 | 89 | $paramName = $this->generateParameterIdentifier('params.unit'); |
90 | - $subqb->andWhere($this->alias . '.unit = :' . $paramName); |
|
91 | - $queryBuilder->setParameter($paramName, $this->unit); |
|
90 | + $subqb->andWhere($this->alias.'.unit = :'.$paramName); |
|
91 | + $queryBuilder->setParameter($paramName, $this->unit); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | //Apply all subfilters |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $queryBuilder->setParameter($parameter->getName(), $parameter->getValue()); |
102 | 102 | } |
103 | 103 | |
104 | - $queryBuilder->andWhere('(' . $subqb->getDQL() . ') > 0'); |
|
104 | + $queryBuilder->andWhere('('.$subqb->getDQL().') > 0'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -102,34 +102,34 @@ |
||
102 | 102 | */ |
103 | 103 | protected function getExpressionForTag(QueryBuilder $queryBuilder, string $tag): Expr\Orx |
104 | 104 | { |
105 | - $tag_identifier_prefix = uniqid($this->identifier . '_', false); |
|
105 | + $tag_identifier_prefix = uniqid($this->identifier.'_', false); |
|
106 | 106 | |
107 | 107 | $expr = $queryBuilder->expr(); |
108 | 108 | |
109 | 109 | $tmp = $expr->orX( |
110 | - $expr->like($this->property, ':' . $tag_identifier_prefix . '_1'), |
|
111 | - $expr->like($this->property, ':' . $tag_identifier_prefix . '_2'), |
|
112 | - $expr->like($this->property, ':' . $tag_identifier_prefix . '_3'), |
|
113 | - $expr->eq($this->property, ':' . $tag_identifier_prefix . '_4'), |
|
110 | + $expr->like($this->property, ':'.$tag_identifier_prefix.'_1'), |
|
111 | + $expr->like($this->property, ':'.$tag_identifier_prefix.'_2'), |
|
112 | + $expr->like($this->property, ':'.$tag_identifier_prefix.'_3'), |
|
113 | + $expr->eq($this->property, ':'.$tag_identifier_prefix.'_4'), |
|
114 | 114 | ); |
115 | 115 | |
116 | 116 | //Set the parameters for the LIKE expression, in each variation of the tag (so with a comma, at the end, at the beginning, and on both ends, and equaling the tag) |
117 | - $queryBuilder->setParameter($tag_identifier_prefix . '_1', '%,' . $tag . ',%'); |
|
118 | - $queryBuilder->setParameter($tag_identifier_prefix . '_2', '%,' . $tag); |
|
119 | - $queryBuilder->setParameter($tag_identifier_prefix . '_3', $tag . ',%'); |
|
120 | - $queryBuilder->setParameter($tag_identifier_prefix . '_4', $tag); |
|
117 | + $queryBuilder->setParameter($tag_identifier_prefix.'_1', '%,'.$tag.',%'); |
|
118 | + $queryBuilder->setParameter($tag_identifier_prefix.'_2', '%,'.$tag); |
|
119 | + $queryBuilder->setParameter($tag_identifier_prefix.'_3', $tag.',%'); |
|
120 | + $queryBuilder->setParameter($tag_identifier_prefix.'_4', $tag); |
|
121 | 121 | |
122 | 122 | return $tmp; |
123 | 123 | } |
124 | 124 | |
125 | 125 | public function apply(QueryBuilder $queryBuilder): void |
126 | 126 | { |
127 | - if(!$this->isEnabled()) { |
|
127 | + if (!$this->isEnabled()) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 | |
131 | - if(!in_array($this->operator, self::ALLOWED_OPERATOR_VALUES, true)) { |
|
132 | - throw new \RuntimeException('Invalid operator '. $this->operator . ' provided. Valid operators are '. implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
131 | + if (!in_array($this->operator, self::ALLOWED_OPERATOR_VALUES, true)) { |
|
132 | + throw new \RuntimeException('Invalid operator '.$this->operator.' provided. Valid operators are '.implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | $tagsExpressions = []; |
@@ -37,13 +37,13 @@ |
||
37 | 37 | public function __construct(string $alias) { |
38 | 38 | $this->alias = $alias; |
39 | 39 | |
40 | - parent::__construct($alias . '.value_typical'); |
|
40 | + parent::__construct($alias.'.value_typical'); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | public function apply(QueryBuilder $queryBuilder): void |
44 | 44 | { |
45 | 45 | //Skip if not enabled |
46 | - if(!$this->isEnabled()) { |
|
46 | + if (!$this->isEnabled()) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 |
@@ -90,25 +90,25 @@ |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | //Ensure we have an valid operator |
93 | - if(!in_array($this->operator, self::ALLOWED_OPERATOR_VALUES, true)) { |
|
94 | - throw new \RuntimeException('Invalid operator '. $this->operator . ' provided. Valid operators are '. implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
93 | + if (!in_array($this->operator, self::ALLOWED_OPERATOR_VALUES, true)) { |
|
94 | + throw new \RuntimeException('Invalid operator '.$this->operator.' provided. Valid operators are '.implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | $expressions = []; |
98 | 98 | |
99 | 99 | if ($this->operator === 'ANY' || $this->operator === 'NONE') { |
100 | - foreach($this->value as $value) { |
|
100 | + foreach ($this->value as $value) { |
|
101 | 101 | //We cannnot use an paramater here, as this is the only way to pass the FCQN to the query (via binded params, we would need to use ClassMetaData). See: https://github.com/doctrine/orm/issues/4462 |
102 | 102 | $expressions[] = ($queryBuilder->expr()->isInstanceOf($this->property, $value)); |
103 | 103 | } |
104 | 104 | |
105 | - if($this->operator === 'ANY') { |
|
105 | + if ($this->operator === 'ANY') { |
|
106 | 106 | $queryBuilder->andWhere($queryBuilder->expr()->orX(...$expressions)); |
107 | 107 | } else { //NONE |
108 | 108 | $queryBuilder->andWhere($queryBuilder->expr()->not($queryBuilder->expr()->orX(...$expressions))); |
109 | 109 | } |
110 | 110 | } else { |
111 | - throw new \RuntimeException('Unknown operator '. $this->operator . ' provided. Valid operators are '. implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
111 | + throw new \RuntimeException('Unknown operator '.$this->operator.' provided. Valid operators are '.implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | } |
115 | 115 | \ No newline at end of file |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | public function setValue(?AbstractDBElement $value): void |
112 | 112 | { |
113 | 113 | if (!$value instanceof $this->class) { |
114 | - throw new \InvalidArgumentException('The value must be an instance of ' . $this->class); |
|
114 | + throw new \InvalidArgumentException('The value must be an instance of '.$this->class); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | $this->value = $value; |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | //Ensure we have an valid operator |
158 | - if(!in_array($this->operator, $this->getAllowedOperatorValues(), true)) { |
|
159 | - throw new \RuntimeException('Invalid operator '. $this->operator . ' provided. Valid operators are '. implode(', ', $this->getAllowedOperatorValues())); |
|
158 | + if (!in_array($this->operator, $this->getAllowedOperatorValues(), true)) { |
|
159 | + throw new \RuntimeException('Invalid operator '.$this->operator.' provided. Valid operators are '.implode(', ', $this->getAllowedOperatorValues())); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | //We need to handle null values differently, as they can not be compared with == or != |
163 | 163 | if ($this->value === null) { |
164 | - if($this->operator === '=' || $this->operator === 'INCLUDING_CHILDREN') { |
|
164 | + if ($this->operator === '=' || $this->operator === 'INCLUDING_CHILDREN') { |
|
165 | 165 | $queryBuilder->andWhere(sprintf("%s IS NULL", $this->property)); |
166 | 166 | return; |
167 | 167 | } |
@@ -171,16 +171,16 @@ discard block |
||
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
174 | - throw new \RuntimeException('Unknown operator '. $this->operator . ' provided. Valid operators are '. implode(', ', $this->getAllowedOperatorValues())); |
|
174 | + throw new \RuntimeException('Unknown operator '.$this->operator.' provided. Valid operators are '.implode(', ', $this->getAllowedOperatorValues())); |
|
175 | 175 | } |
176 | 176 | |
177 | - if($this->operator === '=' || $this->operator === '!=') { |
|
177 | + if ($this->operator === '=' || $this->operator === '!=') { |
|
178 | 178 | $this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier, $this->operator, $this->value); |
179 | 179 | return; |
180 | 180 | } |
181 | 181 | |
182 | 182 | //Otherwise retrieve the children list and apply the operator to it |
183 | - if($this->isStructural()) { |
|
183 | + if ($this->isStructural()) { |
|
184 | 184 | $list = $this->nodesListBuilder->getChildrenFlatList($this->value); |
185 | 185 | //Add the element itself to the list |
186 | 186 | $list[] = $this->value; |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | return; |
196 | 196 | } |
197 | 197 | } else { |
198 | - throw new \RuntimeException('Cannot apply operator '. $this->operator . ' to non-structural type'); |
|
198 | + throw new \RuntimeException('Cannot apply operator '.$this->operator.' to non-structural type'); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | } |
@@ -117,19 +117,19 @@ |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | //Ensure we have an valid operator |
120 | - if(!in_array($this->operator, self::ALLOWED_OPERATOR_VALUES, true)) { |
|
121 | - throw new \RuntimeException('Invalid operator '. $this->operator . ' provided. Valid operators are '. implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
120 | + if (!in_array($this->operator, self::ALLOWED_OPERATOR_VALUES, true)) { |
|
121 | + throw new \RuntimeException('Invalid operator '.$this->operator.' provided. Valid operators are '.implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | if ($this->operator !== 'BETWEEN') { |
125 | 125 | $this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier, $this->operator, $this->value1); |
126 | - } else { |
|
126 | + } else { |
|
127 | 127 | if ($this->value2 === null) { |
128 | 128 | throw new RuntimeException("Cannot use operator BETWEEN without value2!"); |
129 | 129 | } |
130 | 130 | |
131 | - $this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier . '1', '>=', $this->value1); |
|
132 | - $this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier . '2', '<=', $this->value2); |
|
131 | + $this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier.'1', '>=', $this->value1); |
|
132 | + $this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier.'2', '<=', $this->value2); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
136 | 136 | \ No newline at end of file |
@@ -123,7 +123,7 @@ |
||
123 | 123 | |
124 | 124 | if ($this->operator !== 'BETWEEN') { |
125 | 125 | $this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier, $this->operator, $this->value1); |
126 | - } else { |
|
126 | + } else { |
|
127 | 127 | if ($this->value2 === null) { |
128 | 128 | throw new RuntimeException("Cannot use operator BETWEEN without value2!"); |
129 | 129 | } |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | //Ensure we have an valid operator |
90 | - if(!in_array($this->operator, self::ALLOWED_OPERATOR_VALUES, true)) { |
|
91 | - throw new \RuntimeException('Invalid operator '. $this->operator . ' provided. Valid operators are '. implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
90 | + if (!in_array($this->operator, self::ALLOWED_OPERATOR_VALUES, true)) { |
|
91 | + throw new \RuntimeException('Invalid operator '.$this->operator.' provided. Valid operators are '.implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | if ($this->operator === 'ANY') { |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | } elseif ($this->operator === 'NONE') { |
97 | 97 | $this->addSimpleAndConstraint($queryBuilder, $this->property, $this->identifier, 'NOT IN', $this->value); |
98 | 98 | } else { |
99 | - throw new \RuntimeException('Unknown operator '. $this->operator . ' provided. Valid operators are '. implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
99 | + throw new \RuntimeException('Unknown operator '.$this->operator.' provided. Valid operators are '.implode(', ', self::ALLOWED_OPERATOR_VALUES)); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
103 | 103 | \ No newline at end of file |
@@ -74,34 +74,34 @@ discard block |
||
74 | 74 | { |
75 | 75 | $fields_to_search = []; |
76 | 76 | |
77 | - if($this->name) { |
|
77 | + if ($this->name) { |
|
78 | 78 | $fields_to_search[] = 'part.name'; |
79 | 79 | } |
80 | - if($this->category) { |
|
80 | + if ($this->category) { |
|
81 | 81 | $fields_to_search[] = 'category.name'; |
82 | 82 | } |
83 | - if($this->description) { |
|
83 | + if ($this->description) { |
|
84 | 84 | $fields_to_search[] = 'part.description'; |
85 | 85 | } |
86 | - if($this->tags) { |
|
86 | + if ($this->tags) { |
|
87 | 87 | $fields_to_search[] = 'part.tags'; |
88 | 88 | } |
89 | - if($this->storelocation) { |
|
89 | + if ($this->storelocation) { |
|
90 | 90 | $fields_to_search[] = 'storelocations.name'; |
91 | 91 | } |
92 | - if($this->ordernr) { |
|
92 | + if ($this->ordernr) { |
|
93 | 93 | $fields_to_search[] = 'orderdetails.supplierpartnr'; |
94 | 94 | } |
95 | - if($this->mpn) { |
|
95 | + if ($this->mpn) { |
|
96 | 96 | $fields_to_search[] = 'part.manufacturer_product_url'; |
97 | 97 | } |
98 | - if($this->supplier) { |
|
98 | + if ($this->supplier) { |
|
99 | 99 | $fields_to_search[] = 'suppliers.name'; |
100 | 100 | } |
101 | - if($this->manufacturer) { |
|
101 | + if ($this->manufacturer) { |
|
102 | 102 | $fields_to_search[] = 'manufacturer.name'; |
103 | 103 | } |
104 | - if($this->footprint) { |
|
104 | + if ($this->footprint) { |
|
105 | 105 | $fields_to_search[] = 'footprint.name'; |
106 | 106 | } |
107 | 107 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | //Convert the fields to search to a list of expressions |
121 | - $expressions = array_map(function (string $field) { |
|
121 | + $expressions = array_map(function(string $field) { |
|
122 | 122 | if ($this->regex) { |
123 | 123 | return sprintf("REGEXP(%s, :search_query) = 1", $field); |
124 | 124 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | if ($this->regex) { |
136 | 136 | $queryBuilder->setParameter('search_query', $this->keyword); |
137 | 137 | } else { |
138 | - $queryBuilder->setParameter('search_query', '%' . $this->keyword . '%'); |
|
138 | + $queryBuilder->setParameter('search_query', '%'.$this->keyword.'%'); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 |
@@ -42,15 +42,15 @@ |
||
42 | 42 | |
43 | 43 | $value = $property->getValue($this); |
44 | 44 | //We only want filters (objects implementing FilterInterface) |
45 | - if($value instanceof FilterInterface) { |
|
45 | + if ($value instanceof FilterInterface) { |
|
46 | 46 | $filters[$property->getName()] = $value; |
47 | 47 | } |
48 | 48 | |
49 | 49 | //Add filters in collections |
50 | 50 | if ($value instanceof Collection) { |
51 | 51 | foreach ($value as $key => $filter) { |
52 | - if($filter instanceof FilterInterface) { |
|
53 | - $filters[$property->getName() . '.' . (string) $key] = $filter; |
|
52 | + if ($filter instanceof FilterInterface) { |
|
53 | + $filters[$property->getName().'.'.(string) $key] = $filter; |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | } |