@@ -18,7 +18,7 @@ |
||
| 18 | 18 | { |
| 19 | 19 | public function getActor(TokenInterface $token): ?object |
| 20 | 20 | { |
| 21 | - if ($token->getPayload()['ok']) { |
|
| 21 | + if ($token->getPayload()['ok']){ |
|
| 22 | 22 | return new \stdClass(); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -18,7 +18,8 @@ |
||
| 18 | 18 | { |
| 19 | 19 | public function getActor(TokenInterface $token): ?object |
| 20 | 20 | { |
| 21 | - if ($token->getPayload()['ok']) { |
|
| 21 | + if ($token->getPayload()['ok']) |
|
| 22 | + { |
|
| 22 | 23 | return new \stdClass(); |
| 23 | 24 | } |
| 24 | 25 | |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | { |
| 19 | 19 | public function getActor(TokenInterface $token): ?object |
| 20 | 20 | { |
| 21 | - if ($token->getID() === 'ok') { |
|
| 21 | + if ($token->getID() === 'ok'){ |
|
| 22 | 22 | return new \stdClass(); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -18,7 +18,8 @@ |
||
| 18 | 18 | { |
| 19 | 19 | public function getActor(TokenInterface $token): ?object |
| 20 | 20 | { |
| 21 | - if ($token->getID() === 'ok') { |
|
| 21 | + if ($token->getID() === 'ok') |
|
| 22 | + { |
|
| 22 | 23 | return new \stdClass(); |
| 23 | 24 | } |
| 24 | 25 | |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | { |
| 19 | 19 | public function load(string $id): ?TokenInterface |
| 20 | 20 | { |
| 21 | - if ($id === 'bad') { |
|
| 21 | + if ($id === 'bad'){ |
|
| 22 | 22 | return null; |
| 23 | 23 | } |
| 24 | 24 | |
@@ -18,7 +18,8 @@ |
||
| 18 | 18 | { |
| 19 | 19 | public function load(string $id): ?TokenInterface |
| 20 | 20 | { |
| 21 | - if ($id === 'bad') { |
|
| 21 | + if ($id === 'bad') |
|
| 22 | + { |
|
| 22 | 23 | return null; |
| 23 | 24 | } |
| 24 | 25 | |
@@ -23,20 +23,20 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function getClasses($target = null): array |
| 25 | 25 | { |
| 26 | - if (!empty($target) && (is_object($target) || is_string($target))) { |
|
| 26 | + if (!empty($target) && (is_object($target) || is_string($target))){ |
|
| 27 | 27 | $target = new \ReflectionClass($target); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | $result = []; |
| 31 | - foreach ($this->availableClasses() as $class) { |
|
| 32 | - try { |
|
| 31 | + foreach ($this->availableClasses() as $class){ |
|
| 32 | + try{ |
|
| 33 | 33 | $reflection = $this->classReflection($class); |
| 34 | - } catch (LocatorException $e) { |
|
| 34 | + }catch (LocatorException $e){ |
|
| 35 | 35 | //Ignoring |
| 36 | 36 | continue; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
| 39 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()){ |
|
| 40 | 40 | continue; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | { |
| 56 | 56 | $classes = []; |
| 57 | 57 | |
| 58 | - foreach ($this->availableReflections() as $reflection) { |
|
| 58 | + foreach ($this->availableReflections() as $reflection){ |
|
| 59 | 59 | $classes = array_merge($classes, $reflection->getClasses()); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | protected function isTargeted(\ReflectionClass $class, \ReflectionClass $target = null): bool |
| 73 | 73 | { |
| 74 | - if (empty($target)) { |
|
| 74 | + if (empty($target)){ |
|
| 75 | 75 | return true; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if (!$target->isTrait()) { |
|
| 78 | + if (!$target->isTrait()){ |
|
| 79 | 79 | //Target is interface or class |
| 80 | 80 | return $class->isSubclassOf($target) || $class->getName() == $target->getName(); |
| 81 | 81 | } |
@@ -23,20 +23,26 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function getClasses($target = null): array |
| 25 | 25 | { |
| 26 | - if (!empty($target) && (is_object($target) || is_string($target))) { |
|
| 26 | + if (!empty($target) && (is_object($target) || is_string($target))) |
|
| 27 | + { |
|
| 27 | 28 | $target = new \ReflectionClass($target); |
| 28 | 29 | } |
| 29 | 30 | |
| 30 | 31 | $result = []; |
| 31 | - foreach ($this->availableClasses() as $class) { |
|
| 32 | - try { |
|
| 32 | + foreach ($this->availableClasses() as $class) |
|
| 33 | + { |
|
| 34 | + try |
|
| 35 | + { |
|
| 33 | 36 | $reflection = $this->classReflection($class); |
| 34 | - } catch (LocatorException $e) { |
|
| 37 | + } |
|
| 38 | + catch (LocatorException $e) |
|
| 39 | + { |
|
| 35 | 40 | //Ignoring |
| 36 | 41 | continue; |
| 37 | 42 | } |
| 38 | 43 | |
| 39 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
| 44 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) |
|
| 45 | + { |
|
| 40 | 46 | continue; |
| 41 | 47 | } |
| 42 | 48 | |
@@ -55,7 +61,8 @@ discard block |
||
| 55 | 61 | { |
| 56 | 62 | $classes = []; |
| 57 | 63 | |
| 58 | - foreach ($this->availableReflections() as $reflection) { |
|
| 64 | + foreach ($this->availableReflections() as $reflection) |
|
| 65 | + { |
|
| 59 | 66 | $classes = array_merge($classes, $reflection->getClasses()); |
| 60 | 67 | } |
| 61 | 68 | |
@@ -71,11 +78,13 @@ discard block |
||
| 71 | 78 | */ |
| 72 | 79 | protected function isTargeted(\ReflectionClass $class, \ReflectionClass $target = null): bool |
| 73 | 80 | { |
| 74 | - if (empty($target)) { |
|
| 81 | + if (empty($target)) |
|
| 82 | + { |
|
| 75 | 83 | return true; |
| 76 | 84 | } |
| 77 | 85 | |
| 78 | - if (!$target->isTrait()) { |
|
| 86 | + if (!$target->isTrait()) |
|
| 87 | + { |
|
| 79 | 88 | //Target is interface or class |
| 80 | 89 | return $class->isSubclassOf($target) || $class->getName() == $target->getName(); |
| 81 | 90 | } |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | public function createInjection(\ReflectionClass $class, string $context = null) |
| 79 | 79 | { |
| 80 | - if ($class->isSubclassOf(ClassesInterface::class)) { |
|
| 80 | + if ($class->isSubclassOf(ClassesInterface::class)){ |
|
| 81 | 81 | return $this->classLocator(); |
| 82 | - } elseif ($class->isSubclassOf(InvocationsInterface::class)) { |
|
| 82 | + } elseif ($class->isSubclassOf(InvocationsInterface::class)){ |
|
| 83 | 83 | return $this->invocationLocator(); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | $tokens = token_get_all(file_get_contents($filename)); |
| 98 | 98 | |
| 99 | 99 | $line = 0; |
| 100 | - foreach ($tokens as &$token) { |
|
| 101 | - if (isset($token[self::LINE])) { |
|
| 100 | + foreach ($tokens as &$token){ |
|
| 101 | + if (isset($token[self::LINE])){ |
|
| 102 | 102 | $line = $token[self::LINE]; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if (!is_array($token)) { |
|
| 105 | + if (!is_array($token)){ |
|
| 106 | 106 | $token = [$token, $token, $line]; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -122,11 +122,11 @@ discard block |
||
| 122 | 122 | { |
| 123 | 123 | $finder = new Finder(); |
| 124 | 124 | |
| 125 | - if (empty($directories)) { |
|
| 125 | + if (empty($directories)){ |
|
| 126 | 126 | $directories = $this->config->getDirectories(); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - if (empty($exclude)) { |
|
| 129 | + if (empty($exclude)){ |
|
| 130 | 130 | $exclude = $this->config->getExcludes(); |
| 131 | 131 | } |
| 132 | 132 | |
@@ -77,9 +77,12 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | public function createInjection(\ReflectionClass $class, string $context = null) |
| 79 | 79 | { |
| 80 | - if ($class->isSubclassOf(ClassesInterface::class)) { |
|
| 80 | + if ($class->isSubclassOf(ClassesInterface::class)) |
|
| 81 | + { |
|
| 81 | 82 | return $this->classLocator(); |
| 82 | - } elseif ($class->isSubclassOf(InvocationsInterface::class)) { |
|
| 83 | + } |
|
| 84 | + elseif ($class->isSubclassOf(InvocationsInterface::class)) |
|
| 85 | + { |
|
| 83 | 86 | return $this->invocationLocator(); |
| 84 | 87 | } |
| 85 | 88 | |
@@ -97,12 +100,15 @@ discard block |
||
| 97 | 100 | $tokens = token_get_all(file_get_contents($filename)); |
| 98 | 101 | |
| 99 | 102 | $line = 0; |
| 100 | - foreach ($tokens as &$token) { |
|
| 101 | - if (isset($token[self::LINE])) { |
|
| 103 | + foreach ($tokens as &$token) |
|
| 104 | + { |
|
| 105 | + if (isset($token[self::LINE])) |
|
| 106 | + { |
|
| 102 | 107 | $line = $token[self::LINE]; |
| 103 | 108 | } |
| 104 | 109 | |
| 105 | - if (!is_array($token)) { |
|
| 110 | + if (!is_array($token)) |
|
| 111 | + { |
|
| 106 | 112 | $token = [$token, $token, $line]; |
| 107 | 113 | } |
| 108 | 114 | |
@@ -122,11 +128,13 @@ discard block |
||
| 122 | 128 | { |
| 123 | 129 | $finder = new Finder(); |
| 124 | 130 | |
| 125 | - if (empty($directories)) { |
|
| 131 | + if (empty($directories)) |
|
| 132 | + { |
|
| 126 | 133 | $directories = $this->config->getDirectories(); |
| 127 | 134 | } |
| 128 | 135 | |
| 129 | - if (empty($exclude)) { |
|
| 136 | + if (empty($exclude)) |
|
| 137 | + { |
|
| 130 | 138 | $exclude = $this->config->getExcludes(); |
| 131 | 139 | } |
| 132 | 140 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | array $arguments, |
| 70 | 70 | string $source, |
| 71 | 71 | int $level |
| 72 | - ) { |
|
| 72 | + ){ |
|
| 73 | 73 | $this->filename = $filename; |
| 74 | 74 | $this->line = $line; |
| 75 | 75 | $this->class = $class; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | */ |
| 180 | 180 | public function getArgument(int $index): ReflectionArgument |
| 181 | 181 | { |
| 182 | - if (!isset($this->arguments[$index])) { |
|
| 182 | + if (!isset($this->arguments[$index])){ |
|
| 183 | 183 | throw new ReflectionException("No such argument with index '{$index}'"); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -179,7 +179,8 @@ |
||
| 179 | 179 | */ |
| 180 | 180 | public function getArgument(int $index): ReflectionArgument |
| 181 | 181 | { |
| 182 | - if (!isset($this->arguments[$index])) { |
|
| 182 | + if (!isset($this->arguments[$index])) |
|
| 183 | + { |
|
| 183 | 184 | throw new ReflectionException("No such argument with index '{$index}'"); |
| 184 | 185 | } |
| 185 | 186 | |
@@ -69,7 +69,8 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function stringValue(): string |
| 71 | 71 | { |
| 72 | - if ($this->type != self::STRING) { |
|
| 72 | + if ($this->type != self::STRING) |
|
| 73 | + { |
|
| 73 | 74 | throw new ReflectionException( |
| 74 | 75 | "Unable to represent value as string, value type is '{$this->type}'" |
| 75 | 76 | ); |
@@ -91,12 +92,15 @@ discard block |
||
| 91 | 92 | $level = 0; |
| 92 | 93 | |
| 93 | 94 | $result = []; |
| 94 | - foreach ($tokens as $token) { |
|
| 95 | - if ($token[ReflectionFile::TOKEN_TYPE] == T_WHITESPACE) { |
|
| 95 | + foreach ($tokens as $token) |
|
| 96 | + { |
|
| 97 | + if ($token[ReflectionFile::TOKEN_TYPE] == T_WHITESPACE) |
|
| 98 | + { |
|
| 96 | 99 | continue; |
| 97 | 100 | } |
| 98 | 101 | |
| 99 | - if (empty($definition)) { |
|
| 102 | + if (empty($definition)) |
|
| 103 | + { |
|
| 100 | 104 | $definition = ['type' => self::EXPRESSION, 'value' => '', 'tokens' => []]; |
| 101 | 105 | } |
| 102 | 106 | |
@@ -118,12 +122,14 @@ discard block |
||
| 118 | 122 | continue; |
| 119 | 123 | } |
| 120 | 124 | |
| 121 | - if ($level) { |
|
| 125 | + if ($level) |
|
| 126 | + { |
|
| 122 | 127 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
| 123 | 128 | continue; |
| 124 | 129 | } |
| 125 | 130 | |
| 126 | - if ($token[ReflectionFile::TOKEN_TYPE] == ',') { |
|
| 131 | + if ($token[ReflectionFile::TOKEN_TYPE] == ',') |
|
| 132 | + { |
|
| 127 | 133 | $result[] = self::createArgument($definition); |
| 128 | 134 | $definition = null; |
| 129 | 135 | continue; |
@@ -134,9 +140,11 @@ discard block |
||
| 134 | 140 | } |
| 135 | 141 | |
| 136 | 142 | //Last argument |
| 137 | - if (is_array($definition)) { |
|
| 143 | + if (is_array($definition)) |
|
| 144 | + { |
|
| 138 | 145 | $definition = self::createArgument($definition); |
| 139 | - if (!empty($definition->getType())) { |
|
| 146 | + if (!empty($definition->getType())) |
|
| 147 | + { |
|
| 140 | 148 | $result[] = $definition; |
| 141 | 149 | } |
| 142 | 150 | } |
@@ -155,9 +163,11 @@ discard block |
||
| 155 | 163 | { |
| 156 | 164 | $result = new static(self::EXPRESSION, $definition['value']); |
| 157 | 165 | |
| 158 | - if (count($definition['tokens']) == 1) { |
|
| 166 | + if (count($definition['tokens']) == 1) |
|
| 167 | + { |
|
| 159 | 168 | //If argument represent by one token we can try to resolve it's type more precisely |
| 160 | - switch ($definition['tokens'][0][0]) { |
|
| 169 | + switch ($definition['tokens'][0][0]) |
|
| 170 | + { |
|
| 161 | 171 | case T_VARIABLE: |
| 162 | 172 | $result->type = self::VARIABLE; |
| 163 | 173 | break; |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * Argument types. |
| 23 | 23 | */ |
| 24 | - public const CONSTANT = 'constant'; //Scalar constant and not variable. |
|
| 25 | - public const VARIABLE = 'variable'; //PHP variable |
|
| 24 | + public const CONSTANT = 'constant'; //Scalar constant and not variable. |
|
| 25 | + public const VARIABLE = 'variable'; //PHP variable |
|
| 26 | 26 | public const EXPRESSION = 'expression'; //PHP code (expression). |
| 27 | 27 | public const STRING = 'string'; |
| 28 | 28 | private string $type; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function stringValue(): string |
| 61 | 61 | { |
| 62 | - if ($this->type != self::STRING) { |
|
| 62 | + if ($this->type != self::STRING){ |
|
| 63 | 63 | throw new ReflectionException( |
| 64 | 64 | "Unable to represent value as string, value type is '{$this->type}'" |
| 65 | 65 | ); |
@@ -80,19 +80,19 @@ discard block |
||
| 80 | 80 | $level = 0; |
| 81 | 81 | |
| 82 | 82 | $result = []; |
| 83 | - foreach ($tokens as $token) { |
|
| 84 | - if ($token[ReflectionFile::TOKEN_TYPE] == T_WHITESPACE) { |
|
| 83 | + foreach ($tokens as $token){ |
|
| 84 | + if ($token[ReflectionFile::TOKEN_TYPE] == T_WHITESPACE){ |
|
| 85 | 85 | continue; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if (empty($definition)) { |
|
| 88 | + if (empty($definition)){ |
|
| 89 | 89 | $definition = ['type' => self::EXPRESSION, 'value' => '', 'tokens' => []]; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | if ( |
| 93 | 93 | $token[ReflectionFile::TOKEN_TYPE] == '(' |
| 94 | 94 | || $token[ReflectionFile::TOKEN_TYPE] == '[' |
| 95 | - ) { |
|
| 95 | + ){ |
|
| 96 | 96 | ++$level; |
| 97 | 97 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
| 98 | 98 | continue; |
@@ -101,18 +101,18 @@ discard block |
||
| 101 | 101 | if ( |
| 102 | 102 | $token[ReflectionFile::TOKEN_TYPE] == ')' |
| 103 | 103 | || $token[ReflectionFile::TOKEN_TYPE] == ']' |
| 104 | - ) { |
|
| 104 | + ){ |
|
| 105 | 105 | --$level; |
| 106 | 106 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
| 107 | 107 | continue; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if ($level) { |
|
| 110 | + if ($level){ |
|
| 111 | 111 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
| 112 | 112 | continue; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if ($token[ReflectionFile::TOKEN_TYPE] == ',') { |
|
| 115 | + if ($token[ReflectionFile::TOKEN_TYPE] == ','){ |
|
| 116 | 116 | $result[] = self::createArgument($definition); |
| 117 | 117 | $definition = null; |
| 118 | 118 | continue; |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | //Last argument |
| 126 | - if (is_array($definition)) { |
|
| 126 | + if (is_array($definition)){ |
|
| 127 | 127 | $definition = self::createArgument($definition); |
| 128 | - if (!empty($definition->getType())) { |
|
| 128 | + if (!empty($definition->getType())){ |
|
| 129 | 129 | $result[] = $definition; |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -142,9 +142,9 @@ discard block |
||
| 142 | 142 | { |
| 143 | 143 | $result = new static(self::EXPRESSION, $definition['value']); |
| 144 | 144 | |
| 145 | - if (count($definition['tokens']) == 1) { |
|
| 145 | + if (count($definition['tokens']) == 1){ |
|
| 146 | 146 | //If argument represent by one token we can try to resolve it's type more precisely |
| 147 | - switch ($definition['tokens'][0][0]) { |
|
| 147 | + switch ($definition['tokens'][0][0]){ |
|
| 148 | 148 | case T_VARIABLE: |
| 149 | 149 | $result->type = self::VARIABLE; |
| 150 | 150 | break; |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | protected function someFunction() |
| 20 | 20 | { |
| 21 | 21 | $result = $this->sampleMethod('hello world'); |
| 22 | - print_r(self::sampleMethod($result . 'plus')); |
|
| 22 | + print_r(self::sampleMethod($result.'plus')); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function testInstance() |
@@ -22,17 +22,17 @@ |
||
| 22 | 22 | $this->assertContains(TestTrait::class, $reflection->getTraits()); |
| 23 | 23 | $this->assertContains(TestInterface::class, $reflection->getInterfaces()); |
| 24 | 24 | |
| 25 | - $this->assertSame([__NAMESPACE__ . '\hello'], $reflection->getFunctions()); |
|
| 25 | + $this->assertSame([__NAMESPACE__.'\hello'], $reflection->getFunctions()); |
|
| 26 | 26 | |
| 27 | 27 | $functionA = null; |
| 28 | 28 | $functionB = null; |
| 29 | 29 | |
| 30 | - foreach ($reflection->getInvocations() as $invocation) { |
|
| 31 | - if ($invocation->getName() == 'test_function_a') { |
|
| 30 | + foreach ($reflection->getInvocations() as $invocation){ |
|
| 31 | + if ($invocation->getName() == 'test_function_a'){ |
|
| 32 | 32 | $functionA = $invocation; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if ($invocation->getName() == 'test_function_b') { |
|
| 35 | + if ($invocation->getName() == 'test_function_b'){ |
|
| 36 | 36 | $functionB = $invocation; |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -27,12 +27,15 @@ |
||
| 27 | 27 | $functionA = null; |
| 28 | 28 | $functionB = null; |
| 29 | 29 | |
| 30 | - foreach ($reflection->getInvocations() as $invocation) { |
|
| 31 | - if ($invocation->getName() == 'test_function_a') { |
|
| 30 | + foreach ($reflection->getInvocations() as $invocation) |
|
| 31 | + { |
|
| 32 | + if ($invocation->getName() == 'test_function_a') |
|
| 33 | + { |
|
| 32 | 34 | $functionA = $invocation; |
| 33 | 35 | } |
| 34 | 36 | |
| 35 | - if ($invocation->getName() == 'test_function_b') { |
|
| 37 | + if ($invocation->getName() == 'test_function_b') |
|
| 38 | + { |
|
| 36 | 39 | $functionB = $invocation; |
| 37 | 40 | } |
| 38 | 41 | } |