Passed
Pull Request — master (#361)
by Valentin
05:12
created
src/Prototype/src/Command/ListCommand.php 1 patch
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,7 +22,8 @@  discard block
 block discarded – undo
22 22
     public function perform(): void
23 23
     {
24 24
         $prototyped = $this->locator->getTargetClasses();
25
-        if ($prototyped === []) {
25
+        if ($prototyped === [])
26
+        {
26 27
             $this->writeln('<comment>No prototyped classes found.</comment>');
27 28
 
28 29
             return;
@@ -30,7 +31,8 @@  discard block
 block discarded – undo
30 31
 
31 32
         $grid = $this->table(['Class:', 'Property:', 'Target:']);
32 33
 
33
-        foreach ($prototyped as $class) {
34
+        foreach ($prototyped as $class)
35
+        {
34 36
             $proto = $this->getPrototypeProperties($class, $prototyped);
35 37
 
36 38
             $grid->addRow([$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]);
Please login to merge, or discard this patch.
src/Prototype/src/Command/AbstractCommand.php 1 patch
Braces   +19 added lines, -9 removed lines patch added patch discarded remove patch
@@ -58,7 +58,8 @@  discard block
 block discarded – undo
58 58
         $results = [$this->readProperties($class)];
59 59
 
60 60
         $parent = $class->getParentClass();
61
-        while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) {
61
+        while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()]))
62
+        {
62 63
             $results[] = $this->readProperties($parent);
63 64
             $parent = $parent->getParentClass();
64 65
         }
@@ -91,8 +92,10 @@  discard block
 block discarded – undo
91 92
     {
92 93
         $result = [];
93 94
 
94
-        foreach ($properties as $target) {
95
-            if ($target instanceof \Throwable) {
95
+        foreach ($properties as $target)
96
+        {
97
+            if ($target instanceof \Throwable)
98
+            {
96 99
                 $result[] = sprintf(
97 100
                     '<fg=red>%s [f: %s, l: %s]</fg=red>',
98 101
                     $target->getMessage(),
@@ -102,7 +105,8 @@  discard block
 block discarded – undo
102 105
                 continue;
103 106
             }
104 107
 
105
-            if ($target === null) {
108
+            if ($target === null)
109
+            {
106 110
                 $result[] = '<fg=yellow>undefined</fg=yellow>';
107 111
                 continue;
108 112
             }
@@ -115,16 +119,21 @@  discard block
 block discarded – undo
115 119
 
116 120
     private function readProperties(\ReflectionClass $class): array
117 121
     {
118
-        if (isset($this->cache[$class->getFileName()])) {
122
+        if (isset($this->cache[$class->getFileName()]))
123
+        {
119 124
             $proto = $this->cache[$class->getFileName()];
120
-        } else {
125
+        }
126
+        else
127
+        {
121 128
             $proto = $this->getExtractor()->getPrototypeProperties(file_get_contents($class->getFilename()));
122 129
             $this->cache[$class->getFileName()] = $proto;
123 130
         }
124 131
 
125 132
         $result = [];
126
-        foreach ($proto as $name) {
127
-            if (!isset($result[$name])) {
133
+        foreach ($proto as $name)
134
+        {
135
+            if (!isset($result[$name]))
136
+            {
128 137
                 $result[$name] = $this->registry->resolveProperty($name);
129 138
             }
130 139
         }
@@ -134,7 +143,8 @@  discard block
 block discarded – undo
134 143
 
135 144
     private function reverse(array $results): ?\Generator
136 145
     {
137
-        foreach (array_reverse($results) as $result) {
146
+        foreach (array_reverse($results) as $result)
147
+        {
138 148
             yield from $result;
139 149
         }
140 150
     }
Please login to merge, or discard this patch.
src/Prototype/src/Command/InjectCommand.php 1 patch
Braces   +25 added lines, -12 removed lines patch added patch discarded remove patch
@@ -55,7 +55,8 @@  discard block
 block discarded – undo
55 55
     public function perform(): void
56 56
     {
57 57
         $prototyped = $this->locator->getTargetClasses();
58
-        if ($prototyped === []) {
58
+        if ($prototyped === [])
59
+        {
59 60
             $this->writeln('<comment>No prototyped classes found.</comment>');
60 61
 
61 62
             return;
@@ -63,18 +64,23 @@  discard block
 block discarded – undo
63 64
 
64 65
         $targets = [];
65 66
 
66
-        foreach ($prototyped as $class) {
67
+        foreach ($prototyped as $class)
68
+        {
67 69
             $proto = $this->getPrototypeProperties($class, $prototyped);
68
-            if (empty($proto)) {
70
+            if (empty($proto))
71
+            {
69 72
                 $modified = $this->modify($class, $proto);
70
-                if ($modified !== null) {
73
+                if ($modified !== null)
74
+                {
71 75
                     $targets[] = $modified;
72 76
                 }
73 77
                 continue;
74 78
             }
75 79
 
76
-            foreach ($proto as $target) {
77
-                if ($target instanceof \Throwable) {
80
+            foreach ($proto as $target)
81
+            {
82
+                if ($target instanceof \Throwable)
83
+                {
78 84
                     $targets[] = [
79 85
                         $class->getName(),
80 86
                         $target->getMessage(),
@@ -83,7 +89,8 @@  discard block
 block discarded – undo
83 89
                     continue 2;
84 90
                 }
85 91
 
86
-                if ($target === null) {
92
+                if ($target === null)
93
+                {
87 94
                     continue 2;
88 95
                 }
89 96
             }
@@ -91,14 +98,17 @@  discard block
 block discarded – undo
91 98
             $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)];
92 99
 
93 100
             $modified = $this->modify($class, $proto);
94
-            if ($modified !== null) {
101
+            if ($modified !== null)
102
+            {
95 103
                 $targets[] = $modified;
96 104
             }
97 105
         }
98 106
 
99
-        if (!empty($targets)) {
107
+        if (!empty($targets))
108
+        {
100 109
             $grid = $this->table(['Class:', 'Property:', 'Target:']);
101
-            foreach ($targets as $target) {
110
+            foreach ($targets as $target)
111
+            {
102 112
                 $grid->addRow($target);
103 113
             }
104 114
 
@@ -109,7 +119,8 @@  discard block
 block discarded – undo
109 119
     private function modify(\ReflectionClass $class, array $proto): ?array
110 120
     {
111 121
         $classDefinition = $this->extractor->extract($class->getFilename(), $proto);
112
-        try {
122
+        try
123
+        {
113 124
             $modified = $this->injector->injectDependencies(
114 125
                 file_get_contents($class->getFileName()),
115 126
                 $classDefinition,
@@ -120,7 +131,9 @@  discard block
 block discarded – undo
120 131
 
121 132
             file_put_contents($class->getFileName(), $modified);
122 133
             return null;
123
-        } catch (\Throwable $e) {
134
+        }
135
+        catch (\Throwable $e)
136
+        {
124 137
             return [$class->getName(), $e->getMessage(), "{$e->getFile()}:L{$e->getLine()}"];
125 138
         }
126 139
     }
Please login to merge, or discard this patch.
src/Prototype/src/NodeVisitors/UpdateConstructor.php 1 patch
Braces   +53 added lines, -26 removed lines patch added patch discarded remove patch
@@ -42,13 +42,15 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function leaveNode(Node $node)
44 44
     {
45
-        if (!$node instanceof Node\Stmt\Class_) {
45
+        if (!$node instanceof Node\Stmt\Class_)
46
+        {
46 47
             return null;
47 48
         }
48 49
 
49 50
         $constructor = $this->getConstructorAttribute($node);
50 51
         $this->addDependencies($constructor);
51
-        if (!$this->definition->hasConstructor && $this->definition->constructorParams) {
52
+        if (!$this->definition->hasConstructor && $this->definition->constructorParams)
53
+        {
52 54
             $this->addParentConstructorCall($constructor);
53 55
         }
54 56
 
@@ -66,7 +68,8 @@  discard block
 block discarded – undo
66 68
      */
67 69
     private function addDependencies(Node\Stmt\ClassMethod $constructor): void
68 70
     {
69
-        foreach ($this->definition->dependencies as $dependency) {
71
+        foreach ($this->definition->dependencies as $dependency)
72
+        {
70 73
             array_unshift($constructor->params, $this->buildConstructorParam($dependency));
71 74
             array_unshift(
72 75
                 $constructor->stmts,
@@ -92,34 +95,41 @@  discard block
 block discarded – undo
92 95
     private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void
93 96
     {
94 97
         $parentConstructorDependencies = [];
95
-        foreach ($this->definition->constructorParams as $param) {
98
+        foreach ($this->definition->constructorParams as $param)
99
+        {
96 100
             $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name));
97 101
 
98 102
             $cp = new Param($param->name);
99
-            if (!empty($param->type)) {
103
+            if (!empty($param->type))
104
+            {
100 105
                 $type = $this->getParamType($param);
101
-                if ($param->nullable) {
106
+                if ($param->nullable)
107
+                {
102 108
                     $type = "?$type";
103 109
                 }
104 110
 
105 111
                 $cp->setType(new Node\Name($type));
106 112
             }
107 113
 
108
-            if ($param->byRef) {
114
+            if ($param->byRef)
115
+            {
109 116
                 $cp->makeByRef();
110 117
             }
111 118
 
112
-            if ($param->isVariadic) {
119
+            if ($param->isVariadic)
120
+            {
113 121
                 $cp->makeVariadic();
114 122
             }
115 123
 
116
-            if ($param->hasDefault) {
124
+            if ($param->hasDefault)
125
+            {
117 126
                 $cp->setDefault($param->default);
118 127
             }
119 128
             $constructor->params[] = $cp->getNode();
120 129
         }
121 130
 
122
-        if ($parentConstructorDependencies) {
131
+        if ($parentConstructorDependencies)
132
+        {
123 133
             array_unshift(
124 134
                 $constructor->stmts,
125 135
                 new Node\Stmt\Expression(
@@ -154,18 +164,23 @@  discard block
 block discarded – undo
154 164
 
155 165
         $params = [];
156 166
 
157
-        foreach ($this->definition->dependencies as $dependency) {
167
+        foreach ($this->definition->dependencies as $dependency)
168
+        {
158 169
             $params[] = new Annotation\Line(
159 170
                 sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var),
160 171
                 'param'
161 172
             );
162 173
         }
163 174
 
164
-        if (!$this->definition->hasConstructor) {
165
-            foreach ($this->definition->constructorParams as $param) {
166
-                if (!empty($param->type)) {
175
+        if (!$this->definition->hasConstructor)
176
+        {
177
+            foreach ($this->definition->constructorParams as $param)
178
+            {
179
+                if (!empty($param->type))
180
+                {
167 181
                     $type = $this->getParamType($param);
168
-                    if ($param->nullable) {
182
+                    if ($param->nullable)
183
+                    {
169 184
                         $type = "$type|null";
170 185
                     }
171 186
 
@@ -173,7 +188,9 @@  discard block
 block discarded – undo
173 188
                         sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name),
174 189
                         'param'
175 190
                     );
176
-                } else {
191
+                }
192
+                else
193
+                {
177 194
                     $params[] = new Annotation\Line(
178 195
                         sprintf('$%s', $param->name),
179 196
                         'param'
@@ -184,12 +201,14 @@  discard block
 block discarded – undo
184 201
 
185 202
         $placementID = 0;
186 203
         $previous = null;
187
-        foreach ($an->lines as $index => $line) {
204
+        foreach ($an->lines as $index => $line)
205
+        {
188 206
             // always next node
189 207
             $placementID = $index + 1;
190 208
 
191 209
             // inject before this parameters
192
-            if ($line->is(['throws', 'return'])) {
210
+            if ($line->is(['throws', 'return']))
211
+            {
193 212
                 // insert before given node
194 213
                 $placementID--;
195 214
                 break;
@@ -198,7 +217,8 @@  discard block
 block discarded – undo
198 217
             $previous = $line;
199 218
         }
200 219
 
201
-        if ($previous !== null && !$previous->isEmpty()) {
220
+        if ($previous !== null && !$previous->isEmpty())
221
+        {
202 222
             $placementID++;
203 223
         }
204 224
 
@@ -213,9 +233,12 @@  discard block
 block discarded – undo
213 233
      */
214 234
     private function getPropertyType(Dependency $dependency): string
215 235
     {
216
-        foreach ($this->definition->getStmts() as $stmt) {
217
-            if ($stmt->name === $dependency->type->fullName) {
218
-                if ($stmt->alias) {
236
+        foreach ($this->definition->getStmts() as $stmt)
237
+        {
238
+            if ($stmt->name === $dependency->type->fullName)
239
+            {
240
+                if ($stmt->alias)
241
+                {
219 242
                     return $stmt->alias;
220 243
                 }
221 244
             }
@@ -230,15 +253,19 @@  discard block
 block discarded – undo
230 253
      */
231 254
     private function getParamType(ClassNode\ConstructorParam $param): string
232 255
     {
233
-        foreach ($this->definition->getStmts() as $stmt) {
234
-            if ($stmt->name === $param->type->fullName) {
235
-                if ($stmt->alias) {
256
+        foreach ($this->definition->getStmts() as $stmt)
257
+        {
258
+            if ($stmt->name === $param->type->fullName)
259
+            {
260
+                if ($stmt->alias)
261
+                {
236 262
                     return $stmt->alias;
237 263
                 }
238 264
             }
239 265
         }
240 266
 
241
-        if ($param->type->alias) {
267
+        if ($param->type->alias)
268
+        {
242 269
             return $param->type->alias;
243 270
         }
244 271
 
Please login to merge, or discard this patch.