@@ -135,8 +135,6 @@ protected function validateOrder(PersistentCollection $value, CategoriesConstrai
135
135
$ isIncreasing = $ this ->isIncreasing ($ orderedByIndex );
136
136
$ orderedByValueArray = $ value ->toArray ();
137
137
138
- $ isValid = true ;
139
-
140
138
if ($ isIncreasing ) {
141
139
$ inversion = 1 ;
142
140
$ criteria = Criteria::ASC ;
@@ -145,21 +143,7 @@ protected function validateOrder(PersistentCollection $value, CategoriesConstrai
145
143
$ criteria = Criteria::DESC ;
146
144
}
147
145
148
- usort (
149
- $ orderedByValueArray ,
150
- function (RFMMetricCategory $ item1 , RFMMetricCategory $ item2 ) use (&$ isValid , $ inversion ) {
151
- $ minValue1 = $ item1 ->getMinValue ();
152
- $ minValue2 = $ item2 ->getMinValue ();
153
-
154
- if ($ minValue1 === $ minValue2 ||
155
- (!is_null ($ item1 ->getMaxValue ()) && $ item1 ->getMaxValue () <= $ minValue1 )) {
156
- $ isValid = false ;
157
- }
158
-
159
- return (($ minValue1 < $ minValue2 ) ? 1 : -1 ) * $ inversion ;
160
- }
161
- );
162
-
146
+ $ isValid = $ this ->orderByValue ($ orderedByValueArray , $ inversion );
163
147
if (!$ isValid || $ orderedByValueArray !== $ orderedByIndex ->toArray ()) {
164
148
$ this ->context ->addViolationAt ($ constraint ->getType (), $ constraint ->message , ['%order% ' => $ criteria ]);
165
149
}
@@ -182,4 +166,31 @@ protected function isIncreasing(Collection $orderedByIndex)
182
166
return is_null ($ orderedByIndex ->first ()->getMinValue ())
183
167
&& is_null ($ orderedByIndex ->last ()->getMaxValue ());
184
168
}
169
+
170
+ /**
171
+ * @param array $value
172
+ * @param int $inversion
173
+ *
174
+ * @return boolean
175
+ */
176
+ protected function orderByValue (array &$ value , $ inversion )
177
+ {
178
+ $ isValid = true ;
179
+ uasort (
180
+ $ value ,
181
+ function (RFMMetricCategory $ item1 , RFMMetricCategory $ item2 ) use (&$ isValid , $ inversion ) {
182
+ $ minValue1 = $ item1 ->getMinValue ();
183
+ $ minValue2 = $ item2 ->getMinValue ();
184
+
185
+ if ($ minValue1 === $ minValue2 ||
186
+ (!is_null ($ item1 ->getMaxValue ()) && $ item1 ->getMaxValue () <= $ minValue1 )) {
187
+ $ isValid = false ;
188
+ }
189
+
190
+ return (($ minValue1 < $ minValue2 ) ? -1 : 1 ) * $ inversion ;
191
+ }
192
+ );
193
+
194
+ return $ isValid ;
195
+ }
185
196
}
0 commit comments