Passed
Pull Request — master (#1221)
by Aleksei
10:45
created
src/Core/src/Exception/Container/AutowireException.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,4 +7,4 @@
 block discarded – undo
7 7
 /**
8 8
  * When class can not be created.
9 9
  */
10
-class AutowireException extends TracedContainerException {}
10
+class AutowireException extends TracedContainerException{}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,4 +7,6 @@
 block discarded – undo
7 7
 /**
8 8
  * When class can not be created.
9 9
  */
10
-class AutowireException extends TracedContainerException {}
10
+class AutowireException extends TracedContainerException
11
+{
12
+}
Please login to merge, or discard this patch.
src/Core/tests/Internal/Resolver/NullableParameterTest.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
     public function testNullableUnionDefaultScalar(): void
83 83
     {
84 84
         $result = $this->resolveClosure(
85
-            static fn(null|int|string $param = 42) => $param,
85
+            static fn(null | int | string $param = 42) => $param,
86 86
         );
87 87
 
88 88
         $this->assertSame([42], $result);
@@ -103,12 +103,12 @@  discard block
 block discarded – undo
103 103
     {
104 104
         $this->bind(\DateTimeInterface::class, static fn() => throw new \RuntimeException('fail!'));
105 105
 
106
-        try {
106
+        try{
107 107
             $this->resolveClosure(
108 108
                 static fn(\DateTimeInterface $param) => $param,
109 109
             );
110 110
             self::fail('Exception should be thrown');
111
-        } catch (NotFoundException $e) {
111
+        }catch (NotFoundException $e){
112 112
             self::assertNotNull($e->getPrevious());
113 113
             self::assertStringContainsString('fail!', $e->getPrevious()->getMessage());
114 114
         }
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -103,12 +103,15 @@
 block discarded – undo
103 103
     {
104 104
         $this->bind(\DateTimeInterface::class, static fn() => throw new \RuntimeException('fail!'));
105 105
 
106
-        try {
106
+        try
107
+        {
107 108
             $this->resolveClosure(
108 109
                 static fn(\DateTimeInterface $param) => $param,
109 110
             );
110 111
             self::fail('Exception should be thrown');
111
-        } catch (NotFoundException $e) {
112
+        }
113
+        catch (NotFoundException $e)
114
+        {
112 115
             self::assertNotNull($e->getPrevious());
113 116
             self::assertStringContainsString('fail!', $e->getPrevious()->getMessage());
114 117
         }
Please login to merge, or discard this patch.
src/Core/tests/InvokerTest.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     {
74 74
         $this->container->bindSingleton(Bucket::class, $bucket = new Bucket('foo'));
75 75
 
76
-        $result = $this->container->invoke(Storage::class . '::createBucket', ['name' => 'bar']);
76
+        $result = $this->container->invoke(Storage::class.'::createBucket', ['name' => 'bar']);
77 77
 
78 78
         self::assertSame($bucket, $result['bucket']);
79 79
         self::assertInstanceOf(SampleClass::class, $result['class']);
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
         // Note: do not add a return type to the closure
143 143
         $this->container->bind('foo', fn() => throw new \Exception('Factory called'));
144 144
 
145
-        try {
145
+        try{
146 146
             $this->container->invoke(['foo', 'publicMethod'], [42]);
147 147
             self::fail('Exception should be thrown');
148
-        } catch (\Throwable $e) {
148
+        }catch (\Throwable $e){
149 149
             self::assertInstanceOf(NotFoundException::class, $e);
150 150
             self::assertNotNull($e->getPrevious());
151 151
             self::assertStringContainsString('Factory called', $e->getPrevious()->getMessage());
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
      */
158 158
     public function testCallStaticMethodWithoutInstantiationWithOvertypedFactory(): void
159 159
     {
160
-        $this->container->bind('foo', fn(): PrivateConstructor|SampleClass => throw new \Exception('Factory called'));
160
+        $this->container->bind('foo', fn(): PrivateConstructor | SampleClass => throw new \Exception('Factory called'));
161 161
 
162
-        try {
162
+        try{
163 163
             $this->container->invoke(['foo', 'publicMethod'], [42]);
164 164
             self::fail('Exception should be thrown');
165
-        } catch (\Throwable $e) {
165
+        }catch (\Throwable $e){
166 166
             self::assertInstanceOf(NotFoundException::class, $e);
167 167
             self::assertNotNull($e->getPrevious());
168 168
             self::assertStringContainsString('Factory called', $e->getPrevious()->getMessage());
@@ -175,10 +175,10 @@  discard block
 block discarded – undo
175 175
     public function testCallStaticMethodWithoutInstantiationWithNullableTypedFactory(): void
176 176
     {
177 177
         $this->container->bind('foo', fn(): ?PrivateConstructor => throw new \Exception('Factory called'));
178
-        try {
178
+        try{
179 179
             $this->container->invoke(['foo', 'publicMethod'], [42]);
180 180
             self::fail('Exception should be thrown');
181
-        } catch (\Throwable $e) {
181
+        }catch (\Throwable $e){
182 182
             self::assertInstanceOf(NotFoundException::class, $e);
183 183
             self::assertNotNull($e->getPrevious());
184 184
             self::assertStringContainsString('Factory called', $e->getPrevious()->getMessage());
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         $this->expectException(ArgumentResolvingException::class);
191 191
         $this->expectExceptionMessage('Unable to resolve required argument `name` when resolving');
192 192
 
193
-        $this->container->invoke(Storage::class . '::createBucket', ['name' => 'bar']);
193
+        $this->container->invoke(Storage::class.'::createBucket', ['name' => 'bar']);
194 194
     }
195 195
 
196 196
     public function testCallValidClosure(): void
Please login to merge, or discard this patch.
Braces   +15 added lines, -6 removed lines patch added patch discarded remove patch
@@ -142,10 +142,13 @@  discard block
 block discarded – undo
142 142
         // Note: do not add a return type to the closure
143 143
         $this->container->bind('foo', fn() => throw new \Exception('Factory called'));
144 144
 
145
-        try {
145
+        try
146
+        {
146 147
             $this->container->invoke(['foo', 'publicMethod'], [42]);
147 148
             self::fail('Exception should be thrown');
148
-        } catch (\Throwable $e) {
149
+        }
150
+        catch (\Throwable $e)
151
+        {
149 152
             self::assertInstanceOf(NotFoundException::class, $e);
150 153
             self::assertNotNull($e->getPrevious());
151 154
             self::assertStringContainsString('Factory called', $e->getPrevious()->getMessage());
@@ -159,10 +162,13 @@  discard block
 block discarded – undo
159 162
     {
160 163
         $this->container->bind('foo', fn(): PrivateConstructor|SampleClass => throw new \Exception('Factory called'));
161 164
 
162
-        try {
165
+        try
166
+        {
163 167
             $this->container->invoke(['foo', 'publicMethod'], [42]);
164 168
             self::fail('Exception should be thrown');
165
-        } catch (\Throwable $e) {
169
+        }
170
+        catch (\Throwable $e)
171
+        {
166 172
             self::assertInstanceOf(NotFoundException::class, $e);
167 173
             self::assertNotNull($e->getPrevious());
168 174
             self::assertStringContainsString('Factory called', $e->getPrevious()->getMessage());
@@ -175,10 +181,13 @@  discard block
 block discarded – undo
175 181
     public function testCallStaticMethodWithoutInstantiationWithNullableTypedFactory(): void
176 182
     {
177 183
         $this->container->bind('foo', fn(): ?PrivateConstructor => throw new \Exception('Factory called'));
178
-        try {
184
+        try
185
+        {
179 186
             $this->container->invoke(['foo', 'publicMethod'], [42]);
180 187
             self::fail('Exception should be thrown');
181
-        } catch (\Throwable $e) {
188
+        }
189
+        catch (\Throwable $e)
190
+        {
182 191
             self::assertInstanceOf(NotFoundException::class, $e);
183 192
             self::assertNotNull($e->getPrevious());
184 193
             self::assertStringContainsString('Factory called', $e->getPrevious()->getMessage());
Please login to merge, or discard this patch.
src/Core/src/Internal/Factory.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -37,23 +37,23 @@  discard block
 block discarded – undo
37 37
     public function make(
38 38
         string $alias,
39 39
         array $parameters = [],
40
-        \Stringable|string|null $context = null,
40
+        \Stringable | string | null $context = null,
41 41
         ?Tracer $tracer = null,
42 42
     ): mixed {
43
-        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) {
43
+        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){
44 44
             return $this->state->singletons[$alias];
45 45
         }
46 46
 
47 47
 
48 48
         $this->actor->resolveType($alias, $binding, $singleton, $injector, $actor, false);
49
-        if ($parameters === [] && $singleton !== null) {
49
+        if ($parameters === [] && $singleton !== null){
50 50
             return $singleton;
51 51
         }
52 52
 
53 53
         $tracer ??= new Tracer();
54 54
 
55 55
         // Resolve without binding
56
-        if ($binding === null) {
56
+        if ($binding === null){
57 57
             $tracer->push(
58 58
                 false,
59 59
                 action: 'autowire',
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
                 scope: $this->scope->getScopeName(),
62 62
                 context: $context,
63 63
             );
64
-            try {
64
+            try{
65 65
                 // No direct instructions how to construct class, make is automatically
66 66
                 return $this->actor->autowire(
67 67
                     new Ctx(alias: $alias, class: $alias, context: $context, singleton: $parameters === [] ? null : false),
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
                     $actor,
70 70
                     $tracer,
71 71
                 );
72
-            } finally {
72
+            }finally{
73 73
                 $tracer->pop(false);
74 74
             }
75 75
         }
76 76
 
77
-        try {
77
+        try{
78 78
             $tracer->push(
79 79
                 false,
80 80
                 action: 'resolve from binding',
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 
88 88
             $actor->disableBinding($alias);
89 89
             return $actor->resolveBinding($binding, $alias, $context, $parameters, $tracer);
90
-        } finally {
90
+        }finally{
91 91
             $actor->enableBinding($alias, $binding);
92 92
             $tracer->pop(true);
93 93
             $tracer->pop(false);
Please login to merge, or discard this patch.
Braces   +16 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,20 +40,23 @@  discard block
 block discarded – undo
40 40
         \Stringable|string|null $context = null,
41 41
         ?Tracer $tracer = null,
42 42
     ): mixed {
43
-        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) {
43
+        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons))
44
+        {
44 45
             return $this->state->singletons[$alias];
45 46
         }
46 47
 
47 48
 
48 49
         $this->actor->resolveType($alias, $binding, $singleton, $injector, $actor, false);
49
-        if ($parameters === [] && $singleton !== null) {
50
+        if ($parameters === [] && $singleton !== null)
51
+        {
50 52
             return $singleton;
51 53
         }
52 54
 
53 55
         $tracer ??= new Tracer();
54 56
 
55 57
         // Resolve without binding
56
-        if ($binding === null) {
58
+        if ($binding === null)
59
+        {
57 60
             $tracer->push(
58 61
                 false,
59 62
                 action: 'autowire',
@@ -61,7 +64,8 @@  discard block
 block discarded – undo
61 64
                 scope: $this->scope->getScopeName(),
62 65
                 context: $context,
63 66
             );
64
-            try {
67
+            try
68
+            {
65 69
                 // No direct instructions how to construct class, make is automatically
66 70
                 return $this->actor->autowire(
67 71
                     new Ctx(alias: $alias, class: $alias, context: $context, singleton: $parameters === [] ? null : false),
@@ -69,12 +73,15 @@  discard block
 block discarded – undo
69 73
                     $actor,
70 74
                     $tracer,
71 75
                 );
72
-            } finally {
76
+            }
77
+            finally
78
+            {
73 79
                 $tracer->pop(false);
74 80
             }
75 81
         }
76 82
 
77
-        try {
83
+        try
84
+        {
78 85
             $tracer->push(
79 86
                 false,
80 87
                 action: 'resolve from binding',
@@ -87,7 +94,9 @@  discard block
 block discarded – undo
87 94
 
88 95
             $actor->disableBinding($alias);
89 96
             return $actor->resolveBinding($binding, $alias, $context, $parameters, $tracer);
90
-        } finally {
97
+        }
98
+        finally
99
+        {
91 100
             $actor->enableBinding($alias, $binding);
92 101
             $tracer->pop(true);
93 102
             $tracer->pop(false);
Please login to merge, or discard this patch.
src/Router/src/Loader/Configurator/RouteConfigurator.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     private ?string $group = null;
33 33
     private ?array $methods = null;
34 34
     private string $prefix = '';
35
-    private HandlerInterface|CoreInterface|null $core = null;
35
+    private HandlerInterface | CoreInterface | null $core = null;
36 36
     private ?array $middleware = null;
37 37
 
38 38
     /** @var null|string|callable|RequestHandlerInterface|TargetInterface */
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
         private readonly string $name,
47 47
         private readonly string $pattern,
48 48
         private readonly RouteCollection $collection,
49
-    ) {}
49
+    ){}
50 50
 
51 51
     public function controller(string $controller, int $options = 0, string $defaultAction = 'index'): self
52 52
     {
@@ -69,21 +69,21 @@  discard block
 block discarded – undo
69 69
         return $this;
70 70
     }
71 71
 
72
-    public function action(string $controller, string|array $action, int $options = 0): self
72
+    public function action(string $controller, string | array $action, int $options = 0): self
73 73
     {
74 74
         $this->target = new Action($controller, $action, $options);
75 75
 
76 76
         return $this;
77 77
     }
78 78
 
79
-    public function callable(array|\Closure $callable): self
79
+    public function callable(array | \Closure $callable): self
80 80
     {
81 81
         $this->target = $callable;
82 82
 
83 83
         return $this;
84 84
     }
85 85
 
86
-    public function handler(TargetInterface|string $target): self
86
+    public function handler(TargetInterface | string $target): self
87 87
     {
88 88
         $this->target = $target;
89 89
 
@@ -111,16 +111,16 @@  discard block
 block discarded – undo
111 111
         return $this;
112 112
     }
113 113
 
114
-    public function core(HandlerInterface|CoreInterface $core): self
114
+    public function core(HandlerInterface | CoreInterface $core): self
115 115
     {
116 116
         $this->core = $core;
117 117
 
118 118
         return $this;
119 119
     }
120 120
 
121
-    public function middleware(MiddlewareInterface|string|array $middleware): self
121
+    public function middleware(MiddlewareInterface | string | array $middleware): self
122 122
     {
123
-        if (!\is_array($middleware)) {
123
+        if (!\is_array($middleware)){
124 124
             $middleware = [$middleware];
125 125
         }
126 126
 
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
     /**
133 133
      * @param non-empty-string|list<non-empty-string> $methods
134 134
      */
135
-    public function methods(string|array $methods): self
135
+    public function methods(string | array $methods): self
136 136
     {
137
-        $this->methods = (array) $methods;
137
+        $this->methods = (array)$methods;
138 138
 
139 139
         return $this;
140 140
     }
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 
162 162
     public function __destruct()
163 163
     {
164
-        if ($this->target === null) {
164
+        if ($this->target === null){
165 165
             throw new TargetException(
166 166
                 \sprintf('The [%s] route has no defined target. Call one of: `controller`, `action`,
167 167
                     `namespaced`, `groupControllers`, `callable`, `handler` methods.', $this->name),
Please login to merge, or discard this patch.
src/Files/src/Files.php 2 patches
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -39,30 +39,30 @@  discard block
 block discarded – undo
39 39
         ?int $mode = null,
40 40
         bool $recursivePermissions = true,
41 41
     ): bool {
42
-        if (empty($mode)) {
42
+        if (empty($mode)){
43 43
             $mode = self::DEFAULT_FILE_MODE;
44 44
         }
45 45
 
46 46
         //Directories always executable
47 47
         $mode |= 0o111;
48
-        if (\is_dir($directory)) {
48
+        if (\is_dir($directory)){
49 49
             //Exists :(
50 50
             return $this->setPermissions($directory, $mode);
51 51
         }
52 52
 
53
-        if (!$recursivePermissions) {
53
+        if (!$recursivePermissions){
54 54
             return \mkdir($directory, $mode, true);
55 55
         }
56 56
 
57 57
         $directoryChain = [\basename($directory)];
58 58
 
59 59
         $baseDirectory = $directory;
60
-        while (!\is_dir($baseDirectory = \dirname($baseDirectory))) {
60
+        while (!\is_dir($baseDirectory = \dirname($baseDirectory))){
61 61
             $directoryChain[] = \basename($baseDirectory);
62 62
         }
63 63
 
64
-        foreach (\array_reverse($directoryChain) as $dir) {
65
-            if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) {
64
+        foreach (\array_reverse($directoryChain) as $dir){
65
+            if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))){
66 66
                 return false;
67 67
             }
68 68
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 
75 75
     public function read(string $filename): string
76 76
     {
77
-        if (!$this->exists($filename)) {
77
+        if (!$this->exists($filename)){
78 78
             throw new FileNotFoundException($filename);
79 79
         }
80 80
 
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
     ): bool {
97 97
         $mode ??= self::DEFAULT_FILE_MODE;
98 98
 
99
-        try {
100
-            if ($ensureDirectory) {
99
+        try{
100
+            if ($ensureDirectory){
101 101
                 $this->ensureDirectory(\dirname($filename), $mode);
102 102
             }
103 103
 
104
-            if ($this->exists($filename)) {
104
+            if ($this->exists($filename)){
105 105
                 //Forcing mode for existed file
106 106
                 $this->setPermissions($filename, $mode);
107 107
             }
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
                 $append ? FILE_APPEND | LOCK_EX : LOCK_EX,
113 113
             );
114 114
 
115
-            if ($result !== false) {
115
+            if ($result !== false){
116 116
                 //Forcing mode after file creation
117 117
                 $this->setPermissions($filename, $mode);
118 118
             }
119
-        } catch (\Exception $e) {
120
-            throw new WriteErrorException($e->getMessage(), (int) $e->getCode(), $e);
119
+        }catch (\Exception $e){
120
+            throw new WriteErrorException($e->getMessage(), (int)$e->getCode(), $e);
121 121
         }
122 122
 
123 123
         return $result !== false;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
     public function delete(string $filename): bool
136 136
     {
137
-        if ($this->exists($filename)) {
137
+        if ($this->exists($filename)){
138 138
             $result = \unlink($filename);
139 139
 
140 140
             //Wiping out changes in local file cache
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      */
154 154
     public function deleteDirectory(string $directory, bool $contentOnly = false): bool
155 155
     {
156
-        if (!$this->isDirectory($directory)) {
156
+        if (!$this->isDirectory($directory)){
157 157
             throw new FilesException(\sprintf('Undefined or invalid directory %s', $directory));
158 158
         }
159 159
 
@@ -162,15 +162,15 @@  discard block
 block discarded – undo
162 162
             \RecursiveIteratorIterator::CHILD_FIRST,
163 163
         );
164 164
 
165
-        foreach ($files as $file) {
166
-            if ($file->isDir()) {
165
+        foreach ($files as $file){
166
+            if ($file->isDir()){
167 167
                 \rmdir($file->getRealPath());
168
-            } else {
168
+            }else{
169 169
                 $this->delete($file->getRealPath());
170 170
             }
171 171
         }
172 172
 
173
-        if (!$contentOnly) {
173
+        if (!$contentOnly){
174 174
             return \rmdir($directory);
175 175
         }
176 176
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 
180 180
     public function move(string $filename, string $destination): bool
181 181
     {
182
-        if (!$this->exists($filename)) {
182
+        if (!$this->exists($filename)){
183 183
             throw new FileNotFoundException($filename);
184 184
         }
185 185
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
     public function copy(string $filename, string $destination): bool
190 190
     {
191
-        if (!$this->exists($filename)) {
191
+        if (!$this->exists($filename)){
192 192
             throw new FileNotFoundException($filename);
193 193
         }
194 194
 
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 
198 198
     public function touch(string $filename, ?int $mode = null): bool
199 199
     {
200
-        if (!\touch($filename)) {
200
+        if (!\touch($filename)){
201 201
             return false;
202 202
         }
203 203
 
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
     {
214 214
         $this->exists($filename) or throw new FileNotFoundException($filename);
215 215
 
216
-        return (int) \filesize($filename);
216
+        return (int)\filesize($filename);
217 217
     }
218 218
 
219 219
     public function extension(string $filename): string
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 
224 224
     public function md5(string $filename): string
225 225
     {
226
-        if (!$this->exists($filename)) {
226
+        if (!$this->exists($filename)){
227 227
             throw new FileNotFoundException($filename);
228 228
         }
229 229
 
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 
238 238
     public function time(string $filename): int
239 239
     {
240
-        if (!$this->exists($filename)) {
240
+        if (!$this->exists($filename)){
241 241
             throw new FileNotFoundException($filename);
242 242
         }
243 243
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 
269 269
     public function setPermissions(string $filename, int $mode): bool
270 270
     {
271
-        if (\is_dir($filename)) {
271
+        if (\is_dir($filename)){
272 272
             //Directories must always be executable (i.e. 664 for dir => 775)
273 273
             $mode |= 0111;
274 274
         }
@@ -279,14 +279,14 @@  discard block
 block discarded – undo
279 279
     public function getFiles(string $location, ?string $pattern = null): array
280 280
     {
281 281
         $result = [];
282
-        foreach ($this->filesIterator($location, $pattern) as $filename) {
283
-            if ($this->isDirectory($filename->getPathname())) {
284
-                $result = \array_merge($result, $this->getFiles(((string) $filename) . DIRECTORY_SEPARATOR));
282
+        foreach ($this->filesIterator($location, $pattern) as $filename){
283
+            if ($this->isDirectory($filename->getPathname())){
284
+                $result = \array_merge($result, $this->getFiles(((string)$filename).DIRECTORY_SEPARATOR));
285 285
 
286 286
                 continue;
287 287
             }
288 288
 
289
-            $result[] = $this->normalizePath((string) $filename);
289
+            $result[] = $this->normalizePath((string)$filename);
290 290
         }
291 291
 
292 292
         return $result;
@@ -294,14 +294,14 @@  discard block
 block discarded – undo
294 294
 
295 295
     public function tempFilename(string $extension = '', ?string $location = null): string
296 296
     {
297
-        if (empty($location)) {
297
+        if (empty($location)){
298 298
             $location = \sys_get_temp_dir();
299 299
         }
300 300
 
301 301
         $filename = \tempnam($location, 'spiral');
302 302
         $filename === false and throw new FilesException('Unable to create temporary file.');
303 303
 
304
-        if (!empty($extension)) {
304
+        if (!empty($extension)){
305 305
             $old = $filename;
306 306
             $filename = \sprintf('%s.%s', $filename, $extension);
307 307
             \rename($old, $filename);
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
     public function normalizePath(string $path, bool $asDirectory = false): string
315 315
     {
316 316
         $isUnc = \str_starts_with($path, '\\\\') || \str_starts_with($path, '//');
317
-        if ($isUnc) {
317
+        if ($isUnc){
318 318
             $leadingSlashes = \substr($path, 0, 2);
319 319
             $path = \substr($path, 2);
320 320
         }
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
         $path = \str_replace(['//', '\\'], '/', $path);
323 323
 
324 324
         //Potentially open links and ../ type directories?
325
-        return ($isUnc ? $leadingSlashes : '') . \rtrim($path, '/') . ($asDirectory ? '/' : '');
325
+        return ($isUnc ? $leadingSlashes : '').\rtrim($path, '/').($asDirectory ? '/' : '');
326 326
     }
327 327
 
328 328
     /**
@@ -337,21 +337,21 @@  discard block
 block discarded – undo
337 337
         $path = \explode('/', $path);
338 338
         $relative = $path;
339 339
 
340
-        foreach ($from as $depth => $dir) {
340
+        foreach ($from as $depth => $dir){
341 341
             //Find first non-matching dir
342
-            if ($dir === $path[$depth]) {
342
+            if ($dir === $path[$depth]){
343 343
                 //Ignore this directory
344 344
                 \array_shift($relative);
345
-            } else {
345
+            }else{
346 346
                 //Get number of remaining dirs to $from
347 347
                 $remaining = \count($from) - $depth;
348
-                if ($remaining > 1) {
348
+                if ($remaining > 1){
349 349
                     //Add traversals up to first matching directory
350 350
                     $padLength = (\count($relative) + $remaining - 1) * -1;
351 351
                     $relative = \array_pad($relative, $padLength, '..');
352 352
                     break;
353 353
                 }
354
-                $relative[0] = './' . $relative[0];
354
+                $relative[0] = './'.$relative[0];
355 355
             }
356 356
         }
357 357
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      */
364 364
     public function __destruct()
365 365
     {
366
-        foreach ($this->destructFiles as $filename) {
366
+        foreach ($this->destructFiles as $filename){
367 367
             $this->delete($filename);
368 368
         }
369 369
     }
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
     private function filesIterator(string $location, ?string $pattern = null): \GlobIterator
372 372
     {
373 373
         $pattern ??= '*';
374
-        $regexp = \rtrim($location, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . \ltrim($pattern, DIRECTORY_SEPARATOR);
374
+        $regexp = \rtrim($location, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.\ltrim($pattern, DIRECTORY_SEPARATOR);
375 375
 
376 376
         return new \GlobIterator($regexp);
377 377
     }
Please login to merge, or discard this patch.
Braces   +71 added lines, -34 removed lines patch added patch discarded remove patch
@@ -39,30 +39,36 @@  discard block
 block discarded – undo
39 39
         ?int $mode = null,
40 40
         bool $recursivePermissions = true,
41 41
     ): bool {
42
-        if (empty($mode)) {
42
+        if (empty($mode))
43
+        {
43 44
             $mode = self::DEFAULT_FILE_MODE;
44 45
         }
45 46
 
46 47
         //Directories always executable
47 48
         $mode |= 0o111;
48
-        if (\is_dir($directory)) {
49
+        if (\is_dir($directory))
50
+        {
49 51
             //Exists :(
50 52
             return $this->setPermissions($directory, $mode);
51 53
         }
52 54
 
53
-        if (!$recursivePermissions) {
55
+        if (!$recursivePermissions)
56
+        {
54 57
             return \mkdir($directory, $mode, true);
55 58
         }
56 59
 
57 60
         $directoryChain = [\basename($directory)];
58 61
 
59 62
         $baseDirectory = $directory;
60
-        while (!\is_dir($baseDirectory = \dirname($baseDirectory))) {
63
+        while (!\is_dir($baseDirectory = \dirname($baseDirectory)))
64
+        {
61 65
             $directoryChain[] = \basename($baseDirectory);
62 66
         }
63 67
 
64
-        foreach (\array_reverse($directoryChain) as $dir) {
65
-            if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) {
68
+        foreach (\array_reverse($directoryChain) as $dir)
69
+        {
70
+            if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir)))
71
+            {
66 72
                 return false;
67 73
             }
68 74
 
@@ -74,7 +80,8 @@  discard block
 block discarded – undo
74 80
 
75 81
     public function read(string $filename): string
76 82
     {
77
-        if (!$this->exists($filename)) {
83
+        if (!$this->exists($filename))
84
+        {
78 85
             throw new FileNotFoundException($filename);
79 86
         }
80 87
 
@@ -96,12 +103,15 @@  discard block
 block discarded – undo
96 103
     ): bool {
97 104
         $mode ??= self::DEFAULT_FILE_MODE;
98 105
 
99
-        try {
100
-            if ($ensureDirectory) {
106
+        try
107
+        {
108
+            if ($ensureDirectory)
109
+            {
101 110
                 $this->ensureDirectory(\dirname($filename), $mode);
102 111
             }
103 112
 
104
-            if ($this->exists($filename)) {
113
+            if ($this->exists($filename))
114
+            {
105 115
                 //Forcing mode for existed file
106 116
                 $this->setPermissions($filename, $mode);
107 117
             }
@@ -112,11 +122,14 @@  discard block
 block discarded – undo
112 122
                 $append ? FILE_APPEND | LOCK_EX : LOCK_EX,
113 123
             );
114 124
 
115
-            if ($result !== false) {
125
+            if ($result !== false)
126
+            {
116 127
                 //Forcing mode after file creation
117 128
                 $this->setPermissions($filename, $mode);
118 129
             }
119
-        } catch (\Exception $e) {
130
+        }
131
+        catch (\Exception $e)
132
+        {
120 133
             throw new WriteErrorException($e->getMessage(), (int) $e->getCode(), $e);
121 134
         }
122 135
 
@@ -134,7 +147,8 @@  discard block
 block discarded – undo
134 147
 
135 148
     public function delete(string $filename): bool
136 149
     {
137
-        if ($this->exists($filename)) {
150
+        if ($this->exists($filename))
151
+        {
138 152
             $result = \unlink($filename);
139 153
 
140 154
             //Wiping out changes in local file cache
@@ -153,7 +167,8 @@  discard block
 block discarded – undo
153 167
      */
154 168
     public function deleteDirectory(string $directory, bool $contentOnly = false): bool
155 169
     {
156
-        if (!$this->isDirectory($directory)) {
170
+        if (!$this->isDirectory($directory))
171
+        {
157 172
             throw new FilesException(\sprintf('Undefined or invalid directory %s', $directory));
158 173
         }
159 174
 
@@ -162,15 +177,20 @@  discard block
 block discarded – undo
162 177
             \RecursiveIteratorIterator::CHILD_FIRST,
163 178
         );
164 179
 
165
-        foreach ($files as $file) {
166
-            if ($file->isDir()) {
180
+        foreach ($files as $file)
181
+        {
182
+            if ($file->isDir())
183
+            {
167 184
                 \rmdir($file->getRealPath());
168
-            } else {
185
+            }
186
+            else
187
+            {
169 188
                 $this->delete($file->getRealPath());
170 189
             }
171 190
         }
172 191
 
173
-        if (!$contentOnly) {
192
+        if (!$contentOnly)
193
+        {
174 194
             return \rmdir($directory);
175 195
         }
176 196
 
@@ -179,7 +199,8 @@  discard block
 block discarded – undo
179 199
 
180 200
     public function move(string $filename, string $destination): bool
181 201
     {
182
-        if (!$this->exists($filename)) {
202
+        if (!$this->exists($filename))
203
+        {
183 204
             throw new FileNotFoundException($filename);
184 205
         }
185 206
 
@@ -188,7 +209,8 @@  discard block
 block discarded – undo
188 209
 
189 210
     public function copy(string $filename, string $destination): bool
190 211
     {
191
-        if (!$this->exists($filename)) {
212
+        if (!$this->exists($filename))
213
+        {
192 214
             throw new FileNotFoundException($filename);
193 215
         }
194 216
 
@@ -197,7 +219,8 @@  discard block
 block discarded – undo
197 219
 
198 220
     public function touch(string $filename, ?int $mode = null): bool
199 221
     {
200
-        if (!\touch($filename)) {
222
+        if (!\touch($filename))
223
+        {
201 224
             return false;
202 225
         }
203 226
 
@@ -223,7 +246,8 @@  discard block
 block discarded – undo
223 246
 
224 247
     public function md5(string $filename): string
225 248
     {
226
-        if (!$this->exists($filename)) {
249
+        if (!$this->exists($filename))
250
+        {
227 251
             throw new FileNotFoundException($filename);
228 252
         }
229 253
 
@@ -237,7 +261,8 @@  discard block
 block discarded – undo
237 261
 
238 262
     public function time(string $filename): int
239 263
     {
240
-        if (!$this->exists($filename)) {
264
+        if (!$this->exists($filename))
265
+        {
241 266
             throw new FileNotFoundException($filename);
242 267
         }
243 268
 
@@ -268,7 +293,8 @@  discard block
 block discarded – undo
268 293
 
269 294
     public function setPermissions(string $filename, int $mode): bool
270 295
     {
271
-        if (\is_dir($filename)) {
296
+        if (\is_dir($filename))
297
+        {
272 298
             //Directories must always be executable (i.e. 664 for dir => 775)
273 299
             $mode |= 0111;
274 300
         }
@@ -279,8 +305,10 @@  discard block
 block discarded – undo
279 305
     public function getFiles(string $location, ?string $pattern = null): array
280 306
     {
281 307
         $result = [];
282
-        foreach ($this->filesIterator($location, $pattern) as $filename) {
283
-            if ($this->isDirectory($filename->getPathname())) {
308
+        foreach ($this->filesIterator($location, $pattern) as $filename)
309
+        {
310
+            if ($this->isDirectory($filename->getPathname()))
311
+            {
284 312
                 $result = \array_merge($result, $this->getFiles(((string) $filename) . DIRECTORY_SEPARATOR));
285 313
 
286 314
                 continue;
@@ -294,14 +322,16 @@  discard block
 block discarded – undo
294 322
 
295 323
     public function tempFilename(string $extension = '', ?string $location = null): string
296 324
     {
297
-        if (empty($location)) {
325
+        if (empty($location))
326
+        {
298 327
             $location = \sys_get_temp_dir();
299 328
         }
300 329
 
301 330
         $filename = \tempnam($location, 'spiral');
302 331
         $filename === false and throw new FilesException('Unable to create temporary file.');
303 332
 
304
-        if (!empty($extension)) {
333
+        if (!empty($extension))
334
+        {
305 335
             $old = $filename;
306 336
             $filename = \sprintf('%s.%s', $filename, $extension);
307 337
             \rename($old, $filename);
@@ -314,7 +344,8 @@  discard block
 block discarded – undo
314 344
     public function normalizePath(string $path, bool $asDirectory = false): string
315 345
     {
316 346
         $isUnc = \str_starts_with($path, '\\\\') || \str_starts_with($path, '//');
317
-        if ($isUnc) {
347
+        if ($isUnc)
348
+        {
318 349
             $leadingSlashes = \substr($path, 0, 2);
319 350
             $path = \substr($path, 2);
320 351
         }
@@ -337,15 +368,20 @@  discard block
 block discarded – undo
337 368
         $path = \explode('/', $path);
338 369
         $relative = $path;
339 370
 
340
-        foreach ($from as $depth => $dir) {
371
+        foreach ($from as $depth => $dir)
372
+        {
341 373
             //Find first non-matching dir
342
-            if ($dir === $path[$depth]) {
374
+            if ($dir === $path[$depth])
375
+            {
343 376
                 //Ignore this directory
344 377
                 \array_shift($relative);
345
-            } else {
378
+            }
379
+            else
380
+            {
346 381
                 //Get number of remaining dirs to $from
347 382
                 $remaining = \count($from) - $depth;
348
-                if ($remaining > 1) {
383
+                if ($remaining > 1)
384
+                {
349 385
                     //Add traversals up to first matching directory
350 386
                     $padLength = (\count($relative) + $remaining - 1) * -1;
351 387
                     $relative = \array_pad($relative, $padLength, '..');
@@ -363,7 +399,8 @@  discard block
 block discarded – undo
363 399
      */
364 400
     public function __destruct()
365 401
     {
366
-        foreach ($this->destructFiles as $filename) {
402
+        foreach ($this->destructFiles as $filename)
403
+        {
367 404
             $this->delete($filename);
368 405
         }
369 406
     }
Please login to merge, or discard this patch.
src/Core/src/Exception/ScopeException.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,4 +12,4 @@
 block discarded – undo
12 12
  *
13 13
  * Sugar conditions are avoidable.
14 14
  */
15
-class ScopeException extends LogicException implements NotFoundExceptionInterface {}
15
+class ScopeException extends LogicException implements NotFoundExceptionInterface{}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,4 +12,6 @@
 block discarded – undo
12 12
  *
13 13
  * Sugar conditions are avoidable.
14 14
  */
15
-class ScopeException extends LogicException implements NotFoundExceptionInterface {}
15
+class ScopeException extends LogicException implements NotFoundExceptionInterface
16
+{
17
+}
Please login to merge, or discard this patch.
src/Core/src/Internal/Actor.php 2 patches
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public function resolveType(
89 89
         string $alias,
90
-        ?Binding &$binding = null,
90
+        ?Binding & $binding = null,
91 91
         ?object &$singleton = null,
92 92
         ?object &$injector = null,
93 93
         ?self &$actor = null,
@@ -96,20 +96,20 @@  discard block
 block discarded – undo
96 96
         // Aliases to prevent circular dependencies
97 97
         $as = [];
98 98
         $actor = $this;
99
-        do {
99
+        do{
100 100
             $bindings = &$actor->state->bindings;
101 101
             $singletons = &$actor->state->singletons;
102 102
             $injectors = &$actor->state->injectors;
103 103
             $binding = $bindings[$alias] ?? null;
104
-            if (\array_key_exists($alias, $singletons)) {
104
+            if (\array_key_exists($alias, $singletons)){
105 105
                 $singleton = $singletons[$alias];
106 106
                 $injector = $injectors[$alias] ?? null;
107 107
                 return \is_object($singleton::class) ? $singleton::class : null;
108 108
             }
109 109
 
110
-            if ($binding !== null) {
111
-                if ($followAlias && $binding::class === Alias::class) {
112
-                    if ($binding->alias === $alias) {
110
+            if ($binding !== null){
111
+                if ($followAlias && $binding::class === Alias::class){
112
+                    if ($binding->alias === $alias){
113 113
                         break;
114 114
                     }
115 115
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
                 return $binding->getReturnClass();
125 125
             }
126 126
 
127
-            if (\array_key_exists($alias, $injectors)) {
127
+            if (\array_key_exists($alias, $injectors)){
128 128
                 $injector = $injectors[$alias];
129 129
                 $binding = $bindings[$alias] ?? null;
130 130
                 return $alias;
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
 
133 133
             // Go to parent scope
134 134
             $parent = $actor->scope->getParentActor();
135
-            if ($parent === null) {
135
+            if ($parent === null){
136 136
                 break;
137 137
             }
138 138
 
139 139
             $actor = $parent;
140
-        } while (true);
140
+        }while (true);
141 141
 
142 142
         return \class_exists($alias) ? $alias : null;
143 143
     }
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
     public function resolveBinding(
146 146
         object $binding,
147 147
         string $alias,
148
-        \Stringable|string|null $context,
148
+        \Stringable | string | null $context,
149 149
         array $arguments,
150 150
         Tracer $tracer,
151 151
     ): mixed {
@@ -202,18 +202,18 @@  discard block
 block discarded – undo
202 202
     private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments, Tracer $tracer)
203 203
     {
204 204
         $context = $ctx->context;
205
-        try {
205
+        try{
206 206
             $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class);
207
-        } catch (\ReflectionException $e) {
207
+        }catch (\ReflectionException $e){
208 208
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
209 209
         }
210 210
 
211 211
         $injector = $binding->injector;
212 212
 
213
-        try {
213
+        try{
214 214
             $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector);
215 215
 
216
-            if (!$injectorInstance instanceof InjectorInterface) {
216
+            if (!$injectorInstance instanceof InjectorInterface){
217 217
                 throw new InjectionException(
218 218
                     \sprintf(
219 219
                         "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
             static $cache = [];
228 228
             $extended = $cache[$injectorInstance::class] ??= (
229 229
             static fn(\ReflectionType $type): bool =>
230
-                $type::class === \ReflectionUnionType::class || (string) $type === 'mixed'
230
+                $type::class === \ReflectionUnionType::class || (string)$type === 'mixed'
231 231
             )(
232 232
                 ($refMethod = new \ReflectionMethod($injectorInstance, 'createInjection'))
233 233
                     ->getParameters()[1]->getType()
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
             $instance = $injectorInstance->createInjection($reflection, match (true) {
238 238
                 $asIs => $context,
239 239
                 $context instanceof \ReflectionParameter => $context->getName(),
240
-                default => (string) $context,
240
+                default => (string)$context,
241 241
             });
242 242
 
243
-            if (!$reflection->isInstance($instance)) {
243
+            if (!$reflection->isInstance($instance)){
244 244
                 throw new InjectionException(
245 245
                     \sprintf(
246 246
                         "Invalid injection response for '%s'.",
@@ -250,12 +250,12 @@  discard block
 block discarded – undo
250 250
             }
251 251
 
252 252
             return $instance;
253
-        } catch (TracedContainerException $e) {
253
+        }catch (TracedContainerException $e){
254 254
             throw isset($injectorInstance) ? $e : $e::extendTracedException(\sprintf(
255 255
                 'Can\'t resolve `%s`.',
256 256
                 $tracer->getRootAlias(),
257 257
             ), $tracer->getTraces(), $e);
258
-        } finally {
258
+        }finally{
259 259
             $this->state->bindings[$ctx->class] ??= $binding;
260 260
         }
261 261
     }
@@ -263,22 +263,22 @@  discard block
 block discarded – undo
263 263
     private function resolveAlias(
264 264
         Config\Alias $binding,
265 265
         string $alias,
266
-        \Stringable|string|null $context,
266
+        \Stringable | string | null $context,
267 267
         array $arguments,
268 268
         Tracer $tracer,
269 269
     ): mixed {
270
-        if ($binding->alias === $alias) {
270
+        if ($binding->alias === $alias){
271 271
             $instance = $this->autowire(
272 272
                 new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton && $arguments === []),
273 273
                 $arguments,
274 274
                 $this,
275 275
                 $tracer,
276 276
             );
277
-        } else {
278
-            try {
277
+        }else{
278
+            try{
279 279
                 //Binding is pointing to something else
280 280
                 $instance = $this->factory->make($binding->alias, $arguments, $context);
281
-            } catch (TracedContainerException $e) {
281
+            }catch (TracedContainerException $e){
282 282
                 throw $e::extendTracedException(
283 283
                     $alias === $tracer->getRootAlias()
284 284
                         ? "Can't resolve `{$alias}`."
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
         return $instance;
296 296
     }
297 297
 
298
-    private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable|string|null $context): mixed
298
+    private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable | string | null $context): mixed
299 299
     {
300
-        if ($context instanceof RetryContext) {
300
+        if ($context instanceof RetryContext){
301 301
             return $binding->fallbackFactory === null
302 302
                 ? throw new RecursiveProxyException(
303 303
                     $alias,
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 
309 309
         $result = Proxy::create(new \ReflectionClass($binding->getReturnClass()), $context, new Attribute\Proxy());
310 310
 
311
-        if ($binding->singleton) {
311
+        if ($binding->singleton){
312 312
             $this->state->singletons[$alias] = $result;
313 313
         }
314 314
 
@@ -318,11 +318,11 @@  discard block
 block discarded – undo
318 318
     private function resolveShared(
319 319
         Config\Shared $binding,
320 320
         string $alias,
321
-        \Stringable|string|null $context,
321
+        \Stringable | string | null $context,
322 322
         array $arguments,
323 323
         Tracer $tracer,
324 324
     ): object {
325
-        if ($arguments !== []) {
325
+        if ($arguments !== []){
326 326
             // Avoid singleton cache
327 327
             return $this->createInstance(
328 328
                 new Ctx(alias: $alias, class: $binding->value::class, context: $context, singleton: false),
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
             );
333 333
         }
334 334
 
335
-        if ($binding->singleton) {
335
+        if ($binding->singleton){
336 336
             $this->state->singletons[$alias] = $binding->value;
337 337
         }
338 338
 
@@ -342,16 +342,16 @@  discard block
 block discarded – undo
342 342
     private function resolveAutowire(
343 343
         Config\Autowire $binding,
344 344
         string $alias,
345
-        \Stringable|string|null $context,
345
+        \Stringable | string | null $context,
346 346
         array $arguments,
347 347
         Tracer $tracer,
348 348
     ): mixed {
349 349
         $target = $binding->autowire->alias;
350 350
         $ctx = new Ctx(alias: $alias, class: $target, context: $context, singleton: $binding->singleton && $arguments === [] ?: null);
351 351
 
352
-        if ($alias === $target) {
352
+        if ($alias === $target){
353 353
             $instance = $this->autowire($ctx, \array_merge($binding->autowire->parameters, $arguments), $this, $tracer);
354
-        } else {
354
+        }else{
355 355
             $instance = $binding->autowire->resolve($this->factory, $arguments);
356 356
             $this->validateConstraint($instance, $ctx);
357 357
         }
@@ -360,32 +360,32 @@  discard block
 block discarded – undo
360 360
     }
361 361
 
362 362
     private function resolveFactory(
363
-        Config\Factory|Config\DeferredFactory $binding,
363
+        Config\Factory | Config\DeferredFactory $binding,
364 364
         string $alias,
365
-        \Stringable|string|null $context,
365
+        \Stringable | string | null $context,
366 366
         array $arguments,
367 367
         Tracer $tracer,
368 368
     ): mixed {
369 369
         $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton && $arguments === [] ?: null);
370
-        try {
370
+        try{
371 371
             $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0
372 372
                 ? ($binding->factory)()
373 373
                 : $this->invoker->invoke($binding->factory, $arguments);
374
-        } catch (NotCallableException $e) {
374
+        }catch (NotCallableException $e){
375 375
             throw TracedContainerException::createWithTrace(
376 376
                 \sprintf('Invalid callable binding for `%s`.', $ctx->alias),
377 377
                 $tracer->getTraces(),
378 378
                 $e,
379 379
             );
380
-        } catch (TracedContainerException $e) {
380
+        }catch (TracedContainerException $e){
381 381
             throw $e::extendTracedException(
382 382
                 \sprintf("Can't resolve `%s`: factory invocation failed.", $tracer->getRootAlias()),
383 383
                 $tracer->getTraces(),
384 384
                 $e,
385 385
             );
386
-        } catch (ContainerExceptionInterface $e) {
386
+        }catch (ContainerExceptionInterface $e){
387 387
             throw $e;
388
-        } catch (\Throwable $e) {
388
+        }catch (\Throwable $e){
389 389
             throw NotFoundException::createWithTrace(
390 390
                 \sprintf("Can't resolve `%s` due to factory invocation error: %s", $tracer->getRootAlias(), $e->getMessage()),
391 391
                 $tracer->getTraces(),
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
             );
394 394
         }
395 395
 
396
-        if (\is_object($instance)) {
396
+        if (\is_object($instance)){
397 397
             $this->validateConstraint($instance, $ctx);
398 398
             return $this->registerInstance($ctx, $instance);
399 399
         }
@@ -404,14 +404,14 @@  discard block
 block discarded – undo
404 404
     private function resolveWeakReference(
405 405
         Config\WeakReference $binding,
406 406
         string $alias,
407
-        \Stringable|string|null $context,
407
+        \Stringable | string | null $context,
408 408
         array $arguments,
409 409
         Tracer $tracer,
410 410
     ): ?object {
411 411
         $avoidCache = $arguments !== [];
412 412
 
413
-        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) {
414
-            try {
413
+        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){
414
+            try{
415 415
                 $tracer->push(false, alias: $alias, source: \WeakReference::class, context: $context);
416 416
 
417 417
                 $object = $this->createInstance(
@@ -420,17 +420,17 @@  discard block
 block discarded – undo
420 420
                     $this,
421 421
                     $tracer,
422 422
                 );
423
-                if ($avoidCache) {
423
+                if ($avoidCache){
424 424
                     return $object;
425 425
                 }
426 426
                 $binding->reference = \WeakReference::create($object);
427
-            } catch (\Throwable) {
427
+            }catch (\Throwable){
428 428
                 throw TracedContainerException::createWithTrace(\sprintf(
429 429
                     'Can\'t resolve `%s`: can\'t instantiate `%s` from WeakReference binding.',
430 430
                     $tracer->getRootAlias(),
431 431
                     $alias,
432 432
                 ), $tracer->getTraces());
433
-            } finally {
433
+            }finally{
434 434
                 $tracer->pop();
435 435
             }
436 436
         }
@@ -446,13 +446,13 @@  discard block
 block discarded – undo
446 446
         object $instance,
447 447
         Ctx $ctx,
448 448
     ): void {
449
-        if ($this->options->checkScope) {
449
+        if ($this->options->checkScope){
450 450
             // Check scope name
451 451
             $ctx->reflection ??= new \ReflectionClass($instance);
452 452
             $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
453
-            if ($scopeName !== null) {
453
+            if ($scopeName !== null){
454 454
                 $scope = $this->scope;
455
-                while ($scope->getScopeName() !== $scopeName) {
455
+                while ($scope->getScopeName() !== $scopeName){
456 456
                     $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class);
457 457
                 }
458 458
             }
@@ -479,26 +479,26 @@  discard block
 block discarded – undo
479 479
         Tracer $tracer,
480 480
     ): object {
481 481
         $class = $ctx->class;
482
-        try {
482
+        try{
483 483
             $ctx->reflection = $reflection = new \ReflectionClass($class);
484
-        } catch (\ReflectionException $e) {
484
+        }catch (\ReflectionException $e){
485 485
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
486 486
         }
487 487
 
488 488
         // Check Scope attribute
489 489
         $actor = $fallbackActor ?? $this;
490
-        if ($this->options->checkScope) { # todo
490
+        if ($this->options->checkScope){ # todo
491 491
             $ar = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null);
492
-            if ($ar !== null) {
492
+            if ($ar !== null){
493 493
                 /** @var Attribute\Scope $attr */
494 494
                 $attr = $ar->newInstance();
495 495
                 $scope = $this->scope;
496 496
                 $actor = $this;
497 497
                 // Go through all parent scopes
498 498
                 $needed = $actor;
499
-                while ($attr->name !== $scope->getScopeName()) {
499
+                while ($attr->name !== $scope->getScopeName()){
500 500
                     $needed = $scope->getParentActor();
501
-                    if ($needed === null) {
501
+                    if ($needed === null){
502 502
                         throw new BadScopeException($attr->name, $class);
503 503
                     }
504 504
 
@@ -511,11 +511,11 @@  discard block
 block discarded – undo
511 511
         } # todo
512 512
 
513 513
         // We have to construct class using external injector when we know the exact context
514
-        if ($arguments === [] && $actor->binder->hasInjector($class)) {
514
+        if ($arguments === [] && $actor->binder->hasInjector($class)){
515 515
             return $actor->resolveInjector($actor->state->bindings[$ctx->class], $ctx, $arguments, $tracer);
516 516
         }
517 517
 
518
-        if (!$reflection->isInstantiable()) {
518
+        if (!$reflection->isInstantiable()){
519 519
             $itIs = match (true) {
520 520
                 $reflection->isEnum() => 'Enum',
521 521
                 $reflection->isAbstract() => 'Abstract class',
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 
530 530
         $constructor = $reflection->getConstructor();
531 531
 
532
-        if ($constructor !== null) {
533
-            try {
532
+        if ($constructor !== null){
533
+            try{
534 534
                 $newScope = $this !== $actor;
535 535
                 $debug = [
536 536
                     'action' => 'resolve arguments',
@@ -544,39 +544,39 @@  discard block
 block discarded – undo
544 544
                 $tracer->push($newScope, ...$debug);
545 545
                 $tracer->push(true);
546 546
                 $args = $actor->resolver->resolveArguments($constructor, $arguments, $actor->options->validateArguments);
547
-            } catch (ValidationException $e) {
547
+            }catch (ValidationException $e){
548 548
                 throw TracedContainerException::createWithTrace(\sprintf(
549 549
                     'Can\'t resolve `%s`. %s',
550 550
                     $tracer->getRootAlias(),
551 551
                     $e->getMessage(),
552 552
                 ), $tracer->getTraces());
553
-            } catch (TracedContainerException $e) {
553
+            }catch (TracedContainerException $e){
554 554
                 throw $e::extendTracedException(\sprintf(
555 555
                     'Can\'t resolve `%s`.',
556 556
                     $tracer->getRootAlias(),
557 557
                 ), $tracer->getTraces(), $e);
558
-            } finally {
558
+            }finally{
559 559
                 $tracer->pop($newScope);
560 560
                 $tracer->pop(false);
561 561
             }
562
-            try {
562
+            try{
563 563
                 // Using constructor with resolved arguments
564 564
                 $tracer->push(false, call: "$class::__construct", arguments: $args);
565 565
                 $tracer->push(true);
566 566
                 $instance = new $class(...$args);
567
-            } catch (\TypeError $e) {
567
+            }catch (\TypeError $e){
568 568
                 throw new WrongTypeException($constructor, $e);
569
-            } catch (TracedContainerException $e) {
569
+            }catch (TracedContainerException $e){
570 570
                 throw $e::extendTracedException(\sprintf(
571 571
                     'Can\'t resolve `%s`: failed constructing `%s`.',
572 572
                     $tracer->getRootAlias(),
573 573
                     $class,
574 574
                 ), $tracer->getTraces(), $e);
575
-            } finally {
575
+            }finally{
576 576
                 $tracer->pop(true);
577 577
                 $tracer->pop(false);
578 578
             }
579
-        } else {
579
+        }else{
580 580
             // No constructor specified
581 581
             $instance = $reflection->newInstance();
582 582
         }
@@ -608,12 +608,12 @@  discard block
 block discarded – undo
608 608
      */
609 609
     private function isSingleton(Ctx $ctx): bool
610 610
     {
611
-        if (is_bool($ctx->singleton)) {
611
+        if (is_bool($ctx->singleton)){
612 612
             return $ctx->singleton;
613 613
         }
614 614
 
615 615
         /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */
616
-        if ($ctx->reflection->implementsInterface(SingletonInterface::class)) {
616
+        if ($ctx->reflection->implementsInterface(SingletonInterface::class)){
617 617
             return true;
618 618
         }
619 619
 
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
          * @var Attribute\Finalize|null $attribute
628 628
          */
629 629
         $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance();
630
-        if ($attribute === null) {
630
+        if ($attribute === null){
631 631
             return null;
632 632
         }
633 633
 
@@ -641,10 +641,10 @@  discard block
 block discarded – undo
641 641
     {
642 642
         $scope = $this->scope;
643 643
 
644
-        while ($scope !== null) {
645
-            foreach ($this->state->inflectors as $class => $inflectors) {
646
-                if ($instance instanceof $class) {
647
-                    foreach ($inflectors as $inflector) {
644
+        while ($scope !== null){
645
+            foreach ($this->state->inflectors as $class => $inflectors){
646
+                if ($instance instanceof $class){
647
+                    foreach ($inflectors as $inflector){
648 648
                         $instance = $inflector->getParametersCount() > 1
649 649
                             ? $this->invoker->invoke($inflector->inflector, [$instance])
650 650
                             : ($inflector->inflector)($instance);
@@ -660,9 +660,9 @@  discard block
 block discarded – undo
660 660
 
661 661
     private function validateArguments(ContextFunction $reflection, array $arguments = []): bool
662 662
     {
663
-        try {
663
+        try{
664 664
             $this->resolver->validateArguments($reflection, $arguments);
665
-        } catch (\Throwable) {
665
+        }catch (\Throwable){
666 666
             return false;
667 667
         }
668 668
 
Please login to merge, or discard this patch.
Braces   +152 added lines, -65 removed lines patch added patch discarded remove patch
@@ -96,20 +96,25 @@  discard block
 block discarded – undo
96 96
         // Aliases to prevent circular dependencies
97 97
         $as = [];
98 98
         $actor = $this;
99
-        do {
99
+        do
100
+        {
100 101
             $bindings = &$actor->state->bindings;
101 102
             $singletons = &$actor->state->singletons;
102 103
             $injectors = &$actor->state->injectors;
103 104
             $binding = $bindings[$alias] ?? null;
104
-            if (\array_key_exists($alias, $singletons)) {
105
+            if (\array_key_exists($alias, $singletons))
106
+            {
105 107
                 $singleton = $singletons[$alias];
106 108
                 $injector = $injectors[$alias] ?? null;
107 109
                 return \is_object($singleton::class) ? $singleton::class : null;
108 110
             }
109 111
 
110
-            if ($binding !== null) {
111
-                if ($followAlias && $binding::class === Alias::class) {
112
-                    if ($binding->alias === $alias) {
112
+            if ($binding !== null)
113
+            {
114
+                if ($followAlias && $binding::class === Alias::class)
115
+                {
116
+                    if ($binding->alias === $alias)
117
+                    {
113 118
                         break;
114 119
                     }
115 120
 
@@ -124,7 +129,8 @@  discard block
 block discarded – undo
124 129
                 return $binding->getReturnClass();
125 130
             }
126 131
 
127
-            if (\array_key_exists($alias, $injectors)) {
132
+            if (\array_key_exists($alias, $injectors))
133
+            {
128 134
                 $injector = $injectors[$alias];
129 135
                 $binding = $bindings[$alias] ?? null;
130 136
                 return $alias;
@@ -132,7 +138,8 @@  discard block
 block discarded – undo
132 138
 
133 139
             // Go to parent scope
134 140
             $parent = $actor->scope->getParentActor();
135
-            if ($parent === null) {
141
+            if ($parent === null)
142
+            {
136 143
                 break;
137 144
             }
138 145
 
@@ -202,18 +209,23 @@  discard block
 block discarded – undo
202 209
     private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments, Tracer $tracer)
203 210
     {
204 211
         $context = $ctx->context;
205
-        try {
212
+        try
213
+        {
206 214
             $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class);
207
-        } catch (\ReflectionException $e) {
215
+        }
216
+        catch (\ReflectionException $e)
217
+        {
208 218
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
209 219
         }
210 220
 
211 221
         $injector = $binding->injector;
212 222
 
213
-        try {
223
+        try
224
+        {
214 225
             $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector);
215 226
 
216
-            if (!$injectorInstance instanceof InjectorInterface) {
227
+            if (!$injectorInstance instanceof InjectorInterface)
228
+            {
217 229
                 throw new InjectionException(
218 230
                     \sprintf(
219 231
                         "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -240,7 +252,8 @@  discard block
 block discarded – undo
240 252
                 default => (string) $context,
241 253
             });
242 254
 
243
-            if (!$reflection->isInstance($instance)) {
255
+            if (!$reflection->isInstance($instance))
256
+            {
244 257
                 throw new InjectionException(
245 258
                     \sprintf(
246 259
                         "Invalid injection response for '%s'.",
@@ -250,12 +263,16 @@  discard block
 block discarded – undo
250 263
             }
251 264
 
252 265
             return $instance;
253
-        } catch (TracedContainerException $e) {
266
+        }
267
+        catch (TracedContainerException $e)
268
+        {
254 269
             throw isset($injectorInstance) ? $e : $e::extendTracedException(\sprintf(
255 270
                 'Can\'t resolve `%s`.',
256 271
                 $tracer->getRootAlias(),
257 272
             ), $tracer->getTraces(), $e);
258
-        } finally {
273
+        }
274
+        finally
275
+        {
259 276
             $this->state->bindings[$ctx->class] ??= $binding;
260 277
         }
261 278
     }
@@ -267,18 +284,24 @@  discard block
 block discarded – undo
267 284
         array $arguments,
268 285
         Tracer $tracer,
269 286
     ): mixed {
270
-        if ($binding->alias === $alias) {
287
+        if ($binding->alias === $alias)
288
+        {
271 289
             $instance = $this->autowire(
272 290
                 new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton && $arguments === []),
273 291
                 $arguments,
274 292
                 $this,
275 293
                 $tracer,
276 294
             );
277
-        } else {
278
-            try {
295
+        }
296
+        else
297
+        {
298
+            try
299
+            {
279 300
                 //Binding is pointing to something else
280 301
                 $instance = $this->factory->make($binding->alias, $arguments, $context);
281
-            } catch (TracedContainerException $e) {
302
+            }
303
+            catch (TracedContainerException $e)
304
+            {
282 305
                 throw $e::extendTracedException(
283 306
                     $alias === $tracer->getRootAlias()
284 307
                         ? "Can't resolve `{$alias}`."
@@ -297,7 +320,8 @@  discard block
 block discarded – undo
297 320
 
298 321
     private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable|string|null $context): mixed
299 322
     {
300
-        if ($context instanceof RetryContext) {
323
+        if ($context instanceof RetryContext)
324
+        {
301 325
             return $binding->fallbackFactory === null
302 326
                 ? throw new RecursiveProxyException(
303 327
                     $alias,
@@ -308,7 +332,8 @@  discard block
 block discarded – undo
308 332
 
309 333
         $result = Proxy::create(new \ReflectionClass($binding->getReturnClass()), $context, new Attribute\Proxy());
310 334
 
311
-        if ($binding->singleton) {
335
+        if ($binding->singleton)
336
+        {
312 337
             $this->state->singletons[$alias] = $result;
313 338
         }
314 339
 
@@ -322,7 +347,8 @@  discard block
 block discarded – undo
322 347
         array $arguments,
323 348
         Tracer $tracer,
324 349
     ): object {
325
-        if ($arguments !== []) {
350
+        if ($arguments !== [])
351
+        {
326 352
             // Avoid singleton cache
327 353
             return $this->createInstance(
328 354
                 new Ctx(alias: $alias, class: $binding->value::class, context: $context, singleton: false),
@@ -332,7 +358,8 @@  discard block
 block discarded – undo
332 358
             );
333 359
         }
334 360
 
335
-        if ($binding->singleton) {
361
+        if ($binding->singleton)
362
+        {
336 363
             $this->state->singletons[$alias] = $binding->value;
337 364
         }
338 365
 
@@ -349,9 +376,12 @@  discard block
 block discarded – undo
349 376
         $target = $binding->autowire->alias;
350 377
         $ctx = new Ctx(alias: $alias, class: $target, context: $context, singleton: $binding->singleton && $arguments === [] ?: null);
351 378
 
352
-        if ($alias === $target) {
379
+        if ($alias === $target)
380
+        {
353 381
             $instance = $this->autowire($ctx, \array_merge($binding->autowire->parameters, $arguments), $this, $tracer);
354
-        } else {
382
+        }
383
+        else
384
+        {
355 385
             $instance = $binding->autowire->resolve($this->factory, $arguments);
356 386
             $this->validateConstraint($instance, $ctx);
357 387
         }
@@ -367,25 +397,34 @@  discard block
 block discarded – undo
367 397
         Tracer $tracer,
368 398
     ): mixed {
369 399
         $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton && $arguments === [] ?: null);
370
-        try {
400
+        try
401
+        {
371 402
             $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0
372 403
                 ? ($binding->factory)()
373 404
                 : $this->invoker->invoke($binding->factory, $arguments);
374
-        } catch (NotCallableException $e) {
405
+        }
406
+        catch (NotCallableException $e)
407
+        {
375 408
             throw TracedContainerException::createWithTrace(
376 409
                 \sprintf('Invalid callable binding for `%s`.', $ctx->alias),
377 410
                 $tracer->getTraces(),
378 411
                 $e,
379 412
             );
380
-        } catch (TracedContainerException $e) {
413
+        }
414
+        catch (TracedContainerException $e)
415
+        {
381 416
             throw $e::extendTracedException(
382 417
                 \sprintf("Can't resolve `%s`: factory invocation failed.", $tracer->getRootAlias()),
383 418
                 $tracer->getTraces(),
384 419
                 $e,
385 420
             );
386
-        } catch (ContainerExceptionInterface $e) {
421
+        }
422
+        catch (ContainerExceptionInterface $e)
423
+        {
387 424
             throw $e;
388
-        } catch (\Throwable $e) {
425
+        }
426
+        catch (\Throwable $e)
427
+        {
389 428
             throw NotFoundException::createWithTrace(
390 429
                 \sprintf("Can't resolve `%s` due to factory invocation error: %s", $tracer->getRootAlias(), $e->getMessage()),
391 430
                 $tracer->getTraces(),
@@ -393,7 +432,8 @@  discard block
 block discarded – undo
393 432
             );
394 433
         }
395 434
 
396
-        if (\is_object($instance)) {
435
+        if (\is_object($instance))
436
+        {
397 437
             $this->validateConstraint($instance, $ctx);
398 438
             return $this->registerInstance($ctx, $instance);
399 439
         }
@@ -410,8 +450,10 @@  discard block
 block discarded – undo
410 450
     ): ?object {
411 451
         $avoidCache = $arguments !== [];
412 452
 
413
-        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) {
414
-            try {
453
+        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias))
454
+        {
455
+            try
456
+            {
415 457
                 $tracer->push(false, alias: $alias, source: \WeakReference::class, context: $context);
416 458
 
417 459
                 $object = $this->createInstance(
@@ -420,17 +462,22 @@  discard block
 block discarded – undo
420 462
                     $this,
421 463
                     $tracer,
422 464
                 );
423
-                if ($avoidCache) {
465
+                if ($avoidCache)
466
+                {
424 467
                     return $object;
425 468
                 }
426 469
                 $binding->reference = \WeakReference::create($object);
427
-            } catch (\Throwable) {
470
+            }
471
+            catch (\Throwable)
472
+            {
428 473
                 throw TracedContainerException::createWithTrace(\sprintf(
429 474
                     'Can\'t resolve `%s`: can\'t instantiate `%s` from WeakReference binding.',
430 475
                     $tracer->getRootAlias(),
431 476
                     $alias,
432 477
                 ), $tracer->getTraces());
433
-            } finally {
478
+            }
479
+            finally
480
+            {
434 481
                 $tracer->pop();
435 482
             }
436 483
         }
@@ -446,13 +493,16 @@  discard block
 block discarded – undo
446 493
         object $instance,
447 494
         Ctx $ctx,
448 495
     ): void {
449
-        if ($this->options->checkScope) {
496
+        if ($this->options->checkScope)
497
+        {
450 498
             // Check scope name
451 499
             $ctx->reflection ??= new \ReflectionClass($instance);
452 500
             $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
453
-            if ($scopeName !== null) {
501
+            if ($scopeName !== null)
502
+            {
454 503
                 $scope = $this->scope;
455
-                while ($scope->getScopeName() !== $scopeName) {
504
+                while ($scope->getScopeName() !== $scopeName)
505
+                {
456 506
                     $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class);
457 507
                 }
458 508
             }
@@ -479,26 +529,34 @@  discard block
 block discarded – undo
479 529
         Tracer $tracer,
480 530
     ): object {
481 531
         $class = $ctx->class;
482
-        try {
532
+        try
533
+        {
483 534
             $ctx->reflection = $reflection = new \ReflectionClass($class);
484
-        } catch (\ReflectionException $e) {
535
+        }
536
+        catch (\ReflectionException $e)
537
+        {
485 538
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
486 539
         }
487 540
 
488 541
         // Check Scope attribute
489 542
         $actor = $fallbackActor ?? $this;
490
-        if ($this->options->checkScope) { # todo
543
+        if ($this->options->checkScope)
544
+        {
545
+# todo
491 546
             $ar = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null);
492
-            if ($ar !== null) {
547
+            if ($ar !== null)
548
+            {
493 549
                 /** @var Attribute\Scope $attr */
494 550
                 $attr = $ar->newInstance();
495 551
                 $scope = $this->scope;
496 552
                 $actor = $this;
497 553
                 // Go through all parent scopes
498 554
                 $needed = $actor;
499
-                while ($attr->name !== $scope->getScopeName()) {
555
+                while ($attr->name !== $scope->getScopeName())
556
+                {
500 557
                     $needed = $scope->getParentActor();
501
-                    if ($needed === null) {
558
+                    if ($needed === null)
559
+                    {
502 560
                         throw new BadScopeException($attr->name, $class);
503 561
                     }
504 562
 
@@ -511,11 +569,13 @@  discard block
 block discarded – undo
511 569
         } # todo
512 570
 
513 571
         // We have to construct class using external injector when we know the exact context
514
-        if ($arguments === [] && $actor->binder->hasInjector($class)) {
572
+        if ($arguments === [] && $actor->binder->hasInjector($class))
573
+        {
515 574
             return $actor->resolveInjector($actor->state->bindings[$ctx->class], $ctx, $arguments, $tracer);
516 575
         }
517 576
 
518
-        if (!$reflection->isInstantiable()) {
577
+        if (!$reflection->isInstantiable())
578
+        {
519 579
             $itIs = match (true) {
520 580
                 $reflection->isEnum() => 'Enum',
521 581
                 $reflection->isAbstract() => 'Abstract class',
@@ -529,8 +589,10 @@  discard block
 block discarded – undo
529 589
 
530 590
         $constructor = $reflection->getConstructor();
531 591
 
532
-        if ($constructor !== null) {
533
-            try {
592
+        if ($constructor !== null)
593
+        {
594
+            try
595
+            {
534 596
                 $newScope = $this !== $actor;
535 597
                 $debug = [
536 598
                     'action' => 'resolve arguments',
@@ -544,39 +606,54 @@  discard block
 block discarded – undo
544 606
                 $tracer->push($newScope, ...$debug);
545 607
                 $tracer->push(true);
546 608
                 $args = $actor->resolver->resolveArguments($constructor, $arguments, $actor->options->validateArguments);
547
-            } catch (ValidationException $e) {
609
+            }
610
+            catch (ValidationException $e)
611
+            {
548 612
                 throw TracedContainerException::createWithTrace(\sprintf(
549 613
                     'Can\'t resolve `%s`. %s',
550 614
                     $tracer->getRootAlias(),
551 615
                     $e->getMessage(),
552 616
                 ), $tracer->getTraces());
553
-            } catch (TracedContainerException $e) {
617
+            }
618
+            catch (TracedContainerException $e)
619
+            {
554 620
                 throw $e::extendTracedException(\sprintf(
555 621
                     'Can\'t resolve `%s`.',
556 622
                     $tracer->getRootAlias(),
557 623
                 ), $tracer->getTraces(), $e);
558
-            } finally {
624
+            }
625
+            finally
626
+            {
559 627
                 $tracer->pop($newScope);
560 628
                 $tracer->pop(false);
561 629
             }
562
-            try {
630
+            try
631
+            {
563 632
                 // Using constructor with resolved arguments
564 633
                 $tracer->push(false, call: "$class::__construct", arguments: $args);
565 634
                 $tracer->push(true);
566 635
                 $instance = new $class(...$args);
567
-            } catch (\TypeError $e) {
636
+            }
637
+            catch (\TypeError $e)
638
+            {
568 639
                 throw new WrongTypeException($constructor, $e);
569
-            } catch (TracedContainerException $e) {
640
+            }
641
+            catch (TracedContainerException $e)
642
+            {
570 643
                 throw $e::extendTracedException(\sprintf(
571 644
                     'Can\'t resolve `%s`: failed constructing `%s`.',
572 645
                     $tracer->getRootAlias(),
573 646
                     $class,
574 647
                 ), $tracer->getTraces(), $e);
575
-            } finally {
648
+            }
649
+            finally
650
+            {
576 651
                 $tracer->pop(true);
577 652
                 $tracer->pop(false);
578 653
             }
579
-        } else {
654
+        }
655
+        else
656
+        {
580 657
             // No constructor specified
581 658
             $instance = $reflection->newInstance();
582 659
         }
@@ -608,12 +685,14 @@  discard block
 block discarded – undo
608 685
      */
609 686
     private function isSingleton(Ctx $ctx): bool
610 687
     {
611
-        if (is_bool($ctx->singleton)) {
688
+        if (is_bool($ctx->singleton))
689
+        {
612 690
             return $ctx->singleton;
613 691
         }
614 692
 
615 693
         /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */
616
-        if ($ctx->reflection->implementsInterface(SingletonInterface::class)) {
694
+        if ($ctx->reflection->implementsInterface(SingletonInterface::class))
695
+        {
617 696
             return true;
618 697
         }
619 698
 
@@ -627,7 +706,8 @@  discard block
 block discarded – undo
627 706
          * @var Attribute\Finalize|null $attribute
628 707
          */
629 708
         $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance();
630
-        if ($attribute === null) {
709
+        if ($attribute === null)
710
+        {
631 711
             return null;
632 712
         }
633 713
 
@@ -641,10 +721,14 @@  discard block
 block discarded – undo
641 721
     {
642 722
         $scope = $this->scope;
643 723
 
644
-        while ($scope !== null) {
645
-            foreach ($this->state->inflectors as $class => $inflectors) {
646
-                if ($instance instanceof $class) {
647
-                    foreach ($inflectors as $inflector) {
724
+        while ($scope !== null)
725
+        {
726
+            foreach ($this->state->inflectors as $class => $inflectors)
727
+            {
728
+                if ($instance instanceof $class)
729
+                {
730
+                    foreach ($inflectors as $inflector)
731
+                    {
648 732
                         $instance = $inflector->getParametersCount() > 1
649 733
                             ? $this->invoker->invoke($inflector->inflector, [$instance])
650 734
                             : ($inflector->inflector)($instance);
@@ -660,9 +744,12 @@  discard block
 block discarded – undo
660 744
 
661 745
     private function validateArguments(ContextFunction $reflection, array $arguments = []): bool
662 746
     {
663
-        try {
747
+        try
748
+        {
664 749
             $this->resolver->validateArguments($reflection, $arguments);
665
-        } catch (\Throwable) {
750
+        }
751
+        catch (\Throwable)
752
+        {
666 753
             return false;
667 754
         }
668 755
 
Please login to merge, or discard this patch.
src/Core/src/Internal/Invoker.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -42,26 +42,26 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function invoke(mixed $target, array $parameters = []): mixed
44 44
     {
45
-        if (\is_array($target) && isset($target[1])) {
45
+        if (\is_array($target) && isset($target[1])){
46 46
             // In a form of alias and method
47 47
             [$alias, $method] = $target;
48 48
 
49 49
             // Resolver instance or class name if the method is static (i.e. [ClassName::class, 'method'])
50
-            if (\is_string($alias)) {
50
+            if (\is_string($alias)){
51 51
                 // Detect return type
52 52
                 $type = $this->actor->resolveType($alias, $binding, $singleton, $injector);
53 53
 
54
-                if ($singleton === null) {
54
+                if ($singleton === null){
55 55
                     $type ??= $injector === null && $binding === null ? $alias : null;
56 56
                     $alias = \is_callable([$type, $method]) ? $type : $this->container->get($alias);
57
-                } else {
57
+                }else{
58 58
                     $alias = $singleton;
59 59
                 }
60 60
             }
61 61
 
62
-            try {
62
+            try{
63 63
                 $method = new \ReflectionMethod($alias, $method);
64
-            } catch (\ReflectionException $e) {
64
+            }catch (\ReflectionException $e){
65 65
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
66 66
             }
67 67
 
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
             );
73 73
         }
74 74
 
75
-        if (\is_string($target) && \is_callable($target)) {
75
+        if (\is_string($target) && \is_callable($target)){
76 76
             $target = $target(...);
77 77
         }
78 78
 
79
-        if ($target instanceof \Closure) {
80
-            try {
79
+        if ($target instanceof \Closure){
80
+            try{
81 81
                 $reflection = new \ReflectionFunction($target);
82
-            } catch (\ReflectionException $e) {
82
+            }catch (\ReflectionException $e){
83 83
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
84 84
             }
85 85
 
Please login to merge, or discard this patch.
Braces   +23 added lines, -10 removed lines patch added patch discarded remove patch
@@ -42,26 +42,34 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function invoke(mixed $target, array $parameters = []): mixed
44 44
     {
45
-        if (\is_array($target) && isset($target[1])) {
45
+        if (\is_array($target) && isset($target[1]))
46
+        {
46 47
             // In a form of alias and method
47 48
             [$alias, $method] = $target;
48 49
 
49 50
             // Resolver instance or class name if the method is static (i.e. [ClassName::class, 'method'])
50
-            if (\is_string($alias)) {
51
+            if (\is_string($alias))
52
+            {
51 53
                 // Detect return type
52 54
                 $type = $this->actor->resolveType($alias, $binding, $singleton, $injector);
53 55
 
54
-                if ($singleton === null) {
56
+                if ($singleton === null)
57
+                {
55 58
                     $type ??= $injector === null && $binding === null ? $alias : null;
56 59
                     $alias = \is_callable([$type, $method]) ? $type : $this->container->get($alias);
57
-                } else {
60
+                }
61
+                else
62
+                {
58 63
                     $alias = $singleton;
59 64
                 }
60 65
             }
61 66
 
62
-            try {
67
+            try
68
+            {
63 69
                 $method = new \ReflectionMethod($alias, $method);
64
-            } catch (\ReflectionException $e) {
70
+            }
71
+            catch (\ReflectionException $e)
72
+            {
65 73
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
66 74
             }
67 75
 
@@ -72,14 +80,19 @@  discard block
 block discarded – undo
72 80
             );
73 81
         }
74 82
 
75
-        if (\is_string($target) && \is_callable($target)) {
83
+        if (\is_string($target) && \is_callable($target))
84
+        {
76 85
             $target = $target(...);
77 86
         }
78 87
 
79
-        if ($target instanceof \Closure) {
80
-            try {
88
+        if ($target instanceof \Closure)
89
+        {
90
+            try
91
+            {
81 92
                 $reflection = new \ReflectionFunction($target);
82
-            } catch (\ReflectionException $e) {
93
+            }
94
+            catch (\ReflectionException $e)
95
+            {
83 96
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
84 97
             }
85 98
 
Please login to merge, or discard this patch.