Passed
Pull Request — master (#817)
by Maxim
06:26
created
src/Core/tests/Internal/Resolver/CommonCasesTest.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -63,7 +63,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Core/tests/ExceptionsTest.php 1 patch
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -79,9 +79,12 @@  discard block
 block discarded – undo
79 79
 
80 80
         $this->expectException(ContainerException::class);
81 81
 
82
-        try {
82
+        try
83
+        {
83 84
             $container->get(WithContainerInside::class);
84
-        } catch (ContainerException $e) {
85
+        }
86
+        catch (ContainerException $e)
87
+        {
85 88
             $this->assertSame(
86 89
                 \preg_replace('/\s+/', '', 'Can\'tresolve`Spiral\Tests\Core\Fixtures\
87 90
                     WithContainerInside`:undefinedclassorbinding`Spiral\Tests\Core\Fixtures\InvalidClass`.
@@ -101,9 +104,12 @@  discard block
 block discarded – undo
101 104
     {
102 105
         $this->expectException(ContainerException::class);
103 106
 
104
-        try {
107
+        try
108
+        {
105 109
             $container->get(ClassWithUndefinedDependency::class);
106
-        } catch (ContainerException $e) {
110
+        }
111
+        catch (ContainerException $e)
112
+        {
107 113
             $this->assertSame(
108 114
                 \preg_replace('/\s+/', '', $message),
109 115
                 \preg_replace('/\s+/', '', $e->getMessage())
Please login to merge, or discard this patch.
src/Core/src/Internal/Factory.php 1 patch
Braces   +60 added lines, -27 removed lines patch added patch discarded remove patch
@@ -53,7 +53,8 @@  discard block
 block discarded – undo
53 53
      */
54 54
     public function make(string $alias, array $parameters = [], string $context = null): mixed
55 55
     {
56
-        if (!isset($this->state->bindings[$alias])) {
56
+        if (!isset($this->state->bindings[$alias]))
57
+        {
57 58
             $this->tracer->traceAutowire($alias, $context);
58 59
             //No direct instructions how to construct class, make is automatically
59 60
             return $this->autowire($alias, $parameters, $context);
@@ -62,9 +63,12 @@  discard block
 block discarded – undo
62 63
         $binding = $this->state->bindings[$alias];
63 64
         $this->tracer->traceBinding($alias, $binding, $context);
64 65
 
65
-        if (\is_object($binding)) {
66
-            if ($binding::class === WeakReference::class) {
67
-                if ($binding->get() === null && \class_exists($alias)) {
66
+        if (\is_object($binding))
67
+        {
68
+            if ($binding::class === WeakReference::class)
69
+            {
70
+                if ($binding->get() === null && \class_exists($alias))
71
+                {
68 72
                     $object = $this->createInstance($alias, $parameters, $context);
69 73
                     $binding = $this->state->bindings[$alias] = WeakReference::create($object);
70 74
                 }
@@ -74,23 +78,28 @@  discard block
 block discarded – undo
74 78
             return $binding;
75 79
         }
76 80
 
77
-        if (\is_string($binding)) {
81
+        if (\is_string($binding))
82
+        {
78 83
             //Binding is pointing to something else
79 84
             return $this->make($binding, $parameters, $context);
80 85
         }
81 86
 
82 87
         unset($this->state->bindings[$alias]);
83
-        try {
88
+        try
89
+        {
84 90
             $instance = $binding[0] === $alias
85 91
                 ? $this->autowire($alias, $parameters, $context)
86 92
                 : $this->evaluateBinding($alias, $binding[0], $parameters, $context);
87
-        } finally {
93
+        }
94
+        finally
95
+        {
88 96
             /** @psalm-var class-string $alias */
89 97
             $this->state->bindings[$alias] = $binding;
90 98
             $this->tracer->clean();
91 99
         }
92 100
 
93
-        if ($binding[1]) {
101
+        if ($binding[1])
102
+        {
94 103
             // Indicates singleton
95 104
             /** @psalm-var class-string $alias */
96 105
             $this->state->bindings[$alias] = $instance;
@@ -109,7 +118,8 @@  discard block
 block discarded – undo
109 118
      */
110 119
     private function autowire(string $class, array $parameters, string $context = null): object
111 120
     {
112
-        if (!\class_exists($class) && !isset($this->state->injectors[$class])) {
121
+        if (!\class_exists($class) && !isset($this->state->injectors[$class]))
122
+        {
113 123
             throw new NotFoundException(\sprintf(
114 124
                 'Can\'t resolve `%s`: undefined class or binding `%s`.', $this->tracer->getRootConstructedClass(),
115 125
                 $class
@@ -135,18 +145,23 @@  discard block
 block discarded – undo
135 145
         array $parameters,
136 146
         string $context = null
137 147
     ): mixed {
138
-        if (\is_string($target)) {
148
+        if (\is_string($target))
149
+        {
139 150
             // Reference
140 151
             return $this->make($target, $parameters, $context);
141 152
         }
142 153
 
143
-        if ($target instanceof Autowire) {
154
+        if ($target instanceof Autowire)
155
+        {
144 156
             return $target->resolve($this, $parameters);
145 157
         }
146 158
 
147
-        try {
159
+        try
160
+        {
148 161
             return $this->invoker->invoke($target, $parameters);
149
-        } catch (NotCallableException $e) {
162
+        }
163
+        catch (NotCallableException $e)
164
+        {
150 165
             throw new ContainerException(
151 166
                 \sprintf('Invalid binding for `%s`.', $alias),
152 167
                 $e->getCode(),
@@ -171,20 +186,26 @@  discard block
 block discarded – undo
171 186
      */
172 187
     private function createInstance(string $class, array $parameters, string $context = null): object
173 188
     {
174
-        try {
189
+        try
190
+        {
175 191
             $reflection = new \ReflectionClass($class);
176
-        } catch (\ReflectionException $e) {
192
+        }
193
+        catch (\ReflectionException $e)
194
+        {
177 195
             throw new ContainerException($e->getMessage(), $e->getCode(), $e, $this->tracer);
178 196
         }
179 197
 
180 198
         //We have to construct class using external injector when we know exact context
181
-        if ($parameters === [] && $this->binder->hasInjector($class)) {
199
+        if ($parameters === [] && $this->binder->hasInjector($class))
200
+        {
182 201
             $injector = $this->state->injectors[$reflection->getName()];
183 202
 
184
-            try {
203
+            try
204
+            {
185 205
                 $injectorInstance = $this->container->get($injector);
186 206
 
187
-                if (!$injectorInstance instanceof InjectorInterface) {
207
+                if (!$injectorInstance instanceof InjectorInterface)
208
+                {
188 209
                     throw new InjectionException(
189 210
                         \sprintf(
190 211
                             "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -196,7 +217,8 @@  discard block
 block discarded – undo
196 217
 
197 218
                 /** @var InjectorInterface<TObject> $injectorInstance */
198 219
                 $instance = $injectorInstance->createInjection($reflection, $context);
199
-                if (!$reflection->isInstance($instance)) {
220
+                if (!$reflection->isInstance($instance))
221
+                {
200 222
                     throw new InjectionException(
201 223
                         \sprintf(
202 224
                             "Invalid injection response for '%s'.",
@@ -206,12 +228,15 @@  discard block
 block discarded – undo
206 228
                 }
207 229
 
208 230
                 return $instance;
209
-            } finally {
231
+            }
232
+            finally
233
+            {
210 234
                 $this->state->injectors[$reflection->getName()] = $injector;
211 235
             }
212 236
         }
213 237
 
214
-        if (!$reflection->isInstantiable()) {
238
+        if (!$reflection->isInstantiable())
239
+        {
215 240
             $itIs = match (true) {
216 241
                 $reflection->isEnum() => 'Enum',
217 242
                 $reflection->isAbstract() => 'Abstract class',
@@ -227,14 +252,20 @@  discard block
 block discarded – undo
227 252
 
228 253
         $constructor = $reflection->getConstructor();
229 254
 
230
-        if ($constructor !== null) {
231
-            try {
255
+        if ($constructor !== null)
256
+        {
257
+            try
258
+            {
232 259
                 // Using constructor with resolved arguments
233 260
                 $instance = new $class(...$this->resolver->resolveArguments($constructor, $parameters));
234
-            } catch (\TypeError $e) {
261
+            }
262
+            catch (\TypeError $e)
263
+            {
235 264
                 throw new WrongTypeException($constructor, $e);
236 265
             }
237
-        } else {
266
+        }
267
+        else
268
+        {
238 269
             // No constructor specified
239 270
             $instance = $reflection->newInstance();
240 271
         }
@@ -252,9 +283,11 @@  discard block
 block discarded – undo
252 283
     private function registerInstance(object $instance, array $parameters): object
253 284
     {
254 285
         //Declarative singletons (only when class received via direct get)
255
-        if ($parameters === [] && $instance instanceof SingletonInterface) {
286
+        if ($parameters === [] && $instance instanceof SingletonInterface)
287
+        {
256 288
             $alias = $instance::class;
257
-            if (!isset($this->state->bindings[$alias])) {
289
+            if (!isset($this->state->bindings[$alias]))
290
+            {
258 291
                 $this->state->bindings[$alias] = $instance;
259 292
             }
260 293
         }
Please login to merge, or discard this patch.
src/Core/src/Internal/Tracer.php 1 patch
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,10 +43,12 @@
 block discarded – undo
43 43
     public function __toString(): string
44 44
     {
45 45
         $result = [];
46
-        if ($this->traces !== []) {
46
+        if ($this->traces !== [])
47
+        {
47 48
             $result[] = 'Container trace list:';
48 49
 
49
-            foreach ($this->traces as $item) {
50
+            foreach ($this->traces as $item)
51
+            {
50 52
                 $result[] = (string) $item;
51 53
             }
52 54
         }
Please login to merge, or discard this patch.