@@ -154,11 +154,11 @@ |
||
154 | 154 | */ |
155 | 155 | public function setDelay($delay): self |
156 | 156 | { |
157 | - if ($delay instanceof DateInterval) { |
|
157 | + if ($delay instanceof DateInterval){ |
|
158 | 158 | $delay = (new DateTimeImmutable('NOW'))->add($delay); |
159 | 159 | } |
160 | 160 | |
161 | - if ($delay instanceof DateTimeInterface) { |
|
161 | + if ($delay instanceof DateTimeInterface){ |
|
162 | 162 | $delay = max(0, $delay->getTimestamp() - time()); |
163 | 163 | } |
164 | 164 |
@@ -154,11 +154,13 @@ |
||
154 | 154 | */ |
155 | 155 | public function setDelay($delay): self |
156 | 156 | { |
157 | - if ($delay instanceof DateInterval) { |
|
157 | + if ($delay instanceof DateInterval) |
|
158 | + { |
|
158 | 159 | $delay = (new DateTimeImmutable('NOW'))->add($delay); |
159 | 160 | } |
160 | 161 | |
161 | - if ($delay instanceof DateTimeInterface) { |
|
162 | + if ($delay instanceof DateTimeInterface) |
|
163 | + { |
|
162 | 164 | $delay = max(0, $delay->getTimestamp() - time()); |
163 | 165 | } |
164 | 166 |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | $name ??= $this->default; |
64 | 64 | |
65 | - if (!isset($this->resolvers[$name])) { |
|
65 | + if (!isset($this->resolvers[$name])){ |
|
66 | 66 | throw new InvalidArgumentException(\sprintf(self::ERROR_NOT_FOUND, $name)); |
67 | 67 | } |
68 | 68 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function add(string $name, UriResolverInterface $resolver, bool $overwrite = false): void |
76 | 76 | { |
77 | - if ($overwrite === false && isset($this->resolvers[$name])) { |
|
77 | + if ($overwrite === false && isset($this->resolvers[$name])){ |
|
78 | 78 | throw new InvalidArgumentException(\sprintf(self::ERROR_REDEFINITION, $name)); |
79 | 79 | } |
80 | 80 |
@@ -62,7 +62,8 @@ discard block |
||
62 | 62 | { |
63 | 63 | $name ??= $this->default; |
64 | 64 | |
65 | - if (!isset($this->resolvers[$name])) { |
|
65 | + if (!isset($this->resolvers[$name])) |
|
66 | + { |
|
66 | 67 | throw new InvalidArgumentException(\sprintf(self::ERROR_NOT_FOUND, $name)); |
67 | 68 | } |
68 | 69 | |
@@ -74,7 +75,8 @@ discard block |
||
74 | 75 | */ |
75 | 76 | public function add(string $name, UriResolverInterface $resolver, bool $overwrite = false): void |
76 | 77 | { |
77 | - if ($overwrite === false && isset($this->resolvers[$name])) { |
|
78 | + if ($overwrite === false && isset($this->resolvers[$name])) |
|
79 | + { |
|
78 | 80 | throw new InvalidArgumentException(\sprintf(self::ERROR_REDEFINITION, $name)); |
79 | 81 | } |
80 | 82 |
@@ -102,7 +102,7 @@ |
||
102 | 102 | */ |
103 | 103 | private function resolveExpirationInterval($expiration): DateInterval |
104 | 104 | { |
105 | - if ($expiration === null) { |
|
105 | + if ($expiration === null){ |
|
106 | 106 | return $this->expiration; |
107 | 107 | } |
108 | 108 |
@@ -102,7 +102,8 @@ |
||
102 | 102 | */ |
103 | 103 | private function resolveExpirationInterval($expiration): DateInterval |
104 | 104 | { |
105 | - if ($expiration === null) { |
|
105 | + if ($expiration === null) |
|
106 | + { |
|
106 | 107 | return $this->expiration; |
107 | 108 | } |
108 | 109 |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function create($duration): DateInterval |
46 | 46 | { |
47 | - try { |
|
47 | + try{ |
|
48 | 48 | return $this->createOrFail($duration); |
49 | - } catch (InvalidArgumentException $e) { |
|
49 | + }catch (InvalidArgumentException $e){ |
|
50 | 50 | throw $e; |
51 | - } catch (Throwable $e) { |
|
51 | + }catch (Throwable $e){ |
|
52 | 52 | throw new InvalidArgumentException($e->getMessage(), (int)$e->getCode(), $e); |
53 | 53 | } |
54 | 54 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | private function createOrFail($duration): DateInterval |
71 | 71 | { |
72 | - switch (true) { |
|
72 | + switch (true){ |
|
73 | 73 | case $duration instanceof DateInterval: |
74 | 74 | return $duration; |
75 | 75 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | return new DateInterval($duration); |
81 | 81 | |
82 | 82 | case \is_int($duration): |
83 | - return new DateInterval('PT' . $duration . 'S'); |
|
83 | + return new DateInterval('PT'.$duration.'S'); |
|
84 | 84 | |
85 | 85 | case $duration === null: |
86 | 86 | return new DateInterval('PT0S'); |
@@ -44,11 +44,16 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function create($duration): DateInterval |
46 | 46 | { |
47 | - try { |
|
47 | + try |
|
48 | + { |
|
48 | 49 | return $this->createOrFail($duration); |
49 | - } catch (InvalidArgumentException $e) { |
|
50 | + } |
|
51 | + catch (InvalidArgumentException $e) |
|
52 | + { |
|
50 | 53 | throw $e; |
51 | - } catch (Throwable $e) { |
|
54 | + } |
|
55 | + catch (Throwable $e) |
|
56 | + { |
|
52 | 57 | throw new InvalidArgumentException($e->getMessage(), (int)$e->getCode(), $e); |
53 | 58 | } |
54 | 59 | } |
@@ -69,7 +74,8 @@ discard block |
||
69 | 74 | */ |
70 | 75 | private function createOrFail($duration): DateInterval |
71 | 76 | { |
72 | - switch (true) { |
|
77 | + switch (true) |
|
78 | + { |
|
73 | 79 | case $duration instanceof DateInterval: |
74 | 80 | return $duration; |
75 | 81 |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function getPage(): int |
94 | 94 | { |
95 | - if ($this->pageNumber < 1) { |
|
95 | + if ($this->pageNumber < 1){ |
|
96 | 96 | return 1; |
97 | 97 | } |
98 | 98 | |
99 | - if ($this->pageNumber > $this->countPages) { |
|
99 | + if ($this->pageNumber > $this->countPages){ |
|
100 | 100 | return $this->countPages; |
101 | 101 | } |
102 | 102 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | public function paginate(PaginableInterface $target): PaginatorInterface |
118 | 118 | { |
119 | 119 | $paginator = clone $this; |
120 | - if ($target instanceof Countable && $paginator->count === 0) { |
|
120 | + if ($target instanceof Countable && $paginator->count === 0){ |
|
121 | 121 | $paginator->setCount($target->count()); |
122 | 122 | } |
123 | 123 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function countDisplayed(): int |
147 | 147 | { |
148 | - if ($this->getPage() == $this->countPages) { |
|
148 | + if ($this->getPage() == $this->countPages){ |
|
149 | 149 | return $this->count - $this->getOffset(); |
150 | 150 | } |
151 | 151 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function nextPage() |
167 | 167 | { |
168 | - if ($this->getPage() != $this->countPages) { |
|
168 | + if ($this->getPage() != $this->countPages){ |
|
169 | 169 | return $this->getPage() + 1; |
170 | 170 | } |
171 | 171 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function previousPage() |
179 | 179 | { |
180 | - if ($this->getPage() > 1) { |
|
180 | + if ($this->getPage() > 1){ |
|
181 | 181 | return $this->getPage() - 1; |
182 | 182 | } |
183 | 183 | |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | private function setCount(int $count): self |
193 | 193 | { |
194 | 194 | $this->count = max($count, 0); |
195 | - if ($this->count > 0) { |
|
195 | + if ($this->count > 0){ |
|
196 | 196 | $this->countPages = (int)ceil($this->count / $this->limit); |
197 | - } else { |
|
197 | + }else{ |
|
198 | 198 | $this->countPages = 1; |
199 | 199 | } |
200 | 200 |
@@ -92,11 +92,13 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function getPage(): int |
94 | 94 | { |
95 | - if ($this->pageNumber < 1) { |
|
95 | + if ($this->pageNumber < 1) |
|
96 | + { |
|
96 | 97 | return 1; |
97 | 98 | } |
98 | 99 | |
99 | - if ($this->pageNumber > $this->countPages) { |
|
100 | + if ($this->pageNumber > $this->countPages) |
|
101 | + { |
|
100 | 102 | return $this->countPages; |
101 | 103 | } |
102 | 104 | |
@@ -117,7 +119,8 @@ discard block |
||
117 | 119 | public function paginate(PaginableInterface $target): PaginatorInterface |
118 | 120 | { |
119 | 121 | $paginator = clone $this; |
120 | - if ($target instanceof Countable && $paginator->count === 0) { |
|
122 | + if ($target instanceof Countable && $paginator->count === 0) |
|
123 | + { |
|
121 | 124 | $paginator->setCount($target->count()); |
122 | 125 | } |
123 | 126 | |
@@ -145,7 +148,8 @@ discard block |
||
145 | 148 | */ |
146 | 149 | public function countDisplayed(): int |
147 | 150 | { |
148 | - if ($this->getPage() == $this->countPages) { |
|
151 | + if ($this->getPage() == $this->countPages) |
|
152 | + { |
|
149 | 153 | return $this->count - $this->getOffset(); |
150 | 154 | } |
151 | 155 | |
@@ -165,7 +169,8 @@ discard block |
||
165 | 169 | */ |
166 | 170 | public function nextPage() |
167 | 171 | { |
168 | - if ($this->getPage() != $this->countPages) { |
|
172 | + if ($this->getPage() != $this->countPages) |
|
173 | + { |
|
169 | 174 | return $this->getPage() + 1; |
170 | 175 | } |
171 | 176 | |
@@ -177,7 +182,8 @@ discard block |
||
177 | 182 | */ |
178 | 183 | public function previousPage() |
179 | 184 | { |
180 | - if ($this->getPage() > 1) { |
|
185 | + if ($this->getPage() > 1) |
|
186 | + { |
|
181 | 187 | return $this->getPage() - 1; |
182 | 188 | } |
183 | 189 | |
@@ -192,9 +198,12 @@ discard block |
||
192 | 198 | private function setCount(int $count): self |
193 | 199 | { |
194 | 200 | $this->count = max($count, 0); |
195 | - if ($this->count > 0) { |
|
201 | + if ($this->count > 0) |
|
202 | + { |
|
196 | 203 | $this->countPages = (int)ceil($this->count / $this->limit); |
197 | - } else { |
|
204 | + } |
|
205 | + else |
|
206 | + { |
|
198 | 207 | $this->countPages = 1; |
199 | 208 | } |
200 | 209 |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | */ |
49 | 49 | protected function availableReflections(): Generator |
50 | 50 | { |
51 | - foreach ($this->finder->getIterator() as $file) { |
|
51 | + foreach ($this->finder->getIterator() as $file){ |
|
52 | 52 | $reflection = new ReflectionFile((string)$file); |
53 | 53 | |
54 | - if ($reflection->hasIncludes()) { |
|
54 | + if ($reflection->hasIncludes()){ |
|
55 | 55 | // We are not analyzing files which has includes, it's not safe to require such reflections |
56 | 56 | $this->getLogger()->warning( |
57 | 57 | sprintf('File `%s` has includes and excluded from analysis', $file), |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | */ |
78 | 78 | protected function classReflection(string $class): ReflectionClass |
79 | 79 | { |
80 | - $loader = static function ($class) { |
|
81 | - if ($class === LocatorException::class) { |
|
80 | + $loader = static function ($class){ |
|
81 | + if ($class === LocatorException::class){ |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | //To suspend class dependency exception |
89 | 89 | spl_autoload_register($loader); |
90 | 90 | |
91 | - try { |
|
91 | + try{ |
|
92 | 92 | //In some cases reflection can thrown an exception if class invalid or can not be loaded, |
93 | 93 | //we are going to handle such exception and convert it soft exception |
94 | 94 | return new ReflectionClass($class); |
95 | - } catch (Throwable $e) { |
|
96 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
95 | + }catch (Throwable $e){ |
|
96 | + if ($e instanceof LocatorException && $e->getPrevious() != null){ |
|
97 | 97 | $e = $e->getPrevious(); |
98 | 98 | } |
99 | 99 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | ); |
110 | 110 | |
111 | 111 | throw new LocatorException($e->getMessage(), $e->getCode(), $e); |
112 | - } finally { |
|
112 | + }finally{ |
|
113 | 113 | spl_autoload_unregister($loader); |
114 | 114 | } |
115 | 115 | } |
@@ -125,13 +125,13 @@ discard block |
||
125 | 125 | { |
126 | 126 | $traits = []; |
127 | 127 | |
128 | - do { |
|
128 | + do{ |
|
129 | 129 | $traits = \array_merge(\class_uses($class), $traits); |
130 | 130 | $class = \get_parent_class($class); |
131 | - } while ($class !== false); |
|
131 | + }while ($class !== false); |
|
132 | 132 | |
133 | 133 | //Traits from traits |
134 | - foreach (\array_flip($traits) as $trait) { |
|
134 | + foreach (\array_flip($traits) as $trait){ |
|
135 | 135 | $traits = \array_merge(\class_uses($trait), $traits); |
136 | 136 | } |
137 | 137 |
@@ -48,10 +48,12 @@ discard block |
||
48 | 48 | */ |
49 | 49 | protected function availableReflections(): Generator |
50 | 50 | { |
51 | - foreach ($this->finder->getIterator() as $file) { |
|
51 | + foreach ($this->finder->getIterator() as $file) |
|
52 | + { |
|
52 | 53 | $reflection = new ReflectionFile((string)$file); |
53 | 54 | |
54 | - if ($reflection->hasIncludes()) { |
|
55 | + if ($reflection->hasIncludes()) |
|
56 | + { |
|
55 | 57 | // We are not analyzing files which has includes, it's not safe to require such reflections |
56 | 58 | $this->getLogger()->warning( |
57 | 59 | sprintf('File `%s` has includes and excluded from analysis', $file), |
@@ -77,8 +79,10 @@ discard block |
||
77 | 79 | */ |
78 | 80 | protected function classReflection(string $class): ReflectionClass |
79 | 81 | { |
80 | - $loader = static function ($class) { |
|
81 | - if ($class === LocatorException::class) { |
|
82 | + $loader = static function ($class) |
|
83 | + { |
|
84 | + if ($class === LocatorException::class) |
|
85 | + { |
|
82 | 86 | return; |
83 | 87 | } |
84 | 88 | |
@@ -88,12 +92,16 @@ discard block |
||
88 | 92 | //To suspend class dependency exception |
89 | 93 | spl_autoload_register($loader); |
90 | 94 | |
91 | - try { |
|
95 | + try |
|
96 | + { |
|
92 | 97 | //In some cases reflection can thrown an exception if class invalid or can not be loaded, |
93 | 98 | //we are going to handle such exception and convert it soft exception |
94 | 99 | return new ReflectionClass($class); |
95 | - } catch (Throwable $e) { |
|
96 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
100 | + } |
|
101 | + catch (Throwable $e) |
|
102 | + { |
|
103 | + if ($e instanceof LocatorException && $e->getPrevious() != null) |
|
104 | + { |
|
97 | 105 | $e = $e->getPrevious(); |
98 | 106 | } |
99 | 107 | |
@@ -109,7 +117,9 @@ discard block |
||
109 | 117 | ); |
110 | 118 | |
111 | 119 | throw new LocatorException($e->getMessage(), $e->getCode(), $e); |
112 | - } finally { |
|
120 | + } |
|
121 | + finally |
|
122 | + { |
|
113 | 123 | spl_autoload_unregister($loader); |
114 | 124 | } |
115 | 125 | } |
@@ -125,13 +135,15 @@ discard block |
||
125 | 135 | { |
126 | 136 | $traits = []; |
127 | 137 | |
128 | - do { |
|
138 | + do |
|
139 | + { |
|
129 | 140 | $traits = \array_merge(\class_uses($class), $traits); |
130 | 141 | $class = \get_parent_class($class); |
131 | 142 | } while ($class !== false); |
132 | 143 | |
133 | 144 | //Traits from traits |
134 | - foreach (\array_flip($traits) as $trait) { |
|
145 | + foreach (\array_flip($traits) as $trait) |
|
146 | + { |
|
135 | 147 | $traits = \array_merge(\class_uses($trait), $traits); |
136 | 148 | } |
137 | 149 |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | public function getInvocations(ReflectionFunctionAbstract $function): array |
33 | 33 | { |
34 | 34 | $result = []; |
35 | - foreach ($this->availableInvocations($function->getName()) as $invocation) { |
|
36 | - if ($this->isTargeted($invocation, $function)) { |
|
35 | + foreach ($this->availableInvocations($function->getName()) as $invocation){ |
|
36 | + if ($this->isTargeted($invocation, $function)){ |
|
37 | 37 | $result[] = $invocation; |
38 | 38 | } |
39 | 39 | } |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | protected function availableInvocations(string $signature = ''): Generator |
51 | 51 | { |
52 | 52 | $signature = strtolower(trim($signature, '\\')); |
53 | - foreach ($this->availableReflections() as $reflection) { |
|
54 | - foreach ($reflection->getInvocations() as $invocation) { |
|
53 | + foreach ($this->availableReflections() as $reflection){ |
|
54 | + foreach ($reflection->getInvocations() as $invocation){ |
|
55 | 55 | if ( |
56 | 56 | !empty($signature) |
57 | 57 | && strtolower(trim($invocation->getName(), '\\')) != $signature |
58 | - ) { |
|
58 | + ){ |
|
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
@@ -66,13 +66,13 @@ discard block |
||
66 | 66 | |
67 | 67 | protected function isTargeted(ReflectionInvocation $invocation, ReflectionFunctionAbstract $function): bool |
68 | 68 | { |
69 | - if ($function instanceof ReflectionFunction) { |
|
69 | + if ($function instanceof ReflectionFunction){ |
|
70 | 70 | return !$invocation->isMethod(); |
71 | 71 | } |
72 | 72 | |
73 | - try { |
|
73 | + try{ |
|
74 | 74 | $reflection = $this->classReflection($invocation->getClass()); |
75 | - } catch (LocatorException $e) { |
|
75 | + }catch (LocatorException $e){ |
|
76 | 76 | return false; |
77 | 77 | } |
78 | 78 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | $target = $function->getDeclaringClass(); |
83 | 83 | |
84 | - if ($target->isTrait()) { |
|
84 | + if ($target->isTrait()){ |
|
85 | 85 | //Let's compare traits |
86 | 86 | return in_array($target->getName(), $this->fetchTraits($invocation->getClass())); |
87 | 87 | } |
@@ -32,8 +32,10 @@ discard block |
||
32 | 32 | public function getInvocations(ReflectionFunctionAbstract $function): array |
33 | 33 | { |
34 | 34 | $result = []; |
35 | - foreach ($this->availableInvocations($function->getName()) as $invocation) { |
|
36 | - if ($this->isTargeted($invocation, $function)) { |
|
35 | + foreach ($this->availableInvocations($function->getName()) as $invocation) |
|
36 | + { |
|
37 | + if ($this->isTargeted($invocation, $function)) |
|
38 | + { |
|
37 | 39 | $result[] = $invocation; |
38 | 40 | } |
39 | 41 | } |
@@ -50,8 +52,10 @@ discard block |
||
50 | 52 | protected function availableInvocations(string $signature = ''): Generator |
51 | 53 | { |
52 | 54 | $signature = strtolower(trim($signature, '\\')); |
53 | - foreach ($this->availableReflections() as $reflection) { |
|
54 | - foreach ($reflection->getInvocations() as $invocation) { |
|
55 | + foreach ($this->availableReflections() as $reflection) |
|
56 | + { |
|
57 | + foreach ($reflection->getInvocations() as $invocation) |
|
58 | + { |
|
55 | 59 | if ( |
56 | 60 | !empty($signature) |
57 | 61 | && strtolower(trim($invocation->getName(), '\\')) != $signature |
@@ -66,13 +70,17 @@ discard block |
||
66 | 70 | |
67 | 71 | protected function isTargeted(ReflectionInvocation $invocation, ReflectionFunctionAbstract $function): bool |
68 | 72 | { |
69 | - if ($function instanceof ReflectionFunction) { |
|
73 | + if ($function instanceof ReflectionFunction) |
|
74 | + { |
|
70 | 75 | return !$invocation->isMethod(); |
71 | 76 | } |
72 | 77 | |
73 | - try { |
|
78 | + try |
|
79 | + { |
|
74 | 80 | $reflection = $this->classReflection($invocation->getClass()); |
75 | - } catch (LocatorException $e) { |
|
81 | + } |
|
82 | + catch (LocatorException $e) |
|
83 | + { |
|
76 | 84 | return false; |
77 | 85 | } |
78 | 86 | |
@@ -81,7 +89,8 @@ discard block |
||
81 | 89 | */ |
82 | 90 | $target = $function->getDeclaringClass(); |
83 | 91 | |
84 | - if ($target->isTrait()) { |
|
92 | + if ($target->isTrait()) |
|
93 | + { |
|
85 | 94 | //Let's compare traits |
86 | 95 | return in_array($target->getName(), $this->fetchTraits($invocation->getClass())); |
87 | 96 | } |
@@ -24,20 +24,20 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function getClasses($target = null): array |
26 | 26 | { |
27 | - if (!empty($target) && (is_object($target) || is_string($target))) { |
|
27 | + if (!empty($target) && (is_object($target) || is_string($target))){ |
|
28 | 28 | $target = new ReflectionClass($target); |
29 | 29 | } |
30 | 30 | |
31 | 31 | $result = []; |
32 | - foreach ($this->availableClasses() as $class) { |
|
33 | - try { |
|
32 | + foreach ($this->availableClasses() as $class){ |
|
33 | + try{ |
|
34 | 34 | $reflection = $this->classReflection($class); |
35 | - } catch (LocatorException $e) { |
|
35 | + }catch (LocatorException $e){ |
|
36 | 36 | //Ignoring |
37 | 37 | continue; |
38 | 38 | } |
39 | 39 | |
40 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
40 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()){ |
|
41 | 41 | continue; |
42 | 42 | } |
43 | 43 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | { |
55 | 55 | $classes = []; |
56 | 56 | |
57 | - foreach ($this->availableReflections() as $reflection) { |
|
57 | + foreach ($this->availableReflections() as $reflection){ |
|
58 | 58 | $classes = array_merge($classes, $reflection->getClasses()); |
59 | 59 | } |
60 | 60 | |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | */ |
69 | 69 | protected function isTargeted(ReflectionClass $class, ReflectionClass $target = null): bool |
70 | 70 | { |
71 | - if (empty($target)) { |
|
71 | + if (empty($target)){ |
|
72 | 72 | return true; |
73 | 73 | } |
74 | 74 | |
75 | - if (!$target->isTrait()) { |
|
75 | + if (!$target->isTrait()){ |
|
76 | 76 | //Target is interface or class |
77 | 77 | return $class->isSubclassOf($target) || $class->getName() == $target->getName(); |
78 | 78 | } |
@@ -24,20 +24,26 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function getClasses($target = null): array |
26 | 26 | { |
27 | - if (!empty($target) && (is_object($target) || is_string($target))) { |
|
27 | + if (!empty($target) && (is_object($target) || is_string($target))) |
|
28 | + { |
|
28 | 29 | $target = new ReflectionClass($target); |
29 | 30 | } |
30 | 31 | |
31 | 32 | $result = []; |
32 | - foreach ($this->availableClasses() as $class) { |
|
33 | - try { |
|
33 | + foreach ($this->availableClasses() as $class) |
|
34 | + { |
|
35 | + try |
|
36 | + { |
|
34 | 37 | $reflection = $this->classReflection($class); |
35 | - } catch (LocatorException $e) { |
|
38 | + } |
|
39 | + catch (LocatorException $e) |
|
40 | + { |
|
36 | 41 | //Ignoring |
37 | 42 | continue; |
38 | 43 | } |
39 | 44 | |
40 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
45 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) |
|
46 | + { |
|
41 | 47 | continue; |
42 | 48 | } |
43 | 49 | |
@@ -54,7 +60,8 @@ discard block |
||
54 | 60 | { |
55 | 61 | $classes = []; |
56 | 62 | |
57 | - foreach ($this->availableReflections() as $reflection) { |
|
63 | + foreach ($this->availableReflections() as $reflection) |
|
64 | + { |
|
58 | 65 | $classes = array_merge($classes, $reflection->getClasses()); |
59 | 66 | } |
60 | 67 | |
@@ -68,11 +75,13 @@ discard block |
||
68 | 75 | */ |
69 | 76 | protected function isTargeted(ReflectionClass $class, ReflectionClass $target = null): bool |
70 | 77 | { |
71 | - if (empty($target)) { |
|
78 | + if (empty($target)) |
|
79 | + { |
|
72 | 80 | return true; |
73 | 81 | } |
74 | 82 | |
75 | - if (!$target->isTrait()) { |
|
83 | + if (!$target->isTrait()) |
|
84 | + { |
|
76 | 85 | //Target is interface or class |
77 | 86 | return $class->isSubclassOf($target) || $class->getName() == $target->getName(); |
78 | 87 | } |
@@ -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; |