@@ -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 getScopedClasses(string $scope, object|string|null $target = null): array |
|
| 14 | + public function getScopedClasses(string $scope, object | string | null $target = null): array |
|
| 15 | 15 | { |
| 16 | 16 | return $this->tokenizer->scopedClassLocator($scope)->getClasses($target); |
| 17 | 17 | } |
@@ -21,5 +21,5 @@ |
||
| 21 | 21 | * results. |
| 22 | 22 | * @return array<class-string, ReflectionClass> |
| 23 | 23 | */ |
| 24 | - public function getClasses(object|string|null $target = null): array; |
|
| 24 | + public function getClasses(object | string | null $target = null): array; |
|
| 25 | 25 | } |
@@ -16,13 +16,13 @@ |
||
| 16 | 16 | { |
| 17 | 17 | $traits = []; |
| 18 | 18 | |
| 19 | - do { |
|
| 19 | + do{ |
|
| 20 | 20 | $traits = \array_merge(\class_uses($class), $traits); |
| 21 | 21 | $class = \get_parent_class($class); |
| 22 | - } while ($class !== false); |
|
| 22 | + }while ($class !== false); |
|
| 23 | 23 | |
| 24 | 24 | //Traits from traits |
| 25 | - foreach (\array_flip($traits) as $trait) { |
|
| 25 | + foreach (\array_flip($traits) as $trait){ |
|
| 26 | 26 | $traits = \array_merge(\class_uses($trait), $traits); |
| 27 | 27 | } |
| 28 | 28 | |
@@ -16,13 +16,15 @@ |
||
| 16 | 16 | { |
| 17 | 17 | $traits = []; |
| 18 | 18 | |
| 19 | - do { |
|
| 19 | + do |
|
| 20 | + { |
|
| 20 | 21 | $traits = \array_merge(\class_uses($class), $traits); |
| 21 | 22 | $class = \get_parent_class($class); |
| 22 | 23 | } while ($class !== false); |
| 23 | 24 | |
| 24 | 25 | //Traits from traits |
| 25 | - foreach (\array_flip($traits) as $trait) { |
|
| 26 | + foreach (\array_flip($traits) as $trait) |
|
| 27 | + { |
|
| 26 | 28 | $traits = \array_merge(\class_uses($trait), $traits); |
| 27 | 29 | } |
| 28 | 30 | |
@@ -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 | } |
@@ -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 | } |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | public function getInvocations(\ReflectionFunctionAbstract $function): array |
| 22 | 22 | { |
| 23 | 23 | $result = []; |
| 24 | - foreach ($this->availableInvocations($function->getName()) as $invocation) { |
|
| 25 | - if ($this->isTargeted($invocation, $function)) { |
|
| 24 | + foreach ($this->availableInvocations($function->getName()) as $invocation){ |
|
| 25 | + if ($this->isTargeted($invocation, $function)){ |
|
| 26 | 26 | $result[] = $invocation; |
| 27 | 27 | } |
| 28 | 28 | } |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | protected function availableInvocations(string $signature = ''): \Generator |
| 40 | 40 | { |
| 41 | 41 | $signature = \strtolower(\trim($signature, '\\')); |
| 42 | - foreach ($this->availableReflections() as $reflection) { |
|
| 43 | - foreach ($reflection->getInvocations() as $invocation) { |
|
| 42 | + foreach ($this->availableReflections() as $reflection){ |
|
| 43 | + foreach ($reflection->getInvocations() as $invocation){ |
|
| 44 | 44 | if ( |
| 45 | 45 | !empty($signature) |
| 46 | 46 | && \strtolower(\trim($invocation->getName(), '\\')) !== $signature |
| 47 | - ) { |
|
| 47 | + ){ |
|
| 48 | 48 | continue; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -55,14 +55,14 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | protected function isTargeted(ReflectionInvocation $invocation, \ReflectionFunctionAbstract $function): bool |
| 57 | 57 | { |
| 58 | - if ($function instanceof \ReflectionFunction) { |
|
| 58 | + if ($function instanceof \ReflectionFunction){ |
|
| 59 | 59 | return !$invocation->isMethod(); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - try { |
|
| 62 | + try{ |
|
| 63 | 63 | $reflection = $this->classReflection($invocation->getClass()); |
| 64 | - } catch (LocatorException $e) { |
|
| 65 | - if ($this->debug) { |
|
| 64 | + }catch (LocatorException $e){ |
|
| 65 | + if ($this->debug){ |
|
| 66 | 66 | throw $e; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | $target = $function->getDeclaringClass(); |
| 76 | 76 | |
| 77 | - if ($target->isTrait()) { |
|
| 77 | + if ($target->isTrait()){ |
|
| 78 | 78 | //Let's compare traits |
| 79 | 79 | return \in_array($target->getName(), $this->fetchTraits($invocation->getClass())); |
| 80 | 80 | } |
@@ -21,8 +21,10 @@ discard block |
||
| 21 | 21 | public function getInvocations(\ReflectionFunctionAbstract $function): array |
| 22 | 22 | { |
| 23 | 23 | $result = []; |
| 24 | - foreach ($this->availableInvocations($function->getName()) as $invocation) { |
|
| 25 | - if ($this->isTargeted($invocation, $function)) { |
|
| 24 | + foreach ($this->availableInvocations($function->getName()) as $invocation) |
|
| 25 | + { |
|
| 26 | + if ($this->isTargeted($invocation, $function)) |
|
| 27 | + { |
|
| 26 | 28 | $result[] = $invocation; |
| 27 | 29 | } |
| 28 | 30 | } |
@@ -39,8 +41,10 @@ discard block |
||
| 39 | 41 | protected function availableInvocations(string $signature = ''): \Generator |
| 40 | 42 | { |
| 41 | 43 | $signature = \strtolower(\trim($signature, '\\')); |
| 42 | - foreach ($this->availableReflections() as $reflection) { |
|
| 43 | - foreach ($reflection->getInvocations() as $invocation) { |
|
| 44 | + foreach ($this->availableReflections() as $reflection) |
|
| 45 | + { |
|
| 46 | + foreach ($reflection->getInvocations() as $invocation) |
|
| 47 | + { |
|
| 44 | 48 | if ( |
| 45 | 49 | !empty($signature) |
| 46 | 50 | && \strtolower(\trim($invocation->getName(), '\\')) !== $signature |
@@ -55,14 +59,19 @@ discard block |
||
| 55 | 59 | |
| 56 | 60 | protected function isTargeted(ReflectionInvocation $invocation, \ReflectionFunctionAbstract $function): bool |
| 57 | 61 | { |
| 58 | - if ($function instanceof \ReflectionFunction) { |
|
| 62 | + if ($function instanceof \ReflectionFunction) |
|
| 63 | + { |
|
| 59 | 64 | return !$invocation->isMethod(); |
| 60 | 65 | } |
| 61 | 66 | |
| 62 | - try { |
|
| 67 | + try |
|
| 68 | + { |
|
| 63 | 69 | $reflection = $this->classReflection($invocation->getClass()); |
| 64 | - } catch (LocatorException $e) { |
|
| 65 | - if ($this->debug) { |
|
| 70 | + } |
|
| 71 | + catch (LocatorException $e) |
|
| 72 | + { |
|
| 73 | + if ($this->debug) |
|
| 74 | + { |
|
| 66 | 75 | throw $e; |
| 67 | 76 | } |
| 68 | 77 | |
@@ -74,7 +83,8 @@ discard block |
||
| 74 | 83 | */ |
| 75 | 84 | $target = $function->getDeclaringClass(); |
| 76 | 85 | |
| 77 | - if ($target->isTrait()) { |
|
| 86 | + if ($target->isTrait()) |
|
| 87 | + { |
|
| 78 | 88 | //Let's compare traits |
| 79 | 89 | return \in_array($target->getName(), $this->fetchTraits($invocation->getClass())); |
| 80 | 90 | } |
@@ -13,18 +13,18 @@ discard block |
||
| 13 | 13 | { |
| 14 | 14 | public const INJECTOR = ClassLocatorInjector::class; |
| 15 | 15 | |
| 16 | - public function getClasses(object|string|null $target = null): array |
|
| 16 | + public function getClasses(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->availableClasses() as $class) { |
|
| 24 | - try { |
|
| 23 | + foreach ($this->availableClasses() as $class){ |
|
| 24 | + try{ |
|
| 25 | 25 | $reflection = $this->classReflection($class); |
| 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 | $classes = []; |
| 53 | 53 | |
| 54 | - foreach ($this->availableReflections() as $reflection) { |
|
| 54 | + foreach ($this->availableReflections() as $reflection){ |
|
| 55 | 55 | $classes = \array_merge($classes, $reflection->getClasses()); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -65,11 +65,11 @@ 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 | |
| 72 | - if (!$target->isTrait()) { |
|
| 72 | + if (!$target->isTrait()){ |
|
| 73 | 73 | //Target is interface or class |
| 74 | 74 | return $class->isSubclassOf($target) || $class->getName() === $target->getName(); |
| 75 | 75 | } |
@@ -15,16 +15,22 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public function getClasses(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->availableClasses() as $class) { |
|
| 24 | - try { |
|
| 24 | + foreach ($this->availableClasses() as $class) |
|
| 25 | + { |
|
| 26 | + try |
|
| 27 | + { |
|
| 25 | 28 | $reflection = $this->classReflection($class); |
| 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 | $classes = []; |
| 53 | 60 | |
| 54 | - foreach ($this->availableReflections() as $reflection) { |
|
| 61 | + foreach ($this->availableReflections() as $reflection) |
|
| 62 | + { |
|
| 55 | 63 | $classes = \array_merge($classes, $reflection->getClasses()); |
| 56 | 64 | } |
| 57 | 65 | |
@@ -65,11 +73,13 @@ 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 | |
| 72 | - if (!$target->isTrait()) { |
|
| 81 | + if (!$target->isTrait()) |
|
| 82 | + { |
|
| 73 | 83 | //Target is interface or class |
| 74 | 84 | return $class->isSubclassOf($target) || $class->getName() === $target->getName(); |
| 75 | 85 | } |
@@ -17,5 +17,5 @@ |
||
| 17 | 17 | * results. |
| 18 | 18 | * @return \ReflectionClass[] |
| 19 | 19 | */ |
| 20 | - public function getScopedClasses(string $scope, object|string|null $target = null): array; |
|
| 20 | + public function getScopedClasses(string $scope, object | string | null $target = null): array; |
|
| 21 | 21 | } |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | public function __construct( |
| 114 | 114 | private readonly string $filename |
| 115 | - ) { |
|
| 115 | + ){ |
|
| 116 | 116 | $this->tokens = Tokenizer::getTokens($filename); |
| 117 | 117 | $this->countTokens = \count($this->tokens); |
| 118 | 118 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public function getClasses(): array |
| 143 | 143 | { |
| 144 | - if (!isset($this->declarations['T_CLASS'])) { |
|
| 144 | + if (!isset($this->declarations['T_CLASS'])){ |
|
| 145 | 145 | return []; |
| 146 | 146 | } |
| 147 | 147 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | public function getTraits(): array |
| 155 | 155 | { |
| 156 | - if (!isset($this->declarations['T_TRAIT'])) { |
|
| 156 | + if (!isset($this->declarations['T_TRAIT'])){ |
|
| 157 | 157 | return []; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function getInterfaces(): array |
| 167 | 167 | { |
| 168 | - if (!isset($this->declarations['T_INTERFACE'])) { |
|
| 168 | + if (!isset($this->declarations['T_INTERFACE'])){ |
|
| 169 | 169 | return []; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public function getInvocations(): array |
| 198 | 198 | { |
| 199 | - if (empty($this->invocations)) { |
|
| 199 | + if (empty($this->invocations)){ |
|
| 200 | 200 | $this->locateInvocations($this->getTokens()); |
| 201 | 201 | } |
| 202 | 202 | |
@@ -224,12 +224,12 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | protected function locateDeclarations() |
| 226 | 226 | { |
| 227 | - foreach ($this->getTokens() as $tokenID => $token) { |
|
| 228 | - if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens)) { |
|
| 227 | + foreach ($this->getTokens() as $tokenID => $token){ |
|
| 228 | + if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens)){ |
|
| 229 | 229 | continue; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - switch ($token[self::TOKEN_TYPE]) { |
|
| 232 | + switch ($token[self::TOKEN_TYPE]){ |
|
| 233 | 233 | case T_NAMESPACE: |
| 234 | 234 | $this->registerNamespace($tokenID); |
| 235 | 235 | break; |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | case T_CLASS: |
| 246 | 246 | case T_TRAIT: |
| 247 | 247 | case T_INTERFACE: |
| 248 | - if ($this->isClassNameConst($tokenID)) { |
|
| 248 | + if ($this->isClassNameConst($tokenID)){ |
|
| 249 | 249 | //PHP5.5 ClassName::class constant |
| 250 | 250 | continue 2; |
| 251 | 251 | } |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | //Dropping empty namespace |
| 265 | - if (isset($this->namespaces[''])) { |
|
| 265 | + if (isset($this->namespaces[''])){ |
|
| 266 | 266 | $this->namespaces['\\'] = $this->namespaces['']; |
| 267 | 267 | unset($this->namespaces['']); |
| 268 | 268 | } |
@@ -276,14 +276,14 @@ discard block |
||
| 276 | 276 | $namespace = ''; |
| 277 | 277 | $localID = $tokenID + 1; |
| 278 | 278 | |
| 279 | - do { |
|
| 279 | + do{ |
|
| 280 | 280 | $token = $this->tokens[$localID++]; |
| 281 | - if ($token[self::TOKEN_CODE] === '{') { |
|
| 281 | + if ($token[self::TOKEN_CODE] === '{'){ |
|
| 282 | 282 | break; |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | $namespace .= $token[self::TOKEN_CODE]; |
| 286 | - } while ( |
|
| 286 | + }while ( |
|
| 287 | 287 | isset($this->tokens[$localID]) |
| 288 | 288 | && $this->tokens[$localID][self::TOKEN_CODE] !== '{' |
| 289 | 289 | && $this->tokens[$localID][self::TOKEN_CODE] !== ';' |
@@ -293,13 +293,13 @@ discard block |
||
| 293 | 293 | $namespace = \trim($namespace); |
| 294 | 294 | |
| 295 | 295 | $uses = []; |
| 296 | - if (isset($this->namespaces[$namespace])) { |
|
| 296 | + if (isset($this->namespaces[$namespace])){ |
|
| 297 | 297 | $uses = $this->namespaces[$namespace]; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if ($this->tokens[$localID][self::TOKEN_CODE] === ';') { |
|
| 300 | + if ($this->tokens[$localID][self::TOKEN_CODE] === ';'){ |
|
| 301 | 301 | $endingID = \count($this->tokens) - 1; |
| 302 | - } else { |
|
| 302 | + }else{ |
|
| 303 | 303 | $endingID = $this->endingToken($tokenID); |
| 304 | 304 | } |
| 305 | 305 | |
@@ -319,20 +319,20 @@ discard block |
||
| 319 | 319 | |
| 320 | 320 | $class = ''; |
| 321 | 321 | $localAlias = null; |
| 322 | - for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID) { |
|
| 323 | - if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS) { |
|
| 322 | + for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID){ |
|
| 323 | + if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS){ |
|
| 324 | 324 | $localAlias = ''; |
| 325 | 325 | continue; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - if ($localAlias === null) { |
|
| 328 | + if ($localAlias === null){ |
|
| 329 | 329 | $class .= $this->tokens[$localID][self::TOKEN_CODE]; |
| 330 | - } else { |
|
| 330 | + }else{ |
|
| 331 | 331 | $localAlias .= $this->tokens[$localID][self::TOKEN_CODE]; |
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - if (empty($localAlias)) { |
|
| 335 | + if (empty($localAlias)){ |
|
| 336 | 336 | $names = explode('\\', $class); |
| 337 | 337 | $localAlias = end($names); |
| 338 | 338 | } |
@@ -345,9 +345,9 @@ discard block |
||
| 345 | 345 | */ |
| 346 | 346 | private function registerFunction(int $tokenID): void |
| 347 | 347 | { |
| 348 | - foreach ($this->declarations as $declarations) { |
|
| 349 | - foreach ($declarations as $location) { |
|
| 350 | - if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]) { |
|
| 348 | + foreach ($this->declarations as $declarations){ |
|
| 349 | + foreach ($declarations as $location){ |
|
| 350 | + if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]){ |
|
| 351 | 351 | //We are inside class, function is method |
| 352 | 352 | return; |
| 353 | 353 | } |
@@ -355,14 +355,14 @@ discard block |
||
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | $localID = $tokenID + 1; |
| 358 | - while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) { |
|
| 358 | + while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING){ |
|
| 359 | 359 | //Fetching function name |
| 360 | 360 | ++$localID; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | $name = $this->tokens[$localID][self::TOKEN_CODE]; |
| 364 | - if (!empty($namespace = $this->activeNamespace($tokenID))) { |
|
| 365 | - $name = $namespace . self::NS_SEPARATOR . $name; |
|
| 364 | + if (!empty($namespace = $this->activeNamespace($tokenID))){ |
|
| 365 | + $name = $namespace.self::NS_SEPARATOR.$name; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | $this->functions[$name] = [ |
@@ -378,13 +378,13 @@ discard block |
||
| 378 | 378 | private function registerDeclaration(int $tokenID, int $tokenType): void |
| 379 | 379 | { |
| 380 | 380 | $localID = $tokenID + 1; |
| 381 | - while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) { |
|
| 381 | + while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING){ |
|
| 382 | 382 | ++$localID; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | $name = $this->tokens[$localID][self::TOKEN_CODE]; |
| 386 | - if (!empty($namespace = $this->activeNamespace($tokenID))) { |
|
| 387 | - $name = $namespace . self::NS_SEPARATOR . $name; |
|
| 386 | + if (!empty($namespace = $this->activeNamespace($tokenID))){ |
|
| 387 | + $name = $namespace.self::NS_SEPARATOR.$name; |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | $this->declarations[\token_name($tokenType)][$name] = [ |
@@ -430,24 +430,24 @@ discard block |
||
| 430 | 430 | |
| 431 | 431 | //Tokens used to re-enable token detection |
| 432 | 432 | $stopTokens = [T_STRING, T_WHITESPACE, T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_NS_SEPARATOR]; |
| 433 | - foreach ($tokens as $tokenID => $token) { |
|
| 433 | + foreach ($tokens as $tokenID => $token){ |
|
| 434 | 434 | $tokenType = $token[self::TOKEN_TYPE]; |
| 435 | 435 | |
| 436 | 436 | //We are not indexing function declarations or functions called from $objects. |
| 437 | - if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])) { |
|
| 437 | + if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])){ |
|
| 438 | 438 | if ( |
| 439 | 439 | empty($argumentsTID) |
| 440 | 440 | && ( |
| 441 | 441 | empty($invocationTID) |
| 442 | 442 | || $this->getSource($invocationTID, $tokenID - 1) !== '$this' |
| 443 | 443 | ) |
| 444 | - ) { |
|
| 444 | + ){ |
|
| 445 | 445 | //Not a call, function declaration, or object method |
| 446 | 446 | $ignore = true; |
| 447 | 447 | continue; |
| 448 | 448 | } |
| 449 | - } elseif ($ignore) { |
|
| 450 | - if (!\in_array($tokenType, $stopTokens)) { |
|
| 449 | + } elseif ($ignore){ |
|
| 450 | + if (!\in_array($tokenType, $stopTokens)){ |
|
| 451 | 451 | //Returning to search |
| 452 | 452 | $ignore = false; |
| 453 | 453 | } |
@@ -455,13 +455,13 @@ discard block |
||
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | //We are inside function, and there is "(", indexing arguments. |
| 458 | - if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')) { |
|
| 459 | - if (empty($argumentsTID)) { |
|
| 458 | + if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')){ |
|
| 459 | + if (empty($argumentsTID)){ |
|
| 460 | 460 | $argumentsTID = $tokenID; |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | ++$level; |
| 464 | - if ($level != 1) { |
|
| 464 | + if ($level != 1){ |
|
| 465 | 465 | //Not arguments beginning, but arguments part |
| 466 | 466 | $arguments[$tokenID] = $token; |
| 467 | 467 | } |
@@ -470,16 +470,16 @@ discard block |
||
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | //We are inside function arguments and ")" met. |
| 473 | - if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')) { |
|
| 473 | + if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')){ |
|
| 474 | 474 | --$level; |
| 475 | - if ($level == -1) { |
|
| 475 | + if ($level == -1){ |
|
| 476 | 476 | $invocationTID = false; |
| 477 | 477 | $level = 0; |
| 478 | 478 | continue; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | //Function fully indexed, we can process it now. |
| 482 | - if ($level == 0) { |
|
| 482 | + if ($level == 0){ |
|
| 483 | 483 | $this->registerInvocation( |
| 484 | 484 | $invocationTID, |
| 485 | 485 | $argumentsTID, |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | //Closing search |
| 492 | 492 | $arguments = []; |
| 493 | 493 | $argumentsTID = $invocationTID = false; |
| 494 | - } else { |
|
| 494 | + }else{ |
|
| 495 | 495 | //Not arguments beginning, but arguments part |
| 496 | 496 | $arguments[$tokenID] = $token; |
| 497 | 497 | } |
@@ -500,13 +500,13 @@ discard block |
||
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | //Still inside arguments. |
| 503 | - if (!empty($invocationTID) && !empty($level)) { |
|
| 503 | + if (!empty($invocationTID) && !empty($level)){ |
|
| 504 | 504 | $arguments[$tokenID] = $token; |
| 505 | 505 | continue; |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | //Nothing valuable to remember, will be parsed later. |
| 509 | - if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)) { |
|
| 509 | + if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)){ |
|
| 510 | 510 | continue; |
| 511 | 511 | } |
| 512 | 512 | |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | || $tokenType == T_STATIC |
| 517 | 517 | || $tokenType == T_NS_SEPARATOR |
| 518 | 518 | || ($tokenType == T_VARIABLE && $token[self::TOKEN_CODE] === '$this') |
| 519 | - ) { |
|
| 519 | + ){ |
|
| 520 | 520 | $invocationTID = $tokenID; |
| 521 | 521 | $level = 0; |
| 522 | 522 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | |
| 546 | 546 | [$class, $operator, $name] = $this->fetchContext($invocationID, $argumentsID); |
| 547 | 547 | |
| 548 | - if (!empty($operator) && empty($class)) { |
|
| 548 | + if (!empty($operator) && empty($class)){ |
|
| 549 | 549 | //Non detectable |
| 550 | 550 | return; |
| 551 | 551 | } |
@@ -571,17 +571,17 @@ discard block |
||
| 571 | 571 | $name = \trim($this->getSource($invocationTID, $argumentsTID), '( '); |
| 572 | 572 | |
| 573 | 573 | //Let's try to fetch all information we need |
| 574 | - if (\str_contains($name, '->')) { |
|
| 574 | + if (\str_contains($name, '->')){ |
|
| 575 | 575 | $operator = '->'; |
| 576 | - } elseif (\str_contains($name, '::')) { |
|
| 576 | + } elseif (\str_contains($name, '::')){ |
|
| 577 | 577 | $operator = '::'; |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - if (!empty($operator)) { |
|
| 580 | + if (!empty($operator)){ |
|
| 581 | 581 | [$class, $name] = \explode($operator, $name); |
| 582 | 582 | |
| 583 | 583 | //We now have to clarify class name |
| 584 | - if (\in_array($class, ['self', 'static', '$this'])) { |
|
| 584 | + if (\in_array($class, ['self', 'static', '$this'])){ |
|
| 585 | 585 | $class = $this->activeDeclaration($invocationTID); |
| 586 | 586 | } |
| 587 | 587 | } |
@@ -594,9 +594,9 @@ discard block |
||
| 594 | 594 | */ |
| 595 | 595 | private function activeDeclaration(int $tokenID): string |
| 596 | 596 | { |
| 597 | - foreach ($this->declarations as $declarations) { |
|
| 598 | - foreach ($declarations as $name => $position) { |
|
| 599 | - if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) { |
|
| 597 | + foreach ($this->declarations as $declarations){ |
|
| 598 | + foreach ($declarations as $name => $position){ |
|
| 599 | + if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]){ |
|
| 600 | 600 | return $name; |
| 601 | 601 | } |
| 602 | 602 | } |
@@ -611,8 +611,8 @@ discard block |
||
| 611 | 611 | */ |
| 612 | 612 | private function activeNamespace(int $tokenID): string |
| 613 | 613 | { |
| 614 | - foreach ($this->namespaces as $namespace => $position) { |
|
| 615 | - if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) { |
|
| 614 | + foreach ($this->namespaces as $namespace => $position){ |
|
| 615 | + if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]){ |
|
| 616 | 616 | return $namespace; |
| 617 | 617 | } |
| 618 | 618 | } |
@@ -633,18 +633,18 @@ discard block |
||
| 633 | 633 | private function endingToken(int $tokenID): int |
| 634 | 634 | { |
| 635 | 635 | $level = null; |
| 636 | - for ($localID = $tokenID; $localID < $this->countTokens; ++$localID) { |
|
| 636 | + for ($localID = $tokenID; $localID < $this->countTokens; ++$localID){ |
|
| 637 | 637 | $token = $this->tokens[$localID]; |
| 638 | - if ($token[self::TOKEN_CODE] === '{') { |
|
| 638 | + if ($token[self::TOKEN_CODE] === '{'){ |
|
| 639 | 639 | ++$level; |
| 640 | 640 | continue; |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | - if ($token[self::TOKEN_CODE] === '}') { |
|
| 643 | + if ($token[self::TOKEN_CODE] === '}'){ |
|
| 644 | 644 | --$level; |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - if ($level === 0) { |
|
| 647 | + if ($level === 0){ |
|
| 648 | 648 | break; |
| 649 | 649 | } |
| 650 | 650 | } |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | */ |
| 658 | 658 | private function lineNumber(int $tokenID): int |
| 659 | 659 | { |
| 660 | - while (empty($this->tokens[$tokenID][self::TOKEN_LINE])) { |
|
| 660 | + while (empty($this->tokens[$tokenID][self::TOKEN_LINE])){ |
|
| 661 | 661 | --$tokenID; |
| 662 | 662 | } |
| 663 | 663 | |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | private function getSource(int $startID, int $endID): string |
| 671 | 671 | { |
| 672 | 672 | $result = ''; |
| 673 | - for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID) { |
|
| 673 | + for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID){ |
|
| 674 | 674 | //Collecting function usage src |
| 675 | 675 | $result .= $this->tokens[$tokenID][self::TOKEN_CODE]; |
| 676 | 676 | } |
@@ -141,7 +141,8 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public function getClasses(): array |
| 143 | 143 | { |
| 144 | - if (!isset($this->declarations['T_CLASS'])) { |
|
| 144 | + if (!isset($this->declarations['T_CLASS'])) |
|
| 145 | + { |
|
| 145 | 146 | return []; |
| 146 | 147 | } |
| 147 | 148 | |
@@ -153,7 +154,8 @@ discard block |
||
| 153 | 154 | */ |
| 154 | 155 | public function getTraits(): array |
| 155 | 156 | { |
| 156 | - if (!isset($this->declarations['T_TRAIT'])) { |
|
| 157 | + if (!isset($this->declarations['T_TRAIT'])) |
|
| 158 | + { |
|
| 157 | 159 | return []; |
| 158 | 160 | } |
| 159 | 161 | |
@@ -165,7 +167,8 @@ discard block |
||
| 165 | 167 | */ |
| 166 | 168 | public function getInterfaces(): array |
| 167 | 169 | { |
| 168 | - if (!isset($this->declarations['T_INTERFACE'])) { |
|
| 170 | + if (!isset($this->declarations['T_INTERFACE'])) |
|
| 171 | + { |
|
| 169 | 172 | return []; |
| 170 | 173 | } |
| 171 | 174 | |
@@ -196,7 +199,8 @@ discard block |
||
| 196 | 199 | */ |
| 197 | 200 | public function getInvocations(): array |
| 198 | 201 | { |
| 199 | - if (empty($this->invocations)) { |
|
| 202 | + if (empty($this->invocations)) |
|
| 203 | + { |
|
| 200 | 204 | $this->locateInvocations($this->getTokens()); |
| 201 | 205 | } |
| 202 | 206 | |
@@ -224,12 +228,15 @@ discard block |
||
| 224 | 228 | */ |
| 225 | 229 | protected function locateDeclarations() |
| 226 | 230 | { |
| 227 | - foreach ($this->getTokens() as $tokenID => $token) { |
|
| 228 | - if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens)) { |
|
| 231 | + foreach ($this->getTokens() as $tokenID => $token) |
|
| 232 | + { |
|
| 233 | + if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens)) |
|
| 234 | + { |
|
| 229 | 235 | continue; |
| 230 | 236 | } |
| 231 | 237 | |
| 232 | - switch ($token[self::TOKEN_TYPE]) { |
|
| 238 | + switch ($token[self::TOKEN_TYPE]) |
|
| 239 | + { |
|
| 233 | 240 | case T_NAMESPACE: |
| 234 | 241 | $this->registerNamespace($tokenID); |
| 235 | 242 | break; |
@@ -245,7 +252,8 @@ discard block |
||
| 245 | 252 | case T_CLASS: |
| 246 | 253 | case T_TRAIT: |
| 247 | 254 | case T_INTERFACE: |
| 248 | - if ($this->isClassNameConst($tokenID)) { |
|
| 255 | + if ($this->isClassNameConst($tokenID)) |
|
| 256 | + { |
|
| 249 | 257 | //PHP5.5 ClassName::class constant |
| 250 | 258 | continue 2; |
| 251 | 259 | } |
@@ -262,7 +270,8 @@ discard block |
||
| 262 | 270 | } |
| 263 | 271 | |
| 264 | 272 | //Dropping empty namespace |
| 265 | - if (isset($this->namespaces[''])) { |
|
| 273 | + if (isset($this->namespaces[''])) |
|
| 274 | + { |
|
| 266 | 275 | $this->namespaces['\\'] = $this->namespaces['']; |
| 267 | 276 | unset($this->namespaces['']); |
| 268 | 277 | } |
@@ -276,9 +285,11 @@ discard block |
||
| 276 | 285 | $namespace = ''; |
| 277 | 286 | $localID = $tokenID + 1; |
| 278 | 287 | |
| 279 | - do { |
|
| 288 | + do |
|
| 289 | + { |
|
| 280 | 290 | $token = $this->tokens[$localID++]; |
| 281 | - if ($token[self::TOKEN_CODE] === '{') { |
|
| 291 | + if ($token[self::TOKEN_CODE] === '{') |
|
| 292 | + { |
|
| 282 | 293 | break; |
| 283 | 294 | } |
| 284 | 295 | |
@@ -293,13 +304,17 @@ discard block |
||
| 293 | 304 | $namespace = \trim($namespace); |
| 294 | 305 | |
| 295 | 306 | $uses = []; |
| 296 | - if (isset($this->namespaces[$namespace])) { |
|
| 307 | + if (isset($this->namespaces[$namespace])) |
|
| 308 | + { |
|
| 297 | 309 | $uses = $this->namespaces[$namespace]; |
| 298 | 310 | } |
| 299 | 311 | |
| 300 | - if ($this->tokens[$localID][self::TOKEN_CODE] === ';') { |
|
| 312 | + if ($this->tokens[$localID][self::TOKEN_CODE] === ';') |
|
| 313 | + { |
|
| 301 | 314 | $endingID = \count($this->tokens) - 1; |
| 302 | - } else { |
|
| 315 | + } |
|
| 316 | + else |
|
| 317 | + { |
|
| 303 | 318 | $endingID = $this->endingToken($tokenID); |
| 304 | 319 | } |
| 305 | 320 | |
@@ -319,20 +334,26 @@ discard block |
||
| 319 | 334 | |
| 320 | 335 | $class = ''; |
| 321 | 336 | $localAlias = null; |
| 322 | - for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID) { |
|
| 323 | - if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS) { |
|
| 337 | + for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID) |
|
| 338 | + { |
|
| 339 | + if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS) |
|
| 340 | + { |
|
| 324 | 341 | $localAlias = ''; |
| 325 | 342 | continue; |
| 326 | 343 | } |
| 327 | 344 | |
| 328 | - if ($localAlias === null) { |
|
| 345 | + if ($localAlias === null) |
|
| 346 | + { |
|
| 329 | 347 | $class .= $this->tokens[$localID][self::TOKEN_CODE]; |
| 330 | - } else { |
|
| 348 | + } |
|
| 349 | + else |
|
| 350 | + { |
|
| 331 | 351 | $localAlias .= $this->tokens[$localID][self::TOKEN_CODE]; |
| 332 | 352 | } |
| 333 | 353 | } |
| 334 | 354 | |
| 335 | - if (empty($localAlias)) { |
|
| 355 | + if (empty($localAlias)) |
|
| 356 | + { |
|
| 336 | 357 | $names = explode('\\', $class); |
| 337 | 358 | $localAlias = end($names); |
| 338 | 359 | } |
@@ -345,9 +366,12 @@ discard block |
||
| 345 | 366 | */ |
| 346 | 367 | private function registerFunction(int $tokenID): void |
| 347 | 368 | { |
| 348 | - foreach ($this->declarations as $declarations) { |
|
| 349 | - foreach ($declarations as $location) { |
|
| 350 | - if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]) { |
|
| 369 | + foreach ($this->declarations as $declarations) |
|
| 370 | + { |
|
| 371 | + foreach ($declarations as $location) |
|
| 372 | + { |
|
| 373 | + if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]) |
|
| 374 | + { |
|
| 351 | 375 | //We are inside class, function is method |
| 352 | 376 | return; |
| 353 | 377 | } |
@@ -355,13 +379,15 @@ discard block |
||
| 355 | 379 | } |
| 356 | 380 | |
| 357 | 381 | $localID = $tokenID + 1; |
| 358 | - while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) { |
|
| 382 | + while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) |
|
| 383 | + { |
|
| 359 | 384 | //Fetching function name |
| 360 | 385 | ++$localID; |
| 361 | 386 | } |
| 362 | 387 | |
| 363 | 388 | $name = $this->tokens[$localID][self::TOKEN_CODE]; |
| 364 | - if (!empty($namespace = $this->activeNamespace($tokenID))) { |
|
| 389 | + if (!empty($namespace = $this->activeNamespace($tokenID))) |
|
| 390 | + { |
|
| 365 | 391 | $name = $namespace . self::NS_SEPARATOR . $name; |
| 366 | 392 | } |
| 367 | 393 | |
@@ -378,12 +404,14 @@ discard block |
||
| 378 | 404 | private function registerDeclaration(int $tokenID, int $tokenType): void |
| 379 | 405 | { |
| 380 | 406 | $localID = $tokenID + 1; |
| 381 | - while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) { |
|
| 407 | + while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) |
|
| 408 | + { |
|
| 382 | 409 | ++$localID; |
| 383 | 410 | } |
| 384 | 411 | |
| 385 | 412 | $name = $this->tokens[$localID][self::TOKEN_CODE]; |
| 386 | - if (!empty($namespace = $this->activeNamespace($tokenID))) { |
|
| 413 | + if (!empty($namespace = $this->activeNamespace($tokenID))) |
|
| 414 | + { |
|
| 387 | 415 | $name = $namespace . self::NS_SEPARATOR . $name; |
| 388 | 416 | } |
| 389 | 417 | |
@@ -430,11 +458,13 @@ discard block |
||
| 430 | 458 | |
| 431 | 459 | //Tokens used to re-enable token detection |
| 432 | 460 | $stopTokens = [T_STRING, T_WHITESPACE, T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_NS_SEPARATOR]; |
| 433 | - foreach ($tokens as $tokenID => $token) { |
|
| 461 | + foreach ($tokens as $tokenID => $token) |
|
| 462 | + { |
|
| 434 | 463 | $tokenType = $token[self::TOKEN_TYPE]; |
| 435 | 464 | |
| 436 | 465 | //We are not indexing function declarations or functions called from $objects. |
| 437 | - if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])) { |
|
| 466 | + if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])) |
|
| 467 | + { |
|
| 438 | 468 | if ( |
| 439 | 469 | empty($argumentsTID) |
| 440 | 470 | && ( |
@@ -446,8 +476,11 @@ discard block |
||
| 446 | 476 | $ignore = true; |
| 447 | 477 | continue; |
| 448 | 478 | } |
| 449 | - } elseif ($ignore) { |
|
| 450 | - if (!\in_array($tokenType, $stopTokens)) { |
|
| 479 | + } |
|
| 480 | + elseif ($ignore) |
|
| 481 | + { |
|
| 482 | + if (!\in_array($tokenType, $stopTokens)) |
|
| 483 | + { |
|
| 451 | 484 | //Returning to search |
| 452 | 485 | $ignore = false; |
| 453 | 486 | } |
@@ -455,13 +488,16 @@ discard block |
||
| 455 | 488 | } |
| 456 | 489 | |
| 457 | 490 | //We are inside function, and there is "(", indexing arguments. |
| 458 | - if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')) { |
|
| 459 | - if (empty($argumentsTID)) { |
|
| 491 | + if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')) |
|
| 492 | + { |
|
| 493 | + if (empty($argumentsTID)) |
|
| 494 | + { |
|
| 460 | 495 | $argumentsTID = $tokenID; |
| 461 | 496 | } |
| 462 | 497 | |
| 463 | 498 | ++$level; |
| 464 | - if ($level != 1) { |
|
| 499 | + if ($level != 1) |
|
| 500 | + { |
|
| 465 | 501 | //Not arguments beginning, but arguments part |
| 466 | 502 | $arguments[$tokenID] = $token; |
| 467 | 503 | } |
@@ -470,16 +506,19 @@ discard block |
||
| 470 | 506 | } |
| 471 | 507 | |
| 472 | 508 | //We are inside function arguments and ")" met. |
| 473 | - if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')) { |
|
| 509 | + if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')) |
|
| 510 | + { |
|
| 474 | 511 | --$level; |
| 475 | - if ($level == -1) { |
|
| 512 | + if ($level == -1) |
|
| 513 | + { |
|
| 476 | 514 | $invocationTID = false; |
| 477 | 515 | $level = 0; |
| 478 | 516 | continue; |
| 479 | 517 | } |
| 480 | 518 | |
| 481 | 519 | //Function fully indexed, we can process it now. |
| 482 | - if ($level == 0) { |
|
| 520 | + if ($level == 0) |
|
| 521 | + { |
|
| 483 | 522 | $this->registerInvocation( |
| 484 | 523 | $invocationTID, |
| 485 | 524 | $argumentsTID, |
@@ -491,7 +530,9 @@ discard block |
||
| 491 | 530 | //Closing search |
| 492 | 531 | $arguments = []; |
| 493 | 532 | $argumentsTID = $invocationTID = false; |
| 494 | - } else { |
|
| 533 | + } |
|
| 534 | + else |
|
| 535 | + { |
|
| 495 | 536 | //Not arguments beginning, but arguments part |
| 496 | 537 | $arguments[$tokenID] = $token; |
| 497 | 538 | } |
@@ -500,13 +541,15 @@ discard block |
||
| 500 | 541 | } |
| 501 | 542 | |
| 502 | 543 | //Still inside arguments. |
| 503 | - if (!empty($invocationTID) && !empty($level)) { |
|
| 544 | + if (!empty($invocationTID) && !empty($level)) |
|
| 545 | + { |
|
| 504 | 546 | $arguments[$tokenID] = $token; |
| 505 | 547 | continue; |
| 506 | 548 | } |
| 507 | 549 | |
| 508 | 550 | //Nothing valuable to remember, will be parsed later. |
| 509 | - if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)) { |
|
| 551 | + if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)) |
|
| 552 | + { |
|
| 510 | 553 | continue; |
| 511 | 554 | } |
| 512 | 555 | |
@@ -545,7 +588,8 @@ discard block |
||
| 545 | 588 | |
| 546 | 589 | [$class, $operator, $name] = $this->fetchContext($invocationID, $argumentsID); |
| 547 | 590 | |
| 548 | - if (!empty($operator) && empty($class)) { |
|
| 591 | + if (!empty($operator) && empty($class)) |
|
| 592 | + { |
|
| 549 | 593 | //Non detectable |
| 550 | 594 | return; |
| 551 | 595 | } |
@@ -571,17 +615,22 @@ discard block |
||
| 571 | 615 | $name = \trim($this->getSource($invocationTID, $argumentsTID), '( '); |
| 572 | 616 | |
| 573 | 617 | //Let's try to fetch all information we need |
| 574 | - if (\str_contains($name, '->')) { |
|
| 618 | + if (\str_contains($name, '->')) |
|
| 619 | + { |
|
| 575 | 620 | $operator = '->'; |
| 576 | - } elseif (\str_contains($name, '::')) { |
|
| 621 | + } |
|
| 622 | + elseif (\str_contains($name, '::')) |
|
| 623 | + { |
|
| 577 | 624 | $operator = '::'; |
| 578 | 625 | } |
| 579 | 626 | |
| 580 | - if (!empty($operator)) { |
|
| 627 | + if (!empty($operator)) |
|
| 628 | + { |
|
| 581 | 629 | [$class, $name] = \explode($operator, $name); |
| 582 | 630 | |
| 583 | 631 | //We now have to clarify class name |
| 584 | - if (\in_array($class, ['self', 'static', '$this'])) { |
|
| 632 | + if (\in_array($class, ['self', 'static', '$this'])) |
|
| 633 | + { |
|
| 585 | 634 | $class = $this->activeDeclaration($invocationTID); |
| 586 | 635 | } |
| 587 | 636 | } |
@@ -594,9 +643,12 @@ discard block |
||
| 594 | 643 | */ |
| 595 | 644 | private function activeDeclaration(int $tokenID): string |
| 596 | 645 | { |
| 597 | - foreach ($this->declarations as $declarations) { |
|
| 598 | - foreach ($declarations as $name => $position) { |
|
| 599 | - if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) { |
|
| 646 | + foreach ($this->declarations as $declarations) |
|
| 647 | + { |
|
| 648 | + foreach ($declarations as $name => $position) |
|
| 649 | + { |
|
| 650 | + if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) |
|
| 651 | + { |
|
| 600 | 652 | return $name; |
| 601 | 653 | } |
| 602 | 654 | } |
@@ -611,8 +663,10 @@ discard block |
||
| 611 | 663 | */ |
| 612 | 664 | private function activeNamespace(int $tokenID): string |
| 613 | 665 | { |
| 614 | - foreach ($this->namespaces as $namespace => $position) { |
|
| 615 | - if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) { |
|
| 666 | + foreach ($this->namespaces as $namespace => $position) |
|
| 667 | + { |
|
| 668 | + if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) |
|
| 669 | + { |
|
| 616 | 670 | return $namespace; |
| 617 | 671 | } |
| 618 | 672 | } |
@@ -633,18 +687,22 @@ discard block |
||
| 633 | 687 | private function endingToken(int $tokenID): int |
| 634 | 688 | { |
| 635 | 689 | $level = null; |
| 636 | - for ($localID = $tokenID; $localID < $this->countTokens; ++$localID) { |
|
| 690 | + for ($localID = $tokenID; $localID < $this->countTokens; ++$localID) |
|
| 691 | + { |
|
| 637 | 692 | $token = $this->tokens[$localID]; |
| 638 | - if ($token[self::TOKEN_CODE] === '{') { |
|
| 693 | + if ($token[self::TOKEN_CODE] === '{') |
|
| 694 | + { |
|
| 639 | 695 | ++$level; |
| 640 | 696 | continue; |
| 641 | 697 | } |
| 642 | 698 | |
| 643 | - if ($token[self::TOKEN_CODE] === '}') { |
|
| 699 | + if ($token[self::TOKEN_CODE] === '}') |
|
| 700 | + { |
|
| 644 | 701 | --$level; |
| 645 | 702 | } |
| 646 | 703 | |
| 647 | - if ($level === 0) { |
|
| 704 | + if ($level === 0) |
|
| 705 | + { |
|
| 648 | 706 | break; |
| 649 | 707 | } |
| 650 | 708 | } |
@@ -657,7 +715,8 @@ discard block |
||
| 657 | 715 | */ |
| 658 | 716 | private function lineNumber(int $tokenID): int |
| 659 | 717 | { |
| 660 | - while (empty($this->tokens[$tokenID][self::TOKEN_LINE])) { |
|
| 718 | + while (empty($this->tokens[$tokenID][self::TOKEN_LINE])) |
|
| 719 | + { |
|
| 661 | 720 | --$tokenID; |
| 662 | 721 | } |
| 663 | 722 | |
@@ -670,7 +729,8 @@ discard block |
||
| 670 | 729 | private function getSource(int $startID, int $endID): string |
| 671 | 730 | { |
| 672 | 731 | $result = ''; |
| 673 | - for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID) { |
|
| 732 | + for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID) |
|
| 733 | + { |
|
| 674 | 734 | //Collecting function usage src |
| 675 | 735 | $result .= $this->tokens[$tokenID][self::TOKEN_CODE]; |
| 676 | 736 | } |
@@ -14,10 +14,10 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * Argument types. |
| 16 | 16 | */ |
| 17 | - public const CONSTANT = 'constant'; //Scalar constant and not variable. |
|
| 18 | - public const VARIABLE = 'variable'; //PHP variable |
|
| 17 | + public const CONSTANT = 'constant'; //Scalar constant and not variable. |
|
| 18 | + public const VARIABLE = 'variable'; //PHP variable |
|
| 19 | 19 | public const EXPRESSION = 'expression'; //PHP code (expression). |
| 20 | - public const STRING = 'string'; //Simple scalar string, can be fetched using stringValue(). |
|
| 20 | + public const STRING = 'string'; //Simple scalar string, can be fetched using stringValue(). |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * New instance of ReflectionArgument. |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | public function __construct( |
| 29 | 29 | private string $type, |
| 30 | 30 | private readonly string $value |
| 31 | - ) { |
|
| 31 | + ){ |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function getType(): string |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function stringValue(): string |
| 50 | 50 | { |
| 51 | - if ($this->type !== self::STRING) { |
|
| 51 | + if ($this->type !== self::STRING){ |
|
| 52 | 52 | throw new ReflectionException( |
| 53 | 53 | \sprintf("Unable to represent value as string, value type is '%s'", $this->type) |
| 54 | 54 | ); |
@@ -69,33 +69,33 @@ discard block |
||
| 69 | 69 | $level = 0; |
| 70 | 70 | |
| 71 | 71 | $result = []; |
| 72 | - foreach ($tokens as $token) { |
|
| 73 | - if ($token[ReflectionFile::TOKEN_TYPE] === T_WHITESPACE) { |
|
| 72 | + foreach ($tokens as $token){ |
|
| 73 | + if ($token[ReflectionFile::TOKEN_TYPE] === T_WHITESPACE){ |
|
| 74 | 74 | continue; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if (empty($definition)) { |
|
| 77 | + if (empty($definition)){ |
|
| 78 | 78 | $definition = ['type' => self::EXPRESSION, 'value' => '', 'tokens' => []]; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - if ($token[ReflectionFile::TOKEN_TYPE] === '(' || $token[ReflectionFile::TOKEN_TYPE] === '[') { |
|
| 81 | + if ($token[ReflectionFile::TOKEN_TYPE] === '(' || $token[ReflectionFile::TOKEN_TYPE] === '['){ |
|
| 82 | 82 | ++$level; |
| 83 | 83 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
| 84 | 84 | continue; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if ($token[ReflectionFile::TOKEN_TYPE] === ')' || $token[ReflectionFile::TOKEN_TYPE] === ']') { |
|
| 87 | + if ($token[ReflectionFile::TOKEN_TYPE] === ')' || $token[ReflectionFile::TOKEN_TYPE] === ']'){ |
|
| 88 | 88 | --$level; |
| 89 | 89 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
| 90 | 90 | continue; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ($level) { |
|
| 93 | + if ($level){ |
|
| 94 | 94 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
| 95 | 95 | continue; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if ($token[ReflectionFile::TOKEN_TYPE] === ',') { |
|
| 98 | + if ($token[ReflectionFile::TOKEN_TYPE] === ','){ |
|
| 99 | 99 | $result[] = self::createArgument($definition); |
| 100 | 100 | $definition = null; |
| 101 | 101 | continue; |
@@ -106,9 +106,9 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | //Last argument |
| 109 | - if (\is_array($definition)) { |
|
| 109 | + if (\is_array($definition)){ |
|
| 110 | 110 | $definition = self::createArgument($definition); |
| 111 | - if (!empty($definition->getType())) { |
|
| 111 | + if (!empty($definition->getType())){ |
|
| 112 | 112 | $result[] = $definition; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | $result = new static(self::EXPRESSION, $definition['value']); |
| 128 | 128 | |
| 129 | - if (\count($definition['tokens']) == 1) { |
|
| 129 | + if (\count($definition['tokens']) == 1){ |
|
| 130 | 130 | $result->type = match ($definition['tokens'][0][0]) { |
| 131 | 131 | T_VARIABLE => self::VARIABLE, |
| 132 | 132 | T_LNUMBER, T_DNUMBER => self::CONSTANT, |
@@ -48,7 +48,8 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function stringValue(): string |
| 50 | 50 | { |
| 51 | - if ($this->type !== self::STRING) { |
|
| 51 | + if ($this->type !== self::STRING) |
|
| 52 | + { |
|
| 52 | 53 | throw new ReflectionException( |
| 53 | 54 | \sprintf("Unable to represent value as string, value type is '%s'", $this->type) |
| 54 | 55 | ); |
@@ -69,33 +70,40 @@ discard block |
||
| 69 | 70 | $level = 0; |
| 70 | 71 | |
| 71 | 72 | $result = []; |
| 72 | - foreach ($tokens as $token) { |
|
| 73 | - if ($token[ReflectionFile::TOKEN_TYPE] === T_WHITESPACE) { |
|
| 73 | + foreach ($tokens as $token) |
|
| 74 | + { |
|
| 75 | + if ($token[ReflectionFile::TOKEN_TYPE] === T_WHITESPACE) |
|
| 76 | + { |
|
| 74 | 77 | continue; |
| 75 | 78 | } |
| 76 | 79 | |
| 77 | - if (empty($definition)) { |
|
| 80 | + if (empty($definition)) |
|
| 81 | + { |
|
| 78 | 82 | $definition = ['type' => self::EXPRESSION, 'value' => '', 'tokens' => []]; |
| 79 | 83 | } |
| 80 | 84 | |
| 81 | - if ($token[ReflectionFile::TOKEN_TYPE] === '(' || $token[ReflectionFile::TOKEN_TYPE] === '[') { |
|
| 85 | + if ($token[ReflectionFile::TOKEN_TYPE] === '(' || $token[ReflectionFile::TOKEN_TYPE] === '[') |
|
| 86 | + { |
|
| 82 | 87 | ++$level; |
| 83 | 88 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
| 84 | 89 | continue; |
| 85 | 90 | } |
| 86 | 91 | |
| 87 | - if ($token[ReflectionFile::TOKEN_TYPE] === ')' || $token[ReflectionFile::TOKEN_TYPE] === ']') { |
|
| 92 | + if ($token[ReflectionFile::TOKEN_TYPE] === ')' || $token[ReflectionFile::TOKEN_TYPE] === ']') |
|
| 93 | + { |
|
| 88 | 94 | --$level; |
| 89 | 95 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
| 90 | 96 | continue; |
| 91 | 97 | } |
| 92 | 98 | |
| 93 | - if ($level) { |
|
| 99 | + if ($level) |
|
| 100 | + { |
|
| 94 | 101 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
| 95 | 102 | continue; |
| 96 | 103 | } |
| 97 | 104 | |
| 98 | - if ($token[ReflectionFile::TOKEN_TYPE] === ',') { |
|
| 105 | + if ($token[ReflectionFile::TOKEN_TYPE] === ',') |
|
| 106 | + { |
|
| 99 | 107 | $result[] = self::createArgument($definition); |
| 100 | 108 | $definition = null; |
| 101 | 109 | continue; |
@@ -106,9 +114,11 @@ discard block |
||
| 106 | 114 | } |
| 107 | 115 | |
| 108 | 116 | //Last argument |
| 109 | - if (\is_array($definition)) { |
|
| 117 | + if (\is_array($definition)) |
|
| 118 | + { |
|
| 110 | 119 | $definition = self::createArgument($definition); |
| 111 | - if (!empty($definition->getType())) { |
|
| 120 | + if (!empty($definition->getType())) |
|
| 121 | + { |
|
| 112 | 122 | $result[] = $definition; |
| 113 | 123 | } |
| 114 | 124 | } |
@@ -126,7 +136,8 @@ discard block |
||
| 126 | 136 | { |
| 127 | 137 | $result = new static(self::EXPRESSION, $definition['value']); |
| 128 | 138 | |
| 129 | - if (\count($definition['tokens']) == 1) { |
|
| 139 | + if (\count($definition['tokens']) == 1) |
|
| 140 | + { |
|
| 130 | 141 | $result->type = match ($definition['tokens'][0][0]) { |
| 131 | 142 | T_VARIABLE => self::VARIABLE, |
| 132 | 143 | T_LNUMBER, T_DNUMBER => self::CONSTANT, |