@@ -67,6 +67,8 @@ public function getAppliedFilters(string $type = null): array
6767 return \is_array ($ query ) ? array_filter ($ query ) : $ query ;
6868 }, $ requestQuery );
6969
70+ $ this ->manageRangeField ('price ' );
71+
7072 return null !== $ type ? ($ requestQuery [$ type ] ?? []) : $ requestQuery ;
7173 }
7274
@@ -82,6 +84,41 @@ public function getPage(): int
8284 return (int ) $ this ->request ->get ('page ' , 1 );
8385 }
8486
87+ /**
88+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
89+ */
90+ public function manageRangeField (string $ field ): void
91+ {
92+ $ range = $ this ->request ->get ($ field , []);
93+ if (!\is_array ($ range ) || empty ($ range )) {
94+ return ;
95+ }
96+
97+ /** @var array $range */
98+
99+ // Reverse min and max if min is greater than max
100+ if (isset ($ range ['min ' ], $ range ['max ' ])) {
101+ $ min = (float ) $ range ['min ' ];
102+ $ max = (float ) $ range ['max ' ];
103+ if ($ min > $ max ) {
104+ $ range ['min ' ] = $ range ['max ' ];
105+ $ range ['max ' ] = $ range ['min ' ];
106+ }
107+ }
108+
109+ // Remove min value is 0 or less
110+ if (isset ($ range ['min ' ]) && 0 >= (float ) $ range ['min ' ]) {
111+ unset($ range ['min ' ]);
112+ }
113+
114+ // Remove max value if it is 0 or less
115+ if (isset ($ range ['max ' ]) && 0 >= (float ) $ range ['max ' ]) {
116+ unset($ range ['max ' ]);
117+ }
118+
119+ $ this ->request ->query ->set ($ field , $ range );
120+ }
121+
85122 public function getLimit (): int
86123 {
87124 /** @phpstan-ignore-next-line */
0 commit comments