| @@ -49,13 +49,13 @@ | ||
| 49 | 49 | $node instanceof PropertyFetch && | 
| 50 | 50 | $node->var instanceof Variable && | 
| 51 | 51 | $node->var->name === 'this' | 
| 52 | -        ) { | |
| 52 | +        ){ | |
| 53 | 53 | $this->requested[$node->name->name] = $node->name->name; | 
| 54 | 54 | } | 
| 55 | 55 | |
| 56 | -        if ($node instanceof Property) { | |
| 57 | -            foreach ($node->props as $prop) { | |
| 58 | -                if ($prop instanceof PropertyProperty) { | |
| 56 | +        if ($node instanceof Property){ | |
| 57 | +            foreach ($node->props as $prop){ | |
| 58 | +                if ($prop instanceof PropertyProperty){ | |
| 59 | 59 | $this->properties[$prop->name->name] = $prop->name->name; | 
| 60 | 60 | } | 
| 61 | 61 | } | 
| @@ -53,9 +53,12 @@ | ||
| 53 | 53 | $this->requested[$node->name->name] = $node->name->name; | 
| 54 | 54 | } | 
| 55 | 55 | |
| 56 | -        if ($node instanceof Property) { | |
| 57 | -            foreach ($node->props as $prop) { | |
| 58 | -                if ($prop instanceof PropertyProperty) { | |
| 56 | + if ($node instanceof Property) | |
| 57 | +        { | |
| 58 | + foreach ($node->props as $prop) | |
| 59 | +            { | |
| 60 | + if ($prop instanceof PropertyProperty) | |
| 61 | +                { | |
| 59 | 62 | $this->properties[$prop->name->name] = $prop->name->name; | 
| 60 | 63 | } | 
| 61 | 64 | } | 
| @@ -28,15 +28,15 @@ | ||
| 28 | 28 | */ | 
| 29 | 29 | public function leaveNode(Node $node) | 
| 30 | 30 |      { | 
| 31 | -        if (!$node instanceof Class_) { | |
| 31 | +        if (!$node instanceof Class_){ | |
| 32 | 32 | return null; | 
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | 35 | $placementID = 0; | 
| 36 | -        foreach ($node->stmts as $index => $child) { | |
| 36 | +        foreach ($node->stmts as $index => $child){ | |
| 37 | 37 | $placementID = $index; | 
| 38 | -            if ($child instanceof ClassMethod) { | |
| 39 | -                if ($child->name->name === '__construct') { | |
| 38 | +            if ($child instanceof ClassMethod){ | |
| 39 | +                if ($child->name->name === '__construct'){ | |
| 40 | 40 |                      $node->setAttribute('constructor', $child); | 
| 41 | 41 | |
| 42 | 42 | return null; | 
| @@ -28,15 +28,19 @@ | ||
| 28 | 28 | */ | 
| 29 | 29 | public function leaveNode(Node $node) | 
| 30 | 30 |      { | 
| 31 | -        if (!$node instanceof Class_) { | |
| 31 | + if (!$node instanceof Class_) | |
| 32 | +        { | |
| 32 | 33 | return null; | 
| 33 | 34 | } | 
| 34 | 35 | |
| 35 | 36 | $placementID = 0; | 
| 36 | -        foreach ($node->stmts as $index => $child) { | |
| 37 | + foreach ($node->stmts as $index => $child) | |
| 38 | +        { | |
| 37 | 39 | $placementID = $index; | 
| 38 | -            if ($child instanceof ClassMethod) { | |
| 39 | -                if ($child->name->name === '__construct') { | |
| 40 | + if ($child instanceof ClassMethod) | |
| 41 | +            { | |
| 42 | + if ($child->name->name === '__construct') | |
| 43 | +                { | |
| 40 | 44 |                      $node->setAttribute('constructor', $child); | 
| 41 | 45 | |
| 42 | 46 | return null; | 
| @@ -29,26 +29,26 @@ | ||
| 29 | 29 | */ | 
| 30 | 30 | public function leaveNode(Node $node) | 
| 31 | 31 |      { | 
| 32 | -        if (!$node instanceof TraitUse) { | |
| 32 | +        if (!$node instanceof TraitUse){ | |
| 33 | 33 | return null; | 
| 34 | 34 | } | 
| 35 | 35 | |
| 36 | -        foreach ($node->traits as $index => $use) { | |
| 37 | -            if ($use instanceof Name) { | |
| 36 | +        foreach ($node->traits as $index => $use){ | |
| 37 | +            if ($use instanceof Name){ | |
| 38 | 38 |                  $name = $this->trimSlashes(implode('\\', $use->parts)); | 
| 39 | 39 | if ( | 
| 40 | 40 | in_array($name, [ | 
| 41 | 41 | $this->trimSlashes(PrototypeTrait::class), | 
| 42 | 42 | Utils::shortName(PrototypeTrait::class), | 
| 43 | 43 | ], true) | 
| 44 | -                ) { | |
| 44 | +                ){ | |
| 45 | 45 | unset($node->traits[$index]); | 
| 46 | 46 | } | 
| 47 | 47 | } | 
| 48 | 48 | } | 
| 49 | 49 | |
| 50 | 50 | $node->traits = array_values($node->traits); | 
| 51 | -        if (empty($node->traits)) { | |
| 51 | +        if (empty($node->traits)){ | |
| 52 | 52 | return NodeTraverser::REMOVE_NODE; | 
| 53 | 53 | } | 
| 54 | 54 | |
| @@ -29,12 +29,15 @@ discard block | ||
| 29 | 29 | */ | 
| 30 | 30 | public function leaveNode(Node $node) | 
| 31 | 31 |      { | 
| 32 | -        if (!$node instanceof TraitUse) { | |
| 32 | + if (!$node instanceof TraitUse) | |
| 33 | +        { | |
| 33 | 34 | return null; | 
| 34 | 35 | } | 
| 35 | 36 | |
| 36 | -        foreach ($node->traits as $index => $use) { | |
| 37 | -            if ($use instanceof Name) { | |
| 37 | + foreach ($node->traits as $index => $use) | |
| 38 | +        { | |
| 39 | + if ($use instanceof Name) | |
| 40 | +            { | |
| 38 | 41 |                  $name = $this->trimSlashes(implode('\\', $use->parts)); | 
| 39 | 42 | if ( | 
| 40 | 43 | in_array($name, [ | 
| @@ -48,7 +51,8 @@ discard block | ||
| 48 | 51 | } | 
| 49 | 52 | |
| 50 | 53 | $node->traits = array_values($node->traits); | 
| 51 | -        if (empty($node->traits)) { | |
| 54 | + if (empty($node->traits)) | |
| 55 | +        { | |
| 52 | 56 | return NodeTraverser::REMOVE_NODE; | 
| 53 | 57 | } | 
| 54 | 58 | |
| @@ -39,12 +39,12 @@ discard block | ||
| 39 | 39 | */ | 
| 40 | 40 | public function leaveNode(Node $node) | 
| 41 | 41 |      { | 
| 42 | -        if (!$node instanceof Class_) { | |
| 42 | +        if (!$node instanceof Class_){ | |
| 43 | 43 | return null; | 
| 44 | 44 | } | 
| 45 | 45 | |
| 46 | 46 | $nodes = []; | 
| 47 | -        foreach ($this->definition->dependencies as $dependency) { | |
| 47 | +        foreach ($this->definition->dependencies as $dependency){ | |
| 48 | 48 | $nodes[] = $this->buildProperty($dependency); | 
| 49 | 49 | } | 
| 50 | 50 | |
| @@ -56,8 +56,8 @@ discard block | ||
| 56 | 56 | |
| 57 | 57 | private function definePlacementID(Class_ $node): int | 
| 58 | 58 |      { | 
| 59 | -        foreach ($node->stmts as $index => $child) { | |
| 60 | -            if ($child instanceof ClassMethod || $child instanceof Node\Stmt\Property) { | |
| 59 | +        foreach ($node->stmts as $index => $child){ | |
| 60 | +            if ($child instanceof ClassMethod || $child instanceof Node\Stmt\Property){ | |
| 61 | 61 | return $index; | 
| 62 | 62 | } | 
| 63 | 63 | } | 
| @@ -70,11 +70,11 @@ discard block | ||
| 70 | 70 | $b = new Property($dependency->property); | 
| 71 | 71 | $b->makePrivate(); | 
| 72 | 72 | |
| 73 | -        if ($this->useTypedProperty()) { | |
| 73 | +        if ($this->useTypedProperty()){ | |
| 74 | 74 | $b->setType($this->getPropertyType($dependency)); | 
| 75 | 75 | } | 
| 76 | 76 | |
| 77 | -        if ($this->renderDoc()) { | |
| 77 | +        if ($this->renderDoc()){ | |
| 78 | 78 |              $b->setDocComment(new Doc(sprintf('/** @var %s */', $this->getPropertyType($dependency)))); | 
| 79 | 79 | } | 
| 80 | 80 | |
| @@ -93,8 +93,8 @@ discard block | ||
| 93 | 93 | |
| 94 | 94 | private function getPropertyType(Dependency $dependency): string | 
| 95 | 95 |      { | 
| 96 | -        foreach ($this->definition->getStmts() as $stmt) { | |
| 97 | -            if (($stmt->name === $dependency->type->fullName) && $stmt->alias) { | |
| 96 | +        foreach ($this->definition->getStmts() as $stmt){ | |
| 97 | +            if (($stmt->name === $dependency->type->fullName) && $stmt->alias){ | |
| 98 | 98 | return $stmt->alias; | 
| 99 | 99 | } | 
| 100 | 100 | } | 
| @@ -39,12 +39,14 @@ discard block | ||
| 39 | 39 | */ | 
| 40 | 40 | public function leaveNode(Node $node) | 
| 41 | 41 |      { | 
| 42 | -        if (!$node instanceof Class_) { | |
| 42 | + if (!$node instanceof Class_) | |
| 43 | +        { | |
| 43 | 44 | return null; | 
| 44 | 45 | } | 
| 45 | 46 | |
| 46 | 47 | $nodes = []; | 
| 47 | -        foreach ($this->definition->dependencies as $dependency) { | |
| 48 | + foreach ($this->definition->dependencies as $dependency) | |
| 49 | +        { | |
| 48 | 50 | $nodes[] = $this->buildProperty($dependency); | 
| 49 | 51 | } | 
| 50 | 52 | |
| @@ -56,8 +58,10 @@ discard block | ||
| 56 | 58 | |
| 57 | 59 | private function definePlacementID(Class_ $node): int | 
| 58 | 60 |      { | 
| 59 | -        foreach ($node->stmts as $index => $child) { | |
| 60 | -            if ($child instanceof ClassMethod || $child instanceof Node\Stmt\Property) { | |
| 61 | + foreach ($node->stmts as $index => $child) | |
| 62 | +        { | |
| 63 | + if ($child instanceof ClassMethod || $child instanceof Node\Stmt\Property) | |
| 64 | +            { | |
| 61 | 65 | return $index; | 
| 62 | 66 | } | 
| 63 | 67 | } | 
| @@ -70,11 +74,13 @@ discard block | ||
| 70 | 74 | $b = new Property($dependency->property); | 
| 71 | 75 | $b->makePrivate(); | 
| 72 | 76 | |
| 73 | -        if ($this->useTypedProperty()) { | |
| 77 | + if ($this->useTypedProperty()) | |
| 78 | +        { | |
| 74 | 79 | $b->setType($this->getPropertyType($dependency)); | 
| 75 | 80 | } | 
| 76 | 81 | |
| 77 | -        if ($this->renderDoc()) { | |
| 82 | + if ($this->renderDoc()) | |
| 83 | +        { | |
| 78 | 84 |              $b->setDocComment(new Doc(sprintf('/** @var %s */', $this->getPropertyType($dependency)))); | 
| 79 | 85 | } | 
| 80 | 86 | |
| @@ -93,8 +99,10 @@ discard block | ||
| 93 | 99 | |
| 94 | 100 | private function getPropertyType(Dependency $dependency): string | 
| 95 | 101 |      { | 
| 96 | -        foreach ($this->definition->getStmts() as $stmt) { | |
| 97 | -            if (($stmt->name === $dependency->type->fullName) && $stmt->alias) { | |
| 102 | + foreach ($this->definition->getStmts() as $stmt) | |
| 103 | +        { | |
| 104 | + if (($stmt->name === $dependency->type->fullName) && $stmt->alias) | |
| 105 | +            { | |
| 98 | 106 | return $stmt->alias; | 
| 99 | 107 | } | 
| 100 | 108 | } | 
| @@ -40,16 +40,16 @@ discard block | ||
| 40 | 40 | */ | 
| 41 | 41 | public function leaveNode(Node $node) | 
| 42 | 42 |      { | 
| 43 | -        if (!$node instanceof Namespace_) { | |
| 43 | +        if (!$node instanceof Namespace_){ | |
| 44 | 44 | return null; | 
| 45 | 45 | } | 
| 46 | 46 | |
| 47 | 47 | $imported = []; | 
| 48 | -        if (!$this->node->hasConstructor && $this->node->constructorParams) { | |
| 49 | -            foreach ($this->node->constructorParams as $param) { | |
| 50 | -                if (!empty($param->type) && $param->type->fullName) { | |
| 48 | +        if (!$this->node->hasConstructor && $this->node->constructorParams){ | |
| 49 | +            foreach ($this->node->constructorParams as $param){ | |
| 50 | +                if (!empty($param->type) && $param->type->fullName){ | |
| 51 | 51 | $import = [$param->type->fullName, $param->type->alias]; | 
| 52 | -                    if (in_array($import, $imported, true)) { | |
| 52 | +                    if (in_array($import, $imported, true)){ | |
| 53 | 53 | continue; | 
| 54 | 54 | } | 
| 55 | 55 | |
| @@ -59,9 +59,9 @@ discard block | ||
| 59 | 59 | } | 
| 60 | 60 | } | 
| 61 | 61 | |
| 62 | -        foreach ($this->node->dependencies as $dependency) { | |
| 62 | +        foreach ($this->node->dependencies as $dependency){ | |
| 63 | 63 | $import = [$dependency->type->fullName, $dependency->type->alias]; | 
| 64 | -            if (in_array($import, $imported, true)) { | |
| 64 | +            if (in_array($import, $imported, true)){ | |
| 65 | 65 | continue; | 
| 66 | 66 | } | 
| 67 | 67 | |
| @@ -84,8 +84,8 @@ discard block | ||
| 84 | 84 | |
| 85 | 85 | private function definePlacementID(Namespace_ $node): int | 
| 86 | 86 |      { | 
| 87 | -        foreach ($node->stmts as $index => $child) { | |
| 88 | -            if ($child instanceof Class_) { | |
| 87 | +        foreach ($node->stmts as $index => $child){ | |
| 88 | +            if ($child instanceof Class_){ | |
| 89 | 89 | return $index; | 
| 90 | 90 | } | 
| 91 | 91 | } | 
| @@ -102,13 +102,13 @@ discard block | ||
| 102 | 102 |      { | 
| 103 | 103 | $uses = $this->getExistingUseParts($stmts); | 
| 104 | 104 | |
| 105 | -        foreach ($nodes as $i => $node) { | |
| 106 | -            if (!$node instanceof Node\Stmt\Use_) { | |
| 105 | +        foreach ($nodes as $i => $node){ | |
| 106 | +            if (!$node instanceof Node\Stmt\Use_){ | |
| 107 | 107 | continue; | 
| 108 | 108 | } | 
| 109 | 109 | |
| 110 | -            foreach ($node->uses as $use) { | |
| 111 | -                if (in_array($use->name->parts, $uses, true)) { | |
| 110 | +            foreach ($node->uses as $use){ | |
| 111 | +                if (in_array($use->name->parts, $uses, true)){ | |
| 112 | 112 | unset($nodes[$i]); | 
| 113 | 113 | } | 
| 114 | 114 | } | 
| @@ -127,12 +127,12 @@ discard block | ||
| 127 | 127 | private function getExistingUseParts(array $stmts): array | 
| 128 | 128 |      { | 
| 129 | 129 | $uses = []; | 
| 130 | -        foreach ($stmts as $stmt) { | |
| 131 | -            if (!$stmt instanceof Node\Stmt\Use_) { | |
| 130 | +        foreach ($stmts as $stmt){ | |
| 131 | +            if (!$stmt instanceof Node\Stmt\Use_){ | |
| 132 | 132 | continue; | 
| 133 | 133 | } | 
| 134 | 134 | |
| 135 | -            foreach ($stmt->uses as $use) { | |
| 135 | +            foreach ($stmt->uses as $use){ | |
| 136 | 136 | $uses[] = $use->name->parts; | 
| 137 | 137 | } | 
| 138 | 138 | } | 
| @@ -143,7 +143,7 @@ discard block | ||
| 143 | 143 | private function buildUse(string $type, ?string $alias = null): Node\Stmt\Use_ | 
| 144 | 144 |      { | 
| 145 | 145 | $b = new Use_(new Name($type), Node\Stmt\Use_::TYPE_NORMAL); | 
| 146 | -        if (!empty($alias)) { | |
| 146 | +        if (!empty($alias)){ | |
| 147 | 147 | $b->as($alias); | 
| 148 | 148 | } | 
| 149 | 149 | |
| @@ -40,16 +40,21 @@ discard block | ||
| 40 | 40 | */ | 
| 41 | 41 | public function leaveNode(Node $node) | 
| 42 | 42 |      { | 
| 43 | -        if (!$node instanceof Namespace_) { | |
| 43 | + if (!$node instanceof Namespace_) | |
| 44 | +        { | |
| 44 | 45 | return null; | 
| 45 | 46 | } | 
| 46 | 47 | |
| 47 | 48 | $imported = []; | 
| 48 | -        if (!$this->node->hasConstructor && $this->node->constructorParams) { | |
| 49 | -            foreach ($this->node->constructorParams as $param) { | |
| 50 | -                if (!empty($param->type) && $param->type->fullName) { | |
| 49 | + if (!$this->node->hasConstructor && $this->node->constructorParams) | |
| 50 | +        { | |
| 51 | + foreach ($this->node->constructorParams as $param) | |
| 52 | +            { | |
| 53 | + if (!empty($param->type) && $param->type->fullName) | |
| 54 | +                { | |
| 51 | 55 | $import = [$param->type->fullName, $param->type->alias]; | 
| 52 | -                    if (in_array($import, $imported, true)) { | |
| 56 | + if (in_array($import, $imported, true)) | |
| 57 | +                    { | |
| 53 | 58 | continue; | 
| 54 | 59 | } | 
| 55 | 60 | |
| @@ -59,9 +64,11 @@ discard block | ||
| 59 | 64 | } | 
| 60 | 65 | } | 
| 61 | 66 | |
| 62 | -        foreach ($this->node->dependencies as $dependency) { | |
| 67 | + foreach ($this->node->dependencies as $dependency) | |
| 68 | +        { | |
| 63 | 69 | $import = [$dependency->type->fullName, $dependency->type->alias]; | 
| 64 | -            if (in_array($import, $imported, true)) { | |
| 70 | + if (in_array($import, $imported, true)) | |
| 71 | +            { | |
| 65 | 72 | continue; | 
| 66 | 73 | } | 
| 67 | 74 | |
| @@ -84,8 +91,10 @@ discard block | ||
| 84 | 91 | |
| 85 | 92 | private function definePlacementID(Namespace_ $node): int | 
| 86 | 93 |      { | 
| 87 | -        foreach ($node->stmts as $index => $child) { | |
| 88 | -            if ($child instanceof Class_) { | |
| 94 | + foreach ($node->stmts as $index => $child) | |
| 95 | +        { | |
| 96 | + if ($child instanceof Class_) | |
| 97 | +            { | |
| 89 | 98 | return $index; | 
| 90 | 99 | } | 
| 91 | 100 | } | 
| @@ -102,13 +111,17 @@ discard block | ||
| 102 | 111 |      { | 
| 103 | 112 | $uses = $this->getExistingUseParts($stmts); | 
| 104 | 113 | |
| 105 | -        foreach ($nodes as $i => $node) { | |
| 106 | -            if (!$node instanceof Node\Stmt\Use_) { | |
| 114 | + foreach ($nodes as $i => $node) | |
| 115 | +        { | |
| 116 | + if (!$node instanceof Node\Stmt\Use_) | |
| 117 | +            { | |
| 107 | 118 | continue; | 
| 108 | 119 | } | 
| 109 | 120 | |
| 110 | -            foreach ($node->uses as $use) { | |
| 111 | -                if (in_array($use->name->parts, $uses, true)) { | |
| 121 | + foreach ($node->uses as $use) | |
| 122 | +            { | |
| 123 | + if (in_array($use->name->parts, $uses, true)) | |
| 124 | +                { | |
| 112 | 125 | unset($nodes[$i]); | 
| 113 | 126 | } | 
| 114 | 127 | } | 
| @@ -127,12 +140,15 @@ discard block | ||
| 127 | 140 | private function getExistingUseParts(array $stmts): array | 
| 128 | 141 |      { | 
| 129 | 142 | $uses = []; | 
| 130 | -        foreach ($stmts as $stmt) { | |
| 131 | -            if (!$stmt instanceof Node\Stmt\Use_) { | |
| 143 | + foreach ($stmts as $stmt) | |
| 144 | +        { | |
| 145 | + if (!$stmt instanceof Node\Stmt\Use_) | |
| 146 | +            { | |
| 132 | 147 | continue; | 
| 133 | 148 | } | 
| 134 | 149 | |
| 135 | -            foreach ($stmt->uses as $use) { | |
| 150 | + foreach ($stmt->uses as $use) | |
| 151 | +            { | |
| 136 | 152 | $uses[] = $use->name->parts; | 
| 137 | 153 | } | 
| 138 | 154 | } | 
| @@ -143,7 +159,8 @@ discard block | ||
| 143 | 159 | private function buildUse(string $type, ?string $alias = null): Node\Stmt\Use_ | 
| 144 | 160 |      { | 
| 145 | 161 | $b = new Use_(new Name($type), Node\Stmt\Use_::TYPE_NORMAL); | 
| 146 | -        if (!empty($alias)) { | |
| 162 | + if (!empty($alias)) | |
| 163 | +        { | |
| 147 | 164 | $b->as($alias); | 
| 148 | 165 | } | 
| 149 | 166 | |
| @@ -27,16 +27,16 @@ | ||
| 27 | 27 | */ | 
| 28 | 28 | public function enterNode(Node $node) | 
| 29 | 29 |      { | 
| 30 | -        if ($node instanceof Class_) { | |
| 31 | -            foreach ($node->stmts as $stmt) { | |
| 32 | -                if ($stmt instanceof ClassMethod && $stmt->name === '__construct') { | |
| 30 | +        if ($node instanceof Class_){ | |
| 31 | +            foreach ($node->stmts as $stmt){ | |
| 32 | +                if ($stmt instanceof ClassMethod && $stmt->name === '__construct'){ | |
| 33 | 33 | return $stmt; | 
| 34 | 34 | } | 
| 35 | 35 | } | 
| 36 | 36 | return NodeTraverser::DONT_TRAVERSE_CHILDREN; | 
| 37 | 37 | } | 
| 38 | 38 | |
| 39 | -        if ($node instanceof Variable) { | |
| 39 | +        if ($node instanceof Variable){ | |
| 40 | 40 | $this->vars[] = $node->name; | 
| 41 | 41 | } | 
| 42 | 42 | |
| @@ -27,16 +27,20 @@ | ||
| 27 | 27 | */ | 
| 28 | 28 | public function enterNode(Node $node) | 
| 29 | 29 |      { | 
| 30 | -        if ($node instanceof Class_) { | |
| 31 | -            foreach ($node->stmts as $stmt) { | |
| 32 | -                if ($stmt instanceof ClassMethod && $stmt->name === '__construct') { | |
| 30 | + if ($node instanceof Class_) | |
| 31 | +        { | |
| 32 | + foreach ($node->stmts as $stmt) | |
| 33 | +            { | |
| 34 | + if ($stmt instanceof ClassMethod && $stmt->name === '__construct') | |
| 35 | +                { | |
| 33 | 36 | return $stmt; | 
| 34 | 37 | } | 
| 35 | 38 | } | 
| 36 | 39 | return NodeTraverser::DONT_TRAVERSE_CHILDREN; | 
| 37 | 40 | } | 
| 38 | 41 | |
| 39 | -        if ($node instanceof Variable) { | |
| 42 | + if ($node instanceof Variable) | |
| 43 | +        { | |
| 40 | 44 | $this->vars[] = $node->name; | 
| 41 | 45 | } | 
| 42 | 46 | |
| @@ -27,11 +27,11 @@ | ||
| 27 | 27 | */ | 
| 28 | 28 | public function enterNode(Node $node) | 
| 29 | 29 |      { | 
| 30 | -        if ($node instanceof Namespace_) { | |
| 30 | +        if ($node instanceof Namespace_){ | |
| 31 | 31 |              $this->namespace = implode('\\', $node->name->parts); | 
| 32 | 32 | } | 
| 33 | 33 | |
| 34 | -        if ($node instanceof Class_) { | |
| 34 | +        if ($node instanceof Class_){ | |
| 35 | 35 | $this->class = $node->name->name; | 
| 36 | 36 | |
| 37 | 37 | return NodeTraverser::STOP_TRAVERSAL; | 
| @@ -27,11 +27,13 @@ | ||
| 27 | 27 | */ | 
| 28 | 28 | public function enterNode(Node $node) | 
| 29 | 29 |      { | 
| 30 | -        if ($node instanceof Namespace_) { | |
| 30 | + if ($node instanceof Namespace_) | |
| 31 | +        { | |
| 31 | 32 |              $this->namespace = implode('\\', $node->name->parts); | 
| 32 | 33 | } | 
| 33 | 34 | |
| 34 | -        if ($node instanceof Class_) { | |
| 35 | + if ($node instanceof Class_) | |
| 36 | +        { | |
| 35 | 37 | $this->class = $node->name->name; | 
| 36 | 38 | |
| 37 | 39 | return NodeTraverser::STOP_TRAVERSAL; | 
| @@ -27,8 +27,8 @@ | ||
| 27 | 27 | */ | 
| 28 | 28 | public function enterNode(Node $node) | 
| 29 | 29 |      { | 
| 30 | -        if ($node instanceof Use_) { | |
| 31 | -            foreach ($node->uses as $use) { | |
| 30 | +        if ($node instanceof 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, | 
| @@ -27,8 +27,10 @@ | ||
| 27 | 27 | */ | 
| 28 | 28 | public function enterNode(Node $node) | 
| 29 | 29 |      { | 
| 30 | -        if ($node instanceof Use_) { | |
| 31 | -            foreach ($node->uses as $use) { | |
| 30 | + if ($node instanceof 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, | 
| @@ -49,13 +49,13 @@ discard block | ||
| 49 | 49 | */ | 
| 50 | 50 | public function leaveNode(Node $node) | 
| 51 | 51 |      { | 
| 52 | -        if (!$node instanceof Class_) { | |
| 52 | +        if (!$node instanceof Class_){ | |
| 53 | 53 | return null; | 
| 54 | 54 | } | 
| 55 | 55 | |
| 56 | 56 | $constructor = $this->getConstructorAttribute($node); | 
| 57 | 57 | $this->addDependencies($constructor); | 
| 58 | -        if (!$this->definition->hasConstructor && $this->definition->constructorParams) { | |
| 58 | +        if (!$this->definition->hasConstructor && $this->definition->constructorParams){ | |
| 59 | 59 | $this->addParentConstructorCall($constructor); | 
| 60 | 60 | } | 
| 61 | 61 | |
| @@ -71,7 +71,7 @@ discard block | ||
| 71 | 71 | */ | 
| 72 | 72 | private function addDependencies(ClassMethod $constructor): void | 
| 73 | 73 |      { | 
| 74 | -        foreach ($this->definition->dependencies as $dependency) { | |
| 74 | +        foreach ($this->definition->dependencies as $dependency){ | |
| 75 | 75 | array_unshift($constructor->params, $this->buildConstructorParam($dependency)); | 
| 76 | 76 | array_unshift( | 
| 77 | 77 | $constructor->stmts, | 
| @@ -94,34 +94,34 @@ discard block | ||
| 94 | 94 | private function addParentConstructorCall(ClassMethod $constructor): void | 
| 95 | 95 |      { | 
| 96 | 96 | $parentConstructorDependencies = []; | 
| 97 | -        foreach ($this->definition->constructorParams as $param) { | |
| 97 | +        foreach ($this->definition->constructorParams as $param){ | |
| 98 | 98 | $parentConstructorDependencies[] = new Arg(new Variable($param->name)); | 
| 99 | 99 | |
| 100 | 100 | $cp = new Param($param->name); | 
| 101 | -            if (!empty($param->type)) { | |
| 101 | +            if (!empty($param->type)){ | |
| 102 | 102 | $type = $this->getParamType($param); | 
| 103 | -                if ($param->nullable) { | |
| 103 | +                if ($param->nullable){ | |
| 104 | 104 | $type = "?$type"; | 
| 105 | 105 | } | 
| 106 | 106 | |
| 107 | 107 | $cp->setType(new Name($type)); | 
| 108 | 108 | } | 
| 109 | 109 | |
| 110 | -            if ($param->byRef) { | |
| 110 | +            if ($param->byRef){ | |
| 111 | 111 | $cp->makeByRef(); | 
| 112 | 112 | } | 
| 113 | 113 | |
| 114 | -            if ($param->isVariadic) { | |
| 114 | +            if ($param->isVariadic){ | |
| 115 | 115 | $cp->makeVariadic(); | 
| 116 | 116 | } | 
| 117 | 117 | |
| 118 | -            if ($param->hasDefault) { | |
| 118 | +            if ($param->hasDefault){ | |
| 119 | 119 | $cp->setDefault($param->default); | 
| 120 | 120 | } | 
| 121 | 121 | $constructor->params[] = $cp->getNode(); | 
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | -        if ($parentConstructorDependencies) { | |
| 124 | +        if ($parentConstructorDependencies){ | |
| 125 | 125 | array_unshift( | 
| 126 | 126 | $constructor->stmts, | 
| 127 | 127 | new Expression( | 
| @@ -151,18 +151,18 @@ discard block | ||
| 151 | 151 | |
| 152 | 152 | $params = []; | 
| 153 | 153 | |
| 154 | -        foreach ($this->definition->dependencies as $dependency) { | |
| 154 | +        foreach ($this->definition->dependencies as $dependency){ | |
| 155 | 155 | $params[] = new Line( | 
| 156 | 156 |                  sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), | 
| 157 | 157 | 'param' | 
| 158 | 158 | ); | 
| 159 | 159 | } | 
| 160 | 160 | |
| 161 | -        if (!$this->definition->hasConstructor) { | |
| 162 | -            foreach ($this->definition->constructorParams as $param) { | |
| 163 | -                if (!empty($param->type)) { | |
| 161 | +        if (!$this->definition->hasConstructor){ | |
| 162 | +            foreach ($this->definition->constructorParams as $param){ | |
| 163 | +                if (!empty($param->type)){ | |
| 164 | 164 | $type = $this->getParamType($param); | 
| 165 | -                    if ($param->nullable) { | |
| 165 | +                    if ($param->nullable){ | |
| 166 | 166 | $type = "$type|null"; | 
| 167 | 167 | } | 
| 168 | 168 | |
| @@ -170,7 +170,7 @@ discard block | ||
| 170 | 170 | sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), | 
| 171 | 171 | 'param' | 
| 172 | 172 | ); | 
| 173 | -                } else { | |
| 173 | +                }else{ | |
| 174 | 174 | $params[] = new Line( | 
| 175 | 175 |                          sprintf('$%s', $param->name), | 
| 176 | 176 | 'param' | 
| @@ -181,12 +181,12 @@ discard block | ||
| 181 | 181 | |
| 182 | 182 | $placementID = 0; | 
| 183 | 183 | $previous = null; | 
| 184 | -        foreach ($an->lines as $index => $line) { | |
| 184 | +        foreach ($an->lines as $index => $line){ | |
| 185 | 185 | // always next node | 
| 186 | 186 | $placementID = $index + 1; | 
| 187 | 187 | |
| 188 | 188 | // inject before this parameters | 
| 189 | -            if ($line->is(['throws', 'return'])) { | |
| 189 | +            if ($line->is(['throws', 'return'])){ | |
| 190 | 190 | // insert before given node | 
| 191 | 191 | $placementID--; | 
| 192 | 192 | break; | 
| @@ -195,7 +195,7 @@ discard block | ||
| 195 | 195 | $previous = $line; | 
| 196 | 196 | } | 
| 197 | 197 | |
| 198 | -        if ($previous !== null && !$previous->isEmpty()) { | |
| 198 | +        if ($previous !== null && !$previous->isEmpty()){ | |
| 199 | 199 | $placementID++; | 
| 200 | 200 | } | 
| 201 | 201 | |
| @@ -206,9 +206,9 @@ discard block | ||
| 206 | 206 | |
| 207 | 207 | private function getPropertyType(Dependency $dependency): string | 
| 208 | 208 |      { | 
| 209 | -        foreach ($this->definition->getStmts() as $stmt) { | |
| 210 | -            if ($stmt->name === $dependency->type->fullName) { | |
| 211 | -                if ($stmt->alias) { | |
| 209 | +        foreach ($this->definition->getStmts() as $stmt){ | |
| 210 | +            if ($stmt->name === $dependency->type->fullName){ | |
| 211 | +                if ($stmt->alias){ | |
| 212 | 212 | return $stmt->alias; | 
| 213 | 213 | } | 
| 214 | 214 | } | 
| @@ -219,15 +219,15 @@ discard block | ||
| 219 | 219 | |
| 220 | 220 | private function getParamType(ConstructorParam $param): string | 
| 221 | 221 |      { | 
| 222 | -        foreach ($this->definition->getStmts() as $stmt) { | |
| 223 | -            if ($stmt->name === $param->type->fullName) { | |
| 224 | -                if ($stmt->alias) { | |
| 222 | +        foreach ($this->definition->getStmts() as $stmt){ | |
| 223 | +            if ($stmt->name === $param->type->fullName){ | |
| 224 | +                if ($stmt->alias){ | |
| 225 | 225 | return $stmt->alias; | 
| 226 | 226 | } | 
| 227 | 227 | } | 
| 228 | 228 | } | 
| 229 | 229 | |
| 230 | -        if ($param->type->alias) { | |
| 230 | +        if ($param->type->alias){ | |
| 231 | 231 | return $param->type->alias; | 
| 232 | 232 | } | 
| 233 | 233 | |
| @@ -49,13 +49,15 @@ discard block | ||
| 49 | 49 | */ | 
| 50 | 50 | public function leaveNode(Node $node) | 
| 51 | 51 |      { | 
| 52 | -        if (!$node instanceof Class_) { | |
| 52 | + if (!$node instanceof Class_) | |
| 53 | +        { | |
| 53 | 54 | return null; | 
| 54 | 55 | } | 
| 55 | 56 | |
| 56 | 57 | $constructor = $this->getConstructorAttribute($node); | 
| 57 | 58 | $this->addDependencies($constructor); | 
| 58 | -        if (!$this->definition->hasConstructor && $this->definition->constructorParams) { | |
| 59 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams) | |
| 60 | +        { | |
| 59 | 61 | $this->addParentConstructorCall($constructor); | 
| 60 | 62 | } | 
| 61 | 63 | |
| @@ -71,7 +73,8 @@ discard block | ||
| 71 | 73 | */ | 
| 72 | 74 | private function addDependencies(ClassMethod $constructor): void | 
| 73 | 75 |      { | 
| 74 | -        foreach ($this->definition->dependencies as $dependency) { | |
| 76 | + foreach ($this->definition->dependencies as $dependency) | |
| 77 | +        { | |
| 75 | 78 | array_unshift($constructor->params, $this->buildConstructorParam($dependency)); | 
| 76 | 79 | array_unshift( | 
| 77 | 80 | $constructor->stmts, | 
| @@ -94,34 +97,41 @@ discard block | ||
| 94 | 97 | private function addParentConstructorCall(ClassMethod $constructor): void | 
| 95 | 98 |      { | 
| 96 | 99 | $parentConstructorDependencies = []; | 
| 97 | -        foreach ($this->definition->constructorParams as $param) { | |
| 100 | + foreach ($this->definition->constructorParams as $param) | |
| 101 | +        { | |
| 98 | 102 | $parentConstructorDependencies[] = new Arg(new Variable($param->name)); | 
| 99 | 103 | |
| 100 | 104 | $cp = new Param($param->name); | 
| 101 | -            if (!empty($param->type)) { | |
| 105 | + if (!empty($param->type)) | |
| 106 | +            { | |
| 102 | 107 | $type = $this->getParamType($param); | 
| 103 | -                if ($param->nullable) { | |
| 108 | + if ($param->nullable) | |
| 109 | +                { | |
| 104 | 110 | $type = "?$type"; | 
| 105 | 111 | } | 
| 106 | 112 | |
| 107 | 113 | $cp->setType(new Name($type)); | 
| 108 | 114 | } | 
| 109 | 115 | |
| 110 | -            if ($param->byRef) { | |
| 116 | + if ($param->byRef) | |
| 117 | +            { | |
| 111 | 118 | $cp->makeByRef(); | 
| 112 | 119 | } | 
| 113 | 120 | |
| 114 | -            if ($param->isVariadic) { | |
| 121 | + if ($param->isVariadic) | |
| 122 | +            { | |
| 115 | 123 | $cp->makeVariadic(); | 
| 116 | 124 | } | 
| 117 | 125 | |
| 118 | -            if ($param->hasDefault) { | |
| 126 | + if ($param->hasDefault) | |
| 127 | +            { | |
| 119 | 128 | $cp->setDefault($param->default); | 
| 120 | 129 | } | 
| 121 | 130 | $constructor->params[] = $cp->getNode(); | 
| 122 | 131 | } | 
| 123 | 132 | |
| 124 | -        if ($parentConstructorDependencies) { | |
| 133 | + if ($parentConstructorDependencies) | |
| 134 | +        { | |
| 125 | 135 | array_unshift( | 
| 126 | 136 | $constructor->stmts, | 
| 127 | 137 | new Expression( | 
| @@ -151,18 +161,23 @@ discard block | ||
| 151 | 161 | |
| 152 | 162 | $params = []; | 
| 153 | 163 | |
| 154 | -        foreach ($this->definition->dependencies as $dependency) { | |
| 164 | + foreach ($this->definition->dependencies as $dependency) | |
| 165 | +        { | |
| 155 | 166 | $params[] = new Line( | 
| 156 | 167 |                  sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), | 
| 157 | 168 | 'param' | 
| 158 | 169 | ); | 
| 159 | 170 | } | 
| 160 | 171 | |
| 161 | -        if (!$this->definition->hasConstructor) { | |
| 162 | -            foreach ($this->definition->constructorParams as $param) { | |
| 163 | -                if (!empty($param->type)) { | |
| 172 | + if (!$this->definition->hasConstructor) | |
| 173 | +        { | |
| 174 | + foreach ($this->definition->constructorParams as $param) | |
| 175 | +            { | |
| 176 | + if (!empty($param->type)) | |
| 177 | +                { | |
| 164 | 178 | $type = $this->getParamType($param); | 
| 165 | -                    if ($param->nullable) { | |
| 179 | + if ($param->nullable) | |
| 180 | +                    { | |
| 166 | 181 | $type = "$type|null"; | 
| 167 | 182 | } | 
| 168 | 183 | |
| @@ -170,7 +185,9 @@ discard block | ||
| 170 | 185 | sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), | 
| 171 | 186 | 'param' | 
| 172 | 187 | ); | 
| 173 | -                } else { | |
| 188 | + } | |
| 189 | + else | |
| 190 | +                { | |
| 174 | 191 | $params[] = new Line( | 
| 175 | 192 |                          sprintf('$%s', $param->name), | 
| 176 | 193 | 'param' | 
| @@ -181,12 +198,14 @@ discard block | ||
| 181 | 198 | |
| 182 | 199 | $placementID = 0; | 
| 183 | 200 | $previous = null; | 
| 184 | -        foreach ($an->lines as $index => $line) { | |
| 201 | + foreach ($an->lines as $index => $line) | |
| 202 | +        { | |
| 185 | 203 | // always next node | 
| 186 | 204 | $placementID = $index + 1; | 
| 187 | 205 | |
| 188 | 206 | // inject before this parameters | 
| 189 | -            if ($line->is(['throws', 'return'])) { | |
| 207 | + if ($line->is(['throws', 'return'])) | |
| 208 | +            { | |
| 190 | 209 | // insert before given node | 
| 191 | 210 | $placementID--; | 
| 192 | 211 | break; | 
| @@ -195,7 +214,8 @@ discard block | ||
| 195 | 214 | $previous = $line; | 
| 196 | 215 | } | 
| 197 | 216 | |
| 198 | -        if ($previous !== null && !$previous->isEmpty()) { | |
| 217 | + if ($previous !== null && !$previous->isEmpty()) | |
| 218 | +        { | |
| 199 | 219 | $placementID++; | 
| 200 | 220 | } | 
| 201 | 221 | |
| @@ -206,9 +226,12 @@ discard block | ||
| 206 | 226 | |
| 207 | 227 | private function getPropertyType(Dependency $dependency): string | 
| 208 | 228 |      { | 
| 209 | -        foreach ($this->definition->getStmts() as $stmt) { | |
| 210 | -            if ($stmt->name === $dependency->type->fullName) { | |
| 211 | -                if ($stmt->alias) { | |
| 229 | + foreach ($this->definition->getStmts() as $stmt) | |
| 230 | +        { | |
| 231 | + if ($stmt->name === $dependency->type->fullName) | |
| 232 | +            { | |
| 233 | + if ($stmt->alias) | |
| 234 | +                { | |
| 212 | 235 | return $stmt->alias; | 
| 213 | 236 | } | 
| 214 | 237 | } | 
| @@ -219,15 +242,19 @@ discard block | ||
| 219 | 242 | |
| 220 | 243 | private function getParamType(ConstructorParam $param): string | 
| 221 | 244 |      { | 
| 222 | -        foreach ($this->definition->getStmts() as $stmt) { | |
| 223 | -            if ($stmt->name === $param->type->fullName) { | |
| 224 | -                if ($stmt->alias) { | |
| 245 | + foreach ($this->definition->getStmts() as $stmt) | |
| 246 | +        { | |
| 247 | + if ($stmt->name === $param->type->fullName) | |
| 248 | +            { | |
| 249 | + if ($stmt->alias) | |
| 250 | +                { | |
| 225 | 251 | return $stmt->alias; | 
| 226 | 252 | } | 
| 227 | 253 | } | 
| 228 | 254 | } | 
| 229 | 255 | |
| 230 | -        if ($param->type->alias) { | |
| 256 | + if ($param->type->alias) | |
| 257 | +        { | |
| 231 | 258 | return $param->type->alias; | 
| 232 | 259 | } | 
| 233 | 260 | |