@@ -35,15 +35,15 @@ discard block |
||
35 | 35 | |
36 | 36 | protected function getConstructor(\ReflectionClass $class): ?\ReflectionMethod |
37 | 37 | { |
38 | - if ($class->hasMethod(self::CONSTRUCTOR_NAME)) { |
|
38 | + if ($class->hasMethod(self::CONSTRUCTOR_NAME)){ |
|
39 | 39 | return $class->getMethod(self::CONSTRUCTOR_NAME); |
40 | 40 | } |
41 | 41 | |
42 | - if ($constructor = $this->getTraitConstructors($class)) { |
|
42 | + if ($constructor = $this->getTraitConstructors($class)){ |
|
43 | 43 | return $constructor; |
44 | 44 | } |
45 | 45 | |
46 | - if ($parent = $class->getParentClass()) { |
|
46 | + if ($parent = $class->getParentClass()){ |
|
47 | 47 | return $this->getConstructor($parent); |
48 | 48 | } |
49 | 49 | |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | |
53 | 53 | private function getTraitConstructors(\ReflectionClass $class): ?\ReflectionMethod |
54 | 54 | { |
55 | - foreach ($class->getTraits() as $trait) { |
|
56 | - if ($constructor = $this->getConstructor($trait)) { |
|
55 | + foreach ($class->getTraits() as $trait){ |
|
56 | + if ($constructor = $this->getConstructor($trait)){ |
|
57 | 57 | return $constructor; |
58 | 58 | } |
59 | 59 | |
60 | - if ($constructor = $this->getTraitConstructors($trait)) { |
|
60 | + if ($constructor = $this->getTraitConstructors($trait)){ |
|
61 | 61 | return $constructor; |
62 | 62 | } |
63 | 63 | } |
@@ -35,15 +35,18 @@ discard block |
||
35 | 35 | |
36 | 36 | protected function getConstructor(\ReflectionClass $class): ?\ReflectionMethod |
37 | 37 | { |
38 | - if ($class->hasMethod(self::CONSTRUCTOR_NAME)) { |
|
38 | + if ($class->hasMethod(self::CONSTRUCTOR_NAME)) |
|
39 | + { |
|
39 | 40 | return $class->getMethod(self::CONSTRUCTOR_NAME); |
40 | 41 | } |
41 | 42 | |
42 | - if ($constructor = $this->getTraitConstructors($class)) { |
|
43 | + if ($constructor = $this->getTraitConstructors($class)) |
|
44 | + { |
|
43 | 45 | return $constructor; |
44 | 46 | } |
45 | 47 | |
46 | - if ($parent = $class->getParentClass()) { |
|
48 | + if ($parent = $class->getParentClass()) |
|
49 | + { |
|
47 | 50 | return $this->getConstructor($parent); |
48 | 51 | } |
49 | 52 | |
@@ -52,12 +55,15 @@ discard block |
||
52 | 55 | |
53 | 56 | private function getTraitConstructors(\ReflectionClass $class): ?\ReflectionMethod |
54 | 57 | { |
55 | - foreach ($class->getTraits() as $trait) { |
|
56 | - if ($constructor = $this->getConstructor($trait)) { |
|
58 | + foreach ($class->getTraits() as $trait) |
|
59 | + { |
|
60 | + if ($constructor = $this->getConstructor($trait)) |
|
61 | + { |
|
57 | 62 | return $constructor; |
58 | 63 | } |
59 | 64 | |
60 | - if ($constructor = $this->getTraitConstructors($trait)) { |
|
65 | + if ($constructor = $this->getTraitConstructors($trait)) |
|
66 | + { |
|
61 | 67 | return $constructor; |
62 | 68 | } |
63 | 69 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | */ |
50 | 50 | public function instantiate(\ReflectionClass $attr, array $arguments, \Reflector $context = null): object |
51 | 51 | { |
52 | - if ($this->isNamedArguments($attr)) { |
|
52 | + if ($this->isNamedArguments($attr)){ |
|
53 | 53 | return $this->named->instantiate($attr, $arguments, $context); |
54 | 54 | } |
55 | 55 |
@@ -49,7 +49,8 @@ |
||
49 | 49 | */ |
50 | 50 | public function instantiate(\ReflectionClass $attr, array $arguments, \Reflector $context = null): object |
51 | 51 | { |
52 | - if ($this->isNamedArguments($attr)) { |
|
52 | + if ($this->isNamedArguments($attr)) |
|
53 | + { |
|
53 | 54 | return $this->named->instantiate($attr, $arguments, $context); |
54 | 55 | } |
55 | 56 |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | private function checkAvailability(): void |
80 | 80 | { |
81 | - if (!self::isAvailable()) { |
|
81 | + if (!self::isAvailable()){ |
|
82 | 82 | throw new InitializationException('Requires the PHP >= 8.0'); |
83 | 83 | } |
84 | 84 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | private function format(\Reflector $context, iterable $attributes): iterable |
92 | 92 | { |
93 | - foreach ($attributes as $attribute) { |
|
93 | + foreach ($attributes as $attribute){ |
|
94 | 94 | $this->assertClassExists($attribute->getName(), $context); |
95 | 95 | |
96 | 96 | yield new \ReflectionClass($attribute->getName()) => $attribute->getArguments(); |
@@ -78,7 +78,8 @@ discard block |
||
78 | 78 | |
79 | 79 | private function checkAvailability(): void |
80 | 80 | { |
81 | - if (!self::isAvailable()) { |
|
81 | + if (!self::isAvailable()) |
|
82 | + { |
|
82 | 83 | throw new InitializationException('Requires the PHP >= 8.0'); |
83 | 84 | } |
84 | 85 | } |
@@ -90,7 +91,8 @@ discard block |
||
90 | 91 | */ |
91 | 92 | private function format(\Reflector $context, iterable $attributes): iterable |
92 | 93 | { |
93 | - foreach ($attributes as $attribute) { |
|
94 | + foreach ($attributes as $attribute) |
|
95 | + { |
|
94 | 96 | $this->assertClassExists($attribute->getName(), $context); |
95 | 97 | |
96 | 98 | yield new \ReflectionClass($attribute->getName()) => $attribute->getArguments(); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | public function render(?\Reflector $reflector): string |
61 | 61 | { |
62 | - switch (true) { |
|
62 | + switch (true){ |
|
63 | 63 | case $reflector instanceof \ReflectionClass: |
64 | 64 | return $this->renderClassContext($reflector); |
65 | 65 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | |
83 | 83 | public function renderClassContext(\ReflectionClass $class): string |
84 | 84 | { |
85 | - if ($class->isAnonymous()) { |
|
85 | + if ($class->isAnonymous()){ |
|
86 | 86 | return \sprintf(self::FORMAT_ANONYMOUS_CLASS, $class->getFileName(), $class->getStartLine()); |
87 | 87 | } |
88 | 88 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | public function renderFunctionContext(\ReflectionFunction $fn): string |
100 | 100 | { |
101 | - if ($fn->isClosure()) { |
|
101 | + if ($fn->isClosure()){ |
|
102 | 102 | return \sprintf(self::FORMAT_ANONYMOUS_FUNCTION, $fn->getFileName(), $fn->getStartLine()); |
103 | 103 | } |
104 | 104 | |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | |
108 | 108 | public function renderCallableContext(\ReflectionFunctionAbstract $function): string |
109 | 109 | { |
110 | - if ($function instanceof \ReflectionMethod) { |
|
110 | + if ($function instanceof \ReflectionMethod){ |
|
111 | 111 | return $this->renderMethodContext($function); |
112 | 112 | } |
113 | 113 | |
114 | - if ($function instanceof \ReflectionFunction) { |
|
114 | + if ($function instanceof \ReflectionFunction){ |
|
115 | 115 | return $this->renderFunctionContext($function); |
116 | 116 | } |
117 | 117 |
@@ -59,7 +59,8 @@ discard block |
||
59 | 59 | |
60 | 60 | public function render(?\Reflector $reflector): string |
61 | 61 | { |
62 | - switch (true) { |
|
62 | + switch (true) |
|
63 | + { |
|
63 | 64 | case $reflector instanceof \ReflectionClass: |
64 | 65 | return $this->renderClassContext($reflector); |
65 | 66 | |
@@ -82,7 +83,8 @@ discard block |
||
82 | 83 | |
83 | 84 | public function renderClassContext(\ReflectionClass $class): string |
84 | 85 | { |
85 | - if ($class->isAnonymous()) { |
|
86 | + if ($class->isAnonymous()) |
|
87 | + { |
|
86 | 88 | return \sprintf(self::FORMAT_ANONYMOUS_CLASS, $class->getFileName(), $class->getStartLine()); |
87 | 89 | } |
88 | 90 | |
@@ -98,7 +100,8 @@ discard block |
||
98 | 100 | |
99 | 101 | public function renderFunctionContext(\ReflectionFunction $fn): string |
100 | 102 | { |
101 | - if ($fn->isClosure()) { |
|
103 | + if ($fn->isClosure()) |
|
104 | + { |
|
102 | 105 | return \sprintf(self::FORMAT_ANONYMOUS_FUNCTION, $fn->getFileName(), $fn->getStartLine()); |
103 | 106 | } |
104 | 107 | |
@@ -107,11 +110,13 @@ discard block |
||
107 | 110 | |
108 | 111 | public function renderCallableContext(\ReflectionFunctionAbstract $function): string |
109 | 112 | { |
110 | - if ($function instanceof \ReflectionMethod) { |
|
113 | + if ($function instanceof \ReflectionMethod) |
|
114 | + { |
|
111 | 115 | return $this->renderMethodContext($function); |
112 | 116 | } |
113 | 117 | |
114 | - if ($function instanceof \ReflectionFunction) { |
|
118 | + if ($function instanceof \ReflectionFunction) |
|
119 | + { |
|
115 | 120 | return $this->renderFunctionContext($function); |
116 | 121 | } |
117 | 122 |
@@ -33,7 +33,7 @@ |
||
33 | 33 | |
34 | 34 | public function is(array $type): bool |
35 | 35 | { |
36 | - if ($this->type === null) { |
|
36 | + if ($this->type === null){ |
|
37 | 37 | return false; |
38 | 38 | } |
39 | 39 |
@@ -33,7 +33,8 @@ |
||
33 | 33 | |
34 | 34 | public function is(array $type): bool |
35 | 35 | { |
36 | - if ($this->type === null) { |
|
36 | + if ($this->type === null) |
|
37 | + { |
|
37 | 38 | return false; |
38 | 39 | } |
39 | 40 |
@@ -33,7 +33,7 @@ |
||
33 | 33 | |
34 | 34 | public function __toString(): string |
35 | 35 | { |
36 | - if ($this->alias) { |
|
36 | + if ($this->alias){ |
|
37 | 37 | return "{$this->name} as $this->alias"; |
38 | 38 | } |
39 | 39 |
@@ -33,7 +33,8 @@ |
||
33 | 33 | |
34 | 34 | public function __toString(): string |
35 | 35 | { |
36 | - if ($this->alias) { |
|
36 | + if ($this->alias) |
|
37 | + { |
|
37 | 38 | return "{$this->name} as $this->alias"; |
38 | 39 | } |
39 | 40 |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | |
43 | 43 | private function getReservedNamespacesWithAlias(ClassNode $definition, array $namespaces): array |
44 | 44 | { |
45 | - foreach ($definition->getStmts() as $stmt) { |
|
46 | - if (!$stmt->alias) { |
|
45 | + foreach ($definition->getStmts() as $stmt){ |
|
46 | + if (!$stmt->alias){ |
|
47 | 47 | continue; |
48 | 48 | } |
49 | 49 | |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | |
56 | 56 | private function getReservedNamespacesWithoutAlias(ClassNode $definition, array $namespaces): array |
57 | 57 | { |
58 | - foreach ($definition->getStmts() as $stmt) { |
|
59 | - if ($stmt->alias || isset($namespaces[$stmt->shortName])) { |
|
58 | + foreach ($definition->getStmts() as $stmt){ |
|
59 | + if ($stmt->alias || isset($namespaces[$stmt->shortName])){ |
|
60 | 60 | continue; |
61 | 61 | } |
62 | 62 | |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | private function initiateCounters(array $namespaces): array |
70 | 70 | { |
71 | 71 | $counters = []; |
72 | - foreach ($namespaces as $shortName => $fullName) { |
|
72 | + foreach ($namespaces as $shortName => $fullName){ |
|
73 | 73 | $namespace = $this->parseNamespace($shortName, $fullName); |
74 | 74 | |
75 | - if (isset($counters[$namespace->name])) { |
|
75 | + if (isset($counters[$namespace->name])){ |
|
76 | 76 | $counters[$namespace->name][$namespace->sequence] = $namespace; |
77 | - } else { |
|
77 | + }else{ |
|
78 | 78 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
79 | 79 | } |
80 | 80 | } |
@@ -84,52 +84,52 @@ discard block |
||
84 | 84 | |
85 | 85 | private function resolveImportsNamespaces(ClassNode $definition, array $counters): void |
86 | 86 | { |
87 | - if (!$definition->hasConstructor && $definition->constructorParams) { |
|
88 | - foreach ($definition->constructorParams as $param) { |
|
87 | + if (!$definition->hasConstructor && $definition->constructorParams){ |
|
88 | + foreach ($definition->constructorParams as $param){ |
|
89 | 89 | //no type (or type is internal), do nothing |
90 | - if (empty($param->type) || $param->isBuiltIn()) { |
|
90 | + if (empty($param->type) || $param->isBuiltIn()){ |
|
91 | 91 | continue; |
92 | 92 | } |
93 | 93 | |
94 | 94 | $namespace = $this->parseNamespaceFromType($param->type); |
95 | - if (isset($counters[$namespace->name])) { |
|
96 | - if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) { |
|
95 | + if (isset($counters[$namespace->name])){ |
|
96 | + if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)){ |
|
97 | 97 | continue; |
98 | 98 | } |
99 | 99 | |
100 | 100 | $sequence = $this->sequences->find(array_keys($counters[$namespace->name]), $namespace->sequence); |
101 | - if ($sequence !== $namespace->sequence) { |
|
101 | + if ($sequence !== $namespace->sequence){ |
|
102 | 102 | $namespace->sequence = $sequence; |
103 | 103 | |
104 | 104 | $param->type->alias = $namespace->fullName(); |
105 | 105 | } |
106 | 106 | |
107 | 107 | $counters[$namespace->name][$sequence] = $namespace; |
108 | - } else { |
|
108 | + }else{ |
|
109 | 109 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
110 | 110 | } |
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
114 | - foreach ($definition->dependencies as $dependency) { |
|
114 | + foreach ($definition->dependencies as $dependency){ |
|
115 | 115 | $namespace = $this->parseNamespaceFromType($dependency->type); |
116 | - if (isset($counters[$namespace->name])) { |
|
116 | + if (isset($counters[$namespace->name])){ |
|
117 | 117 | $alreadyImported = $this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace); |
118 | - if ($alreadyImported !== null) { |
|
118 | + if ($alreadyImported !== null){ |
|
119 | 119 | $dependency->type->alias = $alreadyImported->fullName(); |
120 | 120 | |
121 | 121 | continue; |
122 | 122 | } |
123 | 123 | |
124 | 124 | $sequence = $this->sequences->find(array_keys($counters[$namespace->name]), $namespace->sequence); |
125 | - if ($sequence !== $namespace->sequence) { |
|
125 | + if ($sequence !== $namespace->sequence){ |
|
126 | 126 | $namespace->sequence = $sequence; |
127 | 127 | |
128 | 128 | $dependency->type->alias = $namespace->fullName(); |
129 | 129 | } |
130 | 130 | |
131 | 131 | $counters[$namespace->name][$sequence] = $namespace; |
132 | - } else { |
|
132 | + }else{ |
|
133 | 133 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
134 | 134 | } |
135 | 135 | } |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | */ |
141 | 141 | private function getAlreadyImportedNamespace(array $counters, NamespaceEntity $namespace): ?NamespaceEntity |
142 | 142 | { |
143 | - foreach ($counters as $counter) { |
|
144 | - if ($counter->equals($namespace)) { |
|
143 | + foreach ($counters as $counter){ |
|
144 | + if ($counter->equals($namespace)){ |
|
145 | 145 | return $counter; |
146 | 146 | } |
147 | 147 | } |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | |
157 | 157 | private function parseNamespace(string $shortName, string $fullName): NamespaceEntity |
158 | 158 | { |
159 | - if (preg_match("/\d+$/", $shortName, $match)) { |
|
159 | + if (preg_match("/\d+$/", $shortName, $match)){ |
|
160 | 160 | $sequence = (int)$match[0]; |
161 | - if ($sequence > 0) { |
|
161 | + if ($sequence > 0){ |
|
162 | 162 | return NamespaceEntity::createWithSequence( |
163 | 163 | Utils::trimTrailingDigits($shortName, $sequence), |
164 | 164 | $fullName, |
@@ -42,8 +42,10 @@ discard block |
||
42 | 42 | |
43 | 43 | private function getReservedNamespacesWithAlias(ClassNode $definition, array $namespaces): array |
44 | 44 | { |
45 | - foreach ($definition->getStmts() as $stmt) { |
|
46 | - if (!$stmt->alias) { |
|
45 | + foreach ($definition->getStmts() as $stmt) |
|
46 | + { |
|
47 | + if (!$stmt->alias) |
|
48 | + { |
|
47 | 49 | continue; |
48 | 50 | } |
49 | 51 | |
@@ -55,8 +57,10 @@ discard block |
||
55 | 57 | |
56 | 58 | private function getReservedNamespacesWithoutAlias(ClassNode $definition, array $namespaces): array |
57 | 59 | { |
58 | - foreach ($definition->getStmts() as $stmt) { |
|
59 | - if ($stmt->alias || isset($namespaces[$stmt->shortName])) { |
|
60 | + foreach ($definition->getStmts() as $stmt) |
|
61 | + { |
|
62 | + if ($stmt->alias || isset($namespaces[$stmt->shortName])) |
|
63 | + { |
|
60 | 64 | continue; |
61 | 65 | } |
62 | 66 | |
@@ -69,12 +73,16 @@ discard block |
||
69 | 73 | private function initiateCounters(array $namespaces): array |
70 | 74 | { |
71 | 75 | $counters = []; |
72 | - foreach ($namespaces as $shortName => $fullName) { |
|
76 | + foreach ($namespaces as $shortName => $fullName) |
|
77 | + { |
|
73 | 78 | $namespace = $this->parseNamespace($shortName, $fullName); |
74 | 79 | |
75 | - if (isset($counters[$namespace->name])) { |
|
80 | + if (isset($counters[$namespace->name])) |
|
81 | + { |
|
76 | 82 | $counters[$namespace->name][$namespace->sequence] = $namespace; |
77 | - } else { |
|
83 | + } |
|
84 | + else |
|
85 | + { |
|
78 | 86 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
79 | 87 | } |
80 | 88 | } |
@@ -84,52 +92,66 @@ discard block |
||
84 | 92 | |
85 | 93 | private function resolveImportsNamespaces(ClassNode $definition, array $counters): void |
86 | 94 | { |
87 | - if (!$definition->hasConstructor && $definition->constructorParams) { |
|
88 | - foreach ($definition->constructorParams as $param) { |
|
95 | + if (!$definition->hasConstructor && $definition->constructorParams) |
|
96 | + { |
|
97 | + foreach ($definition->constructorParams as $param) |
|
98 | + { |
|
89 | 99 | //no type (or type is internal), do nothing |
90 | - if (empty($param->type) || $param->isBuiltIn()) { |
|
100 | + if (empty($param->type) || $param->isBuiltIn()) |
|
101 | + { |
|
91 | 102 | continue; |
92 | 103 | } |
93 | 104 | |
94 | 105 | $namespace = $this->parseNamespaceFromType($param->type); |
95 | - if (isset($counters[$namespace->name])) { |
|
96 | - if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) { |
|
106 | + if (isset($counters[$namespace->name])) |
|
107 | + { |
|
108 | + if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) |
|
109 | + { |
|
97 | 110 | continue; |
98 | 111 | } |
99 | 112 | |
100 | 113 | $sequence = $this->sequences->find(array_keys($counters[$namespace->name]), $namespace->sequence); |
101 | - if ($sequence !== $namespace->sequence) { |
|
114 | + if ($sequence !== $namespace->sequence) |
|
115 | + { |
|
102 | 116 | $namespace->sequence = $sequence; |
103 | 117 | |
104 | 118 | $param->type->alias = $namespace->fullName(); |
105 | 119 | } |
106 | 120 | |
107 | 121 | $counters[$namespace->name][$sequence] = $namespace; |
108 | - } else { |
|
122 | + } |
|
123 | + else |
|
124 | + { |
|
109 | 125 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
110 | 126 | } |
111 | 127 | } |
112 | 128 | } |
113 | 129 | |
114 | - foreach ($definition->dependencies as $dependency) { |
|
130 | + foreach ($definition->dependencies as $dependency) |
|
131 | + { |
|
115 | 132 | $namespace = $this->parseNamespaceFromType($dependency->type); |
116 | - if (isset($counters[$namespace->name])) { |
|
133 | + if (isset($counters[$namespace->name])) |
|
134 | + { |
|
117 | 135 | $alreadyImported = $this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace); |
118 | - if ($alreadyImported !== null) { |
|
136 | + if ($alreadyImported !== null) |
|
137 | + { |
|
119 | 138 | $dependency->type->alias = $alreadyImported->fullName(); |
120 | 139 | |
121 | 140 | continue; |
122 | 141 | } |
123 | 142 | |
124 | 143 | $sequence = $this->sequences->find(array_keys($counters[$namespace->name]), $namespace->sequence); |
125 | - if ($sequence !== $namespace->sequence) { |
|
144 | + if ($sequence !== $namespace->sequence) |
|
145 | + { |
|
126 | 146 | $namespace->sequence = $sequence; |
127 | 147 | |
128 | 148 | $dependency->type->alias = $namespace->fullName(); |
129 | 149 | } |
130 | 150 | |
131 | 151 | $counters[$namespace->name][$sequence] = $namespace; |
132 | - } else { |
|
152 | + } |
|
153 | + else |
|
154 | + { |
|
133 | 155 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
134 | 156 | } |
135 | 157 | } |
@@ -140,8 +162,10 @@ discard block |
||
140 | 162 | */ |
141 | 163 | private function getAlreadyImportedNamespace(array $counters, NamespaceEntity $namespace): ?NamespaceEntity |
142 | 164 | { |
143 | - foreach ($counters as $counter) { |
|
144 | - if ($counter->equals($namespace)) { |
|
165 | + foreach ($counters as $counter) |
|
166 | + { |
|
167 | + if ($counter->equals($namespace)) |
|
168 | + { |
|
145 | 169 | return $counter; |
146 | 170 | } |
147 | 171 | } |
@@ -156,9 +180,11 @@ discard block |
||
156 | 180 | |
157 | 181 | private function parseNamespace(string $shortName, string $fullName): NamespaceEntity |
158 | 182 | { |
159 | - if (preg_match("/\d+$/", $shortName, $match)) { |
|
183 | + if (preg_match("/\d+$/", $shortName, $match)) |
|
184 | + { |
|
160 | 185 | $sequence = (int)$match[0]; |
161 | - if ($sequence > 0) { |
|
186 | + if ($sequence > 0) |
|
187 | + { |
|
162 | 188 | return NamespaceEntity::createWithSequence( |
163 | 189 | Utils::trimTrailingDigits($shortName, $sequence), |
164 | 190 | $fullName, |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | private function getConstructorReservedNames(ClassNode $definition): array |
36 | 36 | { |
37 | 37 | $names = []; |
38 | - foreach ($definition->constructorVars as $name) { |
|
38 | + foreach ($definition->constructorVars as $name){ |
|
39 | 39 | $names[] = $name; |
40 | 40 | } |
41 | 41 | |
42 | - foreach ($definition->constructorParams as $param) { |
|
42 | + foreach ($definition->constructorParams as $param){ |
|
43 | 43 | $names[] = $param->name; |
44 | 44 | } |
45 | 45 | |
@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | private function initiateCounters(array $names): array |
50 | 50 | { |
51 | 51 | $counters = []; |
52 | - foreach ($names as $name) { |
|
52 | + foreach ($names as $name){ |
|
53 | 53 | $name = $this->parseName($name); |
54 | 54 | |
55 | - if (isset($counters[$name->name])) { |
|
55 | + if (isset($counters[$name->name])){ |
|
56 | 56 | $counters[$name->name][$name->sequence] = $name->fullName(); |
57 | - } else { |
|
57 | + }else{ |
|
58 | 58 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
59 | 59 | } |
60 | 60 | } |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | |
65 | 65 | private function addPostfixes(ClassNode $definition, array $counters): void |
66 | 66 | { |
67 | - foreach ($definition->dependencies as $dependency) { |
|
67 | + foreach ($definition->dependencies as $dependency){ |
|
68 | 68 | $name = $this->parseName($dependency->var); |
69 | - if (isset($counters[$name->name])) { |
|
69 | + if (isset($counters[$name->name])){ |
|
70 | 70 | $sequence = $this->sequences->find(array_keys($counters[$name->name]), $name->sequence); |
71 | - if ($sequence !== $name->sequence) { |
|
71 | + if ($sequence !== $name->sequence){ |
|
72 | 72 | $name->sequence = $sequence; |
73 | 73 | |
74 | 74 | $dependency->var = $name->fullName(); |
75 | 75 | } |
76 | 76 | |
77 | 77 | $counters[$name->name][$sequence] = $name->fullName(); |
78 | - } else { |
|
78 | + }else{ |
|
79 | 79 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
80 | 80 | } |
81 | 81 | } |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | |
84 | 84 | private function parseName(string $name): NameEntity |
85 | 85 | { |
86 | - if (preg_match("/\d+$/", $name, $match)) { |
|
86 | + if (preg_match("/\d+$/", $name, $match)){ |
|
87 | 87 | $sequence = (int)$match[0]; |
88 | - if ($sequence > 0) { |
|
88 | + if ($sequence > 0){ |
|
89 | 89 | return NameEntity::createWithSequence(Utils::trimTrailingDigits($name, $sequence), $sequence); |
90 | 90 | } |
91 | 91 | } |
@@ -35,11 +35,13 @@ discard block |
||
35 | 35 | private function getConstructorReservedNames(ClassNode $definition): array |
36 | 36 | { |
37 | 37 | $names = []; |
38 | - foreach ($definition->constructorVars as $name) { |
|
38 | + foreach ($definition->constructorVars as $name) |
|
39 | + { |
|
39 | 40 | $names[] = $name; |
40 | 41 | } |
41 | 42 | |
42 | - foreach ($definition->constructorParams as $param) { |
|
43 | + foreach ($definition->constructorParams as $param) |
|
44 | + { |
|
43 | 45 | $names[] = $param->name; |
44 | 46 | } |
45 | 47 | |
@@ -49,12 +51,16 @@ discard block |
||
49 | 51 | private function initiateCounters(array $names): array |
50 | 52 | { |
51 | 53 | $counters = []; |
52 | - foreach ($names as $name) { |
|
54 | + foreach ($names as $name) |
|
55 | + { |
|
53 | 56 | $name = $this->parseName($name); |
54 | 57 | |
55 | - if (isset($counters[$name->name])) { |
|
58 | + if (isset($counters[$name->name])) |
|
59 | + { |
|
56 | 60 | $counters[$name->name][$name->sequence] = $name->fullName(); |
57 | - } else { |
|
61 | + } |
|
62 | + else |
|
63 | + { |
|
58 | 64 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
59 | 65 | } |
60 | 66 | } |
@@ -64,18 +70,23 @@ discard block |
||
64 | 70 | |
65 | 71 | private function addPostfixes(ClassNode $definition, array $counters): void |
66 | 72 | { |
67 | - foreach ($definition->dependencies as $dependency) { |
|
73 | + foreach ($definition->dependencies as $dependency) |
|
74 | + { |
|
68 | 75 | $name = $this->parseName($dependency->var); |
69 | - if (isset($counters[$name->name])) { |
|
76 | + if (isset($counters[$name->name])) |
|
77 | + { |
|
70 | 78 | $sequence = $this->sequences->find(array_keys($counters[$name->name]), $name->sequence); |
71 | - if ($sequence !== $name->sequence) { |
|
79 | + if ($sequence !== $name->sequence) |
|
80 | + { |
|
72 | 81 | $name->sequence = $sequence; |
73 | 82 | |
74 | 83 | $dependency->var = $name->fullName(); |
75 | 84 | } |
76 | 85 | |
77 | 86 | $counters[$name->name][$sequence] = $name->fullName(); |
78 | - } else { |
|
87 | + } |
|
88 | + else |
|
89 | + { |
|
79 | 90 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
80 | 91 | } |
81 | 92 | } |
@@ -83,9 +94,11 @@ discard block |
||
83 | 94 | |
84 | 95 | private function parseName(string $name): NameEntity |
85 | 96 | { |
86 | - if (preg_match("/\d+$/", $name, $match)) { |
|
97 | + if (preg_match("/\d+$/", $name, $match)) |
|
98 | + { |
|
87 | 99 | $sequence = (int)$match[0]; |
88 | - if ($sequence > 0) { |
|
100 | + if ($sequence > 0) |
|
101 | + { |
|
89 | 102 | return NameEntity::createWithSequence(Utils::trimTrailingDigits($name, $sequence), $sequence); |
90 | 103 | } |
91 | 104 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | $results = [$this->readProperties($class)]; |
53 | 53 | |
54 | 54 | $parent = $class->getParentClass(); |
55 | - while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) { |
|
55 | + while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])){ |
|
56 | 56 | $results[] = $this->readProperties($parent); |
57 | 57 | $parent = $parent->getParentClass(); |
58 | 58 | } |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | { |
81 | 81 | $result = []; |
82 | 82 | |
83 | - foreach ($properties as $target) { |
|
84 | - if ($target instanceof \Throwable) { |
|
83 | + foreach ($properties as $target){ |
|
84 | + if ($target instanceof \Throwable){ |
|
85 | 85 | $result[] = sprintf( |
86 | 86 | '<fg=red>%s [f: %s, l: %s]</fg=red>', |
87 | 87 | $target->getMessage(), |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | continue; |
92 | 92 | } |
93 | 93 | |
94 | - if ($target === null) { |
|
94 | + if ($target === null){ |
|
95 | 95 | $result[] = '<fg=yellow>undefined</fg=yellow>'; |
96 | 96 | continue; |
97 | 97 | } |
@@ -107,16 +107,16 @@ discard block |
||
107 | 107 | */ |
108 | 108 | private function readProperties(\ReflectionClass $class): array |
109 | 109 | { |
110 | - if (isset($this->cache[$class->getFileName()])) { |
|
110 | + if (isset($this->cache[$class->getFileName()])){ |
|
111 | 111 | $proto = $this->cache[$class->getFileName()]; |
112 | - } else { |
|
112 | + }else{ |
|
113 | 113 | $proto = $this->getExtractor()->getPrototypeProperties(file_get_contents($class->getFilename())); |
114 | 114 | $this->cache[$class->getFileName()] = $proto; |
115 | 115 | } |
116 | 116 | |
117 | 117 | $result = []; |
118 | - foreach ($proto as $name) { |
|
119 | - if (!isset($result[$name])) { |
|
118 | + foreach ($proto as $name){ |
|
119 | + if (!isset($result[$name])){ |
|
120 | 120 | $result[$name] = $this->registry->resolveProperty($name); |
121 | 121 | } |
122 | 122 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | */ |
132 | 132 | private function reverse(array $results): \Generator |
133 | 133 | { |
134 | - foreach (\array_reverse($results) as $result) { |
|
134 | + foreach (\array_reverse($results) as $result){ |
|
135 | 135 | yield from $result; |
136 | 136 | } |
137 | 137 | } |
@@ -52,7 +52,8 @@ discard block |
||
52 | 52 | $results = [$this->readProperties($class)]; |
53 | 53 | |
54 | 54 | $parent = $class->getParentClass(); |
55 | - while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) { |
|
55 | + while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) |
|
56 | + { |
|
56 | 57 | $results[] = $this->readProperties($parent); |
57 | 58 | $parent = $parent->getParentClass(); |
58 | 59 | } |
@@ -80,8 +81,10 @@ discard block |
||
80 | 81 | { |
81 | 82 | $result = []; |
82 | 83 | |
83 | - foreach ($properties as $target) { |
|
84 | - if ($target instanceof \Throwable) { |
|
84 | + foreach ($properties as $target) |
|
85 | + { |
|
86 | + if ($target instanceof \Throwable) |
|
87 | + { |
|
85 | 88 | $result[] = sprintf( |
86 | 89 | '<fg=red>%s [f: %s, l: %s]</fg=red>', |
87 | 90 | $target->getMessage(), |
@@ -91,7 +94,8 @@ discard block |
||
91 | 94 | continue; |
92 | 95 | } |
93 | 96 | |
94 | - if ($target === null) { |
|
97 | + if ($target === null) |
|
98 | + { |
|
95 | 99 | $result[] = '<fg=yellow>undefined</fg=yellow>'; |
96 | 100 | continue; |
97 | 101 | } |
@@ -107,16 +111,21 @@ discard block |
||
107 | 111 | */ |
108 | 112 | private function readProperties(\ReflectionClass $class): array |
109 | 113 | { |
110 | - if (isset($this->cache[$class->getFileName()])) { |
|
114 | + if (isset($this->cache[$class->getFileName()])) |
|
115 | + { |
|
111 | 116 | $proto = $this->cache[$class->getFileName()]; |
112 | - } else { |
|
117 | + } |
|
118 | + else |
|
119 | + { |
|
113 | 120 | $proto = $this->getExtractor()->getPrototypeProperties(file_get_contents($class->getFilename())); |
114 | 121 | $this->cache[$class->getFileName()] = $proto; |
115 | 122 | } |
116 | 123 | |
117 | 124 | $result = []; |
118 | - foreach ($proto as $name) { |
|
119 | - if (!isset($result[$name])) { |
|
125 | + foreach ($proto as $name) |
|
126 | + { |
|
127 | + if (!isset($result[$name])) |
|
128 | + { |
|
120 | 129 | $result[$name] = $this->registry->resolveProperty($name); |
121 | 130 | } |
122 | 131 | } |
@@ -131,7 +140,8 @@ discard block |
||
131 | 140 | */ |
132 | 141 | private function reverse(array $results): \Generator |
133 | 142 | { |
134 | - foreach (\array_reverse($results) as $result) { |
|
143 | + foreach (\array_reverse($results) as $result) |
|
144 | + { |
|
135 | 145 | yield from $result; |
136 | 146 | } |
137 | 147 | } |