Passed
Push — master ( ad0a0c...f87c9b )
by butschster
09:41
created
src/Core/src/Internal/Config/StateBinder.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  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
     /**
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function bind(string $alias, mixed $resolver): void
42 42
     {
43
-        if ($resolver instanceof Inflector && (\interface_exists($alias) || \class_exists($alias))) {
43
+        if ($resolver instanceof Inflector && (\interface_exists($alias) || \class_exists($alias))){
44 44
             $this->state->inflectors[$alias][] = $resolver;
45 45
             return;
46 46
         }
47 47
 
48
-        try {
48
+        try{
49 49
             $config = $this->makeConfig($resolver, false);
50
-        } catch (\Throwable $e) {
50
+        }catch (\Throwable $e){
51 51
             throw $this->invalidBindingException($alias, $e);
52 52
         }
53 53
 
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function bindSingleton(string $alias, mixed $resolver): void
61 61
     {
62
-        try {
62
+        try{
63 63
             $config = $this->makeConfig($resolver, true);
64
-        } catch (\Throwable $e) {
64
+        }catch (\Throwable $e){
65 65
             throw $this->invalidBindingException($alias, $e);
66 66
         }
67 67
 
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
         $bindings = &$this->state->bindings;
74 74
 
75 75
         $flags = [];
76
-        while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class) {
76
+        while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class){
77 77
             //Checking alias tree
78
-            if ($flags[$binding->alias] ?? false) {
78
+            if ($flags[$binding->alias] ?? false){
79 79
                 return $binding->alias === $alias ?: throw new Exception('Circular alias detected');
80 80
             }
81 81
 
82
-            if (\array_key_exists($alias, $this->state->singletons)) {
82
+            if (\array_key_exists($alias, $this->state->singletons)){
83 83
                 return true;
84 84
             }
85 85
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
     public function removeInjector(string $class): void
105 105
     {
106 106
         unset($this->state->injectors[$class]);
107
-        if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) {
107
+        if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class){
108 108
             return;
109 109
         }
110 110
         unset($this->state->bindings[$class]);
@@ -112,20 +112,20 @@  discard block
 block discarded – undo
112 112
 
113 113
     public function hasInjector(string $class): bool
114 114
     {
115
-        try {
115
+        try{
116 116
             $reflection = new \ReflectionClass($class);
117
-        } catch (\ReflectionException $e) {
117
+        }catch (\ReflectionException $e){
118 118
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
119 119
         }
120 120
 
121
-        if (\array_key_exists($class, $this->state->injectors)) {
121
+        if (\array_key_exists($class, $this->state->injectors)){
122 122
             return true;
123 123
         }
124 124
 
125 125
         if (
126 126
             $reflection->implementsInterface(InjectableInterface::class)
127 127
             && $reflection->hasConstant('INJECTOR')
128
-        ) {
128
+        ){
129 129
             $const = $reflection->getConstant('INJECTOR');
130 130
             $this->bindInjector($class, $const);
131 131
 
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
         }
134 134
 
135 135
         // check interfaces
136
-        foreach ($this->state->injectors as $target => $injector) {
136
+        foreach ($this->state->injectors as $target => $injector){
137 137
             if (
138 138
                 (\class_exists($target, true) && $reflection->isSubclassOf($target))
139 139
                 ||
140 140
                 (\interface_exists($target, true) && $reflection->implementsInterface($target))
141
-            ) {
141
+            ){
142 142
                 $this->state->bindings[$class] = new Injectable($injector);
143 143
 
144 144
                 return true;
@@ -165,15 +165,15 @@  discard block
 block discarded – undo
165 165
 
166 166
     private function makeConfigFromArray(array $resolver, bool $singleton): Binding
167 167
     {
168
-        if (\is_callable($resolver)) {
168
+        if (\is_callable($resolver)){
169 169
             return new Factory($resolver, $singleton);
170 170
         }
171 171
 
172 172
         // Validate lazy invokable array
173
-        if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') {
173
+        if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === ''){
174 174
             throw new InvalidArgumentException('Incompatible array declaration for resolver.');
175 175
         }
176
-        if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') {
176
+        if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === ''){
177 177
             throw new InvalidArgumentException('Incompatible array declaration for resolver.');
178 178
         }
179 179
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
     private function setBinding(string $alias, Binding $config): void
193 193
     {
194
-        if (isset($this->state->singletons[$alias])) {
194
+        if (isset($this->state->singletons[$alias])){
195 195
             throw new SingletonOverloadException($alias);
196 196
         }
197 197
 
Please login to merge, or discard this patch.
src/Core/tests/Internal/Config/StateBinderTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
         $binder = $this->constructor->get('binder', BinderInterface::class);
47 47
         $factory = $this->constructor->get('factory', FactoryInterface::class);
48 48
 
49
-        $this->bindSingleton('test', new class implements SingletonInterface {});
49
+        $this->bindSingleton('test', new class implements SingletonInterface{});
50 50
         $factory->make('test');
51 51
 
52 52
         $this->assertTrue($binder->hasInstance('test'));
Please login to merge, or discard this patch.