Passed
Pull Request — master (#817)
by Maxim
06:18
created
src/Core/tests/ExceptionsTest.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -77,9 +77,9 @@
 block discarded – undo
77 77
     {
78 78
         $this->expectException(ContainerException::class);
79 79
 
80
-        try {
80
+        try{
81 81
             $container->get(ClassWithUndefinedDependency::class);
82
-        } catch (ContainerException $e) {
82
+        }catch (ContainerException $e){
83 83
             $this->assertSame(
84 84
                 \preg_replace('/\s+/', '', $message),
85 85
                 \preg_replace('/\s+/', '', $e->getMessage())
Please login to merge, or discard this patch.
src/Core/src/Internal/Factory.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -54,15 +54,15 @@  discard block
 block discarded – undo
54 54
     {
55 55
         $this->trace[] = $alias;
56 56
 
57
-        if (!isset($this->state->bindings[$alias])) {
57
+        if (!isset($this->state->bindings[$alias])){
58 58
             //No direct instructions how to construct class, make is automatically
59 59
             return $this->autowire($alias, $parameters, $context);
60 60
         }
61 61
 
62 62
         $binding = $this->state->bindings[$alias];
63
-        if (\is_object($binding)) {
64
-            if ($binding::class === WeakReference::class) {
65
-                if ($binding->get() === null && \class_exists($alias)) {
63
+        if (\is_object($binding)){
64
+            if ($binding::class === WeakReference::class){
65
+                if ($binding->get() === null && \class_exists($alias)){
66 66
                     $object = $this->createInstance($alias, $parameters, $context);
67 67
                     $binding = $this->state->bindings[$alias] = WeakReference::create($object);
68 68
                 }
@@ -72,23 +72,23 @@  discard block
 block discarded – undo
72 72
             return $binding;
73 73
         }
74 74
 
75
-        if (\is_string($binding)) {
75
+        if (\is_string($binding)){
76 76
             //Binding is pointing to something else
77 77
             return $this->make($binding, $parameters, $context);
78 78
         }
79 79
 
80 80
         unset($this->state->bindings[$alias]);
81
-        try {
81
+        try{
82 82
             $instance = $binding[0] === $alias
83 83
                 ? $this->autowire($alias, $parameters, $context)
84 84
                 : $this->evaluateBinding($alias, $binding[0], $parameters, $context);
85
-        } finally {
85
+        }finally{
86 86
             /** @psalm-var class-string $alias */
87 87
             $this->state->bindings[$alias] = $binding;
88 88
             $this->trace = [];
89 89
         }
90 90
 
91
-        if ($binding[1]) {
91
+        if ($binding[1]){
92 92
             // Indicates singleton
93 93
             /** @psalm-var class-string $alias */
94 94
             $this->state->bindings[$alias] = $instance;
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      */
108 108
     private function autowire(string $class, array $parameters, string $context = null): object
109 109
     {
110
-        if (!\class_exists($class) && !isset($this->state->injectors[$class])) {
110
+        if (!\class_exists($class) && !isset($this->state->injectors[$class])){
111 111
             throw new NotFoundException(
112 112
                 message: \sprintf('Undefined class or binding `%s`.', $class),
113 113
                 trace: $this->trace
@@ -133,18 +133,18 @@  discard block
 block discarded – undo
133 133
         array $parameters,
134 134
         string $context = null
135 135
     ): mixed {
136
-        if (\is_string($target)) {
136
+        if (\is_string($target)){
137 137
             // Reference
138 138
             return $this->make($target, $parameters, $context);
139 139
         }
140 140
 
141
-        if ($target instanceof Autowire) {
141
+        if ($target instanceof Autowire){
142 142
             return $target->resolve($this, $parameters);
143 143
         }
144 144
 
145
-        try {
145
+        try{
146 146
             return $this->invoker->invoke($target, $parameters);
147
-        } catch (NotCallableException $e) {
147
+        }catch (NotCallableException $e){
148 148
             throw new ContainerException(
149 149
                 \sprintf('Invalid binding for `%s`.', $alias),
150 150
                 $e->getCode(),
@@ -169,20 +169,20 @@  discard block
 block discarded – undo
169 169
      */
170 170
     private function createInstance(string $class, array $parameters, string $context = null): object
171 171
     {
172
-        try {
172
+        try{
173 173
             $reflection = new \ReflectionClass($class);
174
-        } catch (\ReflectionException $e) {
174
+        }catch (\ReflectionException $e){
175 175
             throw new ContainerException($e->getMessage(), $e->getCode(), $e, $this->trace);
176 176
         }
177 177
 
178 178
         //We have to construct class using external injector when we know exact context
179
-        if ($parameters === [] && $this->binder->hasInjector($class)) {
179
+        if ($parameters === [] && $this->binder->hasInjector($class)){
180 180
             $injector = $this->state->injectors[$reflection->getName()];
181 181
 
182
-            try {
182
+            try{
183 183
                 $injectorInstance = $this->container->get($injector);
184 184
 
185
-                if (!$injectorInstance instanceof InjectorInterface) {
185
+                if (!$injectorInstance instanceof InjectorInterface){
186 186
                     throw new InjectionException(
187 187
                         \sprintf(
188 188
                             "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 
195 195
                 /** @var InjectorInterface<TObject> $injectorInstance */
196 196
                 $instance = $injectorInstance->createInjection($reflection, $context);
197
-                if (!$reflection->isInstance($instance)) {
197
+                if (!$reflection->isInstance($instance)){
198 198
                     throw new InjectionException(
199 199
                         \sprintf(
200 200
                             "Invalid injection response for '%s'.",
@@ -204,12 +204,12 @@  discard block
 block discarded – undo
204 204
                 }
205 205
 
206 206
                 return $instance;
207
-            } finally {
207
+            }finally{
208 208
                 $this->state->injectors[$reflection->getName()] = $injector;
209 209
             }
210 210
         }
211 211
 
212
-        if (!$reflection->isInstantiable()) {
212
+        if (!$reflection->isInstantiable()){
213 213
             $itIs = match (true) {
214 214
                 $reflection->isEnum() => 'Enum',
215 215
                 $reflection->isAbstract() => 'Abstract class',
@@ -223,14 +223,14 @@  discard block
 block discarded – undo
223 223
 
224 224
         $constructor = $reflection->getConstructor();
225 225
 
226
-        if ($constructor !== null) {
227
-            try {
226
+        if ($constructor !== null){
227
+            try{
228 228
                 // Using constructor with resolved arguments
229 229
                 $instance = new $class(...$this->resolver->resolveArguments($constructor, $parameters));
230
-            } catch (\TypeError $e) {
230
+            }catch (\TypeError $e){
231 231
                 throw new WrongTypeException($constructor, $e);
232 232
             }
233
-        } else {
233
+        }else{
234 234
             // No constructor specified
235 235
             $instance = $reflection->newInstance();
236 236
         }
@@ -248,9 +248,9 @@  discard block
 block discarded – undo
248 248
     private function registerInstance(object $instance, array $parameters): object
249 249
     {
250 250
         //Declarative singletons (only when class received via direct get)
251
-        if ($parameters === [] && $instance instanceof SingletonInterface) {
251
+        if ($parameters === [] && $instance instanceof SingletonInterface){
252 252
             $alias = $instance::class;
253
-            if (!isset($this->state->bindings[$alias])) {
253
+            if (!isset($this->state->bindings[$alias])){
254 254
                 $this->state->bindings[$alias] = $instance;
255 255
             }
256 256
         }
Please login to merge, or discard this patch.
src/Core/src/Exception/Container/ContainerException.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
         int $code = 0,
18 18
         ?\Throwable $previous = null,
19 19
         protected array &$trace = []
20
-    ) {
20
+    ){
21 21
         parent::__construct($this->addTrace($message), $code, $previous);
22 22
 
23 23
         $trace = [];
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
         $result = [];
29 29
         $result[] = $message;
30 30
 
31
-        if ($this->trace !== []) {
31
+        if ($this->trace !== []){
32 32
             $result[] = 'Container stack trace:';
33 33
 
34
-            foreach ($this->trace as $item) {
34
+            foreach ($this->trace as $item){
35 35
                 $result[] = $item;
36 36
             }
37 37
         }
Please login to merge, or discard this patch.