@@ -17,5 +17,5 @@ |
||
17 | 17 | * results. |
18 | 18 | * @return \ReflectionClass[] |
19 | 19 | */ |
20 | - public function getScopedInterfaces(string $scope, string|null $target = null): array; |
|
20 | + public function getScopedInterfaces(string $scope, string | null $target = null): array; |
|
21 | 21 | } |
@@ -8,10 +8,10 @@ |
||
8 | 8 | { |
9 | 9 | public function __construct( |
10 | 10 | private readonly Tokenizer $tokenizer |
11 | - ) { |
|
11 | + ){ |
|
12 | 12 | } |
13 | 13 | |
14 | - public function getScopedInterfaces(string $scope, string|null $target = null): array |
|
14 | + public function getScopedInterfaces(string $scope, string | null $target = null): array |
|
15 | 15 | { |
16 | 16 | return $this->tokenizer->scopedInterfaceLocator($scope)->getInterfaces($target); |
17 | 17 | } |
@@ -16,7 +16,7 @@ |
||
16 | 16 | { |
17 | 17 | public function __construct( |
18 | 18 | private readonly Tokenizer $tokenizer |
19 | - ) { |
|
19 | + ){ |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -18,7 +18,7 @@ |
||
18 | 18 | private readonly InterfaceLocatorByTarget $locator, |
19 | 19 | ListenerInvoker $invoker, |
20 | 20 | bool $readCache = true, |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | parent::__construct($reader, $memory, $invoker, $readCache); |
23 | 23 | } |
24 | 24 |
@@ -18,7 +18,7 @@ |
||
18 | 18 | private readonly EnumLocatorByTarget $locator, |
19 | 19 | ListenerInvoker $invoker, |
20 | 20 | bool $readCache = true, |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | parent::__construct($reader, $memory, $invoker, $readCache); |
23 | 23 | } |
24 | 24 |
@@ -29,7 +29,8 @@ discard block |
||
29 | 29 | $targets = \iterator_to_array($this->parseAttributes($listener)); |
30 | 30 | |
31 | 31 | // If there are no targets, then listener can't be cached. |
32 | - if ($targets === []) { |
|
32 | + if ($targets === []) |
|
33 | + { |
|
33 | 34 | return false; |
34 | 35 | } |
35 | 36 | |
@@ -38,11 +39,13 @@ discard block |
||
38 | 39 | // We decided to load classes/enums/interfaces for each target separately. |
39 | 40 | // It allows us to cache classes/enums/interfaces for each target separately and if we reuse the |
40 | 41 | // same target in multiple listeners, we will not have to load classes/enums/interfaces for the same target. |
41 | - foreach ($targets as $target) { |
|
42 | + foreach ($targets as $target) |
|
43 | + { |
|
42 | 44 | $cacheKey = $this->cacheKeyPrefix . $target; |
43 | 45 | |
44 | 46 | $classes = $this->readCache ? $this->memory->loadData($cacheKey) : null; |
45 | - if ($classes === null) { |
|
47 | + if ($classes === null) |
|
48 | + { |
|
46 | 49 | $this->memory->saveData($cacheKey, $classes = call_user_func($locator, $target)); |
47 | 50 | } |
48 | 51 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | protected readonly MemoryInterface $memory, |
19 | 19 | protected readonly ListenerInvoker $invoker, |
20 | 20 | protected readonly bool $readCache = true, |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | protected function doLoad( |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $targets = \iterator_to_array($this->parseAttributes($listener)); |
30 | 30 | |
31 | 31 | // If there are no targets, then listener can't be cached. |
32 | - if ($targets === []) { |
|
32 | + if ($targets === []){ |
|
33 | 33 | return false; |
34 | 34 | } |
35 | 35 | |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | // We decided to load classes/enums/interfaces for each target separately. |
39 | 39 | // It allows us to cache classes/enums/interfaces for each target separately and if we reuse the |
40 | 40 | // same target in multiple listeners, we will not have to load classes/enums/interfaces for the same target. |
41 | - foreach ($targets as $target) { |
|
42 | - $cacheKey = $this->cacheKeyPrefix . $target; |
|
41 | + foreach ($targets as $target){ |
|
42 | + $cacheKey = $this->cacheKeyPrefix.$target; |
|
43 | 43 | |
44 | 44 | $classes = $this->readCache ? $this->memory->loadData($cacheKey) : null; |
45 | - if ($classes === null) { |
|
45 | + if ($classes === null){ |
|
46 | 46 | $this->memory->saveData($cacheKey, $classes = call_user_func($locator, $target)); |
47 | 47 | } |
48 | 48 |
@@ -16,7 +16,7 @@ |
||
16 | 16 | private readonly ClassLocatorByTarget $locator, |
17 | 17 | ListenerInvoker $invoker, |
18 | 18 | bool $readCache = true, |
19 | - ) { |
|
19 | + ){ |
|
20 | 20 | parent::__construct($reader, $memory, $invoker, $readCache); |
21 | 21 | } |
22 | 22 |
@@ -13,18 +13,18 @@ discard block |
||
13 | 13 | { |
14 | 14 | public const INJECTOR = InterfaceLocatorInjector::class; |
15 | 15 | |
16 | - public function getInterfaces(string|null $target = null): array |
|
16 | + public function getInterfaces(string | null $target = null): array |
|
17 | 17 | { |
18 | - if (!empty($target)) { |
|
18 | + if (!empty($target)){ |
|
19 | 19 | $target = new \ReflectionClass($target); |
20 | 20 | } |
21 | 21 | |
22 | 22 | $result = []; |
23 | - foreach ($this->availableInterfaces() as $interface) { |
|
24 | - try { |
|
23 | + foreach ($this->availableInterfaces() as $interface){ |
|
24 | + try{ |
|
25 | 25 | $reflection = $this->classReflection($interface); |
26 | - } catch (LocatorException $e) { |
|
27 | - if ($this->debug) { |
|
26 | + }catch (LocatorException $e){ |
|
27 | + if ($this->debug){ |
|
28 | 28 | throw $e; |
29 | 29 | } |
30 | 30 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | continue; |
33 | 33 | } |
34 | 34 | |
35 | - if (!$this->isTargeted($reflection, $target)) { |
|
35 | + if (!$this->isTargeted($reflection, $target)){ |
|
36 | 36 | continue; |
37 | 37 | } |
38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | { |
52 | 52 | $interfaces = []; |
53 | 53 | |
54 | - foreach ($this->availableReflections() as $reflection) { |
|
54 | + foreach ($this->availableReflections() as $reflection){ |
|
55 | 55 | $interfaces = \array_merge($interfaces, $reflection->getInterfaces()); |
56 | 56 | } |
57 | 57 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function isTargeted(\ReflectionClass $class, \ReflectionClass $target = null): bool |
67 | 67 | { |
68 | - if (empty($target)) { |
|
68 | + if (empty($target)){ |
|
69 | 69 | return true; |
70 | 70 | } |
71 | 71 |
@@ -15,16 +15,22 @@ discard block |
||
15 | 15 | |
16 | 16 | public function getInterfaces(string|null $target = null): array |
17 | 17 | { |
18 | - if (!empty($target)) { |
|
18 | + if (!empty($target)) |
|
19 | + { |
|
19 | 20 | $target = new \ReflectionClass($target); |
20 | 21 | } |
21 | 22 | |
22 | 23 | $result = []; |
23 | - foreach ($this->availableInterfaces() as $interface) { |
|
24 | - try { |
|
24 | + foreach ($this->availableInterfaces() as $interface) |
|
25 | + { |
|
26 | + try |
|
27 | + { |
|
25 | 28 | $reflection = $this->classReflection($interface); |
26 | - } catch (LocatorException $e) { |
|
27 | - if ($this->debug) { |
|
29 | + } |
|
30 | + catch (LocatorException $e) |
|
31 | + { |
|
32 | + if ($this->debug) |
|
33 | + { |
|
28 | 34 | throw $e; |
29 | 35 | } |
30 | 36 | |
@@ -32,7 +38,8 @@ discard block |
||
32 | 38 | continue; |
33 | 39 | } |
34 | 40 | |
35 | - if (!$this->isTargeted($reflection, $target)) { |
|
41 | + if (!$this->isTargeted($reflection, $target)) |
|
42 | + { |
|
36 | 43 | continue; |
37 | 44 | } |
38 | 45 | |
@@ -51,7 +58,8 @@ discard block |
||
51 | 58 | { |
52 | 59 | $interfaces = []; |
53 | 60 | |
54 | - foreach ($this->availableReflections() as $reflection) { |
|
61 | + foreach ($this->availableReflections() as $reflection) |
|
62 | + { |
|
55 | 63 | $interfaces = \array_merge($interfaces, $reflection->getInterfaces()); |
56 | 64 | } |
57 | 65 | |
@@ -65,7 +73,8 @@ discard block |
||
65 | 73 | */ |
66 | 74 | protected function isTargeted(\ReflectionClass $class, \ReflectionClass $target = null): bool |
67 | 75 | { |
68 | - if (empty($target)) { |
|
76 | + if (empty($target)) |
|
77 | + { |
|
69 | 78 | return true; |
70 | 79 | } |
71 | 80 |
@@ -13,18 +13,18 @@ discard block |
||
13 | 13 | { |
14 | 14 | public const INJECTOR = EnumLocatorInjector::class; |
15 | 15 | |
16 | - public function getEnums(object|string|null $target = null): array |
|
16 | + public function getEnums(object | string | null $target = null): array |
|
17 | 17 | { |
18 | - if (!empty($target)) { |
|
18 | + if (!empty($target)){ |
|
19 | 19 | $target = new \ReflectionClass($target); |
20 | 20 | } |
21 | 21 | |
22 | 22 | $result = []; |
23 | - foreach ($this->availableEnums() as $enum) { |
|
24 | - try { |
|
23 | + foreach ($this->availableEnums() as $enum){ |
|
24 | + try{ |
|
25 | 25 | $reflection = $this->enumReflection($enum); |
26 | - } catch (LocatorException $e) { |
|
27 | - if ($this->debug) { |
|
26 | + }catch (LocatorException $e){ |
|
27 | + if ($this->debug){ |
|
28 | 28 | throw $e; |
29 | 29 | } |
30 | 30 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | continue; |
33 | 33 | } |
34 | 34 | |
35 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
35 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()){ |
|
36 | 36 | continue; |
37 | 37 | } |
38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | { |
52 | 52 | $enums = []; |
53 | 53 | |
54 | - foreach ($this->availableReflections() as $reflection) { |
|
54 | + foreach ($this->availableReflections() as $reflection){ |
|
55 | 55 | $enums = \array_merge($enums, $reflection->getEnums()); |
56 | 56 | } |
57 | 57 | |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function isTargeted(\ReflectionEnum $enum, \ReflectionClass $target = null): bool |
67 | 67 | { |
68 | - if (empty($target)) { |
|
68 | + if (empty($target)){ |
|
69 | 69 | return true; |
70 | 70 | } |
71 | 71 | |
72 | - if (!$target->isTrait()) { |
|
72 | + if (!$target->isTrait()){ |
|
73 | 73 | //Target is interface or class |
74 | 74 | return $enum->isSubclassOf($target) || $enum->getName() === $target->getName(); |
75 | 75 | } |
@@ -15,16 +15,22 @@ discard block |
||
15 | 15 | |
16 | 16 | public function getEnums(object|string|null $target = null): array |
17 | 17 | { |
18 | - if (!empty($target)) { |
|
18 | + if (!empty($target)) |
|
19 | + { |
|
19 | 20 | $target = new \ReflectionClass($target); |
20 | 21 | } |
21 | 22 | |
22 | 23 | $result = []; |
23 | - foreach ($this->availableEnums() as $enum) { |
|
24 | - try { |
|
24 | + foreach ($this->availableEnums() as $enum) |
|
25 | + { |
|
26 | + try |
|
27 | + { |
|
25 | 28 | $reflection = $this->enumReflection($enum); |
26 | - } catch (LocatorException $e) { |
|
27 | - if ($this->debug) { |
|
29 | + } |
|
30 | + catch (LocatorException $e) |
|
31 | + { |
|
32 | + if ($this->debug) |
|
33 | + { |
|
28 | 34 | throw $e; |
29 | 35 | } |
30 | 36 | |
@@ -32,7 +38,8 @@ discard block |
||
32 | 38 | continue; |
33 | 39 | } |
34 | 40 | |
35 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
41 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) |
|
42 | + { |
|
36 | 43 | continue; |
37 | 44 | } |
38 | 45 | |
@@ -51,7 +58,8 @@ discard block |
||
51 | 58 | { |
52 | 59 | $enums = []; |
53 | 60 | |
54 | - foreach ($this->availableReflections() as $reflection) { |
|
61 | + foreach ($this->availableReflections() as $reflection) |
|
62 | + { |
|
55 | 63 | $enums = \array_merge($enums, $reflection->getEnums()); |
56 | 64 | } |
57 | 65 | |
@@ -65,11 +73,13 @@ discard block |
||
65 | 73 | */ |
66 | 74 | protected function isTargeted(\ReflectionEnum $enum, \ReflectionClass $target = null): bool |
67 | 75 | { |
68 | - if (empty($target)) { |
|
76 | + if (empty($target)) |
|
77 | + { |
|
69 | 78 | return true; |
70 | 79 | } |
71 | 80 | |
72 | - if (!$target->isTrait()) { |
|
81 | + if (!$target->isTrait()) |
|
82 | + { |
|
73 | 83 | //Target is interface or class |
74 | 84 | return $enum->isSubclassOf($target) || $enum->getName() === $target->getName(); |
75 | 85 | } |