File tree 3 files changed +35
-13
lines changed
tests/DependencyInjection/CompilerPass
3 files changed +35
-13
lines changed Original file line number Diff line number Diff line change 6
6
7
7
use ArrayIterator ;
8
8
use FilterIterator ;
9
- use ReflectionClass ;
10
9
use ReflectionMethod ;
11
10
12
11
use function assert ;
19
18
* @template TKey
20
19
* @template T
21
20
* @template TIterator as ArrayIterator<int, ReflectionMethod>
22
- *
23
21
* @extends FilterIterator<TKey, T, TIterator>
24
22
*/
25
23
class SorterBuilderKeyIterator extends FilterIterator
26
24
{
27
- /** @phpstan-param class-string $className */
28
- public function __construct (string $ className )
29
- {
30
- $ reflectionClass = new ReflectionClass ($ className );
31
- $ methods = $ reflectionClass ->getMethods (ReflectionMethod::IS_PUBLIC );
32
-
33
- parent ::__construct (new ArrayIterator ($ methods ));
34
- }
35
-
36
25
public function accept (): bool
37
26
{
38
27
return ! in_array ($ this ->current (), [
Original file line number Diff line number Diff line change 4
4
5
5
namespace Budgegeria \Bundle \IntlBundle \DependencyInjection ;
6
6
7
+ use ArrayIterator ;
7
8
use Budgegeria \Bundle \IntlBundle \DependencyInjection \CompilerPass \SorterBuilderKeyIterator ;
8
9
use Budgegeria \IntlSort \Builder ;
10
+ use ReflectionClass ;
11
+ use ReflectionMethod ;
9
12
use Symfony \Component \Config \Definition \Builder \NodeDefinition ;
10
13
use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
11
14
use Symfony \Component \Config \Definition \ConfigurationInterface ;
@@ -39,7 +42,8 @@ private function buildSorter(NodeDefinition $node): void
39
42
->arrayPrototype ()
40
43
->children ();
41
44
42
- foreach (new SorterBuilderKeyIterator (Builder::class) as $ sorterConfigNames ) {
45
+ $ methods = new ArrayIterator ($ this ->getClassMethods (Builder::class));
46
+ foreach (new SorterBuilderKeyIterator ($ methods ) as $ sorterConfigNames ) {
43
47
$ sorterChildren ->scalarNode ($ sorterConfigNames )->end ();
44
48
}
45
49
@@ -50,4 +54,16 @@ private function buildSorter(NodeDefinition $node): void
50
54
->end ()
51
55
->end ();
52
56
}
57
+
58
+ /**
59
+ * @phpstan-param class-string $className
60
+ *
61
+ * @phpstan-return list<ReflectionMethod>
62
+ */
63
+ private function getClassMethods (string $ className ): array
64
+ {
65
+ $ reflectionClass = new ReflectionClass ($ className );
66
+
67
+ return $ reflectionClass ->getMethods (ReflectionMethod::IS_PUBLIC );
68
+ }
53
69
}
Original file line number Diff line number Diff line change 4
4
5
5
namespace Budgegeria \Bundle \IntlBundle \Tests \DependencyInjection \CompilerPass ;
6
6
7
+ use ArrayIterator ;
7
8
use Budgegeria \Bundle \IntlBundle \DependencyInjection \CompilerPass \SorterBuilderKeyIterator ;
8
9
use Budgegeria \IntlSort \Builder ;
9
10
use PHPUnit \Framework \TestCase ;
11
+ use ReflectionClass ;
12
+ use ReflectionMethod ;
10
13
11
14
use function array_values ;
12
15
use function iterator_to_array ;
@@ -15,7 +18,9 @@ class SorterBuilderKeyIteratorTest extends TestCase
15
18
{
16
19
public function testIterationContent (): void
17
20
{
18
- $ sorterKeys = iterator_to_array (new SorterBuilderKeyIterator (Builder::class));
21
+ $ sorterKeys = iterator_to_array (new SorterBuilderKeyIterator (
22
+ new ArrayIterator ($ this ->getMethods (Builder::class)),
23
+ ));
19
24
$ expected = [
20
25
'enable_french_collation ' ,
21
26
'disable_french_collation ' ,
@@ -48,4 +53,16 @@ public function testIterationContent(): void
48
53
49
54
self ::assertEquals ($ expected , array_values ($ sorterKeys ));
50
55
}
56
+
57
+ /**
58
+ * @phpstan-param class-string $className
59
+ *
60
+ * @phpstan-return list<ReflectionMethod>
61
+ */
62
+ private function getMethods (string $ className ): array
63
+ {
64
+ $ reflectionClass = new ReflectionClass ($ className );
65
+
66
+ return $ reflectionClass ->getMethods (ReflectionMethod::IS_PUBLIC );
67
+ }
51
68
}
You can’t perform that action at this time.
0 commit comments