Passed
Pull Request — master (#1195)
by butschster
41:55 queued 29:26
created
src/Core/src/Internal/Config/StateBinder.php 1 patch
Braces   +41 added lines, -19 removed lines patch added patch discarded remove patch
@@ -32,21 +32,26 @@  discard block
 block discarded – undo
32 32
 {
33 33
     public function __construct(
34 34
         protected readonly State $state,
35
-    ) {}
35
+    ) {
36
+}
36 37
 
37 38
     /**
38 39
      * @param TResolver|object $resolver
39 40
      */
40 41
     public function bind(string $alias, mixed $resolver): void
41 42
     {
42
-        if ($resolver instanceof Inflector && (\interface_exists($alias) || \class_exists($alias))) {
43
+        if ($resolver instanceof Inflector && (\interface_exists($alias) || \class_exists($alias)))
44
+        {
43 45
             $this->state->inflectors[$alias][] = $resolver;
44 46
             return;
45 47
         }
46 48
 
47
-        try {
49
+        try
50
+        {
48 51
             $config = $this->makeConfig($resolver, false);
49
-        } catch (\Throwable $e) {
52
+        }
53
+        catch (\Throwable $e)
54
+        {
50 55
             throw $this->invalidBindingException($alias, $e);
51 56
         }
52 57
 
@@ -58,9 +63,12 @@  discard block
 block discarded – undo
58 63
      */
59 64
     public function bindSingleton(string $alias, mixed $resolver): void
60 65
     {
61
-        try {
66
+        try
67
+        {
62 68
             $config = $this->makeConfig($resolver, true);
63
-        } catch (\Throwable $e) {
69
+        }
70
+        catch (\Throwable $e)
71
+        {
64 72
             throw $this->invalidBindingException($alias, $e);
65 73
         }
66 74
 
@@ -72,13 +80,16 @@  discard block
 block discarded – undo
72 80
         $bindings = &$this->state->bindings;
73 81
 
74 82
         $flags = [];
75
-        while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class) {
83
+        while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class)
84
+        {
76 85
             //Checking alias tree
77
-            if ($flags[$binding->alias] ?? false) {
86
+            if ($flags[$binding->alias] ?? false)
87
+            {
78 88
                 return $binding->alias === $alias ?: throw new Exception('Circular alias detected');
79 89
             }
80 90
 
81
-            if (\array_key_exists($alias, $this->state->singletons)) {
91
+            if (\array_key_exists($alias, $this->state->singletons))
92
+            {
82 93
                 return true;
83 94
             }
84 95
 
@@ -102,7 +113,8 @@  discard block
 block discarded – undo
102 113
     public function removeInjector(string $class): void
103 114
     {
104 115
         unset($this->state->injectors[$class]);
105
-        if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) {
116
+        if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class)
117
+        {
106 118
             return;
107 119
         }
108 120
         unset($this->state->bindings[$class]);
@@ -110,13 +122,17 @@  discard block
 block discarded – undo
110 122
 
111 123
     public function hasInjector(string $class): bool
112 124
     {
113
-        if (\array_key_exists($class, $this->state->injectors)) {
125
+        if (\array_key_exists($class, $this->state->injectors))
126
+        {
114 127
             return true;
115 128
         }
116 129
 
117
-        try {
130
+        try
131
+        {
118 132
             $reflection = new \ReflectionClass($class);
119
-        } catch (\ReflectionException $e) {
133
+        }
134
+        catch (\ReflectionException $e)
135
+        {
120 136
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
121 137
         }
122 138
 
@@ -131,7 +147,8 @@  discard block
 block discarded – undo
131 147
         }
132 148
 
133 149
         // check interfaces
134
-        foreach ($this->state->injectors as $target => $injector) {
150
+        foreach ($this->state->injectors as $target => $injector)
151
+        {
135 152
             if (
136 153
                 (\class_exists($target, true) && $reflection->isSubclassOf($target))
137 154
                 ||
@@ -163,15 +180,18 @@  discard block
 block discarded – undo
163 180
 
164 181
     private function makeConfigFromArray(array $resolver, bool $singleton): Binding
165 182
     {
166
-        if (\is_callable($resolver)) {
183
+        if (\is_callable($resolver))
184
+        {
167 185
             return new Factory($resolver, $singleton);
168 186
         }
169 187
 
170 188
         // Validate lazy invokable array
171
-        if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') {
189
+        if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '')
190
+        {
172 191
             throw new InvalidArgumentException('Incompatible array declaration for resolver.');
173 192
         }
174
-        if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') {
193
+        if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '')
194
+        {
175 195
             throw new InvalidArgumentException('Incompatible array declaration for resolver.');
176 196
         }
177 197
 
@@ -191,13 +211,15 @@  discard block
 block discarded – undo
191 211
 
192 212
     private function setBinding(string $alias, Binding $config): void
193 213
     {
194
-        if (isset($this->state->singletons[$alias])) {
214
+        if (isset($this->state->singletons[$alias]))
215
+        {
195 216
             throw new SingletonOverloadException($alias);
196 217
         }
197 218
 
198 219
         $this->state->bindings[$alias] = $config;
199 220
 
200
-        if ($config instanceof Injectable) {
221
+        if ($config instanceof Injectable)
222
+        {
201 223
             $this->state->injectors[$alias] = $config->injector;
202 224
         }
203 225
     }
Please login to merge, or discard this patch.