@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | public function perform(): void |
| 23 | 23 | { |
| 24 | 24 | $prototyped = $this->locator->getTargetClasses(); |
| 25 | - if ($prototyped === []) { |
|
| 25 | + if ($prototyped === []){ |
|
| 26 | 26 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 27 | 27 | |
| 28 | 28 | return; |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 32 | 32 | |
| 33 | - foreach ($prototyped as $class) { |
|
| 33 | + foreach ($prototyped as $class){ |
|
| 34 | 34 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 35 | 35 | |
| 36 | 36 | $grid->addRow([$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]); |
@@ -58,7 +58,7 @@ discard block |
||
| 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 | $results[] = $this->readProperties($parent); |
| 63 | 63 | $parent = $parent->getParentClass(); |
| 64 | 64 | } |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | { |
| 92 | 92 | $result = []; |
| 93 | 93 | |
| 94 | - foreach ($properties as $target) { |
|
| 95 | - if ($target instanceof \Throwable) { |
|
| 94 | + foreach ($properties as $target){ |
|
| 95 | + if ($target instanceof \Throwable){ |
|
| 96 | 96 | $result[] = sprintf( |
| 97 | 97 | '<fg=red>%s [f: %s, l: %s]</fg=red>', |
| 98 | 98 | $target->getMessage(), |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if ($target === null) { |
|
| 105 | + if ($target === null){ |
|
| 106 | 106 | $result[] = '<fg=yellow>undefined</fg=yellow>'; |
| 107 | 107 | continue; |
| 108 | 108 | } |
@@ -115,16 +115,16 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | private function readProperties(\ReflectionClass $class): array |
| 117 | 117 | { |
| 118 | - if (isset($this->cache[$class->getFileName()])) { |
|
| 118 | + if (isset($this->cache[$class->getFileName()])){ |
|
| 119 | 119 | $proto = $this->cache[$class->getFileName()]; |
| 120 | - } else { |
|
| 120 | + }else{ |
|
| 121 | 121 | $proto = $this->getExtractor()->getPrototypeProperties(file_get_contents($class->getFilename())); |
| 122 | 122 | $this->cache[$class->getFileName()] = $proto; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $result = []; |
| 126 | - foreach ($proto as $name) { |
|
| 127 | - if (!isset($result[$name])) { |
|
| 126 | + foreach ($proto as $name){ |
|
| 127 | + if (!isset($result[$name])){ |
|
| 128 | 128 | $result[$name] = $this->registry->resolveProperty($name); |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | private function reverse(array $results): ?\Generator |
| 136 | 136 | { |
| 137 | - foreach (array_reverse($results) as $result) { |
|
| 137 | + foreach (array_reverse($results) as $result){ |
|
| 138 | 138 | yield from $result; |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | public function perform(): void |
| 52 | 52 | { |
| 53 | 53 | $prototyped = $this->locator->getTargetClasses(); |
| 54 | - if ($prototyped === []) { |
|
| 54 | + if ($prototyped === []){ |
|
| 55 | 55 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 56 | 56 | |
| 57 | 57 | return; |
@@ -59,18 +59,18 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $targets = []; |
| 61 | 61 | |
| 62 | - foreach ($prototyped as $class) { |
|
| 62 | + foreach ($prototyped as $class){ |
|
| 63 | 63 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 64 | - if (empty($proto)) { |
|
| 64 | + if (empty($proto)){ |
|
| 65 | 65 | $modified = $this->modify($class, $proto); |
| 66 | - if ($modified !== null) { |
|
| 66 | + if ($modified !== null){ |
|
| 67 | 67 | $targets[] = $modified; |
| 68 | 68 | } |
| 69 | 69 | continue; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - foreach ($proto as $target) { |
|
| 73 | - if ($target instanceof \Throwable) { |
|
| 72 | + foreach ($proto as $target){ |
|
| 73 | + if ($target instanceof \Throwable){ |
|
| 74 | 74 | $targets[] = [ |
| 75 | 75 | $class->getName(), |
| 76 | 76 | $target->getMessage(), |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | continue 2; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if ($target === null) { |
|
| 82 | + if ($target === null){ |
|
| 83 | 83 | continue 2; |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -87,14 +87,14 @@ discard block |
||
| 87 | 87 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
| 88 | 88 | |
| 89 | 89 | $modified = $this->modify($class, $proto); |
| 90 | - if ($modified !== null) { |
|
| 90 | + if ($modified !== null){ |
|
| 91 | 91 | $targets[] = $modified; |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if (!empty($targets)) { |
|
| 95 | + if (!empty($targets)){ |
|
| 96 | 96 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 97 | - foreach ($targets as $target) { |
|
| 97 | + foreach ($targets as $target){ |
|
| 98 | 98 | $grid->addRow($target); |
| 99 | 99 | } |
| 100 | 100 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | private function modify(\ReflectionClass $class, array $proto): ?array |
| 106 | 106 | { |
| 107 | 107 | $classDefinition = $this->extractor->extract($class->getFilename(), $proto); |
| 108 | - try { |
|
| 108 | + try{ |
|
| 109 | 109 | $modified = $this->injector->injectDependencies( |
| 110 | 110 | file_get_contents($class->getFileName()), |
| 111 | 111 | $classDefinition, |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | file_put_contents($class->getFileName(), $modified); |
| 118 | 118 | return null; |
| 119 | - } catch (\Throwable $e) { |
|
| 119 | + }catch (\Throwable $e){ |
|
| 120 | 120 | return [$class->getName(), $e->getMessage(), "{$e->getFile()}:L{$e->getLine()}"]; |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | public function setUp(): void |
| 29 | 29 | { |
| 30 | - if ((string)ini_get('zend.assertions') === 1) { |
|
| 30 | + if ((string)ini_get('zend.assertions') === 1){ |
|
| 31 | 31 | ini_set('zend.assertions', 0); |
| 32 | 32 | } |
| 33 | 33 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | $i = new Injector(); |
| 42 | 42 | |
| 43 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 43 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 44 | 44 | $printed = $i->injectDependencies( |
| 45 | 45 | file_get_contents($filename), |
| 46 | 46 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | ): void { |
| 67 | 67 | $i = new Injector(); |
| 68 | 68 | |
| 69 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 69 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 70 | 70 | $printed = $i->injectDependencies( |
| 71 | 71 | file_get_contents($filename), |
| 72 | 72 | $this->getDefinition($filename, ['testClass' => TestClass::class]), |
@@ -75,15 +75,15 @@ discard block |
||
| 75 | 75 | $noPhpDoc |
| 76 | 76 | ); |
| 77 | 77 | |
| 78 | - if ($expectedTypedProperty) { |
|
| 78 | + if ($expectedTypedProperty){ |
|
| 79 | 79 | $this->assertStringContainsString('private TestClass $testClass;', $printed); |
| 80 | - } else { |
|
| 80 | + }else{ |
|
| 81 | 81 | $this->assertStringNotContainsString('private TestClass $testClass;', $printed); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if ($expectedPhpDoc) { |
|
| 84 | + if ($expectedPhpDoc){ |
|
| 85 | 85 | $this->assertRegExp('/@var TestClass[\s|\r\n]/', $printed); |
| 86 | - } else { |
|
| 86 | + }else{ |
|
| 87 | 87 | $this->assertNotRegExp('/@var TestClass[\s|\r\n]/', $printed); |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | { |
| 107 | 107 | $i = new Injector(); |
| 108 | 108 | |
| 109 | - $filename = __DIR__ . '/Fixtures/TestEmptyClass.php'; |
|
| 109 | + $filename = __DIR__.'/Fixtures/TestEmptyClass.php'; |
|
| 110 | 110 | $content = file_get_contents($filename); |
| 111 | 111 | $printed = $i->injectDependencies( |
| 112 | 112 | file_get_contents($filename), |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | { |
| 125 | 125 | $i = new Injector(); |
| 126 | 126 | |
| 127 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 127 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 128 | 128 | $r = $i->injectDependencies( |
| 129 | 129 | file_get_contents($filename), |
| 130 | 130 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | { |
| 150 | 150 | $i = new Injector(); |
| 151 | 151 | |
| 152 | - $filename = __DIR__ . '/Fixtures/ChildClass.php'; |
|
| 152 | + $filename = __DIR__.'/Fixtures/ChildClass.php'; |
|
| 153 | 153 | $r = $i->injectDependencies( |
| 154 | 154 | file_get_contents($filename), |
| 155 | 155 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | { |
| 168 | 168 | $i = new Injector(); |
| 169 | 169 | |
| 170 | - $filename = __DIR__ . '/Fixtures/ChildWithConstructorClass.php'; |
|
| 170 | + $filename = __DIR__.'/Fixtures/ChildWithConstructorClass.php'; |
|
| 171 | 171 | $r = $i->injectDependencies( |
| 172 | 172 | file_get_contents($filename), |
| 173 | 173 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | public function testModifyConstructor(): void |
| 185 | 185 | { |
| 186 | - $filename = __DIR__ . '/Fixtures/WithConstructor.php'; |
|
| 186 | + $filename = __DIR__.'/Fixtures/WithConstructor.php'; |
|
| 187 | 187 | $extractor = new Traverse\Extractor(); |
| 188 | 188 | |
| 189 | 189 | $parameters = $extractor->extractFromFilename($filename); |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | public function testPriorOptionalConstructorParameters(): void |
| 211 | 211 | { |
| 212 | - $filename = __DIR__ . '/Fixtures/OptionalConstructorArgsClass.php'; |
|
| 212 | + $filename = __DIR__.'/Fixtures/OptionalConstructorArgsClass.php'; |
|
| 213 | 213 | $extractor = new Traverse\Extractor(); |
| 214 | 214 | |
| 215 | 215 | $parameters = $extractor->extractFromFilename($filename); |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | { |
| 241 | 241 | $i = new Injector(); |
| 242 | 242 | |
| 243 | - $filename = __DIR__ . '/ClassNode/ConflictResolver/Fixtures/ChildClass.php'; |
|
| 243 | + $filename = __DIR__.'/ClassNode/ConflictResolver/Fixtures/ChildClass.php'; |
|
| 244 | 244 | $printed = $i->injectDependencies( |
| 245 | 245 | file_get_contents($filename), |
| 246 | 246 | $this->getDefinition( |
@@ -42,13 +42,13 @@ discard block |
||
| 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 | return null; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $constructor = $this->getConstructorAttribute($node); |
| 50 | 50 | $this->addDependencies($constructor); |
| 51 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
| 51 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams){ |
|
| 52 | 52 | $this->addParentConstructorCall($constructor); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
| 68 | 68 | { |
| 69 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 69 | + foreach ($this->definition->dependencies as $dependency){ |
|
| 70 | 70 | array_unshift($constructor->params, $this->buildConstructorParam($dependency)); |
| 71 | 71 | array_unshift( |
| 72 | 72 | $constructor->stmts, |
@@ -92,34 +92,34 @@ discard block |
||
| 92 | 92 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
| 93 | 93 | { |
| 94 | 94 | $parentConstructorDependencies = []; |
| 95 | - foreach ($this->definition->constructorParams as $param) { |
|
| 95 | + foreach ($this->definition->constructorParams as $param){ |
|
| 96 | 96 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
| 97 | 97 | |
| 98 | 98 | $cp = new Param($param->name); |
| 99 | - if (!empty($param->type)) { |
|
| 99 | + if (!empty($param->type)){ |
|
| 100 | 100 | $type = $this->getParamType($param); |
| 101 | - if ($param->nullable) { |
|
| 101 | + if ($param->nullable){ |
|
| 102 | 102 | $type = "?$type"; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $cp->setType(new Node\Name($type)); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if ($param->byRef) { |
|
| 108 | + if ($param->byRef){ |
|
| 109 | 109 | $cp->makeByRef(); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if ($param->isVariadic) { |
|
| 112 | + if ($param->isVariadic){ |
|
| 113 | 113 | $cp->makeVariadic(); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ($param->hasDefault) { |
|
| 116 | + if ($param->hasDefault){ |
|
| 117 | 117 | $cp->setDefault($param->default); |
| 118 | 118 | } |
| 119 | 119 | $constructor->params[] = $cp->getNode(); |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - if ($parentConstructorDependencies) { |
|
| 122 | + if ($parentConstructorDependencies){ |
|
| 123 | 123 | array_unshift( |
| 124 | 124 | $constructor->stmts, |
| 125 | 125 | new Node\Stmt\Expression( |
@@ -154,18 +154,18 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | $params = []; |
| 156 | 156 | |
| 157 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 157 | + foreach ($this->definition->dependencies as $dependency){ |
|
| 158 | 158 | $params[] = new Annotation\Line( |
| 159 | 159 | sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), |
| 160 | 160 | 'param' |
| 161 | 161 | ); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - if (!$this->definition->hasConstructor) { |
|
| 165 | - foreach ($this->definition->constructorParams as $param) { |
|
| 166 | - if (!empty($param->type)) { |
|
| 164 | + if (!$this->definition->hasConstructor){ |
|
| 165 | + foreach ($this->definition->constructorParams as $param){ |
|
| 166 | + if (!empty($param->type)){ |
|
| 167 | 167 | $type = $this->getParamType($param); |
| 168 | - if ($param->nullable) { |
|
| 168 | + if ($param->nullable){ |
|
| 169 | 169 | $type = "$type|null"; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), |
| 174 | 174 | 'param' |
| 175 | 175 | ); |
| 176 | - } else { |
|
| 176 | + }else{ |
|
| 177 | 177 | $params[] = new Annotation\Line( |
| 178 | 178 | sprintf('$%s', $param->name), |
| 179 | 179 | 'param' |
@@ -184,12 +184,12 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | $placementID = 0; |
| 186 | 186 | $previous = null; |
| 187 | - foreach ($an->lines as $index => $line) { |
|
| 187 | + foreach ($an->lines as $index => $line){ |
|
| 188 | 188 | // always next node |
| 189 | 189 | $placementID = $index + 1; |
| 190 | 190 | |
| 191 | 191 | // inject before this parameters |
| 192 | - if ($line->is(['throws', 'return'])) { |
|
| 192 | + if ($line->is(['throws', 'return'])){ |
|
| 193 | 193 | // insert before given node |
| 194 | 194 | $placementID--; |
| 195 | 195 | break; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $previous = $line; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - if ($previous !== null && !$previous->isEmpty()) { |
|
| 201 | + if ($previous !== null && !$previous->isEmpty()){ |
|
| 202 | 202 | $placementID++; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -213,9 +213,9 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | private function getPropertyType(Dependency $dependency): string |
| 215 | 215 | { |
| 216 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 217 | - if ($stmt->name === $dependency->type->fullName) { |
|
| 218 | - if ($stmt->alias) { |
|
| 216 | + foreach ($this->definition->getStmts() as $stmt){ |
|
| 217 | + if ($stmt->name === $dependency->type->fullName){ |
|
| 218 | + if ($stmt->alias){ |
|
| 219 | 219 | return $stmt->alias; |
| 220 | 220 | } |
| 221 | 221 | } |
@@ -230,15 +230,15 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | private function getParamType(ClassNode\ConstructorParam $param): string |
| 232 | 232 | { |
| 233 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 234 | - if ($stmt->name === $param->type->fullName) { |
|
| 235 | - if ($stmt->alias) { |
|
| 233 | + foreach ($this->definition->getStmts() as $stmt){ |
|
| 234 | + if ($stmt->name === $param->type->fullName){ |
|
| 235 | + if ($stmt->alias){ |
|
| 236 | 236 | return $stmt->alias; |
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if ($param->type->alias) { |
|
| 241 | + if ($param->type->alias){ |
|
| 242 | 242 | return $param->type->alias; |
| 243 | 243 | } |
| 244 | 244 | |