@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $this->expectExceptionMessage('Enum `Spiral\Tests\Core\Stub\EnumObject` can not be constructed.'); |
64 | 64 | |
65 | 65 | $this->resolveClosure( |
66 | - static function (EnumObject $enum) {}, |
|
66 | + static function (EnumObject $enum){}, |
|
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | ); |
76 | 76 | |
77 | 77 | $this->resolveClosure( |
78 | - static function (TestTrait $enum) {}, |
|
78 | + static function (TestTrait $enum){}, |
|
79 | 79 | ); |
80 | 80 | } |
81 | 81 | } |
@@ -63,7 +63,9 @@ discard block |
||
63 | 63 | $this->expectExceptionMessage('Enum `Spiral\Tests\Core\Stub\EnumObject` can not be constructed.'); |
64 | 64 | |
65 | 65 | $this->resolveClosure( |
66 | - static function (EnumObject $enum) {}, |
|
66 | + static function (EnumObject $enum) |
|
67 | + { |
|
68 | +}, |
|
67 | 69 | ); |
68 | 70 | } |
69 | 71 | |
@@ -75,7 +77,9 @@ discard block |
||
75 | 77 | ); |
76 | 78 | |
77 | 79 | $this->resolveClosure( |
78 | - static function (TestTrait $enum) {}, |
|
80 | + static function (TestTrait $enum) |
|
81 | + { |
|
82 | +}, |
|
79 | 83 | ); |
80 | 84 | } |
81 | 85 | } |
@@ -40,7 +40,7 @@ |
||
40 | 40 | public readonly string $binder = Binder::class, |
41 | 41 | public readonly string $invoker = Invoker::class, |
42 | 42 | public readonly string $tracer = Tracer::class, |
43 | - ) { |
|
43 | + ){ |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | public function getIterator(): Traversable |
@@ -13,7 +13,7 @@ |
||
13 | 13 | public function __construct( |
14 | 14 | \ReflectionFunctionAbstract $reflection, |
15 | 15 | private readonly string $parameter |
16 | - ) { |
|
16 | + ){ |
|
17 | 17 | $pattern = "Invalid argument value type for the `$parameter` parameter when validating arguments for `%s`."; |
18 | 18 | parent::__construct($this->renderFunctionAndParameter($reflection, $pattern)); |
19 | 19 | } |
@@ -18,13 +18,13 @@ discard block |
||
18 | 18 | public function __construct( |
19 | 19 | public readonly string $alias, |
20 | 20 | public array $info, |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function __toString(): string |
25 | 25 | { |
26 | 26 | $info = [$this->alias]; |
27 | - foreach ($this->info as $key => $item) { |
|
27 | + foreach ($this->info as $key => $item){ |
|
28 | 28 | $info[] = "$key: {$this->stringifyValue($item)}"; |
29 | 29 | } |
30 | 30 | return \implode("\n", $info); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | \is_string($item) => "'$item'", |
37 | 37 | \is_scalar($item) => (string)$item, |
38 | 38 | $item instanceof Closure => $this->renderClosureSignature(new ReflectionFunction($item)), |
39 | - \is_object($item) => 'instance of ' . $item::class, |
|
39 | + \is_object($item) => 'instance of '.$item::class, |
|
40 | 40 | default => \gettype($item), |
41 | 41 | }; |
42 | 42 | } |
@@ -24,7 +24,8 @@ |
||
24 | 24 | public function __toString(): string |
25 | 25 | { |
26 | 26 | $info = [$this->alias]; |
27 | - foreach ($this->info as $key => $item) { |
|
27 | + foreach ($this->info as $key => $item) |
|
28 | + { |
|
28 | 29 | $info[] = "$key: {$this->stringifyValue($item)}"; |
29 | 30 | } |
30 | 31 | return \implode("\n", $info); |
@@ -54,34 +54,34 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function make(string $alias, array $parameters = [], string $context = null): mixed |
56 | 56 | { |
57 | - if (!isset($this->state->bindings[$alias])) { |
|
57 | + if (!isset($this->state->bindings[$alias])){ |
|
58 | 58 | $this->tracer->push($alias, false, source: 'autowiring', context: $context); |
59 | - try { |
|
59 | + try{ |
|
60 | 60 | //No direct instructions how to construct class, make is automatically |
61 | 61 | return $this->autowire($alias, $parameters, $context); |
62 | - } finally { |
|
62 | + }finally{ |
|
63 | 63 | $this->tracer->pop(false); |
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
67 | 67 | $binding = $this->state->bindings[$alias]; |
68 | - try { |
|
68 | + try{ |
|
69 | 69 | $this->tracer->push($alias, false, source: 'binding', binding: $binding, context: $context); |
70 | 70 | |
71 | - if (\is_object($binding)) { |
|
72 | - if ($binding::class === WeakReference::class) { |
|
73 | - if ($binding->get() === null && \class_exists($alias)) { |
|
74 | - try { |
|
71 | + if (\is_object($binding)){ |
|
72 | + if ($binding::class === WeakReference::class){ |
|
73 | + if ($binding->get() === null && \class_exists($alias)){ |
|
74 | + try{ |
|
75 | 75 | $this->tracer->push($alias, false, source: 'WeakReference', context: $context); |
76 | 76 | $object = $this->createInstance($alias, $parameters, $context); |
77 | 77 | $binding = $this->state->bindings[$alias] = WeakReference::create($object); |
78 | - } catch (\Throwable) { |
|
78 | + }catch (\Throwable){ |
|
79 | 79 | throw new ContainerException($this->tracer->combineTraceMessage(\sprintf( |
80 | 80 | 'Can\'t resolve `%s`: can\'t instantiate `%s` from WeakReference binding.', |
81 | 81 | $this->tracer->getRootAlias(), |
82 | 82 | $alias, |
83 | 83 | ))); |
84 | - } finally { |
|
84 | + }finally{ |
|
85 | 85 | $this->tracer->pop(); |
86 | 86 | } |
87 | 87 | } |
@@ -92,25 +92,25 @@ discard block |
||
92 | 92 | } |
93 | 93 | $this->tracer->push($alias, false, source: 'binding', binding: $binding, context: $context); |
94 | 94 | |
95 | - if (\is_string($binding)) { |
|
95 | + if (\is_string($binding)){ |
|
96 | 96 | //Binding is pointing to something else |
97 | 97 | return $this->make($binding, $parameters, $context); |
98 | 98 | } |
99 | 99 | |
100 | 100 | unset($this->state->bindings[$alias]); |
101 | - try { |
|
101 | + try{ |
|
102 | 102 | $instance = $binding[0] === $alias |
103 | 103 | ? $this->autowire($alias, $parameters, $context) |
104 | 104 | : $this->evaluateBinding($alias, $binding[0], $parameters, $context); |
105 | - } finally { |
|
105 | + }finally{ |
|
106 | 106 | /** @psalm-var class-string $alias */ |
107 | 107 | $this->state->bindings[$alias] = $binding; |
108 | 108 | } |
109 | - } finally { |
|
109 | + }finally{ |
|
110 | 110 | $this->tracer->pop(false); |
111 | 111 | } |
112 | 112 | |
113 | - if ($binding[1]) { |
|
113 | + if ($binding[1]){ |
|
114 | 114 | // Indicates singleton |
115 | 115 | /** @psalm-var class-string $alias */ |
116 | 116 | $this->state->bindings[$alias] = $instance; |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | private function autowire(string $class, array $parameters, string $context = null): object |
131 | 131 | { |
132 | - if (!\class_exists($class) && !isset($this->state->injectors[$class])) { |
|
132 | + if (!\class_exists($class) && !isset($this->state->injectors[$class])){ |
|
133 | 133 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
134 | 134 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
135 | 135 | $this->tracer->getRootAlias(), |
@@ -156,18 +156,18 @@ discard block |
||
156 | 156 | array $parameters, |
157 | 157 | string $context = null |
158 | 158 | ): mixed { |
159 | - if (\is_string($target)) { |
|
159 | + if (\is_string($target)){ |
|
160 | 160 | // Reference |
161 | 161 | return $this->make($target, $parameters, $context); |
162 | 162 | } |
163 | 163 | |
164 | - if ($target instanceof Autowire) { |
|
164 | + if ($target instanceof Autowire){ |
|
165 | 165 | return $target->resolve($this, $parameters); |
166 | 166 | } |
167 | 167 | |
168 | - try { |
|
168 | + try{ |
|
169 | 169 | return $this->invoker->invoke($target, $parameters); |
170 | - } catch (NotCallableException $e) { |
|
170 | + }catch (NotCallableException $e){ |
|
171 | 171 | throw new ContainerException( |
172 | 172 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $alias)), |
173 | 173 | $e->getCode(), |
@@ -191,20 +191,20 @@ discard block |
||
191 | 191 | */ |
192 | 192 | private function createInstance(string $class, array $parameters, string $context = null): object |
193 | 193 | { |
194 | - try { |
|
194 | + try{ |
|
195 | 195 | $reflection = new \ReflectionClass($class); |
196 | - } catch (\ReflectionException $e) { |
|
196 | + }catch (\ReflectionException $e){ |
|
197 | 197 | throw new ContainerException($e->getMessage(), $e->getCode(), $e, $this->tracer); |
198 | 198 | } |
199 | 199 | |
200 | 200 | //We have to construct class using external injector when we know exact context |
201 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
201 | + if ($parameters === [] && $this->binder->hasInjector($class)){ |
|
202 | 202 | $injector = $this->state->injectors[$reflection->getName()]; |
203 | 203 | |
204 | - try { |
|
204 | + try{ |
|
205 | 205 | $injectorInstance = $this->container->get($injector); |
206 | 206 | |
207 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
207 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
208 | 208 | throw new InjectionException( |
209 | 209 | \sprintf( |
210 | 210 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | |
217 | 217 | /** @var InjectorInterface<TObject> $injectorInstance */ |
218 | 218 | $instance = $injectorInstance->createInjection($reflection, $context); |
219 | - if (!$reflection->isInstance($instance)) { |
|
219 | + if (!$reflection->isInstance($instance)){ |
|
220 | 220 | throw new InjectionException( |
221 | 221 | \sprintf( |
222 | 222 | "Invalid injection response for '%s'.", |
@@ -226,12 +226,12 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | return $instance; |
229 | - } finally { |
|
229 | + }finally{ |
|
230 | 230 | $this->state->injectors[$reflection->getName()] = $injector; |
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
234 | - if (!$reflection->isInstantiable()) { |
|
234 | + if (!$reflection->isInstantiable()){ |
|
235 | 235 | $itIs = match (true) { |
236 | 236 | $reflection->isEnum() => 'Enum', |
237 | 237 | $reflection->isAbstract() => 'Abstract class', |
@@ -244,10 +244,10 @@ discard block |
||
244 | 244 | |
245 | 245 | $constructor = $reflection->getConstructor(); |
246 | 246 | |
247 | - if ($constructor !== null) { |
|
248 | - try { |
|
247 | + if ($constructor !== null){ |
|
248 | + try{ |
|
249 | 249 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
250 | - } catch (ValidationException $e) { |
|
250 | + }catch (ValidationException $e){ |
|
251 | 251 | throw new ContainerException( |
252 | 252 | $this->tracer->combineTraceMessage( |
253 | 253 | \sprintf( |
@@ -258,13 +258,13 @@ discard block |
||
258 | 258 | ), |
259 | 259 | ); |
260 | 260 | } |
261 | - try { |
|
261 | + try{ |
|
262 | 262 | // Using constructor with resolved arguments |
263 | 263 | $instance = new $class(...$arguments); |
264 | - } catch (\TypeError $e) { |
|
264 | + }catch (\TypeError $e){ |
|
265 | 265 | throw new WrongTypeException($constructor, $e); |
266 | 266 | } |
267 | - } else { |
|
267 | + }else{ |
|
268 | 268 | // No constructor specified |
269 | 269 | $instance = $reflection->newInstance(); |
270 | 270 | } |
@@ -282,9 +282,9 @@ discard block |
||
282 | 282 | private function registerInstance(object $instance, array $parameters): object |
283 | 283 | { |
284 | 284 | //Declarative singletons (only when class received via direct get) |
285 | - if ($parameters === [] && $instance instanceof SingletonInterface) { |
|
285 | + if ($parameters === [] && $instance instanceof SingletonInterface){ |
|
286 | 286 | $alias = $instance::class; |
287 | - if (!isset($this->state->bindings[$alias])) { |
|
287 | + if (!isset($this->state->bindings[$alias])){ |
|
288 | 288 | $this->state->bindings[$alias] = $instance; |
289 | 289 | } |
290 | 290 | } |
@@ -54,34 +54,47 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function make(string $alias, array $parameters = [], string $context = null): mixed |
56 | 56 | { |
57 | - if (!isset($this->state->bindings[$alias])) { |
|
57 | + if (!isset($this->state->bindings[$alias])) |
|
58 | + { |
|
58 | 59 | $this->tracer->push($alias, false, source: 'autowiring', context: $context); |
59 | - try { |
|
60 | + try |
|
61 | + { |
|
60 | 62 | //No direct instructions how to construct class, make is automatically |
61 | 63 | return $this->autowire($alias, $parameters, $context); |
62 | - } finally { |
|
64 | + } |
|
65 | + finally |
|
66 | + { |
|
63 | 67 | $this->tracer->pop(false); |
64 | 68 | } |
65 | 69 | } |
66 | 70 | |
67 | 71 | $binding = $this->state->bindings[$alias]; |
68 | - try { |
|
72 | + try |
|
73 | + { |
|
69 | 74 | $this->tracer->push($alias, false, source: 'binding', binding: $binding, context: $context); |
70 | 75 | |
71 | - if (\is_object($binding)) { |
|
72 | - if ($binding::class === WeakReference::class) { |
|
73 | - if ($binding->get() === null && \class_exists($alias)) { |
|
74 | - try { |
|
76 | + if (\is_object($binding)) |
|
77 | + { |
|
78 | + if ($binding::class === WeakReference::class) |
|
79 | + { |
|
80 | + if ($binding->get() === null && \class_exists($alias)) |
|
81 | + { |
|
82 | + try |
|
83 | + { |
|
75 | 84 | $this->tracer->push($alias, false, source: 'WeakReference', context: $context); |
76 | 85 | $object = $this->createInstance($alias, $parameters, $context); |
77 | 86 | $binding = $this->state->bindings[$alias] = WeakReference::create($object); |
78 | - } catch (\Throwable) { |
|
87 | + } |
|
88 | + catch (\Throwable) |
|
89 | + { |
|
79 | 90 | throw new ContainerException($this->tracer->combineTraceMessage(\sprintf( |
80 | 91 | 'Can\'t resolve `%s`: can\'t instantiate `%s` from WeakReference binding.', |
81 | 92 | $this->tracer->getRootAlias(), |
82 | 93 | $alias, |
83 | 94 | ))); |
84 | - } finally { |
|
95 | + } |
|
96 | + finally |
|
97 | + { |
|
85 | 98 | $this->tracer->pop(); |
86 | 99 | } |
87 | 100 | } |
@@ -92,25 +105,32 @@ discard block |
||
92 | 105 | } |
93 | 106 | $this->tracer->push($alias, false, source: 'binding', binding: $binding, context: $context); |
94 | 107 | |
95 | - if (\is_string($binding)) { |
|
108 | + if (\is_string($binding)) |
|
109 | + { |
|
96 | 110 | //Binding is pointing to something else |
97 | 111 | return $this->make($binding, $parameters, $context); |
98 | 112 | } |
99 | 113 | |
100 | 114 | unset($this->state->bindings[$alias]); |
101 | - try { |
|
115 | + try |
|
116 | + { |
|
102 | 117 | $instance = $binding[0] === $alias |
103 | 118 | ? $this->autowire($alias, $parameters, $context) |
104 | 119 | : $this->evaluateBinding($alias, $binding[0], $parameters, $context); |
105 | - } finally { |
|
120 | + } |
|
121 | + finally |
|
122 | + { |
|
106 | 123 | /** @psalm-var class-string $alias */ |
107 | 124 | $this->state->bindings[$alias] = $binding; |
108 | 125 | } |
109 | - } finally { |
|
126 | + } |
|
127 | + finally |
|
128 | + { |
|
110 | 129 | $this->tracer->pop(false); |
111 | 130 | } |
112 | 131 | |
113 | - if ($binding[1]) { |
|
132 | + if ($binding[1]) |
|
133 | + { |
|
114 | 134 | // Indicates singleton |
115 | 135 | /** @psalm-var class-string $alias */ |
116 | 136 | $this->state->bindings[$alias] = $instance; |
@@ -129,7 +149,8 @@ discard block |
||
129 | 149 | */ |
130 | 150 | private function autowire(string $class, array $parameters, string $context = null): object |
131 | 151 | { |
132 | - if (!\class_exists($class) && !isset($this->state->injectors[$class])) { |
|
152 | + if (!\class_exists($class) && !isset($this->state->injectors[$class])) |
|
153 | + { |
|
133 | 154 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
134 | 155 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
135 | 156 | $this->tracer->getRootAlias(), |
@@ -156,18 +177,23 @@ discard block |
||
156 | 177 | array $parameters, |
157 | 178 | string $context = null |
158 | 179 | ): mixed { |
159 | - if (\is_string($target)) { |
|
180 | + if (\is_string($target)) |
|
181 | + { |
|
160 | 182 | // Reference |
161 | 183 | return $this->make($target, $parameters, $context); |
162 | 184 | } |
163 | 185 | |
164 | - if ($target instanceof Autowire) { |
|
186 | + if ($target instanceof Autowire) |
|
187 | + { |
|
165 | 188 | return $target->resolve($this, $parameters); |
166 | 189 | } |
167 | 190 | |
168 | - try { |
|
191 | + try |
|
192 | + { |
|
169 | 193 | return $this->invoker->invoke($target, $parameters); |
170 | - } catch (NotCallableException $e) { |
|
194 | + } |
|
195 | + catch (NotCallableException $e) |
|
196 | + { |
|
171 | 197 | throw new ContainerException( |
172 | 198 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $alias)), |
173 | 199 | $e->getCode(), |
@@ -191,20 +217,26 @@ discard block |
||
191 | 217 | */ |
192 | 218 | private function createInstance(string $class, array $parameters, string $context = null): object |
193 | 219 | { |
194 | - try { |
|
220 | + try |
|
221 | + { |
|
195 | 222 | $reflection = new \ReflectionClass($class); |
196 | - } catch (\ReflectionException $e) { |
|
223 | + } |
|
224 | + catch (\ReflectionException $e) |
|
225 | + { |
|
197 | 226 | throw new ContainerException($e->getMessage(), $e->getCode(), $e, $this->tracer); |
198 | 227 | } |
199 | 228 | |
200 | 229 | //We have to construct class using external injector when we know exact context |
201 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
230 | + if ($parameters === [] && $this->binder->hasInjector($class)) |
|
231 | + { |
|
202 | 232 | $injector = $this->state->injectors[$reflection->getName()]; |
203 | 233 | |
204 | - try { |
|
234 | + try |
|
235 | + { |
|
205 | 236 | $injectorInstance = $this->container->get($injector); |
206 | 237 | |
207 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
238 | + if (!$injectorInstance instanceof InjectorInterface) |
|
239 | + { |
|
208 | 240 | throw new InjectionException( |
209 | 241 | \sprintf( |
210 | 242 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -216,7 +248,8 @@ discard block |
||
216 | 248 | |
217 | 249 | /** @var InjectorInterface<TObject> $injectorInstance */ |
218 | 250 | $instance = $injectorInstance->createInjection($reflection, $context); |
219 | - if (!$reflection->isInstance($instance)) { |
|
251 | + if (!$reflection->isInstance($instance)) |
|
252 | + { |
|
220 | 253 | throw new InjectionException( |
221 | 254 | \sprintf( |
222 | 255 | "Invalid injection response for '%s'.", |
@@ -226,12 +259,15 @@ discard block |
||
226 | 259 | } |
227 | 260 | |
228 | 261 | return $instance; |
229 | - } finally { |
|
262 | + } |
|
263 | + finally |
|
264 | + { |
|
230 | 265 | $this->state->injectors[$reflection->getName()] = $injector; |
231 | 266 | } |
232 | 267 | } |
233 | 268 | |
234 | - if (!$reflection->isInstantiable()) { |
|
269 | + if (!$reflection->isInstantiable()) |
|
270 | + { |
|
235 | 271 | $itIs = match (true) { |
236 | 272 | $reflection->isEnum() => 'Enum', |
237 | 273 | $reflection->isAbstract() => 'Abstract class', |
@@ -244,10 +280,14 @@ discard block |
||
244 | 280 | |
245 | 281 | $constructor = $reflection->getConstructor(); |
246 | 282 | |
247 | - if ($constructor !== null) { |
|
248 | - try { |
|
283 | + if ($constructor !== null) |
|
284 | + { |
|
285 | + try |
|
286 | + { |
|
249 | 287 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
250 | - } catch (ValidationException $e) { |
|
288 | + } |
|
289 | + catch (ValidationException $e) |
|
290 | + { |
|
251 | 291 | throw new ContainerException( |
252 | 292 | $this->tracer->combineTraceMessage( |
253 | 293 | \sprintf( |
@@ -258,13 +298,18 @@ discard block |
||
258 | 298 | ), |
259 | 299 | ); |
260 | 300 | } |
261 | - try { |
|
301 | + try |
|
302 | + { |
|
262 | 303 | // Using constructor with resolved arguments |
263 | 304 | $instance = new $class(...$arguments); |
264 | - } catch (\TypeError $e) { |
|
305 | + } |
|
306 | + catch (\TypeError $e) |
|
307 | + { |
|
265 | 308 | throw new WrongTypeException($constructor, $e); |
266 | 309 | } |
267 | - } else { |
|
310 | + } |
|
311 | + else |
|
312 | + { |
|
268 | 313 | // No constructor specified |
269 | 314 | $instance = $reflection->newInstance(); |
270 | 315 | } |
@@ -282,9 +327,11 @@ discard block |
||
282 | 327 | private function registerInstance(object $instance, array $parameters): object |
283 | 328 | { |
284 | 329 | //Declarative singletons (only when class received via direct get) |
285 | - if ($parameters === [] && $instance instanceof SingletonInterface) { |
|
330 | + if ($parameters === [] && $instance instanceof SingletonInterface) |
|
331 | + { |
|
286 | 332 | $alias = $instance::class; |
287 | - if (!isset($this->state->bindings[$alias])) { |
|
333 | + if (!isset($this->state->bindings[$alias])) |
|
334 | + { |
|
288 | 335 | $this->state->bindings[$alias] = $instance; |
289 | 336 | } |
290 | 337 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | |
19 | 19 | public function __toString(): string |
20 | 20 | { |
21 | - return $this->traces === [] ? '' : "Container trace list:\n" . $this->renderTraceList($this->traces); |
|
21 | + return $this->traces === [] ? '' : "Container trace list:\n".$this->renderTraceList($this->traces); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -34,26 +34,26 @@ discard block |
||
34 | 34 | public function push(string $alias, bool $nextLevel = false, mixed ...$details): void |
35 | 35 | { |
36 | 36 | $trace = new Trace($alias, $details); |
37 | - if ($nextLevel || $this->traces === []) { |
|
37 | + if ($nextLevel || $this->traces === []){ |
|
38 | 38 | $this->traces[] = [$trace]; |
39 | - } else { |
|
39 | + }else{ |
|
40 | 40 | $this->traces[\array_key_last($this->traces)][] = $trace; |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | public function pop(bool $previousLevel = false): void |
45 | 45 | { |
46 | - if ($this->traces === []) { |
|
46 | + if ($this->traces === []){ |
|
47 | 47 | return; |
48 | 48 | } |
49 | - if ($previousLevel) { |
|
49 | + if ($previousLevel){ |
|
50 | 50 | \array_pop($this->traces); |
51 | 51 | return; |
52 | 52 | } |
53 | 53 | $key = \array_key_last($this->traces); |
54 | 54 | $list = &$this->traces[$key]; |
55 | 55 | \array_pop($list); |
56 | - if ($list === []) { |
|
56 | + if ($list === []){ |
|
57 | 57 | unset($this->traces[$key]); |
58 | 58 | } |
59 | 59 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | { |
71 | 71 | $result = []; |
72 | 72 | $i = 0; |
73 | - foreach ($blocks as $block) { |
|
73 | + foreach ($blocks as $block){ |
|
74 | 74 | \array_push($result, ...$this->blockToStringList($block, $i++)); |
75 | 75 | } |
76 | 76 | return \implode("\n", $result); |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | // Separator |
91 | 91 | $s = "\n"; |
92 | 92 | $nexPrefix = "$s$padding "; |
93 | - foreach ($items as $item) { |
|
94 | - $result[] = $firstPrefix . \str_replace($s, $nexPrefix, (string)$item); |
|
93 | + foreach ($items as $item){ |
|
94 | + $result[] = $firstPrefix.\str_replace($s, $nexPrefix, (string)$item); |
|
95 | 95 | } |
96 | 96 | return $result; |
97 | 97 | } |
@@ -34,26 +34,32 @@ discard block |
||
34 | 34 | public function push(string $alias, bool $nextLevel = false, mixed ...$details): void |
35 | 35 | { |
36 | 36 | $trace = new Trace($alias, $details); |
37 | - if ($nextLevel || $this->traces === []) { |
|
37 | + if ($nextLevel || $this->traces === []) |
|
38 | + { |
|
38 | 39 | $this->traces[] = [$trace]; |
39 | - } else { |
|
40 | + } |
|
41 | + else |
|
42 | + { |
|
40 | 43 | $this->traces[\array_key_last($this->traces)][] = $trace; |
41 | 44 | } |
42 | 45 | } |
43 | 46 | |
44 | 47 | public function pop(bool $previousLevel = false): void |
45 | 48 | { |
46 | - if ($this->traces === []) { |
|
49 | + if ($this->traces === []) |
|
50 | + { |
|
47 | 51 | return; |
48 | 52 | } |
49 | - if ($previousLevel) { |
|
53 | + if ($previousLevel) |
|
54 | + { |
|
50 | 55 | \array_pop($this->traces); |
51 | 56 | return; |
52 | 57 | } |
53 | 58 | $key = \array_key_last($this->traces); |
54 | 59 | $list = &$this->traces[$key]; |
55 | 60 | \array_pop($list); |
56 | - if ($list === []) { |
|
61 | + if ($list === []) |
|
62 | + { |
|
57 | 63 | unset($this->traces[$key]); |
58 | 64 | } |
59 | 65 | } |
@@ -70,7 +76,8 @@ discard block |
||
70 | 76 | { |
71 | 77 | $result = []; |
72 | 78 | $i = 0; |
73 | - foreach ($blocks as $block) { |
|
79 | + foreach ($blocks as $block) |
|
80 | + { |
|
74 | 81 | \array_push($result, ...$this->blockToStringList($block, $i++)); |
75 | 82 | } |
76 | 83 | return \implode("\n", $result); |
@@ -90,7 +97,8 @@ discard block |
||
90 | 97 | // Separator |
91 | 98 | $s = "\n"; |
92 | 99 | $nexPrefix = "$s$padding "; |
93 | - foreach ($items as $item) { |
|
100 | + foreach ($items as $item) |
|
101 | + { |
|
94 | 102 | $result[] = $firstPrefix . \str_replace($s, $nexPrefix, (string)$item); |
95 | 103 | } |
96 | 104 | return $result; |