Passed
Pull Request — master (#806)
by Maxim
08:09 queued 01:13
created
src/Core/src/Internal/DestructorTrait.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@
 block discarded – undo
12 12
     public function destruct(): void
13 13
     {
14 14
         $class = new \ReflectionClass($this);
15
-        foreach ($class->getProperties() as $property) {
15
+        foreach ($class->getProperties() as $property){
16 16
             $name = $property->getName();
17
-            if (!isset($this->$name)) {
17
+            if (!isset($this->$name)){
18 18
                 continue;
19 19
             }
20 20
             $value = $this->$name;
21 21
             unset($this->$name);
22
-            if (\is_object($value) && \method_exists($value, 'destruct')) {
22
+            if (\is_object($value) && \method_exists($value, 'destruct')){
23 23
                 $value->destruct();
24 24
             }
25 25
         }
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,14 +12,17 @@
 block discarded – undo
12 12
     public function destruct(): void
13 13
     {
14 14
         $class = new \ReflectionClass($this);
15
-        foreach ($class->getProperties() as $property) {
15
+        foreach ($class->getProperties() as $property)
16
+        {
16 17
             $name = $property->getName();
17
-            if (!isset($this->$name)) {
18
+            if (!isset($this->$name))
19
+            {
18 20
                 continue;
19 21
             }
20 22
             $value = $this->$name;
21 23
             unset($this->$name);
22
-            if (\is_object($value) && \method_exists($value, 'destruct')) {
24
+            if (\is_object($value) && \method_exists($value, 'destruct'))
25
+            {
23 26
                 $value->destruct();
24 27
             }
25 28
         }
Please login to merge, or discard this patch.
src/Core/src/Internal/Registry.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
     public function __construct(
18 18
         private Config $config,
19 19
         private array $objects = [],
20
-    ) {
20
+    ){
21 21
     }
22 22
 
23 23
     public function set(string $name, object $value): void
Please login to merge, or discard this patch.
src/Core/src/Internal/ResolvingState.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
     public function __construct(
24 24
         public readonly ReflectionFunctionAbstract $reflection,
25 25
         private array $arguments,
26
-    ) {
26
+    ){
27 27
         $this->modeNamed = $this->isNamedMode();
28 28
     }
29 29
 
30 30
     public function addResolvedValue(mixed &$value, string $key = null): void
31 31
     {
32
-        if ($key === null) {
32
+        if ($key === null){
33 33
             $this->resolvedValues[] = &$value;
34
-        } else {
34
+        }else{
35 35
             $this->resolvedValues[$key] = &$value;
36 36
         }
37 37
     }
@@ -42,25 +42,25 @@  discard block
 block discarded – undo
42 42
             ? $parameter->getName()
43 43
             : $parameter->getPosition();
44 44
 
45
-        if (!\array_key_exists($key, $this->arguments)) {
45
+        if (!\array_key_exists($key, $this->arguments)){
46 46
             return [];
47 47
         }
48 48
         $_val = &$this->arguments[$key];
49 49
 
50
-        if ($variadic && \is_array($_val)) {
50
+        if ($variadic && \is_array($_val)){
51 51
             // Save keys is possible
52 52
             $positional = true;
53 53
             $result = [];
54
-            foreach ($_val as $key => &$item) {
55
-                if (!$positional && \is_int($key)) {
54
+            foreach ($_val as $key => &$item){
55
+                if (!$positional && \is_int($key)){
56 56
                     throw new ResolvingException(
57 57
                         'Cannot use positional argument after named argument during unpacking named variadic argument.'
58 58
                     );
59 59
                 }
60 60
                 $positional = $positional && \is_int($key);
61
-                if ($positional) {
61
+                if ($positional){
62 62
                     $result[] = &$item;
63
-                } else {
63
+                }else{
64 64
                     $result[$key] = &$item;
65 65
                 }
66 66
             }
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
     {
79 79
         $nums = 0;
80 80
         $strings = 0;
81
-        foreach ($this->arguments as $key => $_) {
82
-            if (\is_int($key)) {
81
+        foreach ($this->arguments as $key => $_){
82
+            if (\is_int($key)){
83 83
                 ++$nums;
84
-            } else {
84
+            }else{
85 85
                 ++$strings;
86 86
             }
87 87
         }
Please login to merge, or discard this patch.
Braces   +25 added lines, -11 removed lines patch added patch discarded remove patch
@@ -29,9 +29,12 @@  discard block
 block discarded – undo
29 29
 
30 30
     public function addResolvedValue(mixed &$value, string $key = null): void
31 31
     {
32
-        if ($key === null) {
32
+        if ($key === null)
33
+        {
33 34
             $this->resolvedValues[] = &$value;
34
-        } else {
35
+        }
36
+        else
37
+        {
35 38
             $this->resolvedValues[$key] = &$value;
36 39
         }
37 40
     }
@@ -42,25 +45,32 @@  discard block
 block discarded – undo
42 45
             ? $parameter->getName()
43 46
             : $parameter->getPosition();
44 47
 
45
-        if (!\array_key_exists($key, $this->arguments)) {
48
+        if (!\array_key_exists($key, $this->arguments))
49
+        {
46 50
             return [];
47 51
         }
48 52
         $_val = &$this->arguments[$key];
49 53
 
50
-        if ($variadic && \is_array($_val)) {
54
+        if ($variadic && \is_array($_val))
55
+        {
51 56
             // Save keys is possible
52 57
             $positional = true;
53 58
             $result = [];
54
-            foreach ($_val as $key => &$item) {
55
-                if (!$positional && \is_int($key)) {
59
+            foreach ($_val as $key => &$item)
60
+            {
61
+                if (!$positional && \is_int($key))
62
+                {
56 63
                     throw new ResolvingException(
57 64
                         'Cannot use positional argument after named argument during unpacking named variadic argument.'
58 65
                     );
59 66
                 }
60 67
                 $positional = $positional && \is_int($key);
61
-                if ($positional) {
68
+                if ($positional)
69
+                {
62 70
                     $result[] = &$item;
63
-                } else {
71
+                }
72
+                else
73
+                {
64 74
                     $result[$key] = &$item;
65 75
                 }
66 76
             }
@@ -78,10 +88,14 @@  discard block
 block discarded – undo
78 88
     {
79 89
         $nums = 0;
80 90
         $strings = 0;
81
-        foreach ($this->arguments as $key => $_) {
82
-            if (\is_int($key)) {
91
+        foreach ($this->arguments as $key => $_)
92
+        {
93
+            if (\is_int($key))
94
+            {
83 95
                 ++$nums;
84
-            } else {
96
+            }
97
+            else
98
+            {
85 99
                 ++$strings;
86 100
             }
87 101
         }
Please login to merge, or discard this patch.
src/Core/src/Internal/Factory.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -51,15 +51,15 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function make(string $alias, array $parameters = [], string $context = null): mixed
53 53
     {
54
-        if (!isset($this->state->bindings[$alias])) {
54
+        if (!isset($this->state->bindings[$alias])){
55 55
             //No direct instructions how to construct class, make is automatically
56 56
             return $this->autowire($alias, $parameters, $context);
57 57
         }
58 58
 
59 59
         $binding = $this->state->bindings[$alias];
60
-        if (\is_object($binding)) {
61
-            if ($binding::class === WeakReference::class) {
62
-                if ($binding->get() === null && \class_exists($alias)) {
60
+        if (\is_object($binding)){
61
+            if ($binding::class === WeakReference::class){
62
+                if ($binding->get() === null && \class_exists($alias)){
63 63
                     $object = $this->createInstance($alias, $parameters, $context);
64 64
                     $binding = $this->state->bindings[$alias] = WeakReference::create($object);
65 65
                 }
@@ -69,22 +69,22 @@  discard block
 block discarded – undo
69 69
             return $binding;
70 70
         }
71 71
 
72
-        if (\is_string($binding)) {
72
+        if (\is_string($binding)){
73 73
             //Binding is pointing to something else
74 74
             return $this->make($binding, $parameters, $context);
75 75
         }
76 76
 
77 77
         unset($this->state->bindings[$alias]);
78
-        try {
78
+        try{
79 79
             $instance = $binding[0] === $alias
80 80
                 ? $this->autowire($alias, $parameters, $context)
81 81
                 : $this->evaluateBinding($alias, $binding[0], $parameters, $context);
82
-        } finally {
82
+        }finally{
83 83
             /** @psalm-var class-string $alias */
84 84
             $this->state->bindings[$alias] = $binding;
85 85
         }
86 86
 
87
-        if ($binding[1]) {
87
+        if ($binding[1]){
88 88
             // Indicates singleton
89 89
             /** @psalm-var class-string $alias */
90 90
             $this->state->bindings[$alias] = $instance;
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     private function autowire(string $class, array $parameters, string $context = null): object
105 105
     {
106
-        if (!\class_exists($class) && !isset($this->state->injectors[$class])) {
106
+        if (!\class_exists($class) && !isset($this->state->injectors[$class])){
107 107
             throw new NotFoundException(\sprintf('Undefined class or binding `%s`.', $class));
108 108
         }
109 109
 
@@ -126,18 +126,18 @@  discard block
 block discarded – undo
126 126
         array $parameters,
127 127
         string $context = null
128 128
     ): mixed {
129
-        if (\is_string($target)) {
129
+        if (\is_string($target)){
130 130
             // Reference
131 131
             return $this->make($target, $parameters, $context);
132 132
         }
133 133
 
134
-        if ($target instanceof Autowire) {
134
+        if ($target instanceof Autowire){
135 135
             return $target->resolve($this, $parameters);
136 136
         }
137 137
 
138
-        try {
138
+        try{
139 139
             return $this->invoker->invoke($target, $parameters);
140
-        } catch (NotCallableException $e) {
140
+        }catch (NotCallableException $e){
141 141
             throw new ContainerException(\sprintf('Invalid binding for `%s`.', $alias), $e->getCode(), $e);
142 142
         }
143 143
     }
@@ -157,20 +157,20 @@  discard block
 block discarded – undo
157 157
      */
158 158
     private function createInstance(string $class, array $parameters, string $context = null): object
159 159
     {
160
-        try {
160
+        try{
161 161
             $reflection = new \ReflectionClass($class);
162
-        } catch (\ReflectionException $e) {
162
+        }catch (\ReflectionException $e){
163 163
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
164 164
         }
165 165
 
166 166
         //We have to construct class using external injector when we know exact context
167
-        if ($parameters === [] && $this->binder->hasInjector($class)) {
167
+        if ($parameters === [] && $this->binder->hasInjector($class)){
168 168
             $injector = $this->state->injectors[$reflection->getName()];
169 169
 
170
-            try {
170
+            try{
171 171
                 $injectorInstance = $this->container->get($injector);
172 172
 
173
-                if (!$injectorInstance instanceof InjectorInterface) {
173
+                if (!$injectorInstance instanceof InjectorInterface){
174 174
                     throw new InjectionException(
175 175
                         \sprintf(
176 176
                             "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 
183 183
                 /** @var InjectorInterface<TObject> $injectorInstance */
184 184
                 $instance = $injectorInstance->createInjection($reflection, $context);
185
-                if (!$reflection->isInstance($instance)) {
185
+                if (!$reflection->isInstance($instance)){
186 186
                     throw new InjectionException(
187 187
                         \sprintf(
188 188
                             "Invalid injection response for '%s'.",
@@ -192,12 +192,12 @@  discard block
 block discarded – undo
192 192
                 }
193 193
 
194 194
                 return $instance;
195
-            } finally {
195
+            }finally{
196 196
                 $this->state->injectors[$reflection->getName()] = $injector;
197 197
             }
198 198
         }
199 199
 
200
-        if (!$reflection->isInstantiable()) {
200
+        if (!$reflection->isInstantiable()){
201 201
             $itIs = match (true) {
202 202
                 $reflection->isEnum() => 'Enum',
203 203
                 $reflection->isAbstract() => 'Abstract class',
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
 
209 209
         $constructor = $reflection->getConstructor();
210 210
 
211
-        if ($constructor !== null) {
212
-            try {
211
+        if ($constructor !== null){
212
+            try{
213 213
                 // Using constructor with resolved arguments
214 214
                 $instance = new $class(...$this->resolver->resolveArguments($constructor, $parameters));
215
-            } catch (\TypeError $e) {
215
+            }catch (\TypeError $e){
216 216
                 throw new WrongTypeException($constructor, $e);
217 217
             }
218
-        } else {
218
+        }else{
219 219
             // No constructor specified
220 220
             $instance = $reflection->newInstance();
221 221
         }
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
     private function registerInstance(object $instance, array $parameters): object
234 234
     {
235 235
         //Declarative singletons (only when class received via direct get)
236
-        if ($parameters === [] && $instance instanceof SingletonInterface) {
236
+        if ($parameters === [] && $instance instanceof SingletonInterface){
237 237
             $alias = $instance::class;
238
-            if (!isset($this->state->bindings[$alias])) {
238
+            if (!isset($this->state->bindings[$alias])){
239 239
                 $this->state->bindings[$alias] = $instance;
240 240
             }
241 241
         }
Please login to merge, or discard this patch.
Braces   +60 added lines, -27 removed lines patch added patch discarded remove patch
@@ -51,15 +51,19 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function make(string $alias, array $parameters = [], string $context = null): mixed
53 53
     {
54
-        if (!isset($this->state->bindings[$alias])) {
54
+        if (!isset($this->state->bindings[$alias]))
55
+        {
55 56
             //No direct instructions how to construct class, make is automatically
56 57
             return $this->autowire($alias, $parameters, $context);
57 58
         }
58 59
 
59 60
         $binding = $this->state->bindings[$alias];
60
-        if (\is_object($binding)) {
61
-            if ($binding::class === WeakReference::class) {
62
-                if ($binding->get() === null && \class_exists($alias)) {
61
+        if (\is_object($binding))
62
+        {
63
+            if ($binding::class === WeakReference::class)
64
+            {
65
+                if ($binding->get() === null && \class_exists($alias))
66
+                {
63 67
                     $object = $this->createInstance($alias, $parameters, $context);
64 68
                     $binding = $this->state->bindings[$alias] = WeakReference::create($object);
65 69
                 }
@@ -69,22 +73,27 @@  discard block
 block discarded – undo
69 73
             return $binding;
70 74
         }
71 75
 
72
-        if (\is_string($binding)) {
76
+        if (\is_string($binding))
77
+        {
73 78
             //Binding is pointing to something else
74 79
             return $this->make($binding, $parameters, $context);
75 80
         }
76 81
 
77 82
         unset($this->state->bindings[$alias]);
78
-        try {
83
+        try
84
+        {
79 85
             $instance = $binding[0] === $alias
80 86
                 ? $this->autowire($alias, $parameters, $context)
81 87
                 : $this->evaluateBinding($alias, $binding[0], $parameters, $context);
82
-        } finally {
88
+        }
89
+        finally
90
+        {
83 91
             /** @psalm-var class-string $alias */
84 92
             $this->state->bindings[$alias] = $binding;
85 93
         }
86 94
 
87
-        if ($binding[1]) {
95
+        if ($binding[1])
96
+        {
88 97
             // Indicates singleton
89 98
             /** @psalm-var class-string $alias */
90 99
             $this->state->bindings[$alias] = $instance;
@@ -103,7 +112,8 @@  discard block
 block discarded – undo
103 112
      */
104 113
     private function autowire(string $class, array $parameters, string $context = null): object
105 114
     {
106
-        if (!\class_exists($class) && !isset($this->state->injectors[$class])) {
115
+        if (!\class_exists($class) && !isset($this->state->injectors[$class]))
116
+        {
107 117
             throw new NotFoundException(\sprintf('Undefined class or binding `%s`.', $class));
108 118
         }
109 119
 
@@ -126,18 +136,23 @@  discard block
 block discarded – undo
126 136
         array $parameters,
127 137
         string $context = null
128 138
     ): mixed {
129
-        if (\is_string($target)) {
139
+        if (\is_string($target))
140
+        {
130 141
             // Reference
131 142
             return $this->make($target, $parameters, $context);
132 143
         }
133 144
 
134
-        if ($target instanceof Autowire) {
145
+        if ($target instanceof Autowire)
146
+        {
135 147
             return $target->resolve($this, $parameters);
136 148
         }
137 149
 
138
-        try {
150
+        try
151
+        {
139 152
             return $this->invoker->invoke($target, $parameters);
140
-        } catch (NotCallableException $e) {
153
+        }
154
+        catch (NotCallableException $e)
155
+        {
141 156
             throw new ContainerException(\sprintf('Invalid binding for `%s`.', $alias), $e->getCode(), $e);
142 157
         }
143 158
     }
@@ -157,20 +172,26 @@  discard block
 block discarded – undo
157 172
      */
158 173
     private function createInstance(string $class, array $parameters, string $context = null): object
159 174
     {
160
-        try {
175
+        try
176
+        {
161 177
             $reflection = new \ReflectionClass($class);
162
-        } catch (\ReflectionException $e) {
178
+        }
179
+        catch (\ReflectionException $e)
180
+        {
163 181
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
164 182
         }
165 183
 
166 184
         //We have to construct class using external injector when we know exact context
167
-        if ($parameters === [] && $this->binder->hasInjector($class)) {
185
+        if ($parameters === [] && $this->binder->hasInjector($class))
186
+        {
168 187
             $injector = $this->state->injectors[$reflection->getName()];
169 188
 
170
-            try {
189
+            try
190
+            {
171 191
                 $injectorInstance = $this->container->get($injector);
172 192
 
173
-                if (!$injectorInstance instanceof InjectorInterface) {
193
+                if (!$injectorInstance instanceof InjectorInterface)
194
+                {
174 195
                     throw new InjectionException(
175 196
                         \sprintf(
176 197
                             "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -182,7 +203,8 @@  discard block
 block discarded – undo
182 203
 
183 204
                 /** @var InjectorInterface<TObject> $injectorInstance */
184 205
                 $instance = $injectorInstance->createInjection($reflection, $context);
185
-                if (!$reflection->isInstance($instance)) {
206
+                if (!$reflection->isInstance($instance))
207
+                {
186 208
                     throw new InjectionException(
187 209
                         \sprintf(
188 210
                             "Invalid injection response for '%s'.",
@@ -192,12 +214,15 @@  discard block
 block discarded – undo
192 214
                 }
193 215
 
194 216
                 return $instance;
195
-            } finally {
217
+            }
218
+            finally
219
+            {
196 220
                 $this->state->injectors[$reflection->getName()] = $injector;
197 221
             }
198 222
         }
199 223
 
200
-        if (!$reflection->isInstantiable()) {
224
+        if (!$reflection->isInstantiable())
225
+        {
201 226
             $itIs = match (true) {
202 227
                 $reflection->isEnum() => 'Enum',
203 228
                 $reflection->isAbstract() => 'Abstract class',
@@ -208,14 +233,20 @@  discard block
 block discarded – undo
208 233
 
209 234
         $constructor = $reflection->getConstructor();
210 235
 
211
-        if ($constructor !== null) {
212
-            try {
236
+        if ($constructor !== null)
237
+        {
238
+            try
239
+            {
213 240
                 // Using constructor with resolved arguments
214 241
                 $instance = new $class(...$this->resolver->resolveArguments($constructor, $parameters));
215
-            } catch (\TypeError $e) {
242
+            }
243
+            catch (\TypeError $e)
244
+            {
216 245
                 throw new WrongTypeException($constructor, $e);
217 246
             }
218
-        } else {
247
+        }
248
+        else
249
+        {
219 250
             // No constructor specified
220 251
             $instance = $reflection->newInstance();
221 252
         }
@@ -233,9 +264,11 @@  discard block
 block discarded – undo
233 264
     private function registerInstance(object $instance, array $parameters): object
234 265
     {
235 266
         //Declarative singletons (only when class received via direct get)
236
-        if ($parameters === [] && $instance instanceof SingletonInterface) {
267
+        if ($parameters === [] && $instance instanceof SingletonInterface)
268
+        {
237 269
             $alias = $instance::class;
238
-            if (!isset($this->state->bindings[$alias])) {
270
+            if (!isset($this->state->bindings[$alias]))
271
+            {
239 272
                 $this->state->bindings[$alias] = $instance;
240 273
             }
241 274
         }
Please login to merge, or discard this patch.
src/Core/src/Internal/Invoker.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -35,18 +35,18 @@  discard block
 block discarded – undo
35 35
      */
36 36
     public function invoke(mixed $target, array $parameters = []): mixed
37 37
     {
38
-        if (\is_array($target) && isset($target[1])) {
38
+        if (\is_array($target) && isset($target[1])){
39 39
             // In a form of resolver and method
40 40
             [$resolver, $method] = $target;
41 41
 
42 42
             // Resolver instance (i.e. [ClassName::class, 'method'])
43
-            if (\is_string($resolver)) {
43
+            if (\is_string($resolver)){
44 44
                 $resolver = $this->container->get($resolver);
45 45
             }
46 46
 
47
-            try {
47
+            try{
48 48
                 $method = new \ReflectionMethod($resolver, $method);
49
-            } catch (\ReflectionException $e) {
49
+            }catch (\ReflectionException $e){
50 50
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
51 51
             }
52 52
 
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
             );
58 58
         }
59 59
 
60
-        if (\is_string($target) && \is_callable($target)) {
60
+        if (\is_string($target) && \is_callable($target)){
61 61
             $target = $target(...);
62 62
         }
63 63
 
64
-        if ($target instanceof \Closure) {
65
-            try {
64
+        if ($target instanceof \Closure){
65
+            try{
66 66
                 $reflection = new \ReflectionFunction($target);
67
-            } catch (\ReflectionException $e) {
67
+            }catch (\ReflectionException $e){
68 68
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
69 69
             }
70 70
 
Please login to merge, or discard this patch.
Braces   +18 added lines, -8 removed lines patch added patch discarded remove patch
@@ -35,18 +35,23 @@  discard block
 block discarded – undo
35 35
      */
36 36
     public function invoke(mixed $target, array $parameters = []): mixed
37 37
     {
38
-        if (\is_array($target) && isset($target[1])) {
38
+        if (\is_array($target) && isset($target[1]))
39
+        {
39 40
             // In a form of resolver and method
40 41
             [$resolver, $method] = $target;
41 42
 
42 43
             // Resolver instance (i.e. [ClassName::class, 'method'])
43
-            if (\is_string($resolver)) {
44
+            if (\is_string($resolver))
45
+            {
44 46
                 $resolver = $this->container->get($resolver);
45 47
             }
46 48
 
47
-            try {
49
+            try
50
+            {
48 51
                 $method = new \ReflectionMethod($resolver, $method);
49
-            } catch (\ReflectionException $e) {
52
+            }
53
+            catch (\ReflectionException $e)
54
+            {
50 55
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
51 56
             }
52 57
 
@@ -57,14 +62,19 @@  discard block
 block discarded – undo
57 62
             );
58 63
         }
59 64
 
60
-        if (\is_string($target) && \is_callable($target)) {
65
+        if (\is_string($target) && \is_callable($target))
66
+        {
61 67
             $target = $target(...);
62 68
         }
63 69
 
64
-        if ($target instanceof \Closure) {
65
-            try {
70
+        if ($target instanceof \Closure)
71
+        {
72
+            try
73
+            {
66 74
                 $reflection = new \ReflectionFunction($target);
67
-            } catch (\ReflectionException $e) {
75
+            }
76
+            catch (\ReflectionException $e)
77
+            {
68 78
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
69 79
             }
70 80
 
Please login to merge, or discard this patch.
src/Core/src/Internal/Container.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,8 @@
 block discarded – undo
50 50
      */
51 51
     public function get(string|Autowire $id, string $context = null): mixed
52 52
     {
53
-        if ($id instanceof Autowire) {
53
+        if ($id instanceof Autowire)
54
+        {
54 55
             return $id->resolve($this->factory);
55 56
         }
56 57
 
Please login to merge, or discard this 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
     use DestructorTrait;
18 18
 
19 19
     private State $state;
20
-    private FactoryInterface|Factory $factory;
20
+    private FactoryInterface | Factory $factory;
21 21
 
22 22
     public function __construct(Registry $constructor)
23 23
     {
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
      * @throws ContainerException
47 47
      * @throws \Throwable
48 48
      */
49
-    public function get(string|Autowire $id, string $context = null): mixed
49
+    public function get(string | Autowire $id, string $context = null): mixed
50 50
     {
51
-        if ($id instanceof Autowire) {
51
+        if ($id instanceof Autowire){
52 52
             return $id->resolve($this->factory);
53 53
         }
54 54
 
Please login to merge, or discard this patch.
src/Core/src/Internal/Resolver.php 2 patches
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
     ): array {
50 50
         $state = new ResolvingState($reflection, $parameters);
51 51
 
52
-        foreach ($reflection->getParameters() as $parameter) {
52
+        foreach ($reflection->getParameters() as $parameter){
53 53
             $this->resolveParameter($parameter, $state, $validate)
54 54
             or
55 55
             throw new ArgumentResolvingException($reflection, $parameter->getName());
@@ -63,46 +63,46 @@  discard block
 block discarded – undo
63 63
         $positional = true;
64 64
         $variadic = false;
65 65
         $parameters = $reflection->getParameters();
66
-        if (\count($parameters) === 0) {
66
+        if (\count($parameters) === 0){
67 67
             return;
68 68
         }
69 69
 
70 70
         $parameter = null;
71
-        while (\count($parameters) > 0 || \count($arguments) > 0) {
71
+        while (\count($parameters) > 0 || \count($arguments) > 0){
72 72
             // get related argument value
73 73
             $key = \key($arguments);
74 74
 
75 75
             // For a variadic parameter it's no sense - named or positional argument will be sent
76 76
             // But you can't send positional argument after named in any case
77
-            if (\is_int($key) && !$positional) {
77
+            if (\is_int($key) && !$positional){
78 78
                 throw new PositionalArgumentException($reflection, $key);
79 79
             }
80 80
 
81 81
             $positional = $positional && \is_int($key);
82 82
 
83
-            if (!$variadic) {
83
+            if (!$variadic){
84 84
                 $parameter = \array_shift($parameters);
85 85
                 $variadic = $parameter?->isVariadic() ?? false;
86 86
             }
87 87
 
88
-            if ($parameter === null) {
88
+            if ($parameter === null){
89 89
                 throw new UnknownParameterException($reflection, $key);
90 90
             }
91 91
             $name = $parameter->getName();
92 92
 
93
-            if (($positional || $variadic) && $key !== null) {
93
+            if (($positional || $variadic) && $key !== null){
94 94
                 $value = \array_shift($arguments);
95
-            } elseif ($key === null || !\array_key_exists($name, $arguments)) {
96
-                if ($parameter->isOptional()) {
95
+            } elseif ($key === null || !\array_key_exists($name, $arguments)){
96
+                if ($parameter->isOptional()){
97 97
                     continue;
98 98
                 }
99 99
                 throw new MissingRequiredArgumentException($reflection, $name);
100
-            } else {
100
+            }else{
101 101
                 $value = &$arguments[$name];
102 102
                 unset($arguments[$name]);
103 103
             }
104 104
 
105
-            if (!$this->validateValueToParameter($parameter, $value)) {
105
+            if (!$this->validateValueToParameter($parameter, $value)){
106 106
                 throw new InvalidArgumentException($reflection, $name);
107 107
             }
108 108
         }
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 
111 111
     private function validateValueToParameter(ReflectionParameter $parameter, mixed $value): bool
112 112
     {
113
-        if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) {
113
+        if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)){
114 114
             return true;
115 115
         }
116 116
         $type = $parameter->getType();
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
             $type instanceof ReflectionIntersectionType => [false, $type->getTypes()],
122 122
         };
123 123
 
124
-        foreach ($types as $t) {
124
+        foreach ($types as $t){
125 125
             \assert($t instanceof ReflectionNamedType);
126
-            if (!$this->validateValueNamedType($t, $value)) {
126
+            if (!$this->validateValueNamedType($t, $value)){
127 127
                 // If it is TypeIntersection
128
-                if ($or) {
128
+                if ($or){
129 129
                     continue;
130 130
                 }
131 131
                 return false;
132 132
             }
133 133
             // If it is not type intersection then we can skip that value after first successful check
134
-            if ($or) {
134
+            if ($or){
135 135
                 return true;
136 136
             }
137 137
         }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     {
147 147
         $name = $type->getName();
148 148
 
149
-        if ($type->isBuiltin()) {
149
+        if ($type->isBuiltin()){
150 150
             return match ($name) {
151 151
                 'mixed' => true,
152 152
                 'string' => \is_string($value),
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 
180 180
         // Try to resolve parameter by name
181 181
         $res = $state->resolveParameterByNameOrPosition($parameter, $isVariadic);
182
-        if ($res !== [] || $isVariadic) {
182
+        if ($res !== [] || $isVariadic){
183 183
             // validate
184
-            if ($isVariadic) {
185
-                foreach ($res as $k => &$v) {
186
-                    $this->processArgument($state, $v, validateWith: $validate ? $parameter : null, key: $k);
184
+            if ($isVariadic){
185
+                foreach ($res as $k => &$v){
186
+                    $this->processArgument($state, $v, validateWith: $validate ? $parameter : null, key : $k);
187 187
                 }
188
-            } else {
188
+            }else{
189 189
                 $this->processArgument($state, $res[0], validateWith: $validate ? $parameter : null);
190 190
             }
191 191
 
@@ -193,39 +193,39 @@  discard block
 block discarded – undo
193 193
         }
194 194
 
195 195
         $error = null;
196
-        if ($hasType) {
196
+        if ($hasType){
197 197
             /** @var ReflectionIntersectionType|ReflectionUnionType|ReflectionNamedType $reflectionType */
198 198
             $reflectionType = $parameter->getType();
199 199
 
200
-            if ($reflectionType instanceof ReflectionIntersectionType) {
200
+            if ($reflectionType instanceof ReflectionIntersectionType){
201 201
                 throw new UnsupportedTypeException($parameter->getDeclaringFunction(), $parameter->getName());
202 202
             }
203 203
 
204 204
             $types = $reflectionType instanceof ReflectionNamedType ? [$reflectionType] : $reflectionType->getTypes();
205
-            foreach ($types as $namedType) {
206
-                try {
207
-                    if ($this->resolveNamedType($state, $parameter, $namedType, $validate)) {
205
+            foreach ($types as $namedType){
206
+                try{
207
+                    if ($this->resolveNamedType($state, $parameter, $namedType, $validate)){
208 208
                         return true;
209 209
                     }
210
-                } catch (Throwable $e) {
210
+                }catch (Throwable $e){
211 211
                     $error = $e;
212 212
                 }
213 213
             }
214 214
         }
215 215
 
216
-        if ($parameter->isDefaultValueAvailable()) {
216
+        if ($parameter->isDefaultValueAvailable()){
217 217
             $argument = $parameter->getDefaultValue();
218 218
             $this->processArgument($state, $argument);
219 219
             return true;
220 220
         }
221 221
 
222
-        if ($hasType && $parameter->allowsNull()) {
222
+        if ($hasType && $parameter->allowsNull()){
223 223
             $argument = null;
224 224
             $this->processArgument($state, $argument);
225 225
             return true;
226 226
         }
227 227
 
228
-        if ($error === null) {
228
+        if ($error === null){
229 229
             return false;
230 230
         }
231 231
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
         ReflectionParameter $parameter,
247 247
         ReflectionNamedType $typeRef,
248 248
         bool $validate
249
-    ) {
249
+    ){
250 250
         return !$typeRef->isBuiltin() && $this->resolveObjectParameter(
251 251
             $state,
252 252
             $typeRef->getName(),
@@ -289,15 +289,15 @@  discard block
 block discarded – undo
289 289
         ResolvingState $state,
290 290
         mixed &$value,
291 291
         ReflectionParameter $validateWith = null,
292
-        int|string $key = null
292
+        int | string $key = null
293 293
     ): void {
294 294
         // Resolve Autowire objects
295
-        if ($value instanceof Autowire) {
295
+        if ($value instanceof Autowire){
296 296
             $value = $value->resolve($this->factory);
297 297
         }
298 298
 
299 299
         // Validation
300
-        if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) {
300
+        if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)){
301 301
             throw new InvalidArgumentException(
302 302
                 $validateWith->getDeclaringFunction(),
303 303
                 $validateWith->getName()
Please login to merge, or discard this patch.
Braces   +68 added lines, -32 removed lines patch added patch discarded remove patch
@@ -49,7 +49,8 @@  discard block
 block discarded – undo
49 49
     ): array {
50 50
         $state = new ResolvingState($reflection, $parameters);
51 51
 
52
-        foreach ($reflection->getParameters() as $parameter) {
52
+        foreach ($reflection->getParameters() as $parameter)
53
+        {
53 54
             $this->resolveParameter($parameter, $state, $validate)
54 55
             or
55 56
             throw new ArgumentResolvingException($reflection, $parameter->getName());
@@ -63,46 +64,58 @@  discard block
 block discarded – undo
63 64
         $positional = true;
64 65
         $variadic = false;
65 66
         $parameters = $reflection->getParameters();
66
-        if (\count($parameters) === 0) {
67
+        if (\count($parameters) === 0)
68
+        {
67 69
             return;
68 70
         }
69 71
 
70 72
         $parameter = null;
71
-        while (\count($parameters) > 0 || \count($arguments) > 0) {
73
+        while (\count($parameters) > 0 || \count($arguments) > 0)
74
+        {
72 75
             // get related argument value
73 76
             $key = \key($arguments);
74 77
 
75 78
             // For a variadic parameter it's no sense - named or positional argument will be sent
76 79
             // But you can't send positional argument after named in any case
77
-            if (\is_int($key) && !$positional) {
80
+            if (\is_int($key) && !$positional)
81
+            {
78 82
                 throw new PositionalArgumentException($reflection, $key);
79 83
             }
80 84
 
81 85
             $positional = $positional && \is_int($key);
82 86
 
83
-            if (!$variadic) {
87
+            if (!$variadic)
88
+            {
84 89
                 $parameter = \array_shift($parameters);
85 90
                 $variadic = $parameter?->isVariadic() ?? false;
86 91
             }
87 92
 
88
-            if ($parameter === null) {
93
+            if ($parameter === null)
94
+            {
89 95
                 throw new UnknownParameterException($reflection, $key);
90 96
             }
91 97
             $name = $parameter->getName();
92 98
 
93
-            if (($positional || $variadic) && $key !== null) {
99
+            if (($positional || $variadic) && $key !== null)
100
+            {
94 101
                 $value = \array_shift($arguments);
95
-            } elseif ($key === null || !\array_key_exists($name, $arguments)) {
96
-                if ($parameter->isOptional()) {
102
+            }
103
+            elseif ($key === null || !\array_key_exists($name, $arguments))
104
+            {
105
+                if ($parameter->isOptional())
106
+                {
97 107
                     continue;
98 108
                 }
99 109
                 throw new MissingRequiredArgumentException($reflection, $name);
100
-            } else {
110
+            }
111
+            else
112
+            {
101 113
                 $value = &$arguments[$name];
102 114
                 unset($arguments[$name]);
103 115
             }
104 116
 
105
-            if (!$this->validateValueToParameter($parameter, $value)) {
117
+            if (!$this->validateValueToParameter($parameter, $value))
118
+            {
106 119
                 throw new InvalidArgumentException($reflection, $name);
107 120
             }
108 121
         }
@@ -110,7 +123,8 @@  discard block
 block discarded – undo
110 123
 
111 124
     private function validateValueToParameter(ReflectionParameter $parameter, mixed $value): bool
112 125
     {
113
-        if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) {
126
+        if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null))
127
+        {
114 128
             return true;
115 129
         }
116 130
         $type = $parameter->getType();
@@ -121,17 +135,21 @@  discard block
 block discarded – undo
121 135
             $type instanceof ReflectionIntersectionType => [false, $type->getTypes()],
122 136
         };
123 137
 
124
-        foreach ($types as $t) {
138
+        foreach ($types as $t)
139
+        {
125 140
             \assert($t instanceof ReflectionNamedType);
126
-            if (!$this->validateValueNamedType($t, $value)) {
141
+            if (!$this->validateValueNamedType($t, $value))
142
+            {
127 143
                 // If it is TypeIntersection
128
-                if ($or) {
144
+                if ($or)
145
+                {
129 146
                     continue;
130 147
                 }
131 148
                 return false;
132 149
             }
133 150
             // If it is not type intersection then we can skip that value after first successful check
134
-            if ($or) {
151
+            if ($or)
152
+            {
135 153
                 return true;
136 154
             }
137 155
         }
@@ -146,7 +164,8 @@  discard block
 block discarded – undo
146 164
     {
147 165
         $name = $type->getName();
148 166
 
149
-        if ($type->isBuiltin()) {
167
+        if ($type->isBuiltin())
168
+        {
150 169
             return match ($name) {
151 170
                 'mixed' => true,
152 171
                 'string' => \is_string($value),
@@ -179,13 +198,18 @@  discard block
 block discarded – undo
179 198
 
180 199
         // Try to resolve parameter by name
181 200
         $res = $state->resolveParameterByNameOrPosition($parameter, $isVariadic);
182
-        if ($res !== [] || $isVariadic) {
201
+        if ($res !== [] || $isVariadic)
202
+        {
183 203
             // validate
184
-            if ($isVariadic) {
185
-                foreach ($res as $k => &$v) {
204
+            if ($isVariadic)
205
+            {
206
+                foreach ($res as $k => &$v)
207
+                {
186 208
                     $this->processArgument($state, $v, validateWith: $validate ? $parameter : null, key: $k);
187 209
                 }
188
-            } else {
210
+            }
211
+            else
212
+            {
189 213
                 $this->processArgument($state, $res[0], validateWith: $validate ? $parameter : null);
190 214
             }
191 215
 
@@ -193,39 +217,49 @@  discard block
 block discarded – undo
193 217
         }
194 218
 
195 219
         $error = null;
196
-        if ($hasType) {
220
+        if ($hasType)
221
+        {
197 222
             /** @var ReflectionIntersectionType|ReflectionUnionType|ReflectionNamedType $reflectionType */
198 223
             $reflectionType = $parameter->getType();
199 224
 
200
-            if ($reflectionType instanceof ReflectionIntersectionType) {
225
+            if ($reflectionType instanceof ReflectionIntersectionType)
226
+            {
201 227
                 throw new UnsupportedTypeException($parameter->getDeclaringFunction(), $parameter->getName());
202 228
             }
203 229
 
204 230
             $types = $reflectionType instanceof ReflectionNamedType ? [$reflectionType] : $reflectionType->getTypes();
205
-            foreach ($types as $namedType) {
206
-                try {
207
-                    if ($this->resolveNamedType($state, $parameter, $namedType, $validate)) {
231
+            foreach ($types as $namedType)
232
+            {
233
+                try
234
+                {
235
+                    if ($this->resolveNamedType($state, $parameter, $namedType, $validate))
236
+                    {
208 237
                         return true;
209 238
                     }
210
-                } catch (Throwable $e) {
239
+                }
240
+                catch (Throwable $e)
241
+                {
211 242
                     $error = $e;
212 243
                 }
213 244
             }
214 245
         }
215 246
 
216
-        if ($parameter->isDefaultValueAvailable()) {
247
+        if ($parameter->isDefaultValueAvailable())
248
+        {
217 249
             $argument = $parameter->getDefaultValue();
218 250
             $this->processArgument($state, $argument);
219 251
             return true;
220 252
         }
221 253
 
222
-        if ($hasType && $parameter->allowsNull()) {
254
+        if ($hasType && $parameter->allowsNull())
255
+        {
223 256
             $argument = null;
224 257
             $this->processArgument($state, $argument);
225 258
             return true;
226 259
         }
227 260
 
228
-        if ($error === null) {
261
+        if ($error === null)
262
+        {
229 263
             return false;
230 264
         }
231 265
 
@@ -292,12 +326,14 @@  discard block
 block discarded – undo
292 326
         int|string $key = null
293 327
     ): void {
294 328
         // Resolve Autowire objects
295
-        if ($value instanceof Autowire) {
329
+        if ($value instanceof Autowire)
330
+        {
296 331
             $value = $value->resolve($this->factory);
297 332
         }
298 333
 
299 334
         // Validation
300
-        if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) {
335
+        if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value))
336
+        {
301 337
             throw new InvalidArgumentException(
302 338
                 $validateWith->getDeclaringFunction(),
303 339
                 $validateWith->getName()
Please login to merge, or discard this patch.
src/Core/src/Container/Autowire.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     public function __construct(
27 27
         private readonly string $alias,
28 28
         private readonly array $parameters = []
29
-    ) {
29
+    ){
30 30
     }
31 31
 
32 32
     public static function __set_state(array $anArray): static
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public static function wire(mixed $definition): Autowire
43 43
     {
44
-        if ($definition instanceof self) {
44
+        if ($definition instanceof self){
45 45
             return $definition;
46 46
         }
47 47
 
48
-        if (\is_string($definition)) {
48
+        if (\is_string($definition)){
49 49
             return new self($definition);
50 50
         }
51 51
 
52
-        if (\is_array($definition) && isset($definition['class'])) {
52
+        if (\is_array($definition) && isset($definition['class'])){
53 53
             return new self(
54 54
                 $definition['class'],
55 55
                 $definition['options'] ?? $definition['params'] ?? []
56 56
             );
57 57
         }
58 58
 
59
-        if (\is_object($definition)) {
59
+        if (\is_object($definition)){
60 60
             $autowire = new self($definition::class, []);
61 61
             $autowire->target = $definition;
62 62
             return $autowire;
Please login to merge, or discard this patch.
Braces   +8 added lines, -4 removed lines patch added patch discarded remove patch
@@ -41,22 +41,26 @@
 block discarded – undo
41 41
      */
42 42
     public static function wire(mixed $definition): Autowire
43 43
     {
44
-        if ($definition instanceof self) {
44
+        if ($definition instanceof self)
45
+        {
45 46
             return $definition;
46 47
         }
47 48
 
48
-        if (\is_string($definition)) {
49
+        if (\is_string($definition))
50
+        {
49 51
             return new self($definition);
50 52
         }
51 53
 
52
-        if (\is_array($definition) && isset($definition['class'])) {
54
+        if (\is_array($definition) && isset($definition['class']))
55
+        {
53 56
             return new self(
54 57
                 $definition['class'],
55 58
                 $definition['options'] ?? $definition['params'] ?? []
56 59
             );
57 60
         }
58 61
 
59
-        if (\is_object($definition)) {
62
+        if (\is_object($definition))
63
+        {
60 64
             $autowire = new self($definition::class, []);
61 65
             $autowire->target = $definition;
62 66
             return $autowire;
Please login to merge, or discard this patch.
src/Core/src/Config.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
         public readonly string $container = Container::class,
38 38
         public readonly string $binder = Binder::class,
39 39
         public readonly string $invoker = Invoker::class,
40
-    ) {
40
+    ){
41 41
     }
42 42
 
43 43
     public function getIterator(): Traversable
Please login to merge, or discard this patch.