@@ -10,7 +10,7 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public function __construct( |
| 12 | 12 | private readonly CoreInterface $core |
| 13 | - ) { |
|
| 13 | + ){ |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -29,13 +29,13 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function __construct($name = null, array $data = [], $dataName = '') |
| 31 | 31 | { |
| 32 | - $this->storage = new Storage($this->dir() . '/Fixtures/'); |
|
| 32 | + $this->storage = new Storage($this->dir().'/Fixtures/'); |
|
| 33 | 33 | parent::__construct($name, $data, $dataName); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | public function setUp(): void |
| 37 | 37 | { |
| 38 | - if (!\class_exists(Kernel::class)) { |
|
| 38 | + if (!\class_exists(Kernel::class)){ |
|
| 39 | 39 | $this->markTestSkipped('A "spiral/framework" dependency is required to run these tests'); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | 'cache' => sys_get_temp_dir() |
| 47 | 47 | ], false)->run(); |
| 48 | 48 | |
| 49 | - foreach (static::STORE as $name) { |
|
| 49 | + foreach (static::STORE as $name){ |
|
| 50 | 50 | $this->storage->store($name); |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | public function tearDown(): void |
| 55 | 55 | { |
| 56 | - foreach (static::STORE as $name) { |
|
| 56 | + foreach (static::STORE as $name){ |
|
| 57 | 57 | $this->storage->restore($name); |
| 58 | 58 | } |
| 59 | 59 | } |
@@ -35,7 +35,8 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function setUp(): void |
| 37 | 37 | { |
| 38 | - if (!\class_exists(Kernel::class)) { |
|
| 38 | + if (!\class_exists(Kernel::class)) |
|
| 39 | + { |
|
| 39 | 40 | $this->markTestSkipped('A "spiral/framework" dependency is required to run these tests'); |
| 40 | 41 | } |
| 41 | 42 | |
@@ -46,14 +47,16 @@ discard block |
||
| 46 | 47 | 'cache' => sys_get_temp_dir() |
| 47 | 48 | ], false)->run(); |
| 48 | 49 | |
| 49 | - foreach (static::STORE as $name) { |
|
| 50 | + foreach (static::STORE as $name) |
|
| 51 | + { |
|
| 50 | 52 | $this->storage->store($name); |
| 51 | 53 | } |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | 56 | public function tearDown(): void |
| 55 | 57 | { |
| 56 | - foreach (static::STORE as $name) { |
|
| 58 | + foreach (static::STORE as $name) |
|
| 59 | + { |
|
| 57 | 60 | $this->storage->restore($name); |
| 58 | 61 | } |
| 59 | 62 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | { |
| 12 | 12 | public function __construct( |
| 13 | 13 | private readonly ScopedClassesInterface $classes |
| 14 | - ) { |
|
| 14 | + ){ |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | private readonly ConflictResolver\Names $namesResolver, |
| 26 | 26 | private readonly ConflictResolver\Namespaces $namespacesResolver, |
| 27 | 27 | Parser $parser = null |
| 28 | - ) { |
|
| 28 | + ){ |
|
| 29 | 29 | $this->parser = $parser ?? (new ParserFactory())->create(ParserFactory::ONLY_PHP7); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -58,11 +58,11 @@ discard block |
||
| 58 | 58 | $declarator = new DeclareClass(); |
| 59 | 59 | $this->traverse($filename, $declarator); |
| 60 | 60 | |
| 61 | - if (empty($declarator->getClass())) { |
|
| 61 | + if (empty($declarator->getClass())){ |
|
| 62 | 62 | throw new ClassNotDeclaredException($filename); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if ($declarator->getNamespace()) { |
|
| 65 | + if ($declarator->getNamespace()){ |
|
| 66 | 66 | return ClassNode::createWithNamespace($declarator->getClass(), $declarator->getNamespace()); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $tr = new NodeTraverser(); |
| 75 | 75 | |
| 76 | - foreach ($visitors as $visitor) { |
|
| 76 | + foreach ($visitors as $visitor){ |
|
| 77 | 77 | $tr->addVisitor($visitor); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | private function fillStmts(ClassNode $definition, array $imports): void |
| 84 | 84 | { |
| 85 | - foreach ($imports as $import) { |
|
| 85 | + foreach ($imports as $import){ |
|
| 86 | 86 | $definition->addImportUsage($import['name'], $import['alias']); |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | $reflection = new \ReflectionClass(\sprintf('%s\%s', $definition->namespace, $definition->class)); |
| 96 | 96 | |
| 97 | 97 | $constructor = $reflection->getConstructor(); |
| 98 | - if ($constructor !== null) { |
|
| 98 | + if ($constructor !== null){ |
|
| 99 | 99 | $definition->hasConstructor = $constructor->getDeclaringClass()->getName() === $reflection->getName(); |
| 100 | 100 | |
| 101 | - foreach ($reflection->getConstructor()->getParameters() as $parameter) { |
|
| 101 | + foreach ($reflection->getConstructor()->getParameters() as $parameter){ |
|
| 102 | 102 | $definition->addParam($parameter); |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | private function fillConstructorVars(array $vars, ClassNode $definition): void |
| 112 | 112 | { |
| 113 | - foreach ($vars as $k => $var) { |
|
| 114 | - if (isset($definition->constructorParams[$var])) { |
|
| 113 | + foreach ($vars as $k => $var){ |
|
| 114 | + if (isset($definition->constructorParams[$var])){ |
|
| 115 | 115 | unset($vars[$k]); |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -58,11 +58,13 @@ discard block |
||
| 58 | 58 | $declarator = new DeclareClass(); |
| 59 | 59 | $this->traverse($filename, $declarator); |
| 60 | 60 | |
| 61 | - if (empty($declarator->getClass())) { |
|
| 61 | + if (empty($declarator->getClass())) |
|
| 62 | + { |
|
| 62 | 63 | throw new ClassNotDeclaredException($filename); |
| 63 | 64 | } |
| 64 | 65 | |
| 65 | - if ($declarator->getNamespace()) { |
|
| 66 | + if ($declarator->getNamespace()) |
|
| 67 | + { |
|
| 66 | 68 | return ClassNode::createWithNamespace($declarator->getClass(), $declarator->getNamespace()); |
| 67 | 69 | } |
| 68 | 70 | |
@@ -73,7 +75,8 @@ discard block |
||
| 73 | 75 | { |
| 74 | 76 | $tr = new NodeTraverser(); |
| 75 | 77 | |
| 76 | - foreach ($visitors as $visitor) { |
|
| 78 | + foreach ($visitors as $visitor) |
|
| 79 | + { |
|
| 77 | 80 | $tr->addVisitor($visitor); |
| 78 | 81 | } |
| 79 | 82 | |
@@ -82,7 +85,8 @@ discard block |
||
| 82 | 85 | |
| 83 | 86 | private function fillStmts(ClassNode $definition, array $imports): void |
| 84 | 87 | { |
| 85 | - foreach ($imports as $import) { |
|
| 88 | + foreach ($imports as $import) |
|
| 89 | + { |
|
| 86 | 90 | $definition->addImportUsage($import['name'], $import['alias']); |
| 87 | 91 | } |
| 88 | 92 | } |
@@ -95,10 +99,12 @@ discard block |
||
| 95 | 99 | $reflection = new \ReflectionClass(\sprintf('%s\%s', $definition->namespace, $definition->class)); |
| 96 | 100 | |
| 97 | 101 | $constructor = $reflection->getConstructor(); |
| 98 | - if ($constructor !== null) { |
|
| 102 | + if ($constructor !== null) |
|
| 103 | + { |
|
| 99 | 104 | $definition->hasConstructor = $constructor->getDeclaringClass()->getName() === $reflection->getName(); |
| 100 | 105 | |
| 101 | - foreach ($reflection->getConstructor()->getParameters() as $parameter) { |
|
| 106 | + foreach ($reflection->getConstructor()->getParameters() as $parameter) |
|
| 107 | + { |
|
| 102 | 108 | $definition->addParam($parameter); |
| 103 | 109 | } |
| 104 | 110 | } |
@@ -110,8 +116,10 @@ discard block |
||
| 110 | 116 | */ |
| 111 | 117 | private function fillConstructorVars(array $vars, ClassNode $definition): void |
| 112 | 118 | { |
| 113 | - foreach ($vars as $k => $var) { |
|
| 114 | - if (isset($definition->constructorParams[$var])) { |
|
| 119 | + foreach ($vars as $k => $var) |
|
| 120 | + { |
|
| 121 | + if (isset($definition->constructorParams[$var])) |
|
| 122 | + { |
|
| 115 | 123 | unset($vars[$k]); |
| 116 | 124 | } |
| 117 | 125 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | public function __construct( |
| 30 | 30 | Lexer $lexer = null, |
| 31 | 31 | private readonly PrettyPrinterAbstract $printer = new Standard() |
| 32 | - ) { |
|
| 32 | + ){ |
|
| 33 | 33 | $this->lexer = $lexer ?? new Lexer\Emulative([ |
| 34 | 34 | 'usedAttributes' => [ |
| 35 | 35 | 'comments', |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | bool $useTypedProperties = false, |
| 58 | 58 | bool $noPhpDoc = false |
| 59 | 59 | ): string { |
| 60 | - if (empty($node->dependencies)) { |
|
| 61 | - if ($removeTrait) { |
|
| 60 | + if (empty($node->dependencies)){ |
|
| 61 | + if ($removeTrait){ |
|
| 62 | 62 | $tr = new NodeTraverser(); |
| 63 | 63 | $tr->addVisitor(new RemoveUse()); |
| 64 | 64 | $tr->addVisitor(new RemoveTrait()); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $tr = new NodeTraverser(); |
| 73 | 73 | $tr->addVisitor(new AddUse($node)); |
| 74 | 74 | |
| 75 | - if ($removeTrait) { |
|
| 75 | + if ($removeTrait){ |
|
| 76 | 76 | $tr->addVisitor(new RemoveUse()); |
| 77 | 77 | $tr->addVisitor(new RemoveTrait()); |
| 78 | 78 | } |
@@ -57,8 +57,10 @@ discard block |
||
| 57 | 57 | bool $useTypedProperties = false, |
| 58 | 58 | bool $noPhpDoc = false |
| 59 | 59 | ): string { |
| 60 | - if (empty($node->dependencies)) { |
|
| 61 | - if ($removeTrait) { |
|
| 60 | + if (empty($node->dependencies)) |
|
| 61 | + { |
|
| 62 | + if ($removeTrait) |
|
| 63 | + { |
|
| 62 | 64 | $tr = new NodeTraverser(); |
| 63 | 65 | $tr->addVisitor(new RemoveUse()); |
| 64 | 66 | $tr->addVisitor(new RemoveTrait()); |
@@ -72,7 +74,8 @@ discard block |
||
| 72 | 74 | $tr = new NodeTraverser(); |
| 73 | 75 | $tr->addVisitor(new AddUse($node)); |
| 74 | 76 | |
| 75 | - if ($removeTrait) { |
|
| 77 | + if ($removeTrait) |
|
| 78 | + { |
|
| 76 | 79 | $tr->addVisitor(new RemoveUse()); |
| 77 | 80 | $tr->addVisitor(new RemoveTrait()); |
| 78 | 81 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | public static function shortName(string $name): string |
| 21 | 21 | { |
| 22 | 22 | $pos = \mb_strrpos($name, '\\'); |
| 23 | - if ($pos === false) { |
|
| 23 | + if ($pos === false){ |
|
| 24 | 24 | return $name; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | public static function trimTrailingDigits(string $name, int $number): string |
| 45 | 45 | { |
| 46 | 46 | $pos = \mb_strripos($name, (string)$number); |
| 47 | - if ($pos === false) { |
|
| 47 | + if ($pos === false){ |
|
| 48 | 48 | return $name; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -20,7 +20,8 @@ discard block |
||
| 20 | 20 | public static function shortName(string $name): string |
| 21 | 21 | { |
| 22 | 22 | $pos = \mb_strrpos($name, '\\'); |
| 23 | - if ($pos === false) { |
|
| 23 | + if ($pos === false) |
|
| 24 | + { |
|
| 24 | 25 | return $name; |
| 25 | 26 | } |
| 26 | 27 | |
@@ -44,7 +45,8 @@ discard block |
||
| 44 | 45 | public static function trimTrailingDigits(string $name, int $number): string |
| 45 | 46 | { |
| 46 | 47 | $pos = \mb_strripos($name, (string)$number); |
| 47 | - if ($pos === false) { |
|
| 48 | + if ($pos === false) |
|
| 49 | + { |
|
| 48 | 50 | return $name; |
| 49 | 51 | } |
| 50 | 52 | |
@@ -20,21 +20,21 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | public function __construct( |
| 22 | 22 | private readonly ClassNode $node |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public function leaveNode(Node $node): ?Node |
| 27 | 27 | { |
| 28 | - if (!$node instanceof Node\Stmt\Namespace_) { |
|
| 28 | + if (!$node instanceof Node\Stmt\Namespace_){ |
|
| 29 | 29 | return null; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $imported = []; |
| 33 | - if (!$this->node->hasConstructor && $this->node->constructorParams) { |
|
| 34 | - foreach ($this->node->constructorParams as $param) { |
|
| 35 | - if (!empty($param->type) && $param->type->fullName) { |
|
| 33 | + if (!$this->node->hasConstructor && $this->node->constructorParams){ |
|
| 34 | + foreach ($this->node->constructorParams as $param){ |
|
| 35 | + if (!empty($param->type) && $param->type->fullName){ |
|
| 36 | 36 | $import = [$param->type->fullName, $param->type->alias]; |
| 37 | - if (\in_array($import, $imported, true)) { |
|
| 37 | + if (\in_array($import, $imported, true)){ |
|
| 38 | 38 | continue; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - foreach ($this->node->dependencies as $dependency) { |
|
| 47 | + foreach ($this->node->dependencies as $dependency){ |
|
| 48 | 48 | $import = [$dependency->type->fullName, $dependency->type->alias]; |
| 49 | - if (\in_array($import, $imported, true)) { |
|
| 49 | + if (\in_array($import, $imported, true)){ |
|
| 50 | 50 | continue; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | private function definePlacementID(Node\Stmt\Namespace_ $node): int |
| 71 | 71 | { |
| 72 | - foreach ($node->stmts as $index => $child) { |
|
| 73 | - if ($child instanceof Node\Stmt\Class_) { |
|
| 72 | + foreach ($node->stmts as $index => $child){ |
|
| 73 | + if ($child instanceof Node\Stmt\Class_){ |
|
| 74 | 74 | return $index; |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -87,13 +87,13 @@ discard block |
||
| 87 | 87 | { |
| 88 | 88 | $uses = $this->getExistingUseParts($stmts); |
| 89 | 89 | |
| 90 | - foreach ($nodes as $i => $node) { |
|
| 91 | - if (!$node instanceof Node\Stmt\Use_) { |
|
| 90 | + foreach ($nodes as $i => $node){ |
|
| 91 | + if (!$node instanceof Node\Stmt\Use_){ |
|
| 92 | 92 | continue; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - foreach ($node->uses as $use) { |
|
| 96 | - if (\in_array($use->name->parts, $uses, true)) { |
|
| 95 | + foreach ($node->uses as $use){ |
|
| 96 | + if (\in_array($use->name->parts, $uses, true)){ |
|
| 97 | 97 | unset($nodes[$i]); |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | private function getExistingUseParts(array $stmts): array |
| 113 | 113 | { |
| 114 | 114 | $uses = []; |
| 115 | - foreach ($stmts as $stmt) { |
|
| 116 | - if (!$stmt instanceof Node\Stmt\Use_) { |
|
| 115 | + foreach ($stmts as $stmt){ |
|
| 116 | + if (!$stmt instanceof Node\Stmt\Use_){ |
|
| 117 | 117 | continue; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - foreach ($stmt->uses as $use) { |
|
| 120 | + foreach ($stmt->uses as $use){ |
|
| 121 | 121 | $uses[] = $use->name->parts; |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | private function buildUse(string $type, ?string $alias = null): Node\Stmt\Use_ |
| 129 | 129 | { |
| 130 | 130 | $b = new Use_(new Node\Name($type), Node\Stmt\Use_::TYPE_NORMAL); |
| 131 | - if (!empty($alias)) { |
|
| 131 | + if (!empty($alias)){ |
|
| 132 | 132 | $b->as($alias); |
| 133 | 133 | } |
| 134 | 134 | |
@@ -25,16 +25,21 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function leaveNode(Node $node): ?Node |
| 27 | 27 | { |
| 28 | - if (!$node instanceof Node\Stmt\Namespace_) { |
|
| 28 | + if (!$node instanceof Node\Stmt\Namespace_) |
|
| 29 | + { |
|
| 29 | 30 | return null; |
| 30 | 31 | } |
| 31 | 32 | |
| 32 | 33 | $imported = []; |
| 33 | - if (!$this->node->hasConstructor && $this->node->constructorParams) { |
|
| 34 | - foreach ($this->node->constructorParams as $param) { |
|
| 35 | - if (!empty($param->type) && $param->type->fullName) { |
|
| 34 | + if (!$this->node->hasConstructor && $this->node->constructorParams) |
|
| 35 | + { |
|
| 36 | + foreach ($this->node->constructorParams as $param) |
|
| 37 | + { |
|
| 38 | + if (!empty($param->type) && $param->type->fullName) |
|
| 39 | + { |
|
| 36 | 40 | $import = [$param->type->fullName, $param->type->alias]; |
| 37 | - if (\in_array($import, $imported, true)) { |
|
| 41 | + if (\in_array($import, $imported, true)) |
|
| 42 | + { |
|
| 38 | 43 | continue; |
| 39 | 44 | } |
| 40 | 45 | |
@@ -44,9 +49,11 @@ discard block |
||
| 44 | 49 | } |
| 45 | 50 | } |
| 46 | 51 | |
| 47 | - foreach ($this->node->dependencies as $dependency) { |
|
| 52 | + foreach ($this->node->dependencies as $dependency) |
|
| 53 | + { |
|
| 48 | 54 | $import = [$dependency->type->fullName, $dependency->type->alias]; |
| 49 | - if (\in_array($import, $imported, true)) { |
|
| 55 | + if (\in_array($import, $imported, true)) |
|
| 56 | + { |
|
| 50 | 57 | continue; |
| 51 | 58 | } |
| 52 | 59 | |
@@ -69,8 +76,10 @@ discard block |
||
| 69 | 76 | |
| 70 | 77 | private function definePlacementID(Node\Stmt\Namespace_ $node): int |
| 71 | 78 | { |
| 72 | - foreach ($node->stmts as $index => $child) { |
|
| 73 | - if ($child instanceof Node\Stmt\Class_) { |
|
| 79 | + foreach ($node->stmts as $index => $child) |
|
| 80 | + { |
|
| 81 | + if ($child instanceof Node\Stmt\Class_) |
|
| 82 | + { |
|
| 74 | 83 | return $index; |
| 75 | 84 | } |
| 76 | 85 | } |
@@ -87,13 +96,17 @@ discard block |
||
| 87 | 96 | { |
| 88 | 97 | $uses = $this->getExistingUseParts($stmts); |
| 89 | 98 | |
| 90 | - foreach ($nodes as $i => $node) { |
|
| 91 | - if (!$node instanceof Node\Stmt\Use_) { |
|
| 99 | + foreach ($nodes as $i => $node) |
|
| 100 | + { |
|
| 101 | + if (!$node instanceof Node\Stmt\Use_) |
|
| 102 | + { |
|
| 92 | 103 | continue; |
| 93 | 104 | } |
| 94 | 105 | |
| 95 | - foreach ($node->uses as $use) { |
|
| 96 | - if (\in_array($use->name->parts, $uses, true)) { |
|
| 106 | + foreach ($node->uses as $use) |
|
| 107 | + { |
|
| 108 | + if (\in_array($use->name->parts, $uses, true)) |
|
| 109 | + { |
|
| 97 | 110 | unset($nodes[$i]); |
| 98 | 111 | } |
| 99 | 112 | } |
@@ -112,12 +125,15 @@ discard block |
||
| 112 | 125 | private function getExistingUseParts(array $stmts): array |
| 113 | 126 | { |
| 114 | 127 | $uses = []; |
| 115 | - foreach ($stmts as $stmt) { |
|
| 116 | - if (!$stmt instanceof Node\Stmt\Use_) { |
|
| 128 | + foreach ($stmts as $stmt) |
|
| 129 | + { |
|
| 130 | + if (!$stmt instanceof Node\Stmt\Use_) |
|
| 131 | + { |
|
| 117 | 132 | continue; |
| 118 | 133 | } |
| 119 | 134 | |
| 120 | - foreach ($stmt->uses as $use) { |
|
| 135 | + foreach ($stmt->uses as $use) |
|
| 136 | + { |
|
| 121 | 137 | $uses[] = $use->name->parts; |
| 122 | 138 | } |
| 123 | 139 | } |
@@ -128,7 +144,8 @@ discard block |
||
| 128 | 144 | private function buildUse(string $type, ?string $alias = null): Node\Stmt\Use_ |
| 129 | 145 | { |
| 130 | 146 | $b = new Use_(new Node\Name($type), Node\Stmt\Use_::TYPE_NORMAL); |
| 131 | - if (!empty($alias)) { |
|
| 147 | + if (!empty($alias)) |
|
| 148 | + { |
|
| 132 | 149 | $b->as($alias); |
| 133 | 150 | } |
| 134 | 151 | |
@@ -20,18 +20,18 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | public function __construct( |
| 22 | 22 | private readonly ClassNode $definition |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - public function leaveNode(Node $node): int|Node|null |
|
| 26 | + public function leaveNode(Node $node): int | Node | null |
|
| 27 | 27 | { |
| 28 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 28 | + if (!$node instanceof Node\Stmt\Class_){ |
|
| 29 | 29 | return null; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $constructor = $this->getConstructorAttribute($node); |
| 33 | 33 | $this->addDependencies($constructor); |
| 34 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
| 34 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams){ |
|
| 35 | 35 | $this->addParentConstructorCall($constructor); |
| 36 | 36 | } |
| 37 | 37 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
| 49 | 49 | { |
| 50 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 50 | + foreach ($this->definition->dependencies as $dependency){ |
|
| 51 | 51 | \array_unshift($constructor->params, $this->buildConstructorParam($dependency)); |
| 52 | 52 | \array_unshift( |
| 53 | 53 | $constructor->stmts, |
@@ -70,34 +70,34 @@ discard block |
||
| 70 | 70 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
| 71 | 71 | { |
| 72 | 72 | $parentConstructorDependencies = []; |
| 73 | - foreach ($this->definition->constructorParams as $param) { |
|
| 73 | + foreach ($this->definition->constructorParams as $param){ |
|
| 74 | 74 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
| 75 | 75 | |
| 76 | 76 | $cp = new Param($param->name); |
| 77 | - if (!empty($param->type)) { |
|
| 77 | + if (!empty($param->type)){ |
|
| 78 | 78 | $type = $this->getParamType($param); |
| 79 | - if ($param->nullable) { |
|
| 79 | + if ($param->nullable){ |
|
| 80 | 80 | $type = \sprintf('?%s', $type); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | $cp->setType(new Node\Name($type)); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if ($param->byRef) { |
|
| 86 | + if ($param->byRef){ |
|
| 87 | 87 | $cp->makeByRef(); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if ($param->isVariadic) { |
|
| 90 | + if ($param->isVariadic){ |
|
| 91 | 91 | $cp->makeVariadic(); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if ($param->hasDefault) { |
|
| 94 | + if ($param->hasDefault){ |
|
| 95 | 95 | $cp->setDefault($param->default); |
| 96 | 96 | } |
| 97 | 97 | $constructor->params[] = $cp->getNode(); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if ($parentConstructorDependencies !== []) { |
|
| 100 | + if ($parentConstructorDependencies !== []){ |
|
| 101 | 101 | \array_unshift( |
| 102 | 102 | $constructor->stmts, |
| 103 | 103 | new Node\Stmt\Expression( |
@@ -125,18 +125,18 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | $params = []; |
| 127 | 127 | |
| 128 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 128 | + foreach ($this->definition->dependencies as $dependency){ |
|
| 129 | 129 | $params[] = new Annotation\Line( |
| 130 | 130 | \sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), |
| 131 | 131 | 'param' |
| 132 | 132 | ); |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if (!$this->definition->hasConstructor) { |
|
| 136 | - foreach ($this->definition->constructorParams as $param) { |
|
| 137 | - if (!empty($param->type)) { |
|
| 135 | + if (!$this->definition->hasConstructor){ |
|
| 136 | + foreach ($this->definition->constructorParams as $param){ |
|
| 137 | + if (!empty($param->type)){ |
|
| 138 | 138 | $type = $this->getParamType($param); |
| 139 | - if ($param->nullable) { |
|
| 139 | + if ($param->nullable){ |
|
| 140 | 140 | $type = \sprintf('%s|null', $type); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | \sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), |
| 145 | 145 | 'param' |
| 146 | 146 | ); |
| 147 | - } else { |
|
| 147 | + }else{ |
|
| 148 | 148 | $params[] = new Annotation\Line( |
| 149 | 149 | \sprintf('$%s', $param->name), |
| 150 | 150 | 'param' |
@@ -155,12 +155,12 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | $placementID = 0; |
| 157 | 157 | $previous = null; |
| 158 | - foreach ($an->lines as $index => $line) { |
|
| 158 | + foreach ($an->lines as $index => $line){ |
|
| 159 | 159 | // always next node |
| 160 | 160 | $placementID = $index + 1; |
| 161 | 161 | |
| 162 | 162 | // inject before this parameters |
| 163 | - if ($line->is(['throws', 'return'])) { |
|
| 163 | + if ($line->is(['throws', 'return'])){ |
|
| 164 | 164 | // insert before given node |
| 165 | 165 | $placementID--; |
| 166 | 166 | break; |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $previous = $line; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if ($previous !== null && !$previous->isEmpty()) { |
|
| 172 | + if ($previous !== null && !$previous->isEmpty()){ |
|
| 173 | 173 | $placementID++; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -180,8 +180,8 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | private function getPropertyType(Dependency $dependency): string |
| 182 | 182 | { |
| 183 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 184 | - if ($stmt->name === $dependency->type->fullName && $stmt->alias) { |
|
| 183 | + foreach ($this->definition->getStmts() as $stmt){ |
|
| 184 | + if ($stmt->name === $dependency->type->fullName && $stmt->alias){ |
|
| 185 | 185 | return $stmt->alias; |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | private function getParamType(ClassNode\ConstructorParam $param): string |
| 193 | 193 | { |
| 194 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 195 | - if ($stmt->name === $param->type->fullName && $stmt->alias) { |
|
| 194 | + foreach ($this->definition->getStmts() as $stmt){ |
|
| 195 | + if ($stmt->name === $param->type->fullName && $stmt->alias){ |
|
| 196 | 196 | return $stmt->alias; |
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - if ($param->type->alias) { |
|
| 200 | + if ($param->type->alias){ |
|
| 201 | 201 | return $param->type->alias; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -25,13 +25,15 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function leaveNode(Node $node): int|Node|null |
| 27 | 27 | { |
| 28 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 28 | + if (!$node instanceof Node\Stmt\Class_) |
|
| 29 | + { |
|
| 29 | 30 | return null; |
| 30 | 31 | } |
| 31 | 32 | |
| 32 | 33 | $constructor = $this->getConstructorAttribute($node); |
| 33 | 34 | $this->addDependencies($constructor); |
| 34 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
| 35 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams) |
|
| 36 | + { |
|
| 35 | 37 | $this->addParentConstructorCall($constructor); |
| 36 | 38 | } |
| 37 | 39 | |
@@ -47,7 +49,8 @@ discard block |
||
| 47 | 49 | */ |
| 48 | 50 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
| 49 | 51 | { |
| 50 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 52 | + foreach ($this->definition->dependencies as $dependency) |
|
| 53 | + { |
|
| 51 | 54 | \array_unshift($constructor->params, $this->buildConstructorParam($dependency)); |
| 52 | 55 | \array_unshift( |
| 53 | 56 | $constructor->stmts, |
@@ -70,34 +73,41 @@ discard block |
||
| 70 | 73 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
| 71 | 74 | { |
| 72 | 75 | $parentConstructorDependencies = []; |
| 73 | - foreach ($this->definition->constructorParams as $param) { |
|
| 76 | + foreach ($this->definition->constructorParams as $param) |
|
| 77 | + { |
|
| 74 | 78 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
| 75 | 79 | |
| 76 | 80 | $cp = new Param($param->name); |
| 77 | - if (!empty($param->type)) { |
|
| 81 | + if (!empty($param->type)) |
|
| 82 | + { |
|
| 78 | 83 | $type = $this->getParamType($param); |
| 79 | - if ($param->nullable) { |
|
| 84 | + if ($param->nullable) |
|
| 85 | + { |
|
| 80 | 86 | $type = \sprintf('?%s', $type); |
| 81 | 87 | } |
| 82 | 88 | |
| 83 | 89 | $cp->setType(new Node\Name($type)); |
| 84 | 90 | } |
| 85 | 91 | |
| 86 | - if ($param->byRef) { |
|
| 92 | + if ($param->byRef) |
|
| 93 | + { |
|
| 87 | 94 | $cp->makeByRef(); |
| 88 | 95 | } |
| 89 | 96 | |
| 90 | - if ($param->isVariadic) { |
|
| 97 | + if ($param->isVariadic) |
|
| 98 | + { |
|
| 91 | 99 | $cp->makeVariadic(); |
| 92 | 100 | } |
| 93 | 101 | |
| 94 | - if ($param->hasDefault) { |
|
| 102 | + if ($param->hasDefault) |
|
| 103 | + { |
|
| 95 | 104 | $cp->setDefault($param->default); |
| 96 | 105 | } |
| 97 | 106 | $constructor->params[] = $cp->getNode(); |
| 98 | 107 | } |
| 99 | 108 | |
| 100 | - if ($parentConstructorDependencies !== []) { |
|
| 109 | + if ($parentConstructorDependencies !== []) |
|
| 110 | + { |
|
| 101 | 111 | \array_unshift( |
| 102 | 112 | $constructor->stmts, |
| 103 | 113 | new Node\Stmt\Expression( |
@@ -125,18 +135,23 @@ discard block |
||
| 125 | 135 | |
| 126 | 136 | $params = []; |
| 127 | 137 | |
| 128 | - foreach ($this->definition->dependencies as $dependency) { |
|
| 138 | + foreach ($this->definition->dependencies as $dependency) |
|
| 139 | + { |
|
| 129 | 140 | $params[] = new Annotation\Line( |
| 130 | 141 | \sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), |
| 131 | 142 | 'param' |
| 132 | 143 | ); |
| 133 | 144 | } |
| 134 | 145 | |
| 135 | - if (!$this->definition->hasConstructor) { |
|
| 136 | - foreach ($this->definition->constructorParams as $param) { |
|
| 137 | - if (!empty($param->type)) { |
|
| 146 | + if (!$this->definition->hasConstructor) |
|
| 147 | + { |
|
| 148 | + foreach ($this->definition->constructorParams as $param) |
|
| 149 | + { |
|
| 150 | + if (!empty($param->type)) |
|
| 151 | + { |
|
| 138 | 152 | $type = $this->getParamType($param); |
| 139 | - if ($param->nullable) { |
|
| 153 | + if ($param->nullable) |
|
| 154 | + { |
|
| 140 | 155 | $type = \sprintf('%s|null', $type); |
| 141 | 156 | } |
| 142 | 157 | |
@@ -144,7 +159,9 @@ discard block |
||
| 144 | 159 | \sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), |
| 145 | 160 | 'param' |
| 146 | 161 | ); |
| 147 | - } else { |
|
| 162 | + } |
|
| 163 | + else |
|
| 164 | + { |
|
| 148 | 165 | $params[] = new Annotation\Line( |
| 149 | 166 | \sprintf('$%s', $param->name), |
| 150 | 167 | 'param' |
@@ -155,12 +172,14 @@ discard block |
||
| 155 | 172 | |
| 156 | 173 | $placementID = 0; |
| 157 | 174 | $previous = null; |
| 158 | - foreach ($an->lines as $index => $line) { |
|
| 175 | + foreach ($an->lines as $index => $line) |
|
| 176 | + { |
|
| 159 | 177 | // always next node |
| 160 | 178 | $placementID = $index + 1; |
| 161 | 179 | |
| 162 | 180 | // inject before this parameters |
| 163 | - if ($line->is(['throws', 'return'])) { |
|
| 181 | + if ($line->is(['throws', 'return'])) |
|
| 182 | + { |
|
| 164 | 183 | // insert before given node |
| 165 | 184 | $placementID--; |
| 166 | 185 | break; |
@@ -169,7 +188,8 @@ discard block |
||
| 169 | 188 | $previous = $line; |
| 170 | 189 | } |
| 171 | 190 | |
| 172 | - if ($previous !== null && !$previous->isEmpty()) { |
|
| 191 | + if ($previous !== null && !$previous->isEmpty()) |
|
| 192 | + { |
|
| 173 | 193 | $placementID++; |
| 174 | 194 | } |
| 175 | 195 | |
@@ -180,8 +200,10 @@ discard block |
||
| 180 | 200 | |
| 181 | 201 | private function getPropertyType(Dependency $dependency): string |
| 182 | 202 | { |
| 183 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 184 | - if ($stmt->name === $dependency->type->fullName && $stmt->alias) { |
|
| 203 | + foreach ($this->definition->getStmts() as $stmt) |
|
| 204 | + { |
|
| 205 | + if ($stmt->name === $dependency->type->fullName && $stmt->alias) |
|
| 206 | + { |
|
| 185 | 207 | return $stmt->alias; |
| 186 | 208 | } |
| 187 | 209 | } |
@@ -191,13 +213,16 @@ discard block |
||
| 191 | 213 | |
| 192 | 214 | private function getParamType(ClassNode\ConstructorParam $param): string |
| 193 | 215 | { |
| 194 | - foreach ($this->definition->getStmts() as $stmt) { |
|
| 195 | - if ($stmt->name === $param->type->fullName && $stmt->alias) { |
|
| 216 | + foreach ($this->definition->getStmts() as $stmt) |
|
| 217 | + { |
|
| 218 | + if ($stmt->name === $param->type->fullName && $stmt->alias) |
|
| 219 | + { |
|
| 196 | 220 | return $stmt->alias; |
| 197 | 221 | } |
| 198 | 222 | } |
| 199 | 223 | |
| 200 | - if ($param->type->alias) { |
|
| 224 | + if ($param->type->alias) |
|
| 225 | + { |
|
| 201 | 226 | return $param->type->alias; |
| 202 | 227 | } |
| 203 | 228 | |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | { |
| 17 | 17 | public function leaveNode(Node $node): ?Node |
| 18 | 18 | { |
| 19 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 19 | + if (!$node instanceof Node\Stmt\Class_){ |
|
| 20 | 20 | return null; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | $placementID = 0; |
| 24 | - foreach ($node->stmts as $index => $child) { |
|
| 24 | + foreach ($node->stmts as $index => $child){ |
|
| 25 | 25 | $placementID = $index; |
| 26 | - if ($child instanceof Node\Stmt\ClassMethod) { |
|
| 27 | - if ($child->name->name === '__construct') { |
|
| 26 | + if ($child instanceof Node\Stmt\ClassMethod){ |
|
| 27 | + if ($child->name->name === '__construct'){ |
|
| 28 | 28 | $node->setAttribute('constructor', $child); |
| 29 | 29 | |
| 30 | 30 | return null; |
@@ -16,15 +16,19 @@ |
||
| 16 | 16 | { |
| 17 | 17 | public function leaveNode(Node $node): ?Node |
| 18 | 18 | { |
| 19 | - if (!$node instanceof Node\Stmt\Class_) { |
|
| 19 | + if (!$node instanceof Node\Stmt\Class_) |
|
| 20 | + { |
|
| 20 | 21 | return null; |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | 24 | $placementID = 0; |
| 24 | - foreach ($node->stmts as $index => $child) { |
|
| 25 | + foreach ($node->stmts as $index => $child) |
|
| 26 | + { |
|
| 25 | 27 | $placementID = $index; |
| 26 | - if ($child instanceof Node\Stmt\ClassMethod) { |
|
| 27 | - if ($child->name->name === '__construct') { |
|
| 28 | + if ($child instanceof Node\Stmt\ClassMethod) |
|
| 29 | + { |
|
| 30 | + if ($child->name->name === '__construct') |
|
| 31 | + { |
|
| 28 | 32 | $node->setAttribute('constructor', $child); |
| 29 | 33 | |
| 30 | 34 | return null; |