@@ -38,7 +38,7 @@ |
||
38 | 38 | */ |
39 | 39 | public function is(array $type): bool |
40 | 40 | { |
41 | - if ($this->type === null) { |
|
41 | + if ($this->type === null){ |
|
42 | 42 | return false; |
43 | 43 | } |
44 | 44 |
@@ -38,7 +38,8 @@ |
||
38 | 38 | */ |
39 | 39 | public function is(array $type): bool |
40 | 40 | { |
41 | - if ($this->type === null) { |
|
41 | + if ($this->type === null) |
|
42 | + { |
|
42 | 43 | return false; |
43 | 44 | } |
44 | 45 |
@@ -26,22 +26,22 @@ discard block |
||
26 | 26 | { |
27 | 27 | $lines = explode("\n", $comment); |
28 | 28 | |
29 | - foreach ($lines as $line) { |
|
29 | + foreach ($lines as $line){ |
|
30 | 30 | // strip up comment prefix |
31 | 31 | $line = preg_replace('/[\t ]*[\/]?\*[\/]? ?/', '', $line); |
32 | 32 | |
33 | - if (preg_match('/ *@([^ ]+) (.*)/iu', $line, $matches)) { |
|
33 | + if (preg_match('/ *@([^ ]+) (.*)/iu', $line, $matches)){ |
|
34 | 34 | $this->lines[] = new Line($matches[2], $matches[1]); |
35 | - } else { |
|
35 | + }else{ |
|
36 | 36 | $this->lines[] = new Line($line); |
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - if (isset($this->lines[0]) && $this->lines[0]->isEmpty()) { |
|
40 | + if (isset($this->lines[0]) && $this->lines[0]->isEmpty()){ |
|
41 | 41 | array_shift($this->lines); |
42 | 42 | } |
43 | 43 | |
44 | - if (isset($this->lines[count($this->lines) - 1]) && $this->lines[count($this->lines) - 1]->isEmpty()) { |
|
44 | + if (isset($this->lines[count($this->lines) - 1]) && $this->lines[count($this->lines) - 1]->isEmpty()){ |
|
45 | 45 | array_pop($this->lines); |
46 | 46 | } |
47 | 47 | } |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | $result[] = '/**'; |
56 | 56 | |
57 | 57 | // skip first and last tokens |
58 | - foreach ($this->lines as $line) { |
|
59 | - if ($line->type === null) { |
|
58 | + foreach ($this->lines as $line){ |
|
59 | + if ($line->type === null){ |
|
60 | 60 | $result[] = sprintf(' * %s', $line->value); |
61 | 61 | continue; |
62 | 62 | } |
@@ -26,22 +26,28 @@ discard block |
||
26 | 26 | { |
27 | 27 | $lines = explode("\n", $comment); |
28 | 28 | |
29 | - foreach ($lines as $line) { |
|
29 | + foreach ($lines as $line) |
|
30 | + { |
|
30 | 31 | // strip up comment prefix |
31 | 32 | $line = preg_replace('/[\t ]*[\/]?\*[\/]? ?/', '', $line); |
32 | 33 | |
33 | - if (preg_match('/ *@([^ ]+) (.*)/iu', $line, $matches)) { |
|
34 | + if (preg_match('/ *@([^ ]+) (.*)/iu', $line, $matches)) |
|
35 | + { |
|
34 | 36 | $this->lines[] = new Line($matches[2], $matches[1]); |
35 | - } else { |
|
37 | + } |
|
38 | + else |
|
39 | + { |
|
36 | 40 | $this->lines[] = new Line($line); |
37 | 41 | } |
38 | 42 | } |
39 | 43 | |
40 | - if (isset($this->lines[0]) && $this->lines[0]->isEmpty()) { |
|
44 | + if (isset($this->lines[0]) && $this->lines[0]->isEmpty()) |
|
45 | + { |
|
41 | 46 | array_shift($this->lines); |
42 | 47 | } |
43 | 48 | |
44 | - if (isset($this->lines[count($this->lines) - 1]) && $this->lines[count($this->lines) - 1]->isEmpty()) { |
|
49 | + if (isset($this->lines[count($this->lines) - 1]) && $this->lines[count($this->lines) - 1]->isEmpty()) |
|
50 | + { |
|
45 | 51 | array_pop($this->lines); |
46 | 52 | } |
47 | 53 | } |
@@ -55,8 +61,10 @@ discard block |
||
55 | 61 | $result[] = '/**'; |
56 | 62 | |
57 | 63 | // skip first and last tokens |
58 | - foreach ($this->lines as $line) { |
|
59 | - if ($line->type === null) { |
|
64 | + foreach ($this->lines as $line) |
|
65 | + { |
|
66 | + if ($line->type === null) |
|
67 | + { |
|
60 | 68 | $result[] = sprintf(' * %s', $line->value); |
61 | 69 | continue; |
62 | 70 | } |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | public function initAnnotations(ContainerInterface $container, bool $reset = false): void |
138 | 138 | { |
139 | 139 | $prototyped = $this->memory->loadData('prototyped'); |
140 | - if (!$reset && $prototyped !== null) { |
|
141 | - foreach ($prototyped as $property => $class) { |
|
140 | + if (!$reset && $prototyped !== null){ |
|
141 | + foreach ($prototyped as $property => $class){ |
|
142 | 142 | $this->bindProperty($property, $class); |
143 | 143 | } |
144 | 144 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $locator = $container->get(AnnotationLocator::class); |
150 | 150 | |
151 | 151 | $prototyped = []; |
152 | - foreach ($locator->findClasses(Prototyped::class) as $class) { |
|
152 | + foreach ($locator->findClasses(Prototyped::class) as $class){ |
|
153 | 153 | $prototyped[$class->getAnnotation()->property] = $class->getClass()->getName(); |
154 | 154 | $this->bindProperty($class->getAnnotation()->property, $class->getClass()->getName()); |
155 | 155 | } |
@@ -162,19 +162,19 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function initCycle(ContainerInterface $container): void |
164 | 164 | { |
165 | - if (!$container->has(ORM\SchemaInterface::class)) { |
|
165 | + if (!$container->has(ORM\SchemaInterface::class)){ |
|
166 | 166 | return; |
167 | 167 | } |
168 | 168 | |
169 | 169 | /** @var ORM\SchemaInterface|null $schema */ |
170 | 170 | $schema = $container->get(ORM\SchemaInterface::class); |
171 | - if ($schema === null) { |
|
171 | + if ($schema === null){ |
|
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - foreach ($schema->getRoles() as $role) { |
|
175 | + foreach ($schema->getRoles() as $role){ |
|
176 | 176 | $repository = $schema->define($role, ORM\SchemaInterface::REPOSITORY); |
177 | - if ($repository === ORM\Select\Repository::class || $repository === null) { |
|
177 | + if ($repository === ORM\Select\Repository::class || $repository === null){ |
|
178 | 178 | // default repository can not be wired |
179 | 179 | continue; |
180 | 180 | } |
@@ -188,23 +188,23 @@ discard block |
||
188 | 188 | */ |
189 | 189 | private function initDefaults(ContainerInterface $container): void |
190 | 190 | { |
191 | - foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut) { |
|
192 | - if (is_array($shortcut) && isset($shortcut['resolve'])) { |
|
193 | - if (isset($shortcut['with'])) { |
|
191 | + foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut){ |
|
192 | + if (is_array($shortcut) && isset($shortcut['resolve'])){ |
|
193 | + if (isset($shortcut['with'])){ |
|
194 | 194 | // check dependencies |
195 | - foreach ($shortcut['with'] as $dep) { |
|
196 | - if (!class_exists($dep, true) && !interface_exists($dep, true)) { |
|
195 | + foreach ($shortcut['with'] as $dep){ |
|
196 | + if (!class_exists($dep, true) && !interface_exists($dep, true)){ |
|
197 | 197 | continue 2; |
198 | 198 | } |
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | - try { |
|
202 | + try{ |
|
203 | 203 | $target = $container->get($shortcut['resolve']); |
204 | - if (is_object($target)) { |
|
204 | + if (is_object($target)){ |
|
205 | 205 | $this->bindProperty($property, get_class($target)); |
206 | 206 | } |
207 | - } catch (ContainerExceptionInterface $e) { |
|
207 | + }catch (ContainerExceptionInterface $e){ |
|
208 | 208 | continue; |
209 | 209 | } |
210 | 210 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | is_string($shortcut) |
216 | 216 | && (class_exists($shortcut, true) |
217 | 217 | || interface_exists($shortcut, true)) |
218 | - ) { |
|
218 | + ){ |
|
219 | 219 | $this->bindProperty($property, $shortcut); |
220 | 220 | } |
221 | 221 | } |
@@ -137,8 +137,10 @@ discard block |
||
137 | 137 | public function initAnnotations(ContainerInterface $container, bool $reset = false): void |
138 | 138 | { |
139 | 139 | $prototyped = $this->memory->loadData('prototyped'); |
140 | - if (!$reset && $prototyped !== null) { |
|
141 | - foreach ($prototyped as $property => $class) { |
|
140 | + if (!$reset && $prototyped !== null) |
|
141 | + { |
|
142 | + foreach ($prototyped as $property => $class) |
|
143 | + { |
|
142 | 144 | $this->bindProperty($property, $class); |
143 | 145 | } |
144 | 146 | |
@@ -149,7 +151,8 @@ discard block |
||
149 | 151 | $locator = $container->get(AnnotationLocator::class); |
150 | 152 | |
151 | 153 | $prototyped = []; |
152 | - foreach ($locator->findClasses(Prototyped::class) as $class) { |
|
154 | + foreach ($locator->findClasses(Prototyped::class) as $class) |
|
155 | + { |
|
153 | 156 | $prototyped[$class->getAnnotation()->property] = $class->getClass()->getName(); |
154 | 157 | $this->bindProperty($class->getAnnotation()->property, $class->getClass()->getName()); |
155 | 158 | } |
@@ -162,19 +165,23 @@ discard block |
||
162 | 165 | */ |
163 | 166 | public function initCycle(ContainerInterface $container): void |
164 | 167 | { |
165 | - if (!$container->has(ORM\SchemaInterface::class)) { |
|
168 | + if (!$container->has(ORM\SchemaInterface::class)) |
|
169 | + { |
|
166 | 170 | return; |
167 | 171 | } |
168 | 172 | |
169 | 173 | /** @var ORM\SchemaInterface|null $schema */ |
170 | 174 | $schema = $container->get(ORM\SchemaInterface::class); |
171 | - if ($schema === null) { |
|
175 | + if ($schema === null) |
|
176 | + { |
|
172 | 177 | return; |
173 | 178 | } |
174 | 179 | |
175 | - foreach ($schema->getRoles() as $role) { |
|
180 | + foreach ($schema->getRoles() as $role) |
|
181 | + { |
|
176 | 182 | $repository = $schema->define($role, ORM\SchemaInterface::REPOSITORY); |
177 | - if ($repository === ORM\Select\Repository::class || $repository === null) { |
|
183 | + if ($repository === ORM\Select\Repository::class || $repository === null) |
|
184 | + { |
|
178 | 185 | // default repository can not be wired |
179 | 186 | continue; |
180 | 187 | } |
@@ -188,23 +195,32 @@ discard block |
||
188 | 195 | */ |
189 | 196 | private function initDefaults(ContainerInterface $container): void |
190 | 197 | { |
191 | - foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut) { |
|
192 | - if (is_array($shortcut) && isset($shortcut['resolve'])) { |
|
193 | - if (isset($shortcut['with'])) { |
|
198 | + foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut) |
|
199 | + { |
|
200 | + if (is_array($shortcut) && isset($shortcut['resolve'])) |
|
201 | + { |
|
202 | + if (isset($shortcut['with'])) |
|
203 | + { |
|
194 | 204 | // check dependencies |
195 | - foreach ($shortcut['with'] as $dep) { |
|
196 | - if (!class_exists($dep, true) && !interface_exists($dep, true)) { |
|
205 | + foreach ($shortcut['with'] as $dep) |
|
206 | + { |
|
207 | + if (!class_exists($dep, true) && !interface_exists($dep, true)) |
|
208 | + { |
|
197 | 209 | continue 2; |
198 | 210 | } |
199 | 211 | } |
200 | 212 | } |
201 | 213 | |
202 | - try { |
|
214 | + try |
|
215 | + { |
|
203 | 216 | $target = $container->get($shortcut['resolve']); |
204 | - if (is_object($target)) { |
|
217 | + if (is_object($target)) |
|
218 | + { |
|
205 | 219 | $this->bindProperty($property, get_class($target)); |
206 | 220 | } |
207 | - } catch (ContainerExceptionInterface $e) { |
|
221 | + } |
|
222 | + catch (ContainerExceptionInterface $e) |
|
223 | + { |
|
208 | 224 | continue; |
209 | 225 | } |
210 | 226 |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | ConflictResolver\Names $namesResolver, |
40 | 40 | ConflictResolver\Namespaces $namespacesResolver, |
41 | 41 | Parser $parser = null |
42 | - ) { |
|
42 | + ){ |
|
43 | 43 | $this->namesResolver = $namesResolver; |
44 | 44 | $this->namespacesResolver = $namespacesResolver; |
45 | 45 | $this->parser = $parser ?? (new ParserFactory())->create(ParserFactory::ONLY_PHP7); |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | $declarator = new DeclareClass(); |
82 | 82 | $this->traverse($filename, $declarator); |
83 | 83 | |
84 | - if (empty($declarator->getClass())) { |
|
84 | + if (empty($declarator->getClass())){ |
|
85 | 85 | throw new ClassNotDeclaredException($filename); |
86 | 86 | } |
87 | 87 | |
88 | - if ($declarator->getNamespace()) { |
|
88 | + if ($declarator->getNamespace()){ |
|
89 | 89 | return ClassNode::createWithNamespace($declarator->getClass(), $declarator->getNamespace()); |
90 | 90 | } |
91 | 91 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | { |
101 | 101 | $tr = new NodeTraverser(); |
102 | 102 | |
103 | - foreach ($visitors as $visitor) { |
|
103 | + foreach ($visitors as $visitor){ |
|
104 | 104 | $tr->addVisitor($visitor); |
105 | 105 | } |
106 | 106 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | private function fillStmts(ClassNode $definition, array $imports): void |
115 | 115 | { |
116 | - foreach ($imports as $import) { |
|
116 | + foreach ($imports as $import){ |
|
117 | 117 | $definition->addImportUsage($import['name'], $import['alias']); |
118 | 118 | } |
119 | 119 | } |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | $reflection = new \ReflectionClass("{$definition->namespace}\\{$definition->class}"); |
129 | 129 | |
130 | 130 | $constructor = $reflection->getConstructor(); |
131 | - if ($constructor !== null) { |
|
131 | + if ($constructor !== null){ |
|
132 | 132 | $definition->hasConstructor = $constructor->getDeclaringClass()->getName() === $reflection->getName(); |
133 | 133 | |
134 | - foreach ($reflection->getConstructor()->getParameters() as $parameter) { |
|
134 | + foreach ($reflection->getConstructor()->getParameters() as $parameter){ |
|
135 | 135 | $definition->addParam($parameter); |
136 | 136 | } |
137 | 137 | } |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | */ |
147 | 147 | private function fillConstructorVars(array $vars, ClassNode $definition): void |
148 | 148 | { |
149 | - foreach ($vars as $k => $var) { |
|
150 | - if (isset($definition->constructorParams[$var])) { |
|
149 | + foreach ($vars as $k => $var){ |
|
150 | + if (isset($definition->constructorParams[$var])){ |
|
151 | 151 | unset($vars[$k]); |
152 | 152 | } |
153 | 153 | } |
@@ -81,11 +81,13 @@ discard block |
||
81 | 81 | $declarator = new DeclareClass(); |
82 | 82 | $this->traverse($filename, $declarator); |
83 | 83 | |
84 | - if (empty($declarator->getClass())) { |
|
84 | + if (empty($declarator->getClass())) |
|
85 | + { |
|
85 | 86 | throw new ClassNotDeclaredException($filename); |
86 | 87 | } |
87 | 88 | |
88 | - if ($declarator->getNamespace()) { |
|
89 | + if ($declarator->getNamespace()) |
|
90 | + { |
|
89 | 91 | return ClassNode::createWithNamespace($declarator->getClass(), $declarator->getNamespace()); |
90 | 92 | } |
91 | 93 | |
@@ -100,7 +102,8 @@ discard block |
||
100 | 102 | { |
101 | 103 | $tr = new NodeTraverser(); |
102 | 104 | |
103 | - foreach ($visitors as $visitor) { |
|
105 | + foreach ($visitors as $visitor) |
|
106 | + { |
|
104 | 107 | $tr->addVisitor($visitor); |
105 | 108 | } |
106 | 109 | |
@@ -113,7 +116,8 @@ discard block |
||
113 | 116 | */ |
114 | 117 | private function fillStmts(ClassNode $definition, array $imports): void |
115 | 118 | { |
116 | - foreach ($imports as $import) { |
|
119 | + foreach ($imports as $import) |
|
120 | + { |
|
117 | 121 | $definition->addImportUsage($import['name'], $import['alias']); |
118 | 122 | } |
119 | 123 | } |
@@ -128,10 +132,12 @@ discard block |
||
128 | 132 | $reflection = new \ReflectionClass("{$definition->namespace}\\{$definition->class}"); |
129 | 133 | |
130 | 134 | $constructor = $reflection->getConstructor(); |
131 | - if ($constructor !== null) { |
|
135 | + if ($constructor !== null) |
|
136 | + { |
|
132 | 137 | $definition->hasConstructor = $constructor->getDeclaringClass()->getName() === $reflection->getName(); |
133 | 138 | |
134 | - foreach ($reflection->getConstructor()->getParameters() as $parameter) { |
|
139 | + foreach ($reflection->getConstructor()->getParameters() as $parameter) |
|
140 | + { |
|
135 | 141 | $definition->addParam($parameter); |
136 | 142 | } |
137 | 143 | } |
@@ -146,8 +152,10 @@ discard block |
||
146 | 152 | */ |
147 | 153 | private function fillConstructorVars(array $vars, ClassNode $definition): void |
148 | 154 | { |
149 | - foreach ($vars as $k => $var) { |
|
150 | - if (isset($definition->constructorParams[$var])) { |
|
155 | + foreach ($vars as $k => $var) |
|
156 | + { |
|
157 | + if (isset($definition->constructorParams[$var])) |
|
158 | + { |
|
151 | 159 | unset($vars[$k]); |
152 | 160 | } |
153 | 161 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct(Lexer $lexer = null, PrettyPrinterAbstract $printer = null) |
49 | 49 | { |
50 | - if ($lexer === null) { |
|
50 | + if ($lexer === null){ |
|
51 | 51 | $lexer = new Lexer\Emulative([ |
52 | 52 | 'usedAttributes' => [ |
53 | 53 | 'comments', |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function injectDependencies(string $code, ClassNode $node, bool $removeTrait = false): string |
81 | 81 | { |
82 | - if (empty($node->dependencies)) { |
|
82 | + if (empty($node->dependencies)){ |
|
83 | 83 | return $code; |
84 | 84 | } |
85 | 85 | |
86 | 86 | $tr = new NodeTraverser(); |
87 | 87 | $tr->addVisitor(new AddUse($node)); |
88 | 88 | |
89 | - if ($removeTrait) { |
|
89 | + if ($removeTrait){ |
|
90 | 90 | $tr->addVisitor(new RemoveUse()); |
91 | 91 | $tr->addVisitor(new RemoveTrait()); |
92 | 92 | } |
@@ -47,7 +47,8 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct(Lexer $lexer = null, PrettyPrinterAbstract $printer = null) |
49 | 49 | { |
50 | - if ($lexer === null) { |
|
50 | + if ($lexer === null) |
|
51 | + { |
|
51 | 52 | $lexer = new Lexer\Emulative([ |
52 | 53 | 'usedAttributes' => [ |
53 | 54 | 'comments', |
@@ -79,14 +80,16 @@ discard block |
||
79 | 80 | */ |
80 | 81 | public function injectDependencies(string $code, ClassNode $node, bool $removeTrait = false): string |
81 | 82 | { |
82 | - if (empty($node->dependencies)) { |
|
83 | + if (empty($node->dependencies)) |
|
84 | + { |
|
83 | 85 | return $code; |
84 | 86 | } |
85 | 87 | |
86 | 88 | $tr = new NodeTraverser(); |
87 | 89 | $tr->addVisitor(new AddUse($node)); |
88 | 90 | |
89 | - if ($removeTrait) { |
|
91 | + if ($removeTrait) |
|
92 | + { |
|
90 | 93 | $tr->addVisitor(new RemoveUse()); |
91 | 94 | $tr->addVisitor(new RemoveTrait()); |
92 | 95 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | public function fullName(): string |
33 | 33 | { |
34 | 34 | $name = $this->name; |
35 | - if ($this->sequence > 0) { |
|
35 | + if ($this->sequence > 0){ |
|
36 | 36 | $name .= $this->sequence; |
37 | 37 | } |
38 | 38 |
@@ -32,7 +32,8 @@ |
||
32 | 32 | public function fullName(): string |
33 | 33 | { |
34 | 34 | $name = $this->name; |
35 | - if ($this->sequence > 0) { |
|
35 | + if ($this->sequence > 0) |
|
36 | + { |
|
36 | 37 | $name .= $this->sequence; |
37 | 38 | } |
38 | 39 |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | private function getConstructorReservedNames(ClassNode $definition): array |
46 | 46 | { |
47 | 47 | $names = []; |
48 | - foreach ($definition->constructorVars as $name) { |
|
48 | + foreach ($definition->constructorVars as $name){ |
|
49 | 49 | $names[] = $name; |
50 | 50 | } |
51 | 51 | |
52 | - foreach ($definition->constructorParams as $param) { |
|
52 | + foreach ($definition->constructorParams as $param){ |
|
53 | 53 | $names[] = $param->name; |
54 | 54 | } |
55 | 55 | |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | private function initiateCounters(array $names): array |
64 | 64 | { |
65 | 65 | $counters = []; |
66 | - foreach ($names as $name) { |
|
66 | + foreach ($names as $name){ |
|
67 | 67 | $name = $this->parseName($name); |
68 | 68 | |
69 | - if (isset($counters[$name->name])) { |
|
69 | + if (isset($counters[$name->name])){ |
|
70 | 70 | $counters[$name->name][$name->sequence] = $name->fullName(); |
71 | - } else { |
|
71 | + }else{ |
|
72 | 72 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
73 | 73 | } |
74 | 74 | } |
@@ -82,18 +82,18 @@ discard block |
||
82 | 82 | */ |
83 | 83 | private function addPostfixes(ClassNode $definition, array $counters): void |
84 | 84 | { |
85 | - foreach ($definition->dependencies as $dependency) { |
|
85 | + foreach ($definition->dependencies as $dependency){ |
|
86 | 86 | $name = $this->parseName($dependency->var); |
87 | - if (isset($counters[$name->name])) { |
|
87 | + if (isset($counters[$name->name])){ |
|
88 | 88 | $sequence = $this->sequences->find(array_keys($counters[$name->name]), $name->sequence); |
89 | - if ($sequence !== $name->sequence) { |
|
89 | + if ($sequence !== $name->sequence){ |
|
90 | 90 | $name->sequence = $sequence; |
91 | 91 | |
92 | 92 | $dependency->var = $name->fullName(); |
93 | 93 | } |
94 | 94 | |
95 | 95 | $counters[$name->name][$sequence] = $name->fullName(); |
96 | - } else { |
|
96 | + }else{ |
|
97 | 97 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
98 | 98 | } |
99 | 99 | } |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | */ |
106 | 106 | private function parseName(string $name): NameEntity |
107 | 107 | { |
108 | - if (preg_match("/\d+$/", $name, $match)) { |
|
108 | + if (preg_match("/\d+$/", $name, $match)){ |
|
109 | 109 | $sequence = (int)$match[0]; |
110 | - if ($sequence > 0) { |
|
110 | + if ($sequence > 0){ |
|
111 | 111 | return NameEntity::createWithSequence(Utils::trimTrailingDigits($name, $sequence), $sequence); |
112 | 112 | } |
113 | 113 | } |
@@ -45,11 +45,13 @@ discard block |
||
45 | 45 | private function getConstructorReservedNames(ClassNode $definition): array |
46 | 46 | { |
47 | 47 | $names = []; |
48 | - foreach ($definition->constructorVars as $name) { |
|
48 | + foreach ($definition->constructorVars as $name) |
|
49 | + { |
|
49 | 50 | $names[] = $name; |
50 | 51 | } |
51 | 52 | |
52 | - foreach ($definition->constructorParams as $param) { |
|
53 | + foreach ($definition->constructorParams as $param) |
|
54 | + { |
|
53 | 55 | $names[] = $param->name; |
54 | 56 | } |
55 | 57 | |
@@ -63,12 +65,16 @@ discard block |
||
63 | 65 | private function initiateCounters(array $names): array |
64 | 66 | { |
65 | 67 | $counters = []; |
66 | - foreach ($names as $name) { |
|
68 | + foreach ($names as $name) |
|
69 | + { |
|
67 | 70 | $name = $this->parseName($name); |
68 | 71 | |
69 | - if (isset($counters[$name->name])) { |
|
72 | + if (isset($counters[$name->name])) |
|
73 | + { |
|
70 | 74 | $counters[$name->name][$name->sequence] = $name->fullName(); |
71 | - } else { |
|
75 | + } |
|
76 | + else |
|
77 | + { |
|
72 | 78 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
73 | 79 | } |
74 | 80 | } |
@@ -82,18 +88,23 @@ discard block |
||
82 | 88 | */ |
83 | 89 | private function addPostfixes(ClassNode $definition, array $counters): void |
84 | 90 | { |
85 | - foreach ($definition->dependencies as $dependency) { |
|
91 | + foreach ($definition->dependencies as $dependency) |
|
92 | + { |
|
86 | 93 | $name = $this->parseName($dependency->var); |
87 | - if (isset($counters[$name->name])) { |
|
94 | + if (isset($counters[$name->name])) |
|
95 | + { |
|
88 | 96 | $sequence = $this->sequences->find(array_keys($counters[$name->name]), $name->sequence); |
89 | - if ($sequence !== $name->sequence) { |
|
97 | + if ($sequence !== $name->sequence) |
|
98 | + { |
|
90 | 99 | $name->sequence = $sequence; |
91 | 100 | |
92 | 101 | $dependency->var = $name->fullName(); |
93 | 102 | } |
94 | 103 | |
95 | 104 | $counters[$name->name][$sequence] = $name->fullName(); |
96 | - } else { |
|
105 | + } |
|
106 | + else |
|
107 | + { |
|
97 | 108 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
98 | 109 | } |
99 | 110 | } |
@@ -105,9 +116,11 @@ discard block |
||
105 | 116 | */ |
106 | 117 | private function parseName(string $name): NameEntity |
107 | 118 | { |
108 | - if (preg_match("/\d+$/", $name, $match)) { |
|
119 | + if (preg_match("/\d+$/", $name, $match)) |
|
120 | + { |
|
109 | 121 | $sequence = (int)$match[0]; |
110 | - if ($sequence > 0) { |
|
122 | + if ($sequence > 0) |
|
123 | + { |
|
111 | 124 | return NameEntity::createWithSequence(Utils::trimTrailingDigits($name, $sequence), $sequence); |
112 | 125 | } |
113 | 126 | } |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | */ |
59 | 59 | private function getReservedNamespacesWithAlias(ClassNode $definition, array $namespaces): array |
60 | 60 | { |
61 | - foreach ($definition->getStmts() as $stmt) { |
|
62 | - if (!$stmt->alias) { |
|
61 | + foreach ($definition->getStmts() as $stmt){ |
|
62 | + if (!$stmt->alias){ |
|
63 | 63 | continue; |
64 | 64 | } |
65 | 65 | |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | */ |
77 | 77 | private function getReservedNamespacesWithoutAlias(ClassNode $definition, array $namespaces): array |
78 | 78 | { |
79 | - foreach ($definition->getStmts() as $stmt) { |
|
80 | - if ($stmt->alias || isset($namespaces[$stmt->shortName])) { |
|
79 | + foreach ($definition->getStmts() as $stmt){ |
|
80 | + if ($stmt->alias || isset($namespaces[$stmt->shortName])){ |
|
81 | 81 | continue; |
82 | 82 | } |
83 | 83 | |
@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | private function initiateCounters(array $namespaces): array |
95 | 95 | { |
96 | 96 | $counters = []; |
97 | - foreach ($namespaces as $shortName => $fullName) { |
|
97 | + foreach ($namespaces as $shortName => $fullName){ |
|
98 | 98 | $namespace = $this->parseNamespace($shortName, $fullName); |
99 | 99 | |
100 | - if (isset($counters[$namespace->name])) { |
|
100 | + if (isset($counters[$namespace->name])){ |
|
101 | 101 | $counters[$namespace->name][$namespace->sequence] = $namespace; |
102 | - } else { |
|
102 | + }else{ |
|
103 | 103 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
104 | 104 | } |
105 | 105 | } |
@@ -113,52 +113,52 @@ discard block |
||
113 | 113 | */ |
114 | 114 | private function resolveImportsNamespaces(ClassNode $definition, array $counters): void |
115 | 115 | { |
116 | - if (!$definition->hasConstructor && $definition->constructorParams) { |
|
117 | - foreach ($definition->constructorParams as $param) { |
|
116 | + if (!$definition->hasConstructor && $definition->constructorParams){ |
|
117 | + foreach ($definition->constructorParams as $param){ |
|
118 | 118 | //no type (or type is internal), do nothing |
119 | - if (empty($param->type) || $param->isBuiltIn()) { |
|
119 | + if (empty($param->type) || $param->isBuiltIn()){ |
|
120 | 120 | continue; |
121 | 121 | } |
122 | 122 | |
123 | 123 | $namespace = $this->parseNamespaceFromType($param->type); |
124 | - if (isset($counters[$namespace->name])) { |
|
125 | - if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) { |
|
124 | + if (isset($counters[$namespace->name])){ |
|
125 | + if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)){ |
|
126 | 126 | continue; |
127 | 127 | } |
128 | 128 | |
129 | 129 | $sequence = $this->sequences->find(array_keys($counters[$namespace->name]), $namespace->sequence); |
130 | - if ($sequence !== $namespace->sequence) { |
|
130 | + if ($sequence !== $namespace->sequence){ |
|
131 | 131 | $namespace->sequence = $sequence; |
132 | 132 | |
133 | 133 | $param->type->alias = $namespace->fullName(); |
134 | 134 | } |
135 | 135 | |
136 | 136 | $counters[$namespace->name][$sequence] = $namespace; |
137 | - } else { |
|
137 | + }else{ |
|
138 | 138 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
139 | 139 | } |
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - foreach ($definition->dependencies as $dependency) { |
|
143 | + foreach ($definition->dependencies as $dependency){ |
|
144 | 144 | $namespace = $this->parseNamespaceFromType($dependency->type); |
145 | - if (isset($counters[$namespace->name])) { |
|
145 | + if (isset($counters[$namespace->name])){ |
|
146 | 146 | $alreadyImported = $this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace); |
147 | - if ($alreadyImported !== null) { |
|
147 | + if ($alreadyImported !== null){ |
|
148 | 148 | $dependency->type->alias = $alreadyImported->fullName(); |
149 | 149 | |
150 | 150 | continue; |
151 | 151 | } |
152 | 152 | |
153 | 153 | $sequence = $this->sequences->find(array_keys($counters[$namespace->name]), $namespace->sequence); |
154 | - if ($sequence !== $namespace->sequence) { |
|
154 | + if ($sequence !== $namespace->sequence){ |
|
155 | 155 | $namespace->sequence = $sequence; |
156 | 156 | |
157 | 157 | $dependency->type->alias = $namespace->fullName(); |
158 | 158 | } |
159 | 159 | |
160 | 160 | $counters[$namespace->name][$sequence] = $namespace; |
161 | - } else { |
|
161 | + }else{ |
|
162 | 162 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
163 | 163 | } |
164 | 164 | } |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | */ |
172 | 172 | private function getAlreadyImportedNamespace(array $counters, NamespaceEntity $namespace): ?NamespaceEntity |
173 | 173 | { |
174 | - foreach ($counters as $counter) { |
|
175 | - if ($counter->equals($namespace)) { |
|
174 | + foreach ($counters as $counter){ |
|
175 | + if ($counter->equals($namespace)){ |
|
176 | 176 | return $counter; |
177 | 177 | } |
178 | 178 | } |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | */ |
197 | 197 | private function parseNamespace(string $shortName, string $fullName): NamespaceEntity |
198 | 198 | { |
199 | - if (preg_match("/\d+$/", $shortName, $match)) { |
|
199 | + if (preg_match("/\d+$/", $shortName, $match)){ |
|
200 | 200 | $sequence = (int)$match[0]; |
201 | - if ($sequence > 0) { |
|
201 | + if ($sequence > 0){ |
|
202 | 202 | return NamespaceEntity::createWithSequence( |
203 | 203 | Utils::trimTrailingDigits($shortName, $sequence), |
204 | 204 | $fullName, |
@@ -58,8 +58,10 @@ discard block |
||
58 | 58 | */ |
59 | 59 | private function getReservedNamespacesWithAlias(ClassNode $definition, array $namespaces): array |
60 | 60 | { |
61 | - foreach ($definition->getStmts() as $stmt) { |
|
62 | - if (!$stmt->alias) { |
|
61 | + foreach ($definition->getStmts() as $stmt) |
|
62 | + { |
|
63 | + if (!$stmt->alias) |
|
64 | + { |
|
63 | 65 | continue; |
64 | 66 | } |
65 | 67 | |
@@ -76,8 +78,10 @@ discard block |
||
76 | 78 | */ |
77 | 79 | private function getReservedNamespacesWithoutAlias(ClassNode $definition, array $namespaces): array |
78 | 80 | { |
79 | - foreach ($definition->getStmts() as $stmt) { |
|
80 | - if ($stmt->alias || isset($namespaces[$stmt->shortName])) { |
|
81 | + foreach ($definition->getStmts() as $stmt) |
|
82 | + { |
|
83 | + if ($stmt->alias || isset($namespaces[$stmt->shortName])) |
|
84 | + { |
|
81 | 85 | continue; |
82 | 86 | } |
83 | 87 | |
@@ -94,12 +98,16 @@ discard block |
||
94 | 98 | private function initiateCounters(array $namespaces): array |
95 | 99 | { |
96 | 100 | $counters = []; |
97 | - foreach ($namespaces as $shortName => $fullName) { |
|
101 | + foreach ($namespaces as $shortName => $fullName) |
|
102 | + { |
|
98 | 103 | $namespace = $this->parseNamespace($shortName, $fullName); |
99 | 104 | |
100 | - if (isset($counters[$namespace->name])) { |
|
105 | + if (isset($counters[$namespace->name])) |
|
106 | + { |
|
101 | 107 | $counters[$namespace->name][$namespace->sequence] = $namespace; |
102 | - } else { |
|
108 | + } |
|
109 | + else |
|
110 | + { |
|
103 | 111 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
104 | 112 | } |
105 | 113 | } |
@@ -113,52 +121,66 @@ discard block |
||
113 | 121 | */ |
114 | 122 | private function resolveImportsNamespaces(ClassNode $definition, array $counters): void |
115 | 123 | { |
116 | - if (!$definition->hasConstructor && $definition->constructorParams) { |
|
117 | - foreach ($definition->constructorParams as $param) { |
|
124 | + if (!$definition->hasConstructor && $definition->constructorParams) |
|
125 | + { |
|
126 | + foreach ($definition->constructorParams as $param) |
|
127 | + { |
|
118 | 128 | //no type (or type is internal), do nothing |
119 | - if (empty($param->type) || $param->isBuiltIn()) { |
|
129 | + if (empty($param->type) || $param->isBuiltIn()) |
|
130 | + { |
|
120 | 131 | continue; |
121 | 132 | } |
122 | 133 | |
123 | 134 | $namespace = $this->parseNamespaceFromType($param->type); |
124 | - if (isset($counters[$namespace->name])) { |
|
125 | - if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) { |
|
135 | + if (isset($counters[$namespace->name])) |
|
136 | + { |
|
137 | + if ($this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace)) |
|
138 | + { |
|
126 | 139 | continue; |
127 | 140 | } |
128 | 141 | |
129 | 142 | $sequence = $this->sequences->find(array_keys($counters[$namespace->name]), $namespace->sequence); |
130 | - if ($sequence !== $namespace->sequence) { |
|
143 | + if ($sequence !== $namespace->sequence) |
|
144 | + { |
|
131 | 145 | $namespace->sequence = $sequence; |
132 | 146 | |
133 | 147 | $param->type->alias = $namespace->fullName(); |
134 | 148 | } |
135 | 149 | |
136 | 150 | $counters[$namespace->name][$sequence] = $namespace; |
137 | - } else { |
|
151 | + } |
|
152 | + else |
|
153 | + { |
|
138 | 154 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
139 | 155 | } |
140 | 156 | } |
141 | 157 | } |
142 | 158 | |
143 | - foreach ($definition->dependencies as $dependency) { |
|
159 | + foreach ($definition->dependencies as $dependency) |
|
160 | + { |
|
144 | 161 | $namespace = $this->parseNamespaceFromType($dependency->type); |
145 | - if (isset($counters[$namespace->name])) { |
|
162 | + if (isset($counters[$namespace->name])) |
|
163 | + { |
|
146 | 164 | $alreadyImported = $this->getAlreadyImportedNamespace($counters[$namespace->name], $namespace); |
147 | - if ($alreadyImported !== null) { |
|
165 | + if ($alreadyImported !== null) |
|
166 | + { |
|
148 | 167 | $dependency->type->alias = $alreadyImported->fullName(); |
149 | 168 | |
150 | 169 | continue; |
151 | 170 | } |
152 | 171 | |
153 | 172 | $sequence = $this->sequences->find(array_keys($counters[$namespace->name]), $namespace->sequence); |
154 | - if ($sequence !== $namespace->sequence) { |
|
173 | + if ($sequence !== $namespace->sequence) |
|
174 | + { |
|
155 | 175 | $namespace->sequence = $sequence; |
156 | 176 | |
157 | 177 | $dependency->type->alias = $namespace->fullName(); |
158 | 178 | } |
159 | 179 | |
160 | 180 | $counters[$namespace->name][$sequence] = $namespace; |
161 | - } else { |
|
181 | + } |
|
182 | + else |
|
183 | + { |
|
162 | 184 | $counters[$namespace->name] = [$namespace->sequence => $namespace]; |
163 | 185 | } |
164 | 186 | } |
@@ -171,8 +193,10 @@ discard block |
||
171 | 193 | */ |
172 | 194 | private function getAlreadyImportedNamespace(array $counters, NamespaceEntity $namespace): ?NamespaceEntity |
173 | 195 | { |
174 | - foreach ($counters as $counter) { |
|
175 | - if ($counter->equals($namespace)) { |
|
196 | + foreach ($counters as $counter) |
|
197 | + { |
|
198 | + if ($counter->equals($namespace)) |
|
199 | + { |
|
176 | 200 | return $counter; |
177 | 201 | } |
178 | 202 | } |
@@ -196,9 +220,11 @@ discard block |
||
196 | 220 | */ |
197 | 221 | private function parseNamespace(string $shortName, string $fullName): NamespaceEntity |
198 | 222 | { |
199 | - if (preg_match("/\d+$/", $shortName, $match)) { |
|
223 | + if (preg_match("/\d+$/", $shortName, $match)) |
|
224 | + { |
|
200 | 225 | $sequence = (int)$match[0]; |
201 | - if ($sequence > 0) { |
|
226 | + if ($sequence > 0) |
|
227 | + { |
|
202 | 228 | return NamespaceEntity::createWithSequence( |
203 | 229 | Utils::trimTrailingDigits($shortName, $sequence), |
204 | 230 | $fullName, |
@@ -24,21 +24,21 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function find(array $sequences, int $originSequence): int |
26 | 26 | { |
27 | - if (empty($sequences) || $originSequence > max($sequences)) { |
|
27 | + if (empty($sequences) || $originSequence > max($sequences)){ |
|
28 | 28 | return $originSequence; |
29 | 29 | } |
30 | 30 | |
31 | 31 | $gaps = $this->skippedSequences($sequences); |
32 | 32 | |
33 | - if (isset($gaps[$originSequence])) { |
|
33 | + if (isset($gaps[$originSequence])){ |
|
34 | 34 | return $originSequence; |
35 | 35 | } |
36 | 36 | |
37 | 37 | //we do not add "1" as postfix: $var, $var2, $var3, etc |
38 | 38 | unset($gaps[1]); |
39 | - if (empty($gaps)) { |
|
39 | + if (empty($gaps)){ |
|
40 | 40 | $max = max($sequences); |
41 | - if ($max === 0) { |
|
41 | + if ($max === 0){ |
|
42 | 42 | return 2; |
43 | 43 | } |
44 | 44 | |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | { |
57 | 57 | $skipped = []; |
58 | 58 | $max = max($sequences); |
59 | - for ($i = 0; $i < $max; $i++) { |
|
60 | - if (!in_array($i, $sequences, true)) { |
|
59 | + for ($i = 0; $i < $max; $i++){ |
|
60 | + if (!in_array($i, $sequences, true)){ |
|
61 | 61 | $skipped[$i] = $i; |
62 | 62 | } |
63 | 63 | } |
@@ -24,21 +24,25 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function find(array $sequences, int $originSequence): int |
26 | 26 | { |
27 | - if (empty($sequences) || $originSequence > max($sequences)) { |
|
27 | + if (empty($sequences) || $originSequence > max($sequences)) |
|
28 | + { |
|
28 | 29 | return $originSequence; |
29 | 30 | } |
30 | 31 | |
31 | 32 | $gaps = $this->skippedSequences($sequences); |
32 | 33 | |
33 | - if (isset($gaps[$originSequence])) { |
|
34 | + if (isset($gaps[$originSequence])) |
|
35 | + { |
|
34 | 36 | return $originSequence; |
35 | 37 | } |
36 | 38 | |
37 | 39 | //we do not add "1" as postfix: $var, $var2, $var3, etc |
38 | 40 | unset($gaps[1]); |
39 | - if (empty($gaps)) { |
|
41 | + if (empty($gaps)) |
|
42 | + { |
|
40 | 43 | $max = max($sequences); |
41 | - if ($max === 0) { |
|
44 | + if ($max === 0) |
|
45 | + { |
|
42 | 46 | return 2; |
43 | 47 | } |
44 | 48 | |
@@ -56,8 +60,10 @@ discard block |
||
56 | 60 | { |
57 | 61 | $skipped = []; |
58 | 62 | $max = max($sequences); |
59 | - for ($i = 0; $i < $max; $i++) { |
|
60 | - if (!in_array($i, $sequences, true)) { |
|
63 | + for ($i = 0; $i < $max; $i++) |
|
64 | + { |
|
65 | + if (!in_array($i, $sequences, true)) |
|
66 | + { |
|
61 | 67 | $skipped[$i] = $i; |
62 | 68 | } |
63 | 69 | } |