Completed
Push — master ( 6366df...fbe022 )
by Kirill
23s queued 19s
created
src/Prototype/src/NodeVisitors/ClassNode/LocateStatements.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@
 block discarded – undo
27 27
      */
28 28
     public function enterNode(Node $node)
29 29
     {
30
-        if ($node instanceof Node\Stmt\Use_) {
31
-            foreach ($node->uses as $use) {
30
+        if ($node instanceof Node\Stmt\Use_){
31
+            foreach ($node->uses as $use){
32 32
                 $this->imports[] = [
33 33
                     'name'  => implode('\\', $use->name->parts),
34 34
                     'alias' => $use->alias->name ?? null,
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,8 +27,10 @@
 block discarded – undo
27 27
      */
28 28
     public function enterNode(Node $node)
29 29
     {
30
-        if ($node instanceof Node\Stmt\Use_) {
31
-            foreach ($node->uses as $use) {
30
+        if ($node instanceof Node\Stmt\Use_)
31
+        {
32
+            foreach ($node->uses as $use)
33
+            {
32 34
                 $this->imports[] = [
33 35
                     'name'  => implode('\\', $use->name->parts),
34 36
                     'alias' => $use->alias->name ?? null,
Please login to merge, or discard this patch.
src/Prototype/src/NodeVisitors/ClassNode/LocateVariables.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,16 +25,16 @@
 block discarded – undo
25 25
      */
26 26
     public function enterNode(Node $node)
27 27
     {
28
-        if ($node instanceof Node\Stmt\Class_) {
29
-            foreach ($node->stmts as $stmt) {
30
-                if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name === '__construct') {
28
+        if ($node instanceof Node\Stmt\Class_){
29
+            foreach ($node->stmts as $stmt){
30
+                if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name === '__construct'){
31 31
                     return $stmt;
32 32
                 }
33 33
             }
34 34
             return NodeTraverser::DONT_TRAVERSE_CHILDREN;
35 35
         }
36 36
 
37
-        if ($node instanceof Node\Expr\Variable) {
37
+        if ($node instanceof Node\Expr\Variable){
38 38
             $this->vars[] = $node->name;
39 39
         }
40 40
 
Please login to merge, or discard this patch.
Braces   +8 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,16 +25,20 @@
 block discarded – undo
25 25
      */
26 26
     public function enterNode(Node $node)
27 27
     {
28
-        if ($node instanceof Node\Stmt\Class_) {
29
-            foreach ($node->stmts as $stmt) {
30
-                if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name === '__construct') {
28
+        if ($node instanceof Node\Stmt\Class_)
29
+        {
30
+            foreach ($node->stmts as $stmt)
31
+            {
32
+                if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name === '__construct')
33
+                {
31 34
                     return $stmt;
32 35
                 }
33 36
             }
34 37
             return NodeTraverser::DONT_TRAVERSE_CHILDREN;
35 38
         }
36 39
 
37
-        if ($node instanceof Node\Expr\Variable) {
40
+        if ($node instanceof Node\Expr\Variable)
41
+        {
38 42
             $this->vars[] = $node->name;
39 43
         }
40 44
 
Please login to merge, or discard this patch.
src/Prototype/tests/Commands/InjectCommandTest.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
         $source = file_get_contents($filename);
30 30
         $this->assertStringContainsString('use PrototypeTrait;', $source);
31 31
 
32
-        try {
32
+        try{
33 33
             $this->app->bindApp();
34 34
 
35 35
             $inp = new ArrayInput(['--remove' => true]);
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
             $this->app->get(Console::class)->run('prototype:inject', $inp, $out);
38 38
 
39 39
             $this->assertStringNotContainsString('use PrototypeTrait;', file_get_contents($filename));
40
-        } finally {
40
+        }finally{
41 41
             file_put_contents($filename, $source);
42 42
         }
43 43
     }
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,7 +29,8 @@  discard block
 block discarded – undo
29 29
         $source = file_get_contents($filename);
30 30
         $this->assertStringContainsString('use PrototypeTrait;', $source);
31 31
 
32
-        try {
32
+        try
33
+        {
33 34
             $this->app->bindApp();
34 35
 
35 36
             $inp = new ArrayInput(['--remove' => true]);
@@ -37,7 +38,9 @@  discard block
 block discarded – undo
37 38
             $this->app->get(Console::class)->run('prototype:inject', $inp, $out);
38 39
 
39 40
             $this->assertStringNotContainsString('use PrototypeTrait;', file_get_contents($filename));
40
-        } finally {
41
+        }
42
+        finally
43
+        {
41 44
             file_put_contents($filename, $source);
42 45
         }
43 46
     }
Please login to merge, or discard this patch.
src/Views/src/Processor/ContextProcessor.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,8 @@
 block discarded – undo
39 39
      */
40 40
     public function process(ViewSource $source, ContextInterface $context): ViewSource
41 41
     {
42
-        return $source->withCode(preg_replace_callback($this->pattern, static function ($matches) use ($context) {
42
+        return $source->withCode(preg_replace_callback($this->pattern, static function ($matches) use ($context)
43
+        {
43 44
             return $context->resolveValue($matches[1]);
44 45
         }, $source->getCode()));
45 46
     }
Please login to merge, or discard this patch.
src/Files/src/Files.php 2 patches
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      */
46 46
     public function __destruct()
47 47
     {
48
-        foreach ($this->destructFiles as $filename) {
48
+        foreach ($this->destructFiles as $filename){
49 49
             $this->delete($filename);
50 50
         }
51 51
     }
@@ -60,30 +60,30 @@  discard block
 block discarded – undo
60 60
         int $mode = null,
61 61
         bool $recursivePermissions = true
62 62
     ): bool {
63
-        if (empty($mode)) {
63
+        if (empty($mode)){
64 64
             $mode = self::DEFAULT_FILE_MODE;
65 65
         }
66 66
 
67 67
         //Directories always executable
68 68
         $mode = $mode | 0111;
69
-        if (is_dir($directory)) {
69
+        if (is_dir($directory)){
70 70
             //Exists :(
71 71
             return $this->setPermissions($directory, $mode);
72 72
         }
73 73
 
74
-        if (!$recursivePermissions) {
74
+        if (!$recursivePermissions){
75 75
             return mkdir($directory, $mode, true);
76 76
         }
77 77
 
78 78
         $directoryChain = [basename($directory)];
79 79
 
80 80
         $baseDirectory = $directory;
81
-        while (!is_dir($baseDirectory = dirname($baseDirectory))) {
81
+        while (!is_dir($baseDirectory = dirname($baseDirectory))){
82 82
             $directoryChain[] = basename($baseDirectory);
83 83
         }
84 84
 
85
-        foreach (array_reverse($directoryChain) as $directory) {
86
-            if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")) {
85
+        foreach (array_reverse($directoryChain) as $directory){
86
+            if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")){
87 87
                 return false;
88 88
             }
89 89
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function read(string $filename): string
100 100
     {
101
-        if (!$this->exists($filename)) {
101
+        if (!$this->exists($filename)){
102 102
             throw new FileNotFoundException($filename);
103 103
         }
104 104
 
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
     ): bool {
120 120
         $mode = $mode ?? self::DEFAULT_FILE_MODE;
121 121
 
122
-        try {
123
-            if ($ensureDirectory) {
122
+        try{
123
+            if ($ensureDirectory){
124 124
                 $this->ensureDirectory(dirname($filename), $mode);
125 125
             }
126 126
 
127
-            if ($this->exists($filename)) {
127
+            if ($this->exists($filename)){
128 128
                 //Forcing mode for existed file
129 129
                 $this->setPermissions($filename, $mode);
130 130
             }
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
                 $append ? FILE_APPEND | LOCK_EX : LOCK_EX
136 136
             );
137 137
 
138
-            if ($result !== false) {
138
+            if ($result !== false){
139 139
                 //Forcing mode after file creation
140 140
                 $this->setPermissions($filename, $mode);
141 141
             }
142
-        } catch (\Exception $e) {
142
+        }catch (\Exception $e){
143 143
             throw new WriteErrorException($e->getMessage(), $e->getCode(), $e);
144 144
         }
145 145
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      */
164 164
     public function delete(string $filename)
165 165
     {
166
-        if ($this->exists($filename)) {
166
+        if ($this->exists($filename)){
167 167
             $result = unlink($filename);
168 168
 
169 169
             //Wiping out changes in local file cache
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
      */
188 188
     public function deleteDirectory(string $directory, bool $contentOnly = false): void
189 189
     {
190
-        if (!$this->isDirectory($directory)) {
190
+        if (!$this->isDirectory($directory)){
191 191
             throw new FilesException("Undefined or invalid directory {$directory}");
192 192
         }
193 193
 
@@ -196,15 +196,15 @@  discard block
 block discarded – undo
196 196
             \RecursiveIteratorIterator::CHILD_FIRST
197 197
         );
198 198
 
199
-        foreach ($files as $file) {
200
-            if ($file->isDir()) {
199
+        foreach ($files as $file){
200
+            if ($file->isDir()){
201 201
                 rmdir($file->getRealPath());
202
-            } else {
202
+            }else{
203 203
                 $this->delete($file->getRealPath());
204 204
             }
205 205
         }
206 206
 
207
-        if (!$contentOnly) {
207
+        if (!$contentOnly){
208 208
             rmdir($directory);
209 209
         }
210 210
     }
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
      */
215 215
     public function move(string $filename, string $destination): bool
216 216
     {
217
-        if (!$this->exists($filename)) {
217
+        if (!$this->exists($filename)){
218 218
             throw new FileNotFoundException($filename);
219 219
         }
220 220
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
      */
227 227
     public function copy(string $filename, string $destination): bool
228 228
     {
229
-        if (!$this->exists($filename)) {
229
+        if (!$this->exists($filename)){
230 230
             throw new FileNotFoundException($filename);
231 231
         }
232 232
 
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      */
239 239
     public function touch(string $filename, int $mode = null): bool
240 240
     {
241
-        if (!touch($filename)) {
241
+        if (!touch($filename)){
242 242
             return false;
243 243
         }
244 244
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      */
259 259
     public function size(string $filename): int
260 260
     {
261
-        if (!$this->exists($filename)) {
261
+        if (!$this->exists($filename)){
262 262
             throw new FileNotFoundException($filename);
263 263
         }
264 264
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      */
279 279
     public function md5(string $filename): string
280 280
     {
281
-        if (!$this->exists($filename)) {
281
+        if (!$this->exists($filename)){
282 282
             throw new FileNotFoundException($filename);
283 283
         }
284 284
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      */
291 291
     public function time(string $filename): int
292 292
     {
293
-        if (!$this->exists($filename)) {
293
+        if (!$this->exists($filename)){
294 294
             throw new FileNotFoundException($filename);
295 295
         }
296 296
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      */
319 319
     public function getPermissions(string $filename): int
320 320
     {
321
-        if (!$this->exists($filename)) {
321
+        if (!$this->exists($filename)){
322 322
             throw new FileNotFoundException($filename);
323 323
         }
324 324
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
      */
331 331
     public function setPermissions(string $filename, int $mode)
332 332
     {
333
-        if (is_dir($filename)) {
333
+        if (is_dir($filename)){
334 334
             //Directories must always be executable (i.e. 664 for dir => 775)
335 335
             $mode |= 0111;
336 336
         }
@@ -344,9 +344,9 @@  discard block
 block discarded – undo
344 344
     public function getFiles(string $location, string $pattern = null): array
345 345
     {
346 346
         $result = [];
347
-        foreach ($this->filesIterator($location, $pattern) as $filename) {
348
-            if ($this->isDirectory($filename->getPathname())) {
349
-                $result = array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR));
347
+        foreach ($this->filesIterator($location, $pattern) as $filename){
348
+            if ($this->isDirectory($filename->getPathname())){
349
+                $result = array_merge($result, $this->getFiles($filename.DIRECTORY_SEPARATOR));
350 350
 
351 351
                 continue;
352 352
             }
@@ -362,13 +362,13 @@  discard block
 block discarded – undo
362 362
      */
363 363
     public function tempFilename(string $extension = '', string $location = null): string
364 364
     {
365
-        if (empty($location)) {
365
+        if (empty($location)){
366 366
             $location = sys_get_temp_dir();
367 367
         }
368 368
 
369 369
         $filename = tempnam($location, 'spiral');
370 370
 
371
-        if (!empty($extension)) {
371
+        if (!empty($extension)){
372 372
             [$old, $filename] = [$filename, "{$filename}.{$extension}"];
373 373
             rename($old, $filename);
374 374
             $this->destructFiles[] = $filename;
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
         $path = str_replace(['//', '\\'], '/', $path);
386 386
 
387 387
         //Potentially open links and ../ type directories?
388
-        return rtrim($path, '/') . ($asDirectory ? '/' : '');
388
+        return rtrim($path, '/').($asDirectory ? '/' : '');
389 389
     }
390 390
 
391 391
     /**
@@ -402,21 +402,21 @@  discard block
 block discarded – undo
402 402
         $path = explode('/', $path);
403 403
         $relative = $path;
404 404
 
405
-        foreach ($from as $depth => $dir) {
405
+        foreach ($from as $depth => $dir){
406 406
             //Find first non-matching dir
407
-            if ($dir === $path[$depth]) {
407
+            if ($dir === $path[$depth]){
408 408
                 //Ignore this directory
409 409
                 array_shift($relative);
410
-            } else {
410
+            }else{
411 411
                 //Get number of remaining dirs to $from
412 412
                 $remaining = count($from) - $depth;
413
-                if ($remaining > 1) {
413
+                if ($remaining > 1){
414 414
                     //Add traversals up to first matching directory
415 415
                     $padLength = (count($relative) + $remaining - 1) * -1;
416 416
                     $relative = array_pad($relative, $padLength, '..');
417 417
                     break;
418 418
                 }
419
-                $relative[0] = './' . $relative[0];
419
+                $relative[0] = './'.$relative[0];
420 420
             }
421 421
         }
422 422
 
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
     private function filesIterator(string $location, string $pattern = null): \GlobIterator
433 433
     {
434 434
         $pattern = $pattern ?? '*';
435
-        $regexp = rtrim($location, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($pattern, DIRECTORY_SEPARATOR);
435
+        $regexp = rtrim($location, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.ltrim($pattern, DIRECTORY_SEPARATOR);
436 436
 
437 437
         return new \GlobIterator($regexp);
438 438
     }
Please login to merge, or discard this patch.
Braces   +73 added lines, -35 removed lines patch added patch discarded remove patch
@@ -45,7 +45,8 @@  discard block
 block discarded – undo
45 45
      */
46 46
     public function __destruct()
47 47
     {
48
-        foreach ($this->destructFiles as $filename) {
48
+        foreach ($this->destructFiles as $filename)
49
+        {
49 50
             $this->delete($filename);
50 51
         }
51 52
     }
@@ -60,30 +61,36 @@  discard block
 block discarded – undo
60 61
         int $mode = null,
61 62
         bool $recursivePermissions = true
62 63
     ): bool {
63
-        if (empty($mode)) {
64
+        if (empty($mode))
65
+        {
64 66
             $mode = self::DEFAULT_FILE_MODE;
65 67
         }
66 68
 
67 69
         //Directories always executable
68 70
         $mode = $mode | 0111;
69
-        if (is_dir($directory)) {
71
+        if (is_dir($directory))
72
+        {
70 73
             //Exists :(
71 74
             return $this->setPermissions($directory, $mode);
72 75
         }
73 76
 
74
-        if (!$recursivePermissions) {
77
+        if (!$recursivePermissions)
78
+        {
75 79
             return mkdir($directory, $mode, true);
76 80
         }
77 81
 
78 82
         $directoryChain = [basename($directory)];
79 83
 
80 84
         $baseDirectory = $directory;
81
-        while (!is_dir($baseDirectory = dirname($baseDirectory))) {
85
+        while (!is_dir($baseDirectory = dirname($baseDirectory)))
86
+        {
82 87
             $directoryChain[] = basename($baseDirectory);
83 88
         }
84 89
 
85
-        foreach (array_reverse($directoryChain) as $directory) {
86
-            if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")) {
90
+        foreach (array_reverse($directoryChain) as $directory)
91
+        {
92
+            if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}"))
93
+            {
87 94
                 return false;
88 95
             }
89 96
 
@@ -98,7 +105,8 @@  discard block
 block discarded – undo
98 105
      */
99 106
     public function read(string $filename): string
100 107
     {
101
-        if (!$this->exists($filename)) {
108
+        if (!$this->exists($filename))
109
+        {
102 110
             throw new FileNotFoundException($filename);
103 111
         }
104 112
 
@@ -119,12 +127,15 @@  discard block
 block discarded – undo
119 127
     ): bool {
120 128
         $mode = $mode ?? self::DEFAULT_FILE_MODE;
121 129
 
122
-        try {
123
-            if ($ensureDirectory) {
130
+        try
131
+        {
132
+            if ($ensureDirectory)
133
+            {
124 134
                 $this->ensureDirectory(dirname($filename), $mode);
125 135
             }
126 136
 
127
-            if ($this->exists($filename)) {
137
+            if ($this->exists($filename))
138
+            {
128 139
                 //Forcing mode for existed file
129 140
                 $this->setPermissions($filename, $mode);
130 141
             }
@@ -135,11 +146,14 @@  discard block
 block discarded – undo
135 146
                 $append ? FILE_APPEND | LOCK_EX : LOCK_EX
136 147
             );
137 148
 
138
-            if ($result !== false) {
149
+            if ($result !== false)
150
+            {
139 151
                 //Forcing mode after file creation
140 152
                 $this->setPermissions($filename, $mode);
141 153
             }
142
-        } catch (\Exception $e) {
154
+        }
155
+        catch (\Exception $e)
156
+        {
143 157
             throw new WriteErrorException($e->getMessage(), $e->getCode(), $e);
144 158
         }
145 159
 
@@ -163,7 +177,8 @@  discard block
 block discarded – undo
163 177
      */
164 178
     public function delete(string $filename)
165 179
     {
166
-        if ($this->exists($filename)) {
180
+        if ($this->exists($filename))
181
+        {
167 182
             $result = unlink($filename);
168 183
 
169 184
             //Wiping out changes in local file cache
@@ -187,7 +202,8 @@  discard block
 block discarded – undo
187 202
      */
188 203
     public function deleteDirectory(string $directory, bool $contentOnly = false): void
189 204
     {
190
-        if (!$this->isDirectory($directory)) {
205
+        if (!$this->isDirectory($directory))
206
+        {
191 207
             throw new FilesException("Undefined or invalid directory {$directory}");
192 208
         }
193 209
 
@@ -196,15 +212,20 @@  discard block
 block discarded – undo
196 212
             \RecursiveIteratorIterator::CHILD_FIRST
197 213
         );
198 214
 
199
-        foreach ($files as $file) {
200
-            if ($file->isDir()) {
215
+        foreach ($files as $file)
216
+        {
217
+            if ($file->isDir())
218
+            {
201 219
                 rmdir($file->getRealPath());
202
-            } else {
220
+            }
221
+            else
222
+            {
203 223
                 $this->delete($file->getRealPath());
204 224
             }
205 225
         }
206 226
 
207
-        if (!$contentOnly) {
227
+        if (!$contentOnly)
228
+        {
208 229
             rmdir($directory);
209 230
         }
210 231
     }
@@ -214,7 +235,8 @@  discard block
 block discarded – undo
214 235
      */
215 236
     public function move(string $filename, string $destination): bool
216 237
     {
217
-        if (!$this->exists($filename)) {
238
+        if (!$this->exists($filename))
239
+        {
218 240
             throw new FileNotFoundException($filename);
219 241
         }
220 242
 
@@ -226,7 +248,8 @@  discard block
 block discarded – undo
226 248
      */
227 249
     public function copy(string $filename, string $destination): bool
228 250
     {
229
-        if (!$this->exists($filename)) {
251
+        if (!$this->exists($filename))
252
+        {
230 253
             throw new FileNotFoundException($filename);
231 254
         }
232 255
 
@@ -238,7 +261,8 @@  discard block
 block discarded – undo
238 261
      */
239 262
     public function touch(string $filename, int $mode = null): bool
240 263
     {
241
-        if (!touch($filename)) {
264
+        if (!touch($filename))
265
+        {
242 266
             return false;
243 267
         }
244 268
 
@@ -258,7 +282,8 @@  discard block
 block discarded – undo
258 282
      */
259 283
     public function size(string $filename): int
260 284
     {
261
-        if (!$this->exists($filename)) {
285
+        if (!$this->exists($filename))
286
+        {
262 287
             throw new FileNotFoundException($filename);
263 288
         }
264 289
 
@@ -278,7 +303,8 @@  discard block
 block discarded – undo
278 303
      */
279 304
     public function md5(string $filename): string
280 305
     {
281
-        if (!$this->exists($filename)) {
306
+        if (!$this->exists($filename))
307
+        {
282 308
             throw new FileNotFoundException($filename);
283 309
         }
284 310
 
@@ -290,7 +316,8 @@  discard block
 block discarded – undo
290 316
      */
291 317
     public function time(string $filename): int
292 318
     {
293
-        if (!$this->exists($filename)) {
319
+        if (!$this->exists($filename))
320
+        {
294 321
             throw new FileNotFoundException($filename);
295 322
         }
296 323
 
@@ -318,7 +345,8 @@  discard block
 block discarded – undo
318 345
      */
319 346
     public function getPermissions(string $filename): int
320 347
     {
321
-        if (!$this->exists($filename)) {
348
+        if (!$this->exists($filename))
349
+        {
322 350
             throw new FileNotFoundException($filename);
323 351
         }
324 352
 
@@ -330,7 +358,8 @@  discard block
 block discarded – undo
330 358
      */
331 359
     public function setPermissions(string $filename, int $mode)
332 360
     {
333
-        if (is_dir($filename)) {
361
+        if (is_dir($filename))
362
+        {
334 363
             //Directories must always be executable (i.e. 664 for dir => 775)
335 364
             $mode |= 0111;
336 365
         }
@@ -344,8 +373,10 @@  discard block
 block discarded – undo
344 373
     public function getFiles(string $location, string $pattern = null): array
345 374
     {
346 375
         $result = [];
347
-        foreach ($this->filesIterator($location, $pattern) as $filename) {
348
-            if ($this->isDirectory($filename->getPathname())) {
376
+        foreach ($this->filesIterator($location, $pattern) as $filename)
377
+        {
378
+            if ($this->isDirectory($filename->getPathname()))
379
+            {
349 380
                 $result = array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR));
350 381
 
351 382
                 continue;
@@ -362,13 +393,15 @@  discard block
 block discarded – undo
362 393
      */
363 394
     public function tempFilename(string $extension = '', string $location = null): string
364 395
     {
365
-        if (empty($location)) {
396
+        if (empty($location))
397
+        {
366 398
             $location = sys_get_temp_dir();
367 399
         }
368 400
 
369 401
         $filename = tempnam($location, 'spiral');
370 402
 
371
-        if (!empty($extension)) {
403
+        if (!empty($extension))
404
+        {
372 405
             [$old, $filename] = [$filename, "{$filename}.{$extension}"];
373 406
             rename($old, $filename);
374 407
             $this->destructFiles[] = $filename;
@@ -402,15 +435,20 @@  discard block
 block discarded – undo
402 435
         $path = explode('/', $path);
403 436
         $relative = $path;
404 437
 
405
-        foreach ($from as $depth => $dir) {
438
+        foreach ($from as $depth => $dir)
439
+        {
406 440
             //Find first non-matching dir
407
-            if ($dir === $path[$depth]) {
441
+            if ($dir === $path[$depth])
442
+            {
408 443
                 //Ignore this directory
409 444
                 array_shift($relative);
410
-            } else {
445
+            }
446
+            else
447
+            {
411 448
                 //Get number of remaining dirs to $from
412 449
                 $remaining = count($from) - $depth;
413
-                if ($remaining > 1) {
450
+                if ($remaining > 1)
451
+                {
414 452
                     //Add traversals up to first matching directory
415 453
                     $padLength = (count($relative) + $remaining - 1) * -1;
416 454
                     $relative = array_pad($relative, $padLength, '..');
Please login to merge, or discard this patch.
src/Core/src/Container.php 2 patches
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
     {
99 99
         $arguments = [];
100 100
 
101
-        foreach ($reflection->getParameters() as $parameter) {
101
+        foreach ($reflection->getParameters() as $parameter){
102 102
             $type = $parameter->getType();
103 103
             $name = $parameter->getName();
104 104
             $class = null;
@@ -107,17 +107,17 @@  discard block
 block discarded – undo
107 107
              * Container do not currently support union types. In the future, we
108 108
              * can provide the possibility of autowiring based on priorities (TBD).
109 109
              */
110
-            if ($type instanceof \ReflectionUnionType) {
110
+            if ($type instanceof \ReflectionUnionType){
111 111
                 $error = 'Parameter $%s in %s contains a union type hint that cannot be inferred unambiguously';
112 112
                 $error = \sprintf($error, $reflection->getName(), $this->getLocationString($reflection));
113 113
 
114 114
                 throw new ContainerException($error);
115 115
             }
116 116
 
117
-            if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) {
118
-                try {
117
+            if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()){
118
+                try{
119 119
                     $class = new \ReflectionClass($type->getName());
120
-                } catch (\ReflectionException $e) {
120
+                }catch (\ReflectionException $e){
121 121
                     $location = $this->getLocationString($reflection);
122 122
 
123 123
                     $error = 'Unable to resolve `\$%s` parameter in %s: %s';
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
                 }
128 128
             }
129 129
 
130
-            if (isset($parameters[$name]) && is_object($parameters[$name])) {
131
-                if ($parameters[$name] instanceof Autowire) {
130
+            if (isset($parameters[$name]) && is_object($parameters[$name])){
131
+                if ($parameters[$name] instanceof Autowire){
132 132
                     // Supplied by user as late dependency
133 133
                     $arguments[] = $parameters[$name]->resolve($this);
134
-                } else {
134
+                }else{
135 135
                     // Supplied by user as object
136 136
                     $arguments[] = $parameters[$name];
137 137
                 }
@@ -139,16 +139,16 @@  discard block
 block discarded – undo
139 139
             }
140 140
 
141 141
             // no declared type or scalar type or array
142
-            if (!isset($class)) {
142
+            if (!isset($class)){
143 143
                 // Provided from outside
144
-                if (\array_key_exists($name, $parameters)) {
144
+                if (\array_key_exists($name, $parameters)){
145 145
                     // Make sure it's properly typed
146 146
                     $this->assertType($parameter, $reflection, $parameters[$name]);
147 147
                     $arguments[] = $parameters[$name];
148 148
                     continue;
149 149
                 }
150 150
 
151
-                if ($parameter->isDefaultValueAvailable()) {
151
+                if ($parameter->isDefaultValueAvailable()){
152 152
                     //Default value
153 153
                     $arguments[] = $parameter->getDefaultValue();
154 154
                     continue;
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
                 throw new ArgumentException($parameter, $reflection);
159 159
             }
160 160
 
161
-            try {
161
+            try{
162 162
                 //Requesting for contextual dependency
163 163
                 $arguments[] = $this->get($class->getName(), $name);
164 164
                 continue;
165
-            } catch (AutowireException $e) {
166
-                if ($parameter->isOptional()) {
165
+            }catch (AutowireException $e){
166
+                if ($parameter->isOptional()){
167 167
                     //This is optional dependency, skip
168 168
                     $arguments[] = null;
169 169
                     continue;
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      */
194 194
     public function get($alias, string $context = null)
195 195
     {
196
-        if ($alias instanceof Autowire) {
196
+        if ($alias instanceof Autowire){
197 197
             return $alias->resolve($this);
198 198
         }
199 199
 
@@ -209,34 +209,34 @@  discard block
 block discarded – undo
209 209
      */
210 210
     public function make(string $alias, array $parameters = [], string $context = null)
211 211
     {
212
-        if (!isset($this->bindings[$alias])) {
212
+        if (!isset($this->bindings[$alias])){
213 213
             //No direct instructions how to construct class, make is automatically
214 214
             return $this->autowire($alias, $parameters, $context);
215 215
         }
216 216
 
217 217
         $binding = $this->bindings[$alias];
218
-        if (\is_object($binding)) {
218
+        if (\is_object($binding)){
219 219
             //When binding is instance, assuming singleton
220 220
             return $binding;
221 221
         }
222 222
 
223
-        if (\is_string($binding)) {
223
+        if (\is_string($binding)){
224 224
             //Binding is pointing to something else
225 225
             return $this->make($binding, $parameters, $context);
226 226
         }
227 227
 
228 228
         unset($this->bindings[$alias]);
229
-        try {
230
-            if ($binding[0] === $alias) {
229
+        try{
230
+            if ($binding[0] === $alias){
231 231
                 $instance = $this->autowire($alias, $parameters, $context);
232
-            } else {
232
+            }else{
233 233
                 $instance = $this->evaluateBinding($alias, $binding[0], $parameters, $context);
234 234
             }
235
-        } finally {
235
+        }finally{
236 236
             $this->bindings[$alias] = $binding;
237 237
         }
238 238
 
239
-        if ($binding[1]) {
239
+        if ($binding[1]){
240 240
             //Indicates singleton
241 241
             $this->bindings[$alias] = $instance;
242 242
         }
@@ -250,28 +250,28 @@  discard block
 block discarded – undo
250 250
     public function runScope(array $bindings, callable $scope)
251 251
     {
252 252
         $cleanup = $previous = [];
253
-        foreach ($bindings as $alias => $resolver) {
254
-            if (isset($this->bindings[$alias])) {
253
+        foreach ($bindings as $alias => $resolver){
254
+            if (isset($this->bindings[$alias])){
255 255
                 $previous[$alias] = $this->bindings[$alias];
256
-            } else {
256
+            }else{
257 257
                 $cleanup[] = $alias;
258 258
             }
259 259
 
260 260
             $this->bind($alias, $resolver);
261 261
         }
262 262
 
263
-        try {
264
-            if (ContainerScope::getContainer() !== $this) {
263
+        try{
264
+            if (ContainerScope::getContainer() !== $this){
265 265
                 return ContainerScope::runScope($this, $scope);
266 266
             }
267 267
 
268 268
             return $scope();
269
-        } finally {
270
-            foreach (\array_reverse($previous) as $alias => $resolver) {
269
+        }finally{
270
+            foreach (\array_reverse($previous) as $alias => $resolver){
271 271
                 $this->bindings[$alias] = $resolver;
272 272
             }
273 273
 
274
-            foreach ($cleanup as $alias) {
274
+            foreach ($cleanup as $alias){
275 275
                 unset($this->bindings[$alias]);
276 276
             }
277 277
         }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      */
288 288
     public function bind(string $alias, $resolver): void
289 289
     {
290
-        if (\is_array($resolver) || $resolver instanceof \Closure || $resolver instanceof Autowire) {
290
+        if (\is_array($resolver) || $resolver instanceof \Closure || $resolver instanceof Autowire){
291 291
             // array means = execute me, false = not singleton
292 292
             $this->bindings[$alias] = [$resolver, false];
293 293
 
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
      */
307 307
     public function bindSingleton(string $alias, $resolver): void
308 308
     {
309
-        if (\is_object($resolver) && !$resolver instanceof \Closure && !$resolver instanceof Autowire) {
309
+        if (\is_object($resolver) && !$resolver instanceof \Closure && !$resolver instanceof Autowire){
310 310
             // direct binding to an instance
311 311
             $this->bindings[$alias] = $resolver;
312 312
 
@@ -324,11 +324,11 @@  discard block
 block discarded – undo
324 324
      */
325 325
     public function hasInstance(string $alias): bool
326 326
     {
327
-        if (!$this->has($alias)) {
327
+        if (!$this->has($alias)){
328 328
             return false;
329 329
         }
330 330
 
331
-        while (isset($this->bindings[$alias]) && \is_string($this->bindings[$alias])) {
331
+        while (isset($this->bindings[$alias]) && \is_string($this->bindings[$alias])){
332 332
             //Checking alias tree
333 333
             $alias = $this->bindings[$alias];
334 334
         }
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
      */
411 411
     protected function autowire(string $class, array $parameters, string $context = null)
412 412
     {
413
-        if (!\class_exists($class)) {
413
+        if (!\class_exists($class)){
414 414
             throw new NotFoundException(\sprintf("Undefined class or binding '%s'", $class));
415 415
         }
416 416
 
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
     {
430 430
         $location = $reflection->getName();
431 431
 
432
-        if ($reflection instanceof \ReflectionMethod) {
432
+        if ($reflection instanceof \ReflectionMethod){
433 433
             return "{$reflection->getDeclaringClass()->getName()}::{$location}()";
434 434
         }
435 435
 
@@ -448,11 +448,11 @@  discard block
 block discarded – undo
448 448
      */
449 449
     private function assertType(\ReflectionParameter $parameter, ContextFunction $context, $value): void
450 450
     {
451
-        if ($value === null) {
451
+        if ($value === null){
452 452
             if (
453 453
                 !$parameter->isOptional() &&
454 454
                 !($parameter->isDefaultValueAvailable() && $parameter->getDefaultValue() === null)
455
-            ) {
455
+            ){
456 456
                 throw new ArgumentException($parameter, $context);
457 457
             }
458 458
 
@@ -460,20 +460,20 @@  discard block
 block discarded – undo
460 460
         }
461 461
 
462 462
         $type = $parameter->getType();
463
-        if ($type === null) {
463
+        if ($type === null){
464 464
             return;
465 465
         }
466 466
 
467 467
         $typeName = $type->getName();
468
-        if ($typeName === 'array' && !\is_array($value)) {
468
+        if ($typeName === 'array' && !\is_array($value)){
469 469
             throw new ArgumentException($parameter, $context);
470 470
         }
471 471
 
472
-        if (($typeName === 'int' || $typeName === 'float') && !\is_numeric($value)) {
472
+        if (($typeName === 'int' || $typeName === 'float') && !\is_numeric($value)){
473 473
             throw new ArgumentException($parameter, $context);
474 474
         }
475 475
 
476
-        if ($typeName === 'bool' && !\is_bool($value) && !\is_numeric($value)) {
476
+        if ($typeName === 'bool' && !\is_bool($value) && !\is_numeric($value)){
477 477
             throw new ArgumentException($parameter, $context);
478 478
         }
479 479
     }
@@ -491,22 +491,22 @@  discard block
 block discarded – undo
491 491
      */
492 492
     private function createInstance(string $class, array $parameters, string $context = null)
493 493
     {
494
-        try {
494
+        try{
495 495
             $reflection = new \ReflectionClass($class);
496
-        } catch (\ReflectionException $e) {
496
+        }catch (\ReflectionException $e){
497 497
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
498 498
         }
499 499
 
500 500
         //We have to construct class using external injector when we know exact context
501
-        if ($parameters === [] && $this->checkInjector($reflection)) {
501
+        if ($parameters === [] && $this->checkInjector($reflection)){
502 502
             $injector = $this->injectors[$reflection->getName()];
503 503
 
504 504
             $instance = null;
505
-            try {
505
+            try{
506 506
                 /** @var InjectorInterface $injectorInstance */
507 507
                 $injectorInstance = $this->get($injector);
508 508
 
509
-                if (!$injectorInstance instanceof InjectorInterface) {
509
+                if (!$injectorInstance instanceof InjectorInterface){
510 510
                     throw new InjectionException(
511 511
                         \sprintf(
512 512
                             "Class '%s' must be an instance of InjectorInterface for '%s'",
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
                 }
518 518
 
519 519
                 $instance = $injectorInstance->createInjection($reflection, $context);
520
-                if (!$reflection->isInstance($instance)) {
520
+                if (!$reflection->isInstance($instance)){
521 521
                     throw new InjectionException(
522 522
                         \sprintf(
523 523
                             "Invalid injection response for '%s'",
@@ -525,23 +525,23 @@  discard block
 block discarded – undo
525 525
                         )
526 526
                     );
527 527
                 }
528
-            } finally {
528
+            }finally{
529 529
                 $this->injectors[$reflection->getName()] = $injector;
530 530
             }
531 531
 
532 532
             return $instance;
533 533
         }
534 534
 
535
-        if (!$reflection->isInstantiable()) {
535
+        if (!$reflection->isInstantiable()){
536 536
             throw new ContainerException(\sprintf("Class '%s' can not be constructed", $class));
537 537
         }
538 538
 
539 539
         $constructor = $reflection->getConstructor();
540 540
 
541
-        if ($constructor !== null) {
541
+        if ($constructor !== null){
542 542
             // Using constructor with resolved arguments
543 543
             $instance = $reflection->newInstanceArgs($this->resolveArguments($constructor, $parameters));
544
-        } else {
544
+        }else{
545 545
             // No constructor specified
546 546
             $instance = $reflection->newInstance();
547 547
         }
@@ -558,28 +558,28 @@  discard block
 block discarded – undo
558 558
     private function checkInjector(\ReflectionClass $reflection): bool
559 559
     {
560 560
         $class = $reflection->getName();
561
-        if (\array_key_exists($class, $this->injectors)) {
561
+        if (\array_key_exists($class, $this->injectors)){
562 562
             return $this->injectors[$class] !== null;
563 563
         }
564 564
 
565 565
         if (
566 566
             $reflection->implementsInterface(InjectableInterface::class)
567 567
             && $reflection->hasConstant('INJECTOR')
568
-        ) {
568
+        ){
569 569
             $this->injectors[$class] = $reflection->getConstant('INJECTOR');
570 570
 
571 571
             return true;
572 572
         }
573 573
 
574
-        if (!isset($this->injectorsCache[$class])) {
574
+        if (!isset($this->injectorsCache[$class])){
575 575
             $this->injectorsCache[$class] = null;
576 576
 
577 577
             // check interfaces
578
-            foreach ($this->injectors as $target => $injector) {
578
+            foreach ($this->injectors as $target => $injector){
579 579
                 if (
580 580
                     \class_exists($target, true)
581 581
                     && $reflection->isSubclassOf($target)
582
-                ) {
582
+                ){
583 583
                     $this->injectors[$class] = $injector;
584 584
 
585 585
                     return true;
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
                 if (
589 589
                     \interface_exists($target, true)
590 590
                     && $reflection->implementsInterface($target)
591
-                ) {
591
+                ){
592 592
                     $this->injectors[$class] = $injector;
593 593
 
594 594
                     return true;
@@ -610,9 +610,9 @@  discard block
 block discarded – undo
610 610
     private function registerInstance($instance, array $parameters)
611 611
     {
612 612
         //Declarative singletons (only when class received via direct get)
613
-        if ($parameters === [] && $instance instanceof SingletonInterface) {
613
+        if ($parameters === [] && $instance instanceof SingletonInterface){
614 614
             $alias = \get_class($instance);
615
-            if (!isset($this->bindings[$alias])) {
615
+            if (!isset($this->bindings[$alias])){
616 616
                 $this->bindings[$alias] = $instance;
617 617
             }
618 618
         }
@@ -633,19 +633,19 @@  discard block
 block discarded – undo
633 633
      */
634 634
     private function evaluateBinding(string $alias, $target, array $parameters, string $context = null)
635 635
     {
636
-        if (\is_string($target)) {
636
+        if (\is_string($target)){
637 637
             // Reference
638 638
             return $this->make($target, $parameters, $context);
639 639
         }
640 640
 
641
-        if ($target instanceof Autowire) {
641
+        if ($target instanceof Autowire){
642 642
             return $target->resolve($this, $parameters);
643 643
         }
644 644
 
645
-        if ($target instanceof \Closure) {
646
-            try {
645
+        if ($target instanceof \Closure){
646
+            try{
647 647
                 $reflection = new \ReflectionFunction($target);
648
-            } catch (\ReflectionException $e) {
648
+            }catch (\ReflectionException $e){
649 649
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
650 650
             }
651 651
 
@@ -655,16 +655,16 @@  discard block
 block discarded – undo
655 655
             );
656 656
         }
657 657
 
658
-        if (is_array($target) && isset($target[1])) {
658
+        if (is_array($target) && isset($target[1])){
659 659
             // In a form of resolver and method
660 660
             [$resolver, $method] = $target;
661 661
 
662 662
             // Resolver instance (i.e. [ClassName::class, 'method'])
663 663
             $resolver = $this->get($resolver);
664 664
 
665
-            try {
665
+            try{
666 666
                 $method = new \ReflectionMethod($resolver, $method);
667
-            } catch (\ReflectionException $e) {
667
+            }catch (\ReflectionException $e){
668 668
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
669 669
             }
670 670
 
Please login to merge, or discard this patch.
Braces   +142 added lines, -65 removed lines patch added patch discarded remove patch
@@ -98,7 +98,8 @@  discard block
 block discarded – undo
98 98
     {
99 99
         $arguments = [];
100 100
 
101
-        foreach ($reflection->getParameters() as $parameter) {
101
+        foreach ($reflection->getParameters() as $parameter)
102
+        {
102 103
             $type = $parameter->getType();
103 104
             $name = $parameter->getName();
104 105
             $class = null;
@@ -107,17 +108,22 @@  discard block
 block discarded – undo
107 108
              * Container do not currently support union types. In the future, we
108 109
              * can provide the possibility of autowiring based on priorities (TBD).
109 110
              */
110
-            if ($type instanceof \ReflectionUnionType) {
111
+            if ($type instanceof \ReflectionUnionType)
112
+            {
111 113
                 $error = 'Parameter $%s in %s contains a union type hint that cannot be inferred unambiguously';
112 114
                 $error = \sprintf($error, $reflection->getName(), $this->getLocationString($reflection));
113 115
 
114 116
                 throw new ContainerException($error);
115 117
             }
116 118
 
117
-            if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) {
118
-                try {
119
+            if ($type instanceof \ReflectionNamedType && !$type->isBuiltin())
120
+            {
121
+                try
122
+                {
119 123
                     $class = new \ReflectionClass($type->getName());
120
-                } catch (\ReflectionException $e) {
124
+                }
125
+                catch (\ReflectionException $e)
126
+                {
121 127
                     $location = $this->getLocationString($reflection);
122 128
 
123 129
                     $error = 'Unable to resolve `\$%s` parameter in %s: %s';
@@ -127,11 +133,15 @@  discard block
 block discarded – undo
127 133
                 }
128 134
             }
129 135
 
130
-            if (isset($parameters[$name]) && is_object($parameters[$name])) {
131
-                if ($parameters[$name] instanceof Autowire) {
136
+            if (isset($parameters[$name]) && is_object($parameters[$name]))
137
+            {
138
+                if ($parameters[$name] instanceof Autowire)
139
+                {
132 140
                     // Supplied by user as late dependency
133 141
                     $arguments[] = $parameters[$name]->resolve($this);
134
-                } else {
142
+                }
143
+                else
144
+                {
135 145
                     // Supplied by user as object
136 146
                     $arguments[] = $parameters[$name];
137 147
                 }
@@ -139,16 +149,19 @@  discard block
 block discarded – undo
139 149
             }
140 150
 
141 151
             // no declared type or scalar type or array
142
-            if (!isset($class)) {
152
+            if (!isset($class))
153
+            {
143 154
                 // Provided from outside
144
-                if (\array_key_exists($name, $parameters)) {
155
+                if (\array_key_exists($name, $parameters))
156
+                {
145 157
                     // Make sure it's properly typed
146 158
                     $this->assertType($parameter, $reflection, $parameters[$name]);
147 159
                     $arguments[] = $parameters[$name];
148 160
                     continue;
149 161
                 }
150 162
 
151
-                if ($parameter->isDefaultValueAvailable()) {
163
+                if ($parameter->isDefaultValueAvailable())
164
+                {
152 165
                     //Default value
153 166
                     $arguments[] = $parameter->getDefaultValue();
154 167
                     continue;
@@ -158,12 +171,16 @@  discard block
 block discarded – undo
158 171
                 throw new ArgumentException($parameter, $reflection);
159 172
             }
160 173
 
161
-            try {
174
+            try
175
+            {
162 176
                 //Requesting for contextual dependency
163 177
                 $arguments[] = $this->get($class->getName(), $name);
164 178
                 continue;
165
-            } catch (AutowireException $e) {
166
-                if ($parameter->isOptional()) {
179
+            }
180
+            catch (AutowireException $e)
181
+            {
182
+                if ($parameter->isOptional())
183
+                {
167 184
                     //This is optional dependency, skip
168 185
                     $arguments[] = null;
169 186
                     continue;
@@ -193,7 +210,8 @@  discard block
 block discarded – undo
193 210
      */
194 211
     public function get($alias, string $context = null)
195 212
     {
196
-        if ($alias instanceof Autowire) {
213
+        if ($alias instanceof Autowire)
214
+        {
197 215
             return $alias->resolve($this);
198 216
         }
199 217
 
@@ -209,34 +227,44 @@  discard block
 block discarded – undo
209 227
      */
210 228
     public function make(string $alias, array $parameters = [], string $context = null)
211 229
     {
212
-        if (!isset($this->bindings[$alias])) {
230
+        if (!isset($this->bindings[$alias]))
231
+        {
213 232
             //No direct instructions how to construct class, make is automatically
214 233
             return $this->autowire($alias, $parameters, $context);
215 234
         }
216 235
 
217 236
         $binding = $this->bindings[$alias];
218
-        if (\is_object($binding)) {
237
+        if (\is_object($binding))
238
+        {
219 239
             //When binding is instance, assuming singleton
220 240
             return $binding;
221 241
         }
222 242
 
223
-        if (\is_string($binding)) {
243
+        if (\is_string($binding))
244
+        {
224 245
             //Binding is pointing to something else
225 246
             return $this->make($binding, $parameters, $context);
226 247
         }
227 248
 
228 249
         unset($this->bindings[$alias]);
229
-        try {
230
-            if ($binding[0] === $alias) {
250
+        try
251
+        {
252
+            if ($binding[0] === $alias)
253
+            {
231 254
                 $instance = $this->autowire($alias, $parameters, $context);
232
-            } else {
255
+            }
256
+            else
257
+            {
233 258
                 $instance = $this->evaluateBinding($alias, $binding[0], $parameters, $context);
234 259
             }
235
-        } finally {
260
+        }
261
+        finally
262
+        {
236 263
             $this->bindings[$alias] = $binding;
237 264
         }
238 265
 
239
-        if ($binding[1]) {
266
+        if ($binding[1])
267
+        {
240 268
             //Indicates singleton
241 269
             $this->bindings[$alias] = $instance;
242 270
         }
@@ -250,28 +278,38 @@  discard block
 block discarded – undo
250 278
     public function runScope(array $bindings, callable $scope)
251 279
     {
252 280
         $cleanup = $previous = [];
253
-        foreach ($bindings as $alias => $resolver) {
254
-            if (isset($this->bindings[$alias])) {
281
+        foreach ($bindings as $alias => $resolver)
282
+        {
283
+            if (isset($this->bindings[$alias]))
284
+            {
255 285
                 $previous[$alias] = $this->bindings[$alias];
256
-            } else {
286
+            }
287
+            else
288
+            {
257 289
                 $cleanup[] = $alias;
258 290
             }
259 291
 
260 292
             $this->bind($alias, $resolver);
261 293
         }
262 294
 
263
-        try {
264
-            if (ContainerScope::getContainer() !== $this) {
295
+        try
296
+        {
297
+            if (ContainerScope::getContainer() !== $this)
298
+            {
265 299
                 return ContainerScope::runScope($this, $scope);
266 300
             }
267 301
 
268 302
             return $scope();
269
-        } finally {
270
-            foreach (\array_reverse($previous) as $alias => $resolver) {
303
+        }
304
+        finally
305
+        {
306
+            foreach (\array_reverse($previous) as $alias => $resolver)
307
+            {
271 308
                 $this->bindings[$alias] = $resolver;
272 309
             }
273 310
 
274
-            foreach ($cleanup as $alias) {
311
+            foreach ($cleanup as $alias)
312
+            {
275 313
                 unset($this->bindings[$alias]);
276 314
             }
277 315
         }
@@ -287,7 +325,8 @@  discard block
 block discarded – undo
287 325
      */
288 326
     public function bind(string $alias, $resolver): void
289 327
     {
290
-        if (\is_array($resolver) || $resolver instanceof \Closure || $resolver instanceof Autowire) {
328
+        if (\is_array($resolver) || $resolver instanceof \Closure || $resolver instanceof Autowire)
329
+        {
291 330
             // array means = execute me, false = not singleton
292 331
             $this->bindings[$alias] = [$resolver, false];
293 332
 
@@ -306,7 +345,8 @@  discard block
 block discarded – undo
306 345
      */
307 346
     public function bindSingleton(string $alias, $resolver): void
308 347
     {
309
-        if (\is_object($resolver) && !$resolver instanceof \Closure && !$resolver instanceof Autowire) {
348
+        if (\is_object($resolver) && !$resolver instanceof \Closure && !$resolver instanceof Autowire)
349
+        {
310 350
             // direct binding to an instance
311 351
             $this->bindings[$alias] = $resolver;
312 352
 
@@ -324,11 +364,13 @@  discard block
 block discarded – undo
324 364
      */
325 365
     public function hasInstance(string $alias): bool
326 366
     {
327
-        if (!$this->has($alias)) {
367
+        if (!$this->has($alias))
368
+        {
328 369
             return false;
329 370
         }
330 371
 
331
-        while (isset($this->bindings[$alias]) && \is_string($this->bindings[$alias])) {
372
+        while (isset($this->bindings[$alias]) && \is_string($this->bindings[$alias]))
373
+        {
332 374
             //Checking alias tree
333 375
             $alias = $this->bindings[$alias];
334 376
         }
@@ -410,7 +452,8 @@  discard block
 block discarded – undo
410 452
      */
411 453
     protected function autowire(string $class, array $parameters, string $context = null)
412 454
     {
413
-        if (!\class_exists($class)) {
455
+        if (!\class_exists($class))
456
+        {
414 457
             throw new NotFoundException(\sprintf("Undefined class or binding '%s'", $class));
415 458
         }
416 459
 
@@ -429,7 +472,8 @@  discard block
 block discarded – undo
429 472
     {
430 473
         $location = $reflection->getName();
431 474
 
432
-        if ($reflection instanceof \ReflectionMethod) {
475
+        if ($reflection instanceof \ReflectionMethod)
476
+        {
433 477
             return "{$reflection->getDeclaringClass()->getName()}::{$location}()";
434 478
         }
435 479
 
@@ -448,7 +492,8 @@  discard block
 block discarded – undo
448 492
      */
449 493
     private function assertType(\ReflectionParameter $parameter, ContextFunction $context, $value): void
450 494
     {
451
-        if ($value === null) {
495
+        if ($value === null)
496
+        {
452 497
             if (
453 498
                 !$parameter->isOptional() &&
454 499
                 !($parameter->isDefaultValueAvailable() && $parameter->getDefaultValue() === null)
@@ -460,20 +505,24 @@  discard block
 block discarded – undo
460 505
         }
461 506
 
462 507
         $type = $parameter->getType();
463
-        if ($type === null) {
508
+        if ($type === null)
509
+        {
464 510
             return;
465 511
         }
466 512
 
467 513
         $typeName = $type->getName();
468
-        if ($typeName === 'array' && !\is_array($value)) {
514
+        if ($typeName === 'array' && !\is_array($value))
515
+        {
469 516
             throw new ArgumentException($parameter, $context);
470 517
         }
471 518
 
472
-        if (($typeName === 'int' || $typeName === 'float') && !\is_numeric($value)) {
519
+        if (($typeName === 'int' || $typeName === 'float') && !\is_numeric($value))
520
+        {
473 521
             throw new ArgumentException($parameter, $context);
474 522
         }
475 523
 
476
-        if ($typeName === 'bool' && !\is_bool($value) && !\is_numeric($value)) {
524
+        if ($typeName === 'bool' && !\is_bool($value) && !\is_numeric($value))
525
+        {
477 526
             throw new ArgumentException($parameter, $context);
478 527
         }
479 528
     }
@@ -491,22 +540,28 @@  discard block
 block discarded – undo
491 540
      */
492 541
     private function createInstance(string $class, array $parameters, string $context = null)
493 542
     {
494
-        try {
543
+        try
544
+        {
495 545
             $reflection = new \ReflectionClass($class);
496
-        } catch (\ReflectionException $e) {
546
+        }
547
+        catch (\ReflectionException $e)
548
+        {
497 549
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
498 550
         }
499 551
 
500 552
         //We have to construct class using external injector when we know exact context
501
-        if ($parameters === [] && $this->checkInjector($reflection)) {
553
+        if ($parameters === [] && $this->checkInjector($reflection))
554
+        {
502 555
             $injector = $this->injectors[$reflection->getName()];
503 556
 
504 557
             $instance = null;
505
-            try {
558
+            try
559
+            {
506 560
                 /** @var InjectorInterface $injectorInstance */
507 561
                 $injectorInstance = $this->get($injector);
508 562
 
509
-                if (!$injectorInstance instanceof InjectorInterface) {
563
+                if (!$injectorInstance instanceof InjectorInterface)
564
+                {
510 565
                     throw new InjectionException(
511 566
                         \sprintf(
512 567
                             "Class '%s' must be an instance of InjectorInterface for '%s'",
@@ -517,7 +572,8 @@  discard block
 block discarded – undo
517 572
                 }
518 573
 
519 574
                 $instance = $injectorInstance->createInjection($reflection, $context);
520
-                if (!$reflection->isInstance($instance)) {
575
+                if (!$reflection->isInstance($instance))
576
+                {
521 577
                     throw new InjectionException(
522 578
                         \sprintf(
523 579
                             "Invalid injection response for '%s'",
@@ -525,23 +581,29 @@  discard block
 block discarded – undo
525 581
                         )
526 582
                     );
527 583
                 }
528
-            } finally {
584
+            }
585
+            finally
586
+            {
529 587
                 $this->injectors[$reflection->getName()] = $injector;
530 588
             }
531 589
 
532 590
             return $instance;
533 591
         }
534 592
 
535
-        if (!$reflection->isInstantiable()) {
593
+        if (!$reflection->isInstantiable())
594
+        {
536 595
             throw new ContainerException(\sprintf("Class '%s' can not be constructed", $class));
537 596
         }
538 597
 
539 598
         $constructor = $reflection->getConstructor();
540 599
 
541
-        if ($constructor !== null) {
600
+        if ($constructor !== null)
601
+        {
542 602
             // Using constructor with resolved arguments
543 603
             $instance = $reflection->newInstanceArgs($this->resolveArguments($constructor, $parameters));
544
-        } else {
604
+        }
605
+        else
606
+        {
545 607
             // No constructor specified
546 608
             $instance = $reflection->newInstance();
547 609
         }
@@ -558,7 +620,8 @@  discard block
 block discarded – undo
558 620
     private function checkInjector(\ReflectionClass $reflection): bool
559 621
     {
560 622
         $class = $reflection->getName();
561
-        if (\array_key_exists($class, $this->injectors)) {
623
+        if (\array_key_exists($class, $this->injectors))
624
+        {
562 625
             return $this->injectors[$class] !== null;
563 626
         }
564 627
 
@@ -571,11 +634,13 @@  discard block
 block discarded – undo
571 634
             return true;
572 635
         }
573 636
 
574
-        if (!isset($this->injectorsCache[$class])) {
637
+        if (!isset($this->injectorsCache[$class]))
638
+        {
575 639
             $this->injectorsCache[$class] = null;
576 640
 
577 641
             // check interfaces
578
-            foreach ($this->injectors as $target => $injector) {
642
+            foreach ($this->injectors as $target => $injector)
643
+            {
579 644
                 if (
580 645
                     \class_exists($target, true)
581 646
                     && $reflection->isSubclassOf($target)
@@ -610,9 +675,11 @@  discard block
 block discarded – undo
610 675
     private function registerInstance($instance, array $parameters)
611 676
     {
612 677
         //Declarative singletons (only when class received via direct get)
613
-        if ($parameters === [] && $instance instanceof SingletonInterface) {
678
+        if ($parameters === [] && $instance instanceof SingletonInterface)
679
+        {
614 680
             $alias = \get_class($instance);
615
-            if (!isset($this->bindings[$alias])) {
681
+            if (!isset($this->bindings[$alias]))
682
+            {
616 683
                 $this->bindings[$alias] = $instance;
617 684
             }
618 685
         }
@@ -633,19 +700,25 @@  discard block
 block discarded – undo
633 700
      */
634 701
     private function evaluateBinding(string $alias, $target, array $parameters, string $context = null)
635 702
     {
636
-        if (\is_string($target)) {
703
+        if (\is_string($target))
704
+        {
637 705
             // Reference
638 706
             return $this->make($target, $parameters, $context);
639 707
         }
640 708
 
641
-        if ($target instanceof Autowire) {
709
+        if ($target instanceof Autowire)
710
+        {
642 711
             return $target->resolve($this, $parameters);
643 712
         }
644 713
 
645
-        if ($target instanceof \Closure) {
646
-            try {
714
+        if ($target instanceof \Closure)
715
+        {
716
+            try
717
+            {
647 718
                 $reflection = new \ReflectionFunction($target);
648
-            } catch (\ReflectionException $e) {
719
+            }
720
+            catch (\ReflectionException $e)
721
+            {
649 722
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
650 723
             }
651 724
 
@@ -655,16 +728,20 @@  discard block
 block discarded – undo
655 728
             );
656 729
         }
657 730
 
658
-        if (is_array($target) && isset($target[1])) {
731
+        if (is_array($target) && isset($target[1]))
732
+        {
659 733
             // In a form of resolver and method
660 734
             [$resolver, $method] = $target;
661 735
 
662 736
             // Resolver instance (i.e. [ClassName::class, 'method'])
663 737
             $resolver = $this->get($resolver);
664 738
 
665
-            try {
739
+            try
740
+            {
666 741
                 $method = new \ReflectionMethod($resolver, $method);
667
-            } catch (\ReflectionException $e) {
742
+            }
743
+            catch (\ReflectionException $e)
744
+            {
668 745
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
669 746
             }
670 747
 
Please login to merge, or discard this patch.
src/Attributes/src/Internal/Instantiator/Instantiator.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,15 +24,15 @@  discard block
 block discarded – undo
24 24
      */
25 25
     protected function getConstructor(\ReflectionClass $class): ?\ReflectionMethod
26 26
     {
27
-        if ($class->hasMethod(self::CONSTRUCTOR_NAME)) {
27
+        if ($class->hasMethod(self::CONSTRUCTOR_NAME)){
28 28
             return $class->getMethod(self::CONSTRUCTOR_NAME);
29 29
         }
30 30
 
31
-        if ($constructor = $this->getTraitConstructors($class)) {
31
+        if ($constructor = $this->getTraitConstructors($class)){
32 32
             return $constructor;
33 33
         }
34 34
 
35
-        if ($parent = $class->getParentClass()) {
35
+        if ($parent = $class->getParentClass()){
36 36
             return $this->getConstructor($parent);
37 37
         }
38 38
 
@@ -45,12 +45,12 @@  discard block
 block discarded – undo
45 45
      */
46 46
     private function getTraitConstructors(\ReflectionClass $class): ?\ReflectionMethod
47 47
     {
48
-        foreach ($class->getTraits() as $trait) {
49
-            if ($constructor = $this->getConstructor($trait)) {
48
+        foreach ($class->getTraits() as $trait){
49
+            if ($constructor = $this->getConstructor($trait)){
50 50
                 return $constructor;
51 51
             }
52 52
 
53
-            if ($constructor = $this->getTraitConstructors($trait)) {
53
+            if ($constructor = $this->getTraitConstructors($trait)){
54 54
                 return $constructor;
55 55
             }
56 56
         }
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,15 +24,18 @@  discard block
 block discarded – undo
24 24
      */
25 25
     protected function getConstructor(\ReflectionClass $class): ?\ReflectionMethod
26 26
     {
27
-        if ($class->hasMethod(self::CONSTRUCTOR_NAME)) {
27
+        if ($class->hasMethod(self::CONSTRUCTOR_NAME))
28
+        {
28 29
             return $class->getMethod(self::CONSTRUCTOR_NAME);
29 30
         }
30 31
 
31
-        if ($constructor = $this->getTraitConstructors($class)) {
32
+        if ($constructor = $this->getTraitConstructors($class))
33
+        {
32 34
             return $constructor;
33 35
         }
34 36
 
35
-        if ($parent = $class->getParentClass()) {
37
+        if ($parent = $class->getParentClass())
38
+        {
36 39
             return $this->getConstructor($parent);
37 40
         }
38 41
 
@@ -45,12 +48,15 @@  discard block
 block discarded – undo
45 48
      */
46 49
     private function getTraitConstructors(\ReflectionClass $class): ?\ReflectionMethod
47 50
     {
48
-        foreach ($class->getTraits() as $trait) {
49
-            if ($constructor = $this->getConstructor($trait)) {
51
+        foreach ($class->getTraits() as $trait)
52
+        {
53
+            if ($constructor = $this->getConstructor($trait))
54
+            {
50 55
                 return $constructor;
51 56
             }
52 57
 
53
-            if ($constructor = $this->getTraitConstructors($trait)) {
58
+            if ($constructor = $this->getTraitConstructors($trait))
59
+            {
54 60
                 return $constructor;
55 61
             }
56 62
         }
Please login to merge, or discard this patch.
src/Attributes/src/Internal/Instantiator/DoctrineInstantiator.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      * @var string
31 31
      */
32 32
     private const ERROR_INVALID_PROPERTY =
33
-        'The attribute #[%s] declared on %s does not have a property named "%s".' . "\n" .
33
+        'The attribute #[%s] declared on %s does not have a property named "%s".'."\n".
34 34
         'Available properties: %s'
35 35
     ;
36 36
 
@@ -61,23 +61,23 @@  discard block
 block discarded – undo
61 61
         $arguments = $this->formatArguments($arguments);
62 62
 
63 63
         // Using constructor
64
-        if ($this->getConstructor($attr)) {
64
+        if ($this->getConstructor($attr)){
65 65
             return $attr->newInstance($arguments);
66 66
         }
67 67
 
68 68
         // Using direct insert
69 69
         $instance = $attr->newInstanceWithoutConstructor();
70 70
 
71
-        foreach ($arguments as $name => $value) {
72
-            try {
71
+        foreach ($arguments as $name => $value){
72
+            try{
73 73
                 $property = $attr->getProperty($name);
74 74
 
75
-                if (!$property->isPublic()) {
75
+                if (!$property->isPublic()){
76 76
                     throw $this->propertyNotFound($attr, $name, $context);
77 77
                 }
78 78
 
79 79
                 $instance->$name = $value;
80
-            } catch (\Throwable $e) {
80
+            }catch (\Throwable $e){
81 81
                 throw $this->propertyNotFound($attr, $name, $context);
82 82
             }
83 83
         }
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
     {
94 94
         $result = [];
95 95
 
96
-        foreach ($arguments as $name => $value) {
97
-            if (\is_int($name)) {
96
+        foreach ($arguments as $name => $value){
97
+            if (\is_int($name)){
98 98
                 $this->validateArgumentPosition($name, $value);
99 99
 
100 100
                 $name = self::DEFAULT_PROPERTY_NAME;
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      */
113 113
     private function validateArgumentPosition(int $index, $value): void
114 114
     {
115
-        if ($index === 0) {
115
+        if ($index === 0){
116 116
             return;
117 117
         }
118 118
 
Please login to merge, or discard this patch.
Braces   +17 added lines, -8 removed lines patch added patch discarded remove patch
@@ -61,23 +61,29 @@  discard block
 block discarded – undo
61 61
         $arguments = $this->formatArguments($arguments);
62 62
 
63 63
         // Using constructor
64
-        if ($this->getConstructor($attr)) {
64
+        if ($this->getConstructor($attr))
65
+        {
65 66
             return $attr->newInstance($arguments);
66 67
         }
67 68
 
68 69
         // Using direct insert
69 70
         $instance = $attr->newInstanceWithoutConstructor();
70 71
 
71
-        foreach ($arguments as $name => $value) {
72
-            try {
72
+        foreach ($arguments as $name => $value)
73
+        {
74
+            try
75
+            {
73 76
                 $property = $attr->getProperty($name);
74 77
 
75
-                if (!$property->isPublic()) {
78
+                if (!$property->isPublic())
79
+                {
76 80
                     throw $this->propertyNotFound($attr, $name, $context);
77 81
                 }
78 82
 
79 83
                 $instance->$name = $value;
80
-            } catch (\Throwable $e) {
84
+            }
85
+            catch (\Throwable $e)
86
+            {
81 87
                 throw $this->propertyNotFound($attr, $name, $context);
82 88
             }
83 89
         }
@@ -93,8 +99,10 @@  discard block
 block discarded – undo
93 99
     {
94 100
         $result = [];
95 101
 
96
-        foreach ($arguments as $name => $value) {
97
-            if (\is_int($name)) {
102
+        foreach ($arguments as $name => $value)
103
+        {
104
+            if (\is_int($name))
105
+            {
98 106
                 $this->validateArgumentPosition($name, $value);
99 107
 
100 108
                 $name = self::DEFAULT_PROPERTY_NAME;
@@ -112,7 +120,8 @@  discard block
 block discarded – undo
112 120
      */
113 121
     private function validateArgumentPosition(int $index, $value): void
114 122
     {
115
-        if ($index === 0) {
123
+        if ($index === 0)
124
+        {
116 125
             return;
117 126
         }
118 127
 
Please login to merge, or discard this patch.
src/SendIt/src/MailJob.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -56,15 +56,15 @@  discard block
 block discarded – undo
56 56
 
57 57
         $email = $this->renderer->render($message);
58 58
 
59
-        if ($email->getFrom() === []) {
59
+        if ($email->getFrom() === []){
60 60
             $email->from(Address::create($this->config->getFromAddress()));
61 61
         }
62 62
 
63 63
         $recipients = $this->getRecipients($email);
64 64
 
65
-        try {
65
+        try{
66 66
             $this->mailer->send($email);
67
-        } catch (TransportExceptionInterface $e) {
67
+        }catch (TransportExceptionInterface $e){
68 68
             $this->getLogger()->error(
69 69
                 sprintf(
70 70
                     'Failed to send `%s` to "%s": %s',
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
         $addresses = array_merge($message->getTo(), $message->getCc(), $message->getBcc());
100 100
 
101
-        foreach ($addresses as $address) {
101
+        foreach ($addresses as $address){
102 102
             $emails[] = $address->toString();
103 103
         }
104 104
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -56,15 +56,19 @@  discard block
 block discarded – undo
56 56
 
57 57
         $email = $this->renderer->render($message);
58 58
 
59
-        if ($email->getFrom() === []) {
59
+        if ($email->getFrom() === [])
60
+        {
60 61
             $email->from(Address::create($this->config->getFromAddress()));
61 62
         }
62 63
 
63 64
         $recipients = $this->getRecipients($email);
64 65
 
65
-        try {
66
+        try
67
+        {
66 68
             $this->mailer->send($email);
67
-        } catch (TransportExceptionInterface $e) {
69
+        }
70
+        catch (TransportExceptionInterface $e)
71
+        {
68 72
             $this->getLogger()->error(
69 73
                 sprintf(
70 74
                     'Failed to send `%s` to "%s": %s',
@@ -98,7 +102,8 @@  discard block
 block discarded – undo
98 102
 
99 103
         $addresses = array_merge($message->getTo(), $message->getCc(), $message->getBcc());
100 104
 
101
-        foreach ($addresses as $address) {
105
+        foreach ($addresses as $address)
106
+        {
102 107
             $emails[] = $address->toString();
103 108
         }
104 109
 
Please login to merge, or discard this patch.