@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | public function __construct( |
| 26 | 26 | protected Finder $finder, |
| 27 | 27 | protected readonly bool $debug = false, |
| 28 | - ) { |
|
| 28 | + ){ |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | protected function availableReflections(): \Generator |
| 39 | 39 | { |
| 40 | - foreach ($this->finder->getIterator() as $file) { |
|
| 40 | + foreach ($this->finder->getIterator() as $file){ |
|
| 41 | 41 | $reflection = new ReflectionFile((string)$file); |
| 42 | 42 | |
| 43 | - if ($reflection->hasIncludes()) { |
|
| 43 | + if ($reflection->hasIncludes()){ |
|
| 44 | 44 | // We are not analyzing files which has includes, it's not safe to require such reflections |
| 45 | 45 | $this->getLogger()->warning( |
| 46 | - \sprintf('File `%s` has includes and excluded from analysis', (string) $file), |
|
| 46 | + \sprintf('File `%s` has includes and excluded from analysis', (string)$file), |
|
| 47 | 47 | ['file' => $file] |
| 48 | 48 | ); |
| 49 | 49 | |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | protected function classReflection(string $class): \ReflectionClass |
| 68 | 68 | { |
| 69 | - $loader = static function ($class) { |
|
| 70 | - if ($class === LocatorException::class) { |
|
| 69 | + $loader = static function ($class){ |
|
| 70 | + if ($class === LocatorException::class){ |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | //To suspend class dependency exception |
| 78 | 78 | \spl_autoload_register($loader); |
| 79 | 79 | |
| 80 | - try { |
|
| 80 | + try{ |
|
| 81 | 81 | //In some cases reflection can thrown an exception if class invalid or can not be loaded, |
| 82 | 82 | //we are going to handle such exception and convert it soft exception |
| 83 | 83 | return new \ReflectionClass($class); |
| 84 | - } catch (\Throwable $e) { |
|
| 85 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
| 84 | + }catch (\Throwable $e){ |
|
| 85 | + if ($e instanceof LocatorException && $e->getPrevious() != null){ |
|
| 86 | 86 | $e = $e->getPrevious(); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | ['error' => $e] |
| 98 | 98 | ); |
| 99 | 99 | |
| 100 | - throw new LocatorException($e->getMessage(), (int) $e->getCode(), $e); |
|
| 101 | - } finally { |
|
| 100 | + throw new LocatorException($e->getMessage(), (int)$e->getCode(), $e); |
|
| 101 | + }finally{ |
|
| 102 | 102 | \spl_autoload_unregister($loader); |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | protected function enumReflection(string $enum): \ReflectionEnum |
| 117 | 117 | { |
| 118 | 118 | $loader = static function (string $enum): void { |
| 119 | - if ($enum === LocatorException::class) { |
|
| 119 | + if ($enum === LocatorException::class){ |
|
| 120 | 120 | return; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | //To suspend class dependency exception |
| 127 | 127 | \spl_autoload_register($loader); |
| 128 | 128 | |
| 129 | - try { |
|
| 129 | + try{ |
|
| 130 | 130 | //In some enum reflection can thrown an exception if enum invalid or can not be loaded, |
| 131 | 131 | //we are going to handle such exception and convert it soft exception |
| 132 | 132 | return new \ReflectionEnum($enum); |
| 133 | - } catch (\Throwable $e) { |
|
| 134 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
| 133 | + }catch (\Throwable $e){ |
|
| 134 | + if ($e instanceof LocatorException && $e->getPrevious() != null){ |
|
| 135 | 135 | $e = $e->getPrevious(); |
| 136 | 136 | } |
| 137 | 137 | |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | ['error' => $e] |
| 147 | 147 | ); |
| 148 | 148 | |
| 149 | - throw new LocatorException($e->getMessage(), (int) $e->getCode(), $e); |
|
| 150 | - } finally { |
|
| 149 | + throw new LocatorException($e->getMessage(), (int)$e->getCode(), $e); |
|
| 150 | + }finally{ |
|
| 151 | 151 | \spl_autoload_unregister($loader); |
| 152 | 152 | } |
| 153 | 153 | } |
@@ -37,10 +37,12 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | protected function availableReflections(): \Generator |
| 39 | 39 | { |
| 40 | - foreach ($this->finder->getIterator() as $file) { |
|
| 40 | + foreach ($this->finder->getIterator() as $file) |
|
| 41 | + { |
|
| 41 | 42 | $reflection = new ReflectionFile((string)$file); |
| 42 | 43 | |
| 43 | - if ($reflection->hasIncludes()) { |
|
| 44 | + if ($reflection->hasIncludes()) |
|
| 45 | + { |
|
| 44 | 46 | // We are not analyzing files which has includes, it's not safe to require such reflections |
| 45 | 47 | $this->getLogger()->warning( |
| 46 | 48 | \sprintf('File `%s` has includes and excluded from analysis', (string) $file), |
@@ -66,8 +68,10 @@ discard block |
||
| 66 | 68 | */ |
| 67 | 69 | protected function classReflection(string $class): \ReflectionClass |
| 68 | 70 | { |
| 69 | - $loader = static function ($class) { |
|
| 70 | - if ($class === LocatorException::class) { |
|
| 71 | + $loader = static function ($class) |
|
| 72 | + { |
|
| 73 | + if ($class === LocatorException::class) |
|
| 74 | + { |
|
| 71 | 75 | return; |
| 72 | 76 | } |
| 73 | 77 | |
@@ -77,12 +81,16 @@ discard block |
||
| 77 | 81 | //To suspend class dependency exception |
| 78 | 82 | \spl_autoload_register($loader); |
| 79 | 83 | |
| 80 | - try { |
|
| 84 | + try |
|
| 85 | + { |
|
| 81 | 86 | //In some cases reflection can thrown an exception if class invalid or can not be loaded, |
| 82 | 87 | //we are going to handle such exception and convert it soft exception |
| 83 | 88 | return new \ReflectionClass($class); |
| 84 | - } catch (\Throwable $e) { |
|
| 85 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
| 89 | + } |
|
| 90 | + catch (\Throwable $e) |
|
| 91 | + { |
|
| 92 | + if ($e instanceof LocatorException && $e->getPrevious() != null) |
|
| 93 | + { |
|
| 86 | 94 | $e = $e->getPrevious(); |
| 87 | 95 | } |
| 88 | 96 | |
@@ -98,7 +106,9 @@ discard block |
||
| 98 | 106 | ); |
| 99 | 107 | |
| 100 | 108 | throw new LocatorException($e->getMessage(), (int) $e->getCode(), $e); |
| 101 | - } finally { |
|
| 109 | + } |
|
| 110 | + finally |
|
| 111 | + { |
|
| 102 | 112 | \spl_autoload_unregister($loader); |
| 103 | 113 | } |
| 104 | 114 | } |
@@ -116,7 +126,8 @@ discard block |
||
| 116 | 126 | protected function enumReflection(string $enum): \ReflectionEnum |
| 117 | 127 | { |
| 118 | 128 | $loader = static function (string $enum): void { |
| 119 | - if ($enum === LocatorException::class) { |
|
| 129 | + if ($enum === LocatorException::class) |
|
| 130 | + { |
|
| 120 | 131 | return; |
| 121 | 132 | } |
| 122 | 133 | |
@@ -126,12 +137,16 @@ discard block |
||
| 126 | 137 | //To suspend class dependency exception |
| 127 | 138 | \spl_autoload_register($loader); |
| 128 | 139 | |
| 129 | - try { |
|
| 140 | + try |
|
| 141 | + { |
|
| 130 | 142 | //In some enum reflection can thrown an exception if enum invalid or can not be loaded, |
| 131 | 143 | //we are going to handle such exception and convert it soft exception |
| 132 | 144 | return new \ReflectionEnum($enum); |
| 133 | - } catch (\Throwable $e) { |
|
| 134 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
| 145 | + } |
|
| 146 | + catch (\Throwable $e) |
|
| 147 | + { |
|
| 148 | + if ($e instanceof LocatorException && $e->getPrevious() != null) |
|
| 149 | + { |
|
| 135 | 150 | $e = $e->getPrevious(); |
| 136 | 151 | } |
| 137 | 152 | |
@@ -147,7 +162,9 @@ discard block |
||
| 147 | 162 | ); |
| 148 | 163 | |
| 149 | 164 | throw new LocatorException($e->getMessage(), (int) $e->getCode(), $e); |
| 150 | - } finally { |
|
| 165 | + } |
|
| 166 | + finally |
|
| 167 | + { |
|
| 151 | 168 | \spl_autoload_unregister($loader); |
| 152 | 169 | } |
| 153 | 170 | } |
@@ -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 | } |
@@ -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 | } |
@@ -20,5 +20,5 @@ |
||
| 20 | 20 | * |
| 21 | 21 | * @return array<class-string, ReflectionEnum> |
| 22 | 22 | */ |
| 23 | - public function getEnums(object|string|null $target = null): array; |
|
| 23 | + public function getEnums(object | string | null $target = null): array; |
|
| 24 | 24 | } |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | public function __construct( |
| 17 | 17 | private readonly EnumsInterface $enums, |
| 18 | 18 | private readonly ScopedEnumsInterface $scopedEnums, |
| 19 | - ) { |
|
| 19 | + ){ |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | private readonly EnumLocatorByTarget $locator, |
| 18 | 18 | private readonly ListenerInvoker $invoker, |
| 19 | 19 | private readonly bool $readCache = true, |
| 20 | - ) { |
|
| 20 | + ){ |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function loadEnums(TokenizationListenerInterface $listener): bool |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | $targets = \iterator_to_array($this->parseAttributes($listener)); |
| 26 | 26 | |
| 27 | 27 | // If there are no targets, then listener can't be cached. |
| 28 | - if ($targets === []) { |
|
| 28 | + if ($targets === []){ |
|
| 29 | 29 | return false; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | // We decided to load classes for each target separately. |
| 35 | 35 | // It allows us to cache classes for each target separately and if we reuse the |
| 36 | 36 | // same target in multiple listeners, we will not have to load classes for the same target. |
| 37 | - foreach ($targets as $target) { |
|
| 38 | - $cacheKey = 'enums-' . $target; |
|
| 37 | + foreach ($targets as $target){ |
|
| 38 | + $cacheKey = 'enums-'.$target; |
|
| 39 | 39 | |
| 40 | 40 | $enums = $this->readCache ? $this->memory->loadData($cacheKey) : null; |
| 41 | - if ($enums === null) { |
|
| 41 | + if ($enums === null){ |
|
| 42 | 42 | $this->memory->saveData( |
| 43 | 43 | $cacheKey, |
| 44 | 44 | $enums = $this->locator->getEnums($target), |
@@ -25,7 +25,8 @@ discard block |
||
| 25 | 25 | $targets = \iterator_to_array($this->parseAttributes($listener)); |
| 26 | 26 | |
| 27 | 27 | // If there are no targets, then listener can't be cached. |
| 28 | - if ($targets === []) { |
|
| 28 | + if ($targets === []) |
|
| 29 | + { |
|
| 29 | 30 | return false; |
| 30 | 31 | } |
| 31 | 32 | |
@@ -34,11 +35,13 @@ discard block |
||
| 34 | 35 | // We decided to load classes for each target separately. |
| 35 | 36 | // It allows us to cache classes for each target separately and if we reuse the |
| 36 | 37 | // same target in multiple listeners, we will not have to load classes for the same target. |
| 37 | - foreach ($targets as $target) { |
|
| 38 | + foreach ($targets as $target) |
|
| 39 | + { |
|
| 38 | 40 | $cacheKey = 'enums-' . $target; |
| 39 | 41 | |
| 40 | 42 | $enums = $this->readCache ? $this->memory->loadData($cacheKey) : null; |
| 41 | - if ($enums === null) { |
|
| 43 | + if ($enums === null) |
|
| 44 | + { |
|
| 42 | 45 | $this->memory->saveData( |
| 43 | 46 | $cacheKey, |
| 44 | 47 | $enums = $this->locator->getEnums($target), |
@@ -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 | /** |
@@ -16,5 +16,5 @@ |
||
| 16 | 16 | * |
| 17 | 17 | * @return \ReflectionEnum[] |
| 18 | 18 | */ |
| 19 | - public function getScopedEnums(string $scope, object|string|null $target = null): array; |
|
| 19 | + public function getScopedEnums(string $scope, object | string | null $target = null): array; |
|
| 20 | 20 | } |
@@ -101,16 +101,16 @@ |
||
| 101 | 101 | |
| 102 | 102 | public function isLoadClassesEnabled(): bool |
| 103 | 103 | { |
| 104 | - return (bool) ($this->config['load']['classes'] ?? true); |
|
| 104 | + return (bool)($this->config['load']['classes'] ?? true); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | public function isLoadEnumsEnabled(): bool |
| 108 | 108 | { |
| 109 | - return (bool) ($this->config['load']['enums'] ?? false); |
|
| 109 | + return (bool)($this->config['load']['enums'] ?? false); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | public function isLoadInterfacesEnabled(): bool |
| 113 | 113 | { |
| 114 | - return (bool) ($this->config['load']['interfaces'] ?? false); |
|
| 114 | + return (bool)($this->config['load']['interfaces'] ?? false); |
|
| 115 | 115 | } |
| 116 | 116 | } |
@@ -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 getScopedEnums(string $scope, object|string|null $target = null): array |
|
| 14 | + public function getScopedEnums(string $scope, object | string | null $target = null): array |
|
| 15 | 15 | { |
| 16 | 16 | return $this->tokenizer->scopedEnumLocator($scope)->getEnums($target); |
| 17 | 17 | } |