1414use Phake \IMock ;
1515use PHPUnit \Framework \Attributes \DataProvider ;
1616use PHPUnit \Framework \TestCase ;
17+
18+ use function array_values ;
1719use function in_array ;
1820
1921final class SearchTest extends TestCase
@@ -31,7 +33,7 @@ public function testICanBuildSearchObjects(): void
3133 self ::assertArrayHasKey ('empty ' , $ list );
3234 self ::assertArrayHasKey ('withData ' , $ list );
3335 self ::assertArrayHasKey ('withNestedData ' , $ list );
34- [$ searchA , $ searchB , $ searchC ] = $ list ;
36+ [$ searchA , $ searchB , $ searchC ] = array_values ( $ list) ;
3537
3638 self ::assertSame ('empty ' , $ searchA ->getName ());
3739 self ::assertSame ([], $ searchA ->getConfig ());
@@ -46,28 +48,28 @@ public function testICanBuildSearchObjects(): void
4648 */
4749 public static function provideSearchAndMetrics (): Generator
4850 {
49- [$ search ] = Search::buildListFromArray (['test ' => []]);
51+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => []]);
5052 $ metric = Phake::mock (Metric::class);
5153 $ checkCallback = static function (IMock &Metric $ metric ): void {
5254 Phake::verifyNoInteraction ($ metric );
5355 };
5456 yield 'No search configuration ' => [$ metric , $ search , false , $ checkCallback ];
5557
56- [$ search ] = Search::buildListFromArray (['test ' => ['type ' => 'class ' ]]);
58+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['type ' => 'class ' ]]);
5759 $ metric = Phake::mock (Metric::class);
5860 $ checkCallback = static function (IMock &Metric $ metric ): void {
5961 Phake::verifyNoInteraction ($ metric );
6062 };
6163 yield 'Search type "class", none found ' => [$ metric , $ search , false , $ checkCallback ];
6264
63- [$ search ] = Search::buildListFromArray (['test ' => ['type ' => 'class ' ]]);
65+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['type ' => 'class ' ]]);
6466 $ metric = Phake::mock (ClassMetric::class);
6567 $ checkCallback = static function (IMock &Metric $ metric ): void {
6668 Phake::verifyNoInteraction ($ metric );
6769 };
6870 yield 'Search type "class", found ' => [$ metric , $ search , true , $ checkCallback ];
6971
70- [$ search ] = Search::buildListFromArray (['test ' => ['type ' => 'class ' , 'failIfFound ' => true ]]);
72+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['type ' => 'class ' , 'failIfFound ' => true ]]);
7173 $ metric = Phake::mock (ClassMetric::class);
7274 Phake::when ($ metric )->__call ('get ' , ['was-not-expected-by ' ])->thenReturn (null );
7375 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -78,28 +80,28 @@ public static function provideSearchAndMetrics(): Generator
7880 };
7981 yield 'Search type "class", found. Fail if found. ' => [$ metric , $ search , true , $ checkCallback ];
8082
81- [$ search ] = Search::buildListFromArray (['test ' => ['type ' => 'class ' ]]);
83+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['type ' => 'class ' ]]);
8284 $ metric = Phake::mock (InterfaceMetric::class);
8385 $ checkCallback = static function (IMock &Metric $ metric ): void {
8486 Phake::verifyNoInteraction ($ metric );
8587 };
8688 yield 'Search type "class", interface found ' => [$ metric , $ search , false , $ checkCallback ];
8789
88- [$ search ] = Search::buildListFromArray (['test ' => ['type ' => 'interface ' ]]);
90+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['type ' => 'interface ' ]]);
8991 $ metric = Phake::mock (Metric::class);
9092 $ checkCallback = static function (IMock &Metric $ metric ): void {
9193 Phake::verifyNoInteraction ($ metric );
9294 };
9395 yield 'Search type "interface", none found ' => [$ metric , $ search , false , $ checkCallback ];
9496
95- [$ search ] = Search::buildListFromArray (['test ' => ['type ' => 'interface ' ]]);
97+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['type ' => 'interface ' ]]);
9698 $ metric = Phake::mock (InterfaceMetric::class);
9799 $ checkCallback = static function (IMock &Metric $ metric ): void {
98100 Phake::verifyNoInteraction ($ metric );
99101 };
100102 yield 'Search type "interface", found ' => [$ metric , $ search , true , $ checkCallback ];
101103
102- [$ search ] = Search::buildListFromArray (['test ' => ['type ' => 'interface ' , 'failIfFound ' => true ]]);
104+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['type ' => 'interface ' , 'failIfFound ' => true ]]);
103105 $ metric = Phake::mock (InterfaceMetric::class);
104106 Phake::when ($ metric )->__call ('get ' , ['was-not-expected-by ' ])->thenReturn (null );
105107 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -110,7 +112,7 @@ public static function provideSearchAndMetrics(): Generator
110112 };
111113 yield 'Search type "interface", found. Fail if found. ' => [$ metric , $ search , true , $ checkCallback ];
112114
113- [$ search ] = Search::buildListFromArray (['test ' => ['nameMatches ' => '^a|b|c$ ' ]]);
115+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['nameMatches ' => '^a|b|c$ ' ]]);
114116 $ metric = Phake::mock (Metric::class);
115117 Phake::when ($ metric )->__call ('getName ' , [])->thenReturn ('d ' );
116118 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -119,7 +121,7 @@ public static function provideSearchAndMetrics(): Generator
119121 };
120122 yield 'Search name matches, but does not match ' => [$ metric , $ search , false , $ checkCallback ];
121123
122- [$ search ] = Search::buildListFromArray (['test ' => ['nameMatches ' => '^a|b|c$ ' ]]);
124+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['nameMatches ' => '^a|b|c$ ' ]]);
123125 $ metric = Phake::mock (Metric::class);
124126 Phake::when ($ metric )->__call ('getName ' , [])->thenReturn ('B ' );
125127 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -128,7 +130,9 @@ public static function provideSearchAndMetrics(): Generator
128130 };
129131 yield 'Search name matches, and matches ' => [$ metric , $ search , true , $ checkCallback ];
130132
131- [$ search ] = Search::buildListFromArray (['test ' => ['nameMatches ' => '^a|b|c$ ' , 'failIfFound ' => true ]]);
133+ ['test ' => $ search ] = Search::buildListFromArray (
134+ ['test ' => ['nameMatches ' => '^a|b|c$ ' , 'failIfFound ' => true ]]
135+ );
132136 $ metric = Phake::mock (Metric::class);
133137 Phake::when ($ metric )->__call ('getName ' , [])->thenReturn ('B ' );
134138 Phake::when ($ metric )->__call ('get ' , ['was-not-expected-by ' ])->thenReturn (null );
@@ -141,7 +145,7 @@ public static function provideSearchAndMetrics(): Generator
141145 };
142146 yield 'Search name matches, and matches. Fail if found. ' => [$ metric , $ search , true , $ checkCallback ];
143147
144- [$ search ] = Search::buildListFromArray (['test ' => ['instanceOf ' => ['\\A ' , 'B ' ]]]);
148+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['instanceOf ' => ['\\A ' , 'B ' ]]]);
145149 $ metric = Phake::mock (Metric::class);
146150 Phake::when ($ metric )->__call ('get ' , ['implements ' ])->thenReturn ('' );
147151 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -150,7 +154,7 @@ public static function provideSearchAndMetrics(): Generator
150154 };
151155 yield 'Search instance of, none found ' => [$ metric , $ search , false , $ checkCallback ];
152156
153- [$ search ] = Search::buildListFromArray (['test ' => ['instanceOf ' => ['\\A ' , 'B ' ]]]);
157+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['instanceOf ' => ['\\A ' , 'B ' ]]]);
154158 $ metric = Phake::mock (Metric::class);
155159 Phake::when ($ metric )->__call ('get ' , ['implements ' ])->thenReturn (['A ' ]);
156160 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -159,7 +163,7 @@ public static function provideSearchAndMetrics(): Generator
159163 };
160164 yield 'Search instance of, but only 1 ' => [$ metric , $ search , false , $ checkCallback ];
161165
162- [$ search ] = Search::buildListFromArray (['test ' => ['instanceOf ' => ['\\A ' , 'B ' ]]]);
166+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['instanceOf ' => ['\\A ' , 'B ' ]]]);
163167 $ metric = Phake::mock (Metric::class);
164168 Phake::when ($ metric )->__call ('get ' , ['implements ' ])->thenReturn (['A ' , 'B ' ]);
165169 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -168,7 +172,9 @@ public static function provideSearchAndMetrics(): Generator
168172 };
169173 yield 'Search instance of, and got all ' => [$ metric , $ search , true , $ checkCallback ];
170174
171- [$ search ] = Search::buildListFromArray (['test ' => ['instanceOf ' => ['\\A ' , 'B ' ], 'failIfFound ' => true ]]);
175+ ['test ' => $ search ] = Search::buildListFromArray (
176+ ['test ' => ['instanceOf ' => ['\\A ' , 'B ' ], 'failIfFound ' => true ]]
177+ );
172178 $ metric = Phake::mock (Metric::class);
173179 Phake::when ($ metric )->__call ('get ' , ['implements ' ])->thenReturn (['A ' , 'B ' ]);
174180 Phake::when ($ metric )->__call ('get ' , ['was-not-expected-by ' ])->thenReturn (null );
@@ -181,7 +187,7 @@ public static function provideSearchAndMetrics(): Generator
181187 };
182188 yield 'Search instance of, and got all. Fail if found. ' => [$ metric , $ search , true , $ checkCallback ];
183189
184- [$ search ] = Search::buildListFromArray (['test ' => ['instanceOf ' => ['\\A ' , 'B ' ]]]);
190+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['instanceOf ' => ['\\A ' , 'B ' ]]]);
185191 $ metric = Phake::mock (Metric::class);
186192 Phake::when ($ metric )->__call ('get ' , ['implements ' ])->thenReturn (['A ' , 'B ' , 'C ' ]);
187193 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -190,7 +196,9 @@ public static function provideSearchAndMetrics(): Generator
190196 };
191197 yield 'Search instance of, and got more than all ' => [$ metric , $ search , true , $ checkCallback ];
192198
193- [$ search ] = Search::buildListFromArray (['test ' => ['instanceOf ' => ['\\A ' , 'B ' ], 'failIfFound ' => true ]]);
199+ ['test ' => $ search ] = Search::buildListFromArray (
200+ ['test ' => ['instanceOf ' => ['\\A ' , 'B ' ], 'failIfFound ' => true ]]
201+ );
194202 $ metric = Phake::mock (Metric::class);
195203 Phake::when ($ metric )->__call ('get ' , ['implements ' ])->thenReturn (['A ' , 'B ' , 'C ' ]);
196204 Phake::when ($ metric )->__call ('get ' , ['was-not-expected-by ' ])->thenReturn (null );
@@ -203,7 +211,7 @@ public static function provideSearchAndMetrics(): Generator
203211 };
204212 yield 'Search instance of, and got more than all. Fail if found. ' => [$ metric , $ search , true , $ checkCallback ];
205213
206- [$ search ] = Search::buildListFromArray (['test ' => ['usesClasses ' => ['^(A|B)$ ' , '^C ' , 'D$ ' ]]]);
214+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['usesClasses ' => ['^(A|B)$ ' , '^C ' , 'D$ ' ]]]);
207215 $ metric = Phake::mock (Metric::class);
208216 Phake::when ($ metric )->__call ('get ' , ['externals ' ])->thenReturn ('' );
209217 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -212,7 +220,7 @@ public static function provideSearchAndMetrics(): Generator
212220 };
213221 yield 'Search uses of, none found ' => [$ metric , $ search , false , $ checkCallback ];
214222
215- [$ search ] = Search::buildListFromArray (['test ' => ['usesClasses ' => ['^(A|B)$ ' , '^C ' , 'D$ ' ]]]);
223+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['usesClasses ' => ['^(A|B)$ ' , '^C ' , 'D$ ' ]]]);
216224 $ metric = Phake::mock (Metric::class);
217225 Phake::when ($ metric )->__call ('get ' , ['externals ' ])->thenReturn (['XxX ' , 'xXx ' , 'xxx ' , 'XXX ' ]);
218226 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -221,7 +229,7 @@ public static function provideSearchAndMetrics(): Generator
221229 };
222230 yield 'Search uses of, none found but externals exist ' => [$ metric , $ search , false , $ checkCallback ];
223231
224- [$ search ] = Search::buildListFromArray (['test ' => ['usesClasses ' => ['^(A|B)$ ' , '^C ' , 'D$ ' ]]]);
232+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['usesClasses ' => ['^(A|B)$ ' , '^C ' , 'D$ ' ]]]);
225233 $ metric = Phake::mock (Metric::class);
226234 Phake::when ($ metric )->__call ('get ' , ['externals ' ])->thenReturn (['b ' ]);
227235 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -230,7 +238,7 @@ public static function provideSearchAndMetrics(): Generator
230238 };
231239 yield 'Search uses of, found 1st time ' => [$ metric , $ search , true , $ checkCallback ];
232240
233- [$ search ] = Search::buildListFromArray (['test ' => ['usesClasses ' => ['^(A|B)$ ' , '^C ' , 'D$ ' ]]]);
241+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['usesClasses ' => ['^(A|B)$ ' , '^C ' , 'D$ ' ]]]);
234242 $ metric = Phake::mock (Metric::class);
235243 Phake::when ($ metric )->__call ('get ' , ['externals ' ])->thenReturn (['XxX ' , 'classThatWorks ' ]);
236244 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -239,7 +247,7 @@ public static function provideSearchAndMetrics(): Generator
239247 };
240248 yield 'Search uses of, found 2nd time ' => [$ metric , $ search , true , $ checkCallback ];
241249
242- [$ search ] = Search::buildListFromArray (['test ' => ['usesClasses ' => ['^(A|B)$ ' , '^C ' , 'D$ ' ]]]);
250+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['usesClasses ' => ['^(A|B)$ ' , '^C ' , 'D$ ' ]]]);
243251 $ metric = Phake::mock (Metric::class);
244252 Phake::when ($ metric )->__call ('get ' , ['externals ' ])->thenReturn (['XxX ' , 'xXx ' , 'NowWeEnd ' ]);
245253 $ checkCallback = static function (IMock &Metric $ metric ): void {
@@ -248,7 +256,7 @@ public static function provideSearchAndMetrics(): Generator
248256 };
249257 yield 'Search uses of, found 3rd time ' => [$ metric , $ search , true , $ checkCallback ];
250258
251- [$ search ] = Search::buildListFromArray (
259+ [' test ' => $ search ] = Search::buildListFromArray (
252260 ['test ' => ['usesClasses ' => ['^(A|B)$ ' , '^C ' , 'D$ ' ], 'failIfFound ' => true ]]
253261 );
254262 $ metric = Phake::mock (Metric::class);
@@ -267,7 +275,7 @@ public static function provideSearchAndMetrics(): Generator
267275 foreach (Registry::allForStructures () as $ structName ) {
268276 // Represent every managed operator that passes the regex check. Added ">=<" for default case.
269277 foreach (['' , '= ' , '> ' , '< ' , '>= ' , '=> ' , '<= ' , '=< ' , '>=< ' ] as $ operator ) {
270- [$ search ] = Search::buildListFromArray (['test ' => [$ structName => $ operator . '0.5 ' ]]);
278+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => [$ structName => $ operator . '0.5 ' ]]);
271279 $ metric = Phake::mock (Metric::class);
272280 Phake::when ($ metric )->__call ('get ' , [$ structName ])->thenReturn (0.5 );
273281 $ match = in_array ($ operator , ['' , '= ' , '>= ' , '=> ' , '<= ' , '=< ' ], true );
@@ -278,7 +286,7 @@ public static function provideSearchAndMetrics(): Generator
278286 yield 'Search ' . $ structName . ', operator " ' . $ operator . '", metric is same value ' =>
279287 [$ metric , $ search , $ match , $ checkCallback ];
280288
281- [$ search ] = Search::buildListFromArray (['test ' => [$ structName => $ operator . '0.5 ' ]]);
289+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => [$ structName => $ operator . '0.5 ' ]]);
282290 $ metric = Phake::mock (Metric::class);
283291 Phake::when ($ metric )->__call ('get ' , [$ structName ])->thenReturn (0.3 );
284292 $ match = in_array ($ operator , ['<= ' , '< ' , '=< ' ], true );
@@ -289,7 +297,7 @@ public static function provideSearchAndMetrics(): Generator
289297 yield 'Search ' . $ structName . ', operator " ' . $ operator . '", metric is less ' =>
290298 [$ metric , $ search , $ match , $ checkCallback ];
291299
292- [$ search ] = Search::buildListFromArray (['test ' => [$ structName => $ operator . '0.5 ' ]]);
300+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => [$ structName => $ operator . '0.5 ' ]]);
293301 $ metric = Phake::mock (Metric::class);
294302 Phake::when ($ metric )->__call ('get ' , [$ structName ])->thenReturn (2.8 );
295303 $ match = in_array ($ operator , ['>= ' , '> ' , '=> ' ], true );
@@ -323,7 +331,7 @@ public function testICanMatchSearchesWithMetrics(
323331
324332 public function testExceptionIsThrownWhenCustomSearchMetricsIsInvalid (): void
325333 {
326- [$ search ] = Search::buildListFromArray (['test ' => ['loc ' => '= invalidValue ' ]]);
334+ [' test ' => $ search ] = Search::buildListFromArray (['test ' => ['loc ' => '= invalidValue ' ]]);
327335 $ metric = Phake::mock (Metric::class);
328336
329337 $ this ->expectExceptionObject (SearchValidationException::invalidCustomMetricComparison ('= invalidValue ' ));
0 commit comments