@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | public function setUp(): void |
| 22 | 22 | { |
| 23 | - if ((string)ini_get('zend.assertions') === 1) { |
|
| 23 | + if ((string)ini_get('zend.assertions') === 1){ |
|
| 24 | 24 | ini_set('zend.assertions', 0); |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | $i = new Injector(); |
| 35 | 35 | |
| 36 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 36 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 37 | 37 | $printed = $i->injectDependencies( |
| 38 | 38 | file_get_contents($filename), |
| 39 | 39 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | { |
| 47 | 47 | $i = new Injector(); |
| 48 | 48 | |
| 49 | - $filename = __DIR__ . '/Fixtures/WithPromotedProperty.php'; |
|
| 49 | + $filename = __DIR__.'/Fixtures/WithPromotedProperty.php'; |
|
| 50 | 50 | $printed = $i->injectDependencies( |
| 51 | 51 | file_get_contents($filename), |
| 52 | 52 | $this->getDefinition($filename, ['two' => InjectionTwo::class]) |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | { |
| 67 | 67 | $i = new Injector(); |
| 68 | 68 | |
| 69 | - $filename = __DIR__ . '/Fixtures/TestEmptyClass.php'; |
|
| 69 | + $filename = __DIR__.'/Fixtures/TestEmptyClass.php'; |
|
| 70 | 70 | $content = file_get_contents($filename); |
| 71 | 71 | $printed = $i->injectDependencies( |
| 72 | 72 | file_get_contents($filename), |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | { |
| 85 | 85 | $i = new Injector(); |
| 86 | 86 | |
| 87 | - $filename = __DIR__ . '/Fixtures/TestClass.php'; |
|
| 87 | + $filename = __DIR__.'/Fixtures/TestClass.php'; |
|
| 88 | 88 | $r = $i->injectDependencies( |
| 89 | 89 | file_get_contents($filename), |
| 90 | 90 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | { |
| 110 | 110 | $i = new Injector(); |
| 111 | 111 | |
| 112 | - $filename = __DIR__ . '/Fixtures/ChildClass.php'; |
|
| 112 | + $filename = __DIR__.'/Fixtures/ChildClass.php'; |
|
| 113 | 113 | $r = $i->injectDependencies( |
| 114 | 114 | file_get_contents($filename), |
| 115 | 115 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | { |
| 128 | 128 | $i = new Injector(); |
| 129 | 129 | |
| 130 | - $filename = __DIR__ . '/Fixtures/ChildWithConstructorClass.php'; |
|
| 130 | + $filename = __DIR__.'/Fixtures/ChildWithConstructorClass.php'; |
|
| 131 | 131 | $r = $i->injectDependencies( |
| 132 | 132 | file_get_contents($filename), |
| 133 | 133 | $this->getDefinition($filename, ['testClass' => TestClass::class]) |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | public function testModifyConstructor(): void |
| 145 | 145 | { |
| 146 | - $filename = __DIR__ . '/Fixtures/WithConstructor.php'; |
|
| 146 | + $filename = __DIR__.'/Fixtures/WithConstructor.php'; |
|
| 147 | 147 | $extractor = new Extractor(); |
| 148 | 148 | |
| 149 | 149 | $parameters = $extractor->extractFromFilename($filename); |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | public function testPriorOptionalConstructorParameters(): void |
| 171 | 171 | { |
| 172 | - $filename = __DIR__ . '/Fixtures/OptionalConstructorArgsClass.php'; |
|
| 172 | + $filename = __DIR__.'/Fixtures/OptionalConstructorArgsClass.php'; |
|
| 173 | 173 | $extractor = new Extractor(); |
| 174 | 174 | |
| 175 | 175 | $parameters = $extractor->extractFromFilename($filename); |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | { |
| 201 | 201 | $i = new Injector(); |
| 202 | 202 | |
| 203 | - $filename = __DIR__ . '/ClassNode/ConflictResolver/Fixtures/ChildClass.php'; |
|
| 203 | + $filename = __DIR__.'/ClassNode/ConflictResolver/Fixtures/ChildClass.php'; |
|
| 204 | 204 | $printed = $i->injectDependencies( |
| 205 | 205 | file_get_contents($filename), |
| 206 | 206 | $this->getDefinition( |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | private readonly Names $namesResolver, |
| 28 | 28 | private readonly Namespaces $namespacesResolver, |
| 29 | 29 | Parser $parser = null |
| 30 | - ) { |
|
| 30 | + ){ |
|
| 31 | 31 | $this->parser = $parser ?? (new ParserFactory())->create(ParserFactory::ONLY_PHP7); |
| 32 | 32 | } |
| 33 | 33 | |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | $declarator = new DeclareClass(); |
| 61 | 61 | $this->traverse($filename, $declarator); |
| 62 | 62 | |
| 63 | - if (empty($declarator->getClass())) { |
|
| 63 | + if (empty($declarator->getClass())){ |
|
| 64 | 64 | throw new ClassNotDeclaredException($filename); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if ($declarator->getNamespace()) { |
|
| 67 | + if ($declarator->getNamespace()){ |
|
| 68 | 68 | return ClassNode::createWithNamespace($declarator->getClass(), $declarator->getNamespace()); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | { |
| 76 | 76 | $tr = new NodeTraverser(); |
| 77 | 77 | |
| 78 | - foreach ($visitors as $visitor) { |
|
| 78 | + foreach ($visitors as $visitor){ |
|
| 79 | 79 | $tr->addVisitor($visitor); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | private function fillStmts(ClassNode $definition, array $imports): void |
| 86 | 86 | { |
| 87 | - foreach ($imports as $import) { |
|
| 87 | + foreach ($imports as $import){ |
|
| 88 | 88 | $definition->addImportUsage($import['name'], $import['alias']); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | $reflection = new \ReflectionClass(\sprintf('%s\%s', $definition->namespace, $definition->class)); |
| 98 | 98 | |
| 99 | 99 | $constructor = $reflection->getConstructor(); |
| 100 | - if ($constructor !== null) { |
|
| 100 | + if ($constructor !== null){ |
|
| 101 | 101 | $definition->hasConstructor = $constructor->getDeclaringClass()->getName() === $reflection->getName(); |
| 102 | 102 | |
| 103 | - foreach ($reflection->getConstructor()->getParameters() as $parameter) { |
|
| 103 | + foreach ($reflection->getConstructor()->getParameters() as $parameter){ |
|
| 104 | 104 | $definition->addParam($parameter); |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | private function fillConstructorVars(array $vars, ClassNode $definition): void |
| 114 | 114 | { |
| 115 | - foreach ($vars as $k => $var) { |
|
| 116 | - if (isset($definition->constructorParams[$var])) { |
|
| 115 | + foreach ($vars as $k => $var){ |
|
| 116 | + if (isset($definition->constructorParams[$var])){ |
|
| 117 | 117 | unset($vars[$k]); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | public function __construct( |
| 31 | 31 | Lexer $lexer = null, |
| 32 | 32 | private readonly PrettyPrinterAbstract $printer = new Standard() |
| 33 | - ) { |
|
| 33 | + ){ |
|
| 34 | 34 | $this->lexer = $lexer ?? new Emulative([ |
| 35 | 35 | 'usedAttributes' => [ |
| 36 | 36 | 'comments', |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function injectDependencies(string $code, ClassNode $node, bool $removeTrait = false): string |
| 55 | 55 | { |
| 56 | - if (empty($node->dependencies)) { |
|
| 57 | - if ($removeTrait) { |
|
| 56 | + if (empty($node->dependencies)){ |
|
| 57 | + if ($removeTrait){ |
|
| 58 | 58 | $tr = new NodeTraverser(); |
| 59 | 59 | $tr->addVisitor(new RemoveUse()); |
| 60 | 60 | $tr->addVisitor(new RemoveTrait()); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $tr = new NodeTraverser(); |
| 69 | 69 | $tr->addVisitor(new AddUse($node)); |
| 70 | 70 | |
| 71 | - if ($removeTrait) { |
|
| 71 | + if ($removeTrait){ |
|
| 72 | 72 | $tr->addVisitor(new RemoveUse()); |
| 73 | 73 | $tr->addVisitor(new RemoveTrait()); |
| 74 | 74 | } |
@@ -45,13 +45,13 @@ discard block |
||
| 45 | 45 | $node->var instanceof Variable && |
| 46 | 46 | $node->var->name === 'this' && |
| 47 | 47 | $node->name instanceof Identifier |
| 48 | - ) { |
|
| 48 | + ){ |
|
| 49 | 49 | $this->requested[$node->name->name] = $node->name->name; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - if ($node instanceof Property) { |
|
| 53 | - foreach ($node->props as $prop) { |
|
| 54 | - if ($prop instanceof PropertyProperty) { |
|
| 52 | + if ($node instanceof Property){ |
|
| 53 | + foreach ($node->props as $prop){ |
|
| 54 | + if ($prop instanceof PropertyProperty){ |
|
| 55 | 55 | $this->properties[$prop->name->name] = $prop->name->name; |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | private function promotedProperties(Node $node): void |
| 64 | 64 | { |
| 65 | - if (!$node instanceof Param || !$node->var instanceof Variable) { |
|
| 65 | + if (!$node instanceof Param || !$node->var instanceof Variable){ |
|
| 66 | 66 | return; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $node->flags & Class_::MODIFIER_PUBLIC || |
| 71 | 71 | $node->flags & Class_::MODIFIER_PROTECTED || |
| 72 | 72 | $node->flags & Class_::MODIFIER_PRIVATE |
| 73 | - ) { |
|
| 73 | + ){ |
|
| 74 | 74 | $this->properties[$node->var->name] = $node->var->name; |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -49,9 +49,12 @@ discard block |
||
| 49 | 49 | $this->requested[$node->name->name] = $node->name->name; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - if ($node instanceof Property) { |
|
| 53 | - foreach ($node->props as $prop) { |
|
| 54 | - if ($prop instanceof PropertyProperty) { |
|
| 52 | + if ($node instanceof Property) |
|
| 53 | + { |
|
| 54 | + foreach ($node->props as $prop) |
|
| 55 | + { |
|
| 56 | + if ($prop instanceof PropertyProperty) |
|
| 57 | + { |
|
| 55 | 58 | $this->properties[$prop->name->name] = $prop->name->name; |
| 56 | 59 | } |
| 57 | 60 | } |
@@ -62,7 +65,8 @@ discard block |
||
| 62 | 65 | |
| 63 | 66 | private function promotedProperties(Node $node): void |
| 64 | 67 | { |
| 65 | - if (!$node instanceof Param || !$node->var instanceof Variable) { |
|
| 68 | + if (!$node instanceof Param || !$node->var instanceof Variable) |
|
| 69 | + { |
|
| 66 | 70 | return; |
| 67 | 71 | } |
| 68 | 72 | |
@@ -25,18 +25,18 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | public function __construct( |
| 27 | 27 | private readonly ClassNode $definition |
| 28 | - ) { |
|
| 28 | + ){ |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function leaveNode(Node $node): int|Node|null |
|
| 31 | + public function leaveNode(Node $node): int | Node | null |
|
| 32 | 32 | { |
| 33 | - if (!$node instanceof Class_) { |
|
| 33 | + if (!$node instanceof Class_){ |
|
| 34 | 34 | return null; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $constructor = $this->getConstructorAttribute($node); |
| 38 | 38 | $this->addDependencies($constructor); |
| 39 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
| 39 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams){ |
|
| 40 | 40 | $this->addParentConstructorCall($constructor); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | private function addDependencies(ClassMethod $constructor): void |
| 50 | 50 | { |
| 51 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 51 | + foreach ($this->definition->dependencies as $dependency){ |
|
| 52 | 52 | \array_unshift($constructor->params, $this->buildConstructorParam($dependency)); |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -65,34 +65,34 @@ discard block |
||
| 65 | 65 | private function addParentConstructorCall(ClassMethod $constructor): void |
| 66 | 66 | { |
| 67 | 67 | $parentConstructorDependencies = []; |
| 68 | - foreach ($this->definition->constructorParams as $param) { |
|
| 68 | + foreach ($this->definition->constructorParams as $param){ |
|
| 69 | 69 | $parentConstructorDependencies[] = new Arg(new Variable($param->name)); |
| 70 | 70 | |
| 71 | 71 | $cp = new Param($param->name); |
| 72 | - if (!empty($param->type)) { |
|
| 72 | + if (!empty($param->type)){ |
|
| 73 | 73 | $type = $this->getParamType($param); |
| 74 | - if ($param->nullable) { |
|
| 74 | + if ($param->nullable){ |
|
| 75 | 75 | $type = \sprintf('?%s', $type); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $cp->setType(new Name($type)); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - if ($param->byRef) { |
|
| 81 | + if ($param->byRef){ |
|
| 82 | 82 | $cp->makeByRef(); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if ($param->isVariadic) { |
|
| 85 | + if ($param->isVariadic){ |
|
| 86 | 86 | $cp->makeVariadic(); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if ($param->hasDefault) { |
|
| 89 | + if ($param->hasDefault){ |
|
| 90 | 90 | $cp->setDefault($param->default); |
| 91 | 91 | } |
| 92 | 92 | $constructor->params[] = $cp->getNode(); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if ($parentConstructorDependencies !== []) { |
|
| 95 | + if ($parentConstructorDependencies !== []){ |
|
| 96 | 96 | \array_unshift( |
| 97 | 97 | $constructor->stmts, |
| 98 | 98 | new Expression( |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | private function getPropertyType(Dependency $dependency): string |
| 115 | 115 | { |
| 116 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 117 | - if ($stmt->name === $dependency->type->fullName && $stmt->alias) { |
|
| 116 | + foreach ($this->definition->getStmts() as $stmt){ |
|
| 117 | + if ($stmt->name === $dependency->type->fullName && $stmt->alias){ |
|
| 118 | 118 | return $stmt->alias; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -124,13 +124,13 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | private function getParamType(ConstructorParam $param): string |
| 126 | 126 | { |
| 127 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 128 | - if ($stmt->name === $param->type->fullName && $stmt->alias) { |
|
| 127 | + foreach ($this->definition->getStmts() as $stmt){ |
|
| 128 | + if ($stmt->name === $param->type->fullName && $stmt->alias){ |
|
| 129 | 129 | return $stmt->alias; |
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - if ($param->type->alias) { |
|
| 133 | + if ($param->type->alias){ |
|
| 134 | 134 | return $param->type->alias; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -30,13 +30,15 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function leaveNode(Node $node): int|Node|null |
| 32 | 32 | { |
| 33 | - if (!$node instanceof Class_) { |
|
| 33 | + if (!$node instanceof Class_) |
|
| 34 | + { |
|
| 34 | 35 | return null; |
| 35 | 36 | } |
| 36 | 37 | |
| 37 | 38 | $constructor = $this->getConstructorAttribute($node); |
| 38 | 39 | $this->addDependencies($constructor); |
| 39 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
| 40 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams) |
|
| 41 | + { |
|
| 40 | 42 | $this->addParentConstructorCall($constructor); |
| 41 | 43 | } |
| 42 | 44 | |
@@ -48,7 +50,8 @@ discard block |
||
| 48 | 50 | */ |
| 49 | 51 | private function addDependencies(ClassMethod $constructor): void |
| 50 | 52 | { |
| 51 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 53 | + foreach ($this->definition->dependencies as $dependency) |
|
| 54 | + { |
|
| 52 | 55 | \array_unshift($constructor->params, $this->buildConstructorParam($dependency)); |
| 53 | 56 | } |
| 54 | 57 | } |
@@ -65,34 +68,41 @@ discard block |
||
| 65 | 68 | private function addParentConstructorCall(ClassMethod $constructor): void |
| 66 | 69 | { |
| 67 | 70 | $parentConstructorDependencies = []; |
| 68 | - foreach ($this->definition->constructorParams as $param) { |
|
| 71 | + foreach ($this->definition->constructorParams as $param) |
|
| 72 | + { |
|
| 69 | 73 | $parentConstructorDependencies[] = new Arg(new Variable($param->name)); |
| 70 | 74 | |
| 71 | 75 | $cp = new Param($param->name); |
| 72 | - if (!empty($param->type)) { |
|
| 76 | + if (!empty($param->type)) |
|
| 77 | + { |
|
| 73 | 78 | $type = $this->getParamType($param); |
| 74 | - if ($param->nullable) { |
|
| 79 | + if ($param->nullable) |
|
| 80 | + { |
|
| 75 | 81 | $type = \sprintf('?%s', $type); |
| 76 | 82 | } |
| 77 | 83 | |
| 78 | 84 | $cp->setType(new Name($type)); |
| 79 | 85 | } |
| 80 | 86 | |
| 81 | - if ($param->byRef) { |
|
| 87 | + if ($param->byRef) |
|
| 88 | + { |
|
| 82 | 89 | $cp->makeByRef(); |
| 83 | 90 | } |
| 84 | 91 | |
| 85 | - if ($param->isVariadic) { |
|
| 92 | + if ($param->isVariadic) |
|
| 93 | + { |
|
| 86 | 94 | $cp->makeVariadic(); |
| 87 | 95 | } |
| 88 | 96 | |
| 89 | - if ($param->hasDefault) { |
|
| 97 | + if ($param->hasDefault) |
|
| 98 | + { |
|
| 90 | 99 | $cp->setDefault($param->default); |
| 91 | 100 | } |
| 92 | 101 | $constructor->params[] = $cp->getNode(); |
| 93 | 102 | } |
| 94 | 103 | |
| 95 | - if ($parentConstructorDependencies !== []) { |
|
| 104 | + if ($parentConstructorDependencies !== []) |
|
| 105 | + { |
|
| 96 | 106 | \array_unshift( |
| 97 | 107 | $constructor->stmts, |
| 98 | 108 | new Expression( |
@@ -113,8 +123,10 @@ discard block |
||
| 113 | 123 | |
| 114 | 124 | private function getPropertyType(Dependency $dependency): string |
| 115 | 125 | { |
| 116 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 117 | - if ($stmt->name === $dependency->type->fullName && $stmt->alias) { |
|
| 126 | + foreach ($this->definition->getStmts() as $stmt) |
|
| 127 | + { |
|
| 128 | + if ($stmt->name === $dependency->type->fullName && $stmt->alias) |
|
| 129 | + { |
|
| 118 | 130 | return $stmt->alias; |
| 119 | 131 | } |
| 120 | 132 | } |
@@ -124,13 +136,16 @@ discard block |
||
| 124 | 136 | |
| 125 | 137 | private function getParamType(ConstructorParam $param): string |
| 126 | 138 | { |
| 127 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 128 | - if ($stmt->name === $param->type->fullName && $stmt->alias) { |
|
| 139 | + foreach ($this->definition->getStmts() as $stmt) |
|
| 140 | + { |
|
| 141 | + if ($stmt->name === $param->type->fullName && $stmt->alias) |
|
| 142 | + { |
|
| 129 | 143 | return $stmt->alias; |
| 130 | 144 | } |
| 131 | 145 | } |
| 132 | 146 | |
| 133 | - if ($param->type->alias) { |
|
| 147 | + if ($param->type->alias) |
|
| 148 | + { |
|
| 134 | 149 | return $param->type->alias; |
| 135 | 150 | } |
| 136 | 151 | |
@@ -17,11 +17,11 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function enterNode(Node $node): ?int |
| 19 | 19 | { |
| 20 | - if ($node instanceof Namespace_) { |
|
| 20 | + if ($node instanceof Namespace_){ |
|
| 21 | 21 | $this->namespace = \implode('\\', $node->name->parts); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - if ($node instanceof Class_) { |
|
| 24 | + if ($node instanceof Class_){ |
|
| 25 | 25 | $this->class = $node->name->name; |
| 26 | 26 | |
| 27 | 27 | return NodeTraverser::STOP_TRAVERSAL; |
@@ -17,11 +17,13 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function enterNode(Node $node): ?int |
| 19 | 19 | { |
| 20 | - if ($node instanceof Namespace_) { |
|
| 20 | + if ($node instanceof Namespace_) |
|
| 21 | + { |
|
| 21 | 22 | $this->namespace = \implode('\\', $node->name->parts); |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | - if ($node instanceof Class_) { |
|
| 25 | + if ($node instanceof Class_) |
|
| 26 | + { |
|
| 25 | 27 | $this->class = $node->name->name; |
| 26 | 28 | |
| 27 | 29 | return NodeTraverser::STOP_TRAVERSAL; |
@@ -17,8 +17,8 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function enterNode(Node $node): void |
| 19 | 19 | { |
| 20 | - if ($node instanceof Use_) { |
|
| 21 | - foreach ($node->uses as $use) { |
|
| 20 | + if ($node instanceof Use_){ |
|
| 21 | + foreach ($node->uses as $use){ |
|
| 22 | 22 | $this->imports[] = [ |
| 23 | 23 | 'name' => \implode('\\', $use->name->parts), |
| 24 | 24 | 'alias' => $use->alias->name ?? null, |
@@ -17,8 +17,10 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function enterNode(Node $node): void |
| 19 | 19 | { |
| 20 | - if ($node instanceof Use_) { |
|
| 21 | - foreach ($node->uses as $use) { |
|
| 20 | + if ($node instanceof Use_) |
|
| 21 | + { |
|
| 22 | + foreach ($node->uses as $use) |
|
| 23 | + { |
|
| 22 | 24 | $this->imports[] = [ |
| 23 | 25 | 'name' => \implode('\\', $use->name->parts), |
| 24 | 26 | 'alias' => $use->alias->name ?? null, |
@@ -15,18 +15,18 @@ |
||
| 15 | 15 | { |
| 16 | 16 | private array $vars = []; |
| 17 | 17 | |
| 18 | - public function enterNode(Node $node): int|ClassMethod|null |
|
| 18 | + public function enterNode(Node $node): int | ClassMethod | null |
|
| 19 | 19 | { |
| 20 | - if ($node instanceof Class_) { |
|
| 21 | - foreach ($node->stmts as $stmt) { |
|
| 22 | - if ($stmt instanceof ClassMethod && $stmt->name === '__construct') { |
|
| 20 | + if ($node instanceof Class_){ |
|
| 21 | + foreach ($node->stmts as $stmt){ |
|
| 22 | + if ($stmt instanceof ClassMethod && $stmt->name === '__construct'){ |
|
| 23 | 23 | return $stmt; |
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | 26 | return NodeTraverser::DONT_TRAVERSE_CHILDREN; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if ($node instanceof Variable) { |
|
| 29 | + if ($node instanceof Variable){ |
|
| 30 | 30 | $this->vars[] = $node->name; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -17,16 +17,20 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function enterNode(Node $node): int|ClassMethod|null |
| 19 | 19 | { |
| 20 | - if ($node instanceof Class_) { |
|
| 21 | - foreach ($node->stmts as $stmt) { |
|
| 22 | - if ($stmt instanceof ClassMethod && $stmt->name === '__construct') { |
|
| 20 | + if ($node instanceof Class_) |
|
| 21 | + { |
|
| 22 | + foreach ($node->stmts as $stmt) |
|
| 23 | + { |
|
| 24 | + if ($stmt instanceof ClassMethod && $stmt->name === '__construct') |
|
| 25 | + { |
|
| 23 | 26 | return $stmt; |
| 24 | 27 | } |
| 25 | 28 | } |
| 26 | 29 | return NodeTraverser::DONT_TRAVERSE_CHILDREN; |
| 27 | 30 | } |
| 28 | 31 | |
| 29 | - if ($node instanceof Variable) { |
|
| 32 | + if ($node instanceof Variable) |
|
| 33 | + { |
|
| 30 | 34 | $this->vars[] = $node->name; |
| 31 | 35 | } |
| 32 | 36 | |
@@ -15,19 +15,19 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | final class RemoveUse extends NodeVisitorAbstract |
| 17 | 17 | { |
| 18 | - public function leaveNode(Node $node): int|Node|null |
|
| 18 | + public function leaveNode(Node $node): int | Node | null |
|
| 19 | 19 | { |
| 20 | - if (!$node instanceof Use_) { |
|
| 20 | + if (!$node instanceof Use_){ |
|
| 21 | 21 | return null; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - foreach ($node->uses as $index => $use) { |
|
| 25 | - if ($use->name->toString() === PrototypeTrait::class) { |
|
| 24 | + foreach ($node->uses as $index => $use){ |
|
| 25 | + if ($use->name->toString() === PrototypeTrait::class){ |
|
| 26 | 26 | unset($node->uses[$index]); |
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - if (empty($node->uses)) { |
|
| 30 | + if (empty($node->uses)){ |
|
| 31 | 31 | return NodeTraverser::REMOVE_NODE; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -17,17 +17,21 @@ |
||
| 17 | 17 | { |
| 18 | 18 | public function leaveNode(Node $node): int|Node|null |
| 19 | 19 | { |
| 20 | - if (!$node instanceof Use_) { |
|
| 20 | + if (!$node instanceof Use_) |
|
| 21 | + { |
|
| 21 | 22 | return null; |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | - foreach ($node->uses as $index => $use) { |
|
| 25 | - if ($use->name->toString() === PrototypeTrait::class) { |
|
| 25 | + foreach ($node->uses as $index => $use) |
|
| 26 | + { |
|
| 27 | + if ($use->name->toString() === PrototypeTrait::class) |
|
| 28 | + { |
|
| 26 | 29 | unset($node->uses[$index]); |
| 27 | 30 | } |
| 28 | 31 | } |
| 29 | 32 | |
| 30 | - if (empty($node->uses)) { |
|
| 33 | + if (empty($node->uses)) |
|
| 34 | + { |
|
| 31 | 35 | return NodeTraverser::REMOVE_NODE; |
| 32 | 36 | } |
| 33 | 37 | |