@@ -20,7 +20,7 @@ |
||
| 20 | 20 | string $name, |
| 21 | 21 | ?string $comment = null, |
| 22 | 22 | ?string $namespace = null, |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | $this->namespace = new PhpNamespace($namespace ?? $this->config->classNamespace(static::TYPE, $name)); |
| 25 | 25 | |
| 26 | 26 | $this->class = $this->namespace |
@@ -95,7 +95,7 @@ |
||
| 95 | 95 | $this->files->write( |
| 96 | 96 | $filename, |
| 97 | 97 | $file->render() . PHP_EOL . (new Dumper())->dump(new Literal('return [];')), |
| 98 | - FilesInterface::READONLY, |
|
| 98 | + FilesInterface::readonly, |
|
| 99 | 99 | true, |
| 100 | 100 | ); |
| 101 | 101 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | protected ?string $comment = null, |
| 35 | 35 | private readonly string $directory = '', |
| 36 | 36 | ?string $namespace = null, |
| 37 | - ) { |
|
| 37 | + ){ |
|
| 38 | 38 | parent::__construct($config, $name, $comment, $namespace); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | $this->class->addConstant('CONFIG', $configName)->setPublic(); |
| 44 | 44 | |
| 45 | 45 | $filename = $this->makeConfigFilename($configName); |
| 46 | - if ($reverse) { |
|
| 47 | - if (!$this->files->exists($filename)) { |
|
| 46 | + if ($reverse){ |
|
| 47 | + if (!$this->files->exists($filename)){ |
|
| 48 | 48 | throw new ScaffolderException(\sprintf("Config filename %s doesn't exist", $filename)); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $this->declareGetters($defaultsFromFile); |
| 53 | 53 | |
| 54 | 54 | $this->class->getProperty('config')->setValue($this->defaultValues->get($defaultsFromFile)); |
| 55 | - } elseif (!$this->files->exists($filename)) { |
|
| 55 | + } elseif (!$this->files->exists($filename)){ |
|
| 56 | 56 | $this->touchConfigFile($filename); |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | $this->files->write( |
| 110 | 110 | $filename, |
| 111 | - $file->render() . PHP_EOL . (new Dumper())->dump(new Literal('return [];')), |
|
| 111 | + $file->render().PHP_EOL.(new Dumper())->dump(new Literal('return [];')), |
|
| 112 | 112 | FilesInterface::READONLY, |
| 113 | 113 | true, |
| 114 | 114 | ); |
@@ -126,27 +126,27 @@ discard block |
||
| 126 | 126 | $getters = []; |
| 127 | 127 | $gettersByKey = []; |
| 128 | 128 | |
| 129 | - foreach ($defaults as $key => $value) { |
|
| 130 | - $key = (string) $key; |
|
| 129 | + foreach ($defaults as $key => $value){ |
|
| 130 | + $key = (string)$key; |
|
| 131 | 131 | $getter = $this->makeGetterName($key); |
| 132 | 132 | $getters[] = $getter; |
| 133 | 133 | |
| 134 | 134 | $method = $this->class->addMethod($getter)->setPublic(); |
| 135 | 135 | $method->setBody(\sprintf('return $this->config[\'%s\'];', $key)); |
| 136 | 136 | |
| 137 | - if (\is_array($value)) { |
|
| 137 | + if (\is_array($value)){ |
|
| 138 | 138 | $gettersByKey[] = ['key' => $key, 'value' => $value]; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $returnTypeHint = $this->typeHints->getHint(\gettype($value)); |
| 142 | - if ($returnTypeHint !== null) { |
|
| 142 | + if ($returnTypeHint !== null){ |
|
| 143 | 143 | $method->setReturnType($returnTypeHint); |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - foreach ($gettersByKey as $item) { |
|
| 147 | + foreach ($gettersByKey as $item){ |
|
| 148 | 148 | $method = $this->declareGettersByKey($getters, $item['key'], $item['value']); |
| 149 | - if ($method !== null) { |
|
| 149 | + if ($method !== null){ |
|
| 150 | 150 | $getters[] = $method->getName(); |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -155,30 +155,30 @@ discard block |
||
| 155 | 155 | private function declareGettersByKey(array $methodNames, string $key, array $value): ?Method |
| 156 | 156 | { |
| 157 | 157 | //Won't create if there's less than 2 sub-items |
| 158 | - if (\count($value) < 2) { |
|
| 158 | + if (\count($value) < 2){ |
|
| 159 | 159 | return null; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | $singularKey = $this->singularize($key); |
| 163 | 163 | $name = $this->makeGetterName($singularKey); |
| 164 | - if (\in_array($name, $methodNames, true)) { |
|
| 164 | + if (\in_array($name, $methodNames, true)){ |
|
| 165 | 165 | $name = $this->makeGetterName($singularKey, 'get', 'by'); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | //Name conflict, won't merge |
| 169 | - if (\in_array($name, $methodNames, true)) { |
|
| 169 | + if (\in_array($name, $methodNames, true)){ |
|
| 170 | 170 | return null; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | $keyType = defineArrayType(\array_keys($value), '-mixed-'); |
| 174 | 174 | $valueType = defineArrayType(\array_values($value), '-mixed-'); |
| 175 | 175 | //We need a fixed structure here |
| 176 | - if ($keyType === '-mixed-' || $valueType === '-mixed-') { |
|
| 176 | + if ($keyType === '-mixed-' || $valueType === '-mixed-'){ |
|
| 177 | 177 | return null; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | //Won't create for associated arrays |
| 181 | - if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value)) { |
|
| 181 | + if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value)){ |
|
| 182 | 182 | return null; |
| 183 | 183 | } |
| 184 | 184 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $param = $method->addParameter($singularKey); |
| 190 | 190 | $paramTypeHint = $this->typeHints->getHint($keyType); |
| 191 | - if ($paramTypeHint !== null) { |
|
| 191 | + if ($paramTypeHint !== null){ |
|
| 192 | 192 | $param->setType($paramTypeHint); |
| 193 | 193 | } |
| 194 | 194 | |
@@ -198,13 +198,13 @@ discard block |
||
| 198 | 198 | private function makeGetterName(string $name, string $prefix = 'get', string $postfix = ''): string |
| 199 | 199 | { |
| 200 | 200 | $chunks = []; |
| 201 | - if (!empty($prefix)) { |
|
| 201 | + if (!empty($prefix)){ |
|
| 202 | 202 | $chunks[] = $prefix; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | $name = $this->slugify->slugify($name, ['lowercase' => false]); |
| 206 | 206 | $chunks[] = \count($chunks) !== 0 ? $this->classify($name) : $name; |
| 207 | - if (!empty($postfix)) { |
|
| 207 | + if (!empty($postfix)){ |
|
| 208 | 208 | $chunks[] = \ucfirst($postfix); |
| 209 | 209 | } |
| 210 | 210 | |
@@ -43,8 +43,10 @@ discard block |
||
| 43 | 43 | $this->class->addConstant('CONFIG', $configName)->setPublic(); |
| 44 | 44 | |
| 45 | 45 | $filename = $this->makeConfigFilename($configName); |
| 46 | - if ($reverse) { |
|
| 47 | - if (!$this->files->exists($filename)) { |
|
| 46 | + if ($reverse) |
|
| 47 | + { |
|
| 48 | + if (!$this->files->exists($filename)) |
|
| 49 | + { |
|
| 48 | 50 | throw new ScaffolderException(\sprintf("Config filename %s doesn't exist", $filename)); |
| 49 | 51 | } |
| 50 | 52 | |
@@ -52,7 +54,9 @@ discard block |
||
| 52 | 54 | $this->declareGetters($defaultsFromFile); |
| 53 | 55 | |
| 54 | 56 | $this->class->getProperty('config')->setValue($this->defaultValues->get($defaultsFromFile)); |
| 55 | - } elseif (!$this->files->exists($filename)) { |
|
| 57 | + } |
|
| 58 | + elseif (!$this->files->exists($filename)) |
|
| 59 | + { |
|
| 56 | 60 | $this->touchConfigFile($filename); |
| 57 | 61 | } |
| 58 | 62 | } |
@@ -126,7 +130,8 @@ discard block |
||
| 126 | 130 | $getters = []; |
| 127 | 131 | $gettersByKey = []; |
| 128 | 132 | |
| 129 | - foreach ($defaults as $key => $value) { |
|
| 133 | + foreach ($defaults as $key => $value) |
|
| 134 | + { |
|
| 130 | 135 | $key = (string) $key; |
| 131 | 136 | $getter = $this->makeGetterName($key); |
| 132 | 137 | $getters[] = $getter; |
@@ -134,19 +139,23 @@ discard block |
||
| 134 | 139 | $method = $this->class->addMethod($getter)->setPublic(); |
| 135 | 140 | $method->setBody(\sprintf('return $this->config[\'%s\'];', $key)); |
| 136 | 141 | |
| 137 | - if (\is_array($value)) { |
|
| 142 | + if (\is_array($value)) |
|
| 143 | + { |
|
| 138 | 144 | $gettersByKey[] = ['key' => $key, 'value' => $value]; |
| 139 | 145 | } |
| 140 | 146 | |
| 141 | 147 | $returnTypeHint = $this->typeHints->getHint(\gettype($value)); |
| 142 | - if ($returnTypeHint !== null) { |
|
| 148 | + if ($returnTypeHint !== null) |
|
| 149 | + { |
|
| 143 | 150 | $method->setReturnType($returnTypeHint); |
| 144 | 151 | } |
| 145 | 152 | } |
| 146 | 153 | |
| 147 | - foreach ($gettersByKey as $item) { |
|
| 154 | + foreach ($gettersByKey as $item) |
|
| 155 | + { |
|
| 148 | 156 | $method = $this->declareGettersByKey($getters, $item['key'], $item['value']); |
| 149 | - if ($method !== null) { |
|
| 157 | + if ($method !== null) |
|
| 158 | + { |
|
| 150 | 159 | $getters[] = $method->getName(); |
| 151 | 160 | } |
| 152 | 161 | } |
@@ -155,30 +164,35 @@ discard block |
||
| 155 | 164 | private function declareGettersByKey(array $methodNames, string $key, array $value): ?Method |
| 156 | 165 | { |
| 157 | 166 | //Won't create if there's less than 2 sub-items |
| 158 | - if (\count($value) < 2) { |
|
| 167 | + if (\count($value) < 2) |
|
| 168 | + { |
|
| 159 | 169 | return null; |
| 160 | 170 | } |
| 161 | 171 | |
| 162 | 172 | $singularKey = $this->singularize($key); |
| 163 | 173 | $name = $this->makeGetterName($singularKey); |
| 164 | - if (\in_array($name, $methodNames, true)) { |
|
| 174 | + if (\in_array($name, $methodNames, true)) |
|
| 175 | + { |
|
| 165 | 176 | $name = $this->makeGetterName($singularKey, 'get', 'by'); |
| 166 | 177 | } |
| 167 | 178 | |
| 168 | 179 | //Name conflict, won't merge |
| 169 | - if (\in_array($name, $methodNames, true)) { |
|
| 180 | + if (\in_array($name, $methodNames, true)) |
|
| 181 | + { |
|
| 170 | 182 | return null; |
| 171 | 183 | } |
| 172 | 184 | |
| 173 | 185 | $keyType = defineArrayType(\array_keys($value), '-mixed-'); |
| 174 | 186 | $valueType = defineArrayType(\array_values($value), '-mixed-'); |
| 175 | 187 | //We need a fixed structure here |
| 176 | - if ($keyType === '-mixed-' || $valueType === '-mixed-') { |
|
| 188 | + if ($keyType === '-mixed-' || $valueType === '-mixed-') |
|
| 189 | + { |
|
| 177 | 190 | return null; |
| 178 | 191 | } |
| 179 | 192 | |
| 180 | 193 | //Won't create for associated arrays |
| 181 | - if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value)) { |
|
| 194 | + if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value)) |
|
| 195 | + { |
|
| 182 | 196 | return null; |
| 183 | 197 | } |
| 184 | 198 | |
@@ -188,7 +202,8 @@ discard block |
||
| 188 | 202 | |
| 189 | 203 | $param = $method->addParameter($singularKey); |
| 190 | 204 | $paramTypeHint = $this->typeHints->getHint($keyType); |
| 191 | - if ($paramTypeHint !== null) { |
|
| 205 | + if ($paramTypeHint !== null) |
|
| 206 | + { |
|
| 192 | 207 | $param->setType($paramTypeHint); |
| 193 | 208 | } |
| 194 | 209 | |
@@ -198,13 +213,15 @@ discard block |
||
| 198 | 213 | private function makeGetterName(string $name, string $prefix = 'get', string $postfix = ''): string |
| 199 | 214 | { |
| 200 | 215 | $chunks = []; |
| 201 | - if (!empty($prefix)) { |
|
| 216 | + if (!empty($prefix)) |
|
| 217 | + { |
|
| 202 | 218 | $chunks[] = $prefix; |
| 203 | 219 | } |
| 204 | 220 | |
| 205 | 221 | $name = $this->slugify->slugify($name, ['lowercase' => false]); |
| 206 | 222 | $chunks[] = \count($chunks) !== 0 ? $this->classify($name) : $name; |
| 207 | - if (!empty($postfix)) { |
|
| 223 | + if (!empty($postfix)) |
|
| 224 | + { |
|
| 208 | 225 | $chunks[] = \ucfirst($postfix); |
| 209 | 226 | } |
| 210 | 227 | |
@@ -19,7 +19,8 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function __construct(array $visitors = []) |
| 21 | 21 | { |
| 22 | - foreach ($visitors as $visitor) { |
|
| 22 | + foreach ($visitors as $visitor) |
|
| 23 | + { |
|
| 23 | 24 | $this->addVisitor($visitor); |
| 24 | 25 | } |
| 25 | 26 | } |
@@ -34,8 +35,10 @@ discard block |
||
| 34 | 35 | |
| 35 | 36 | public function removeVisitor(VisitorInterface $visitor): void |
| 36 | 37 | { |
| 37 | - foreach ($this->visitors as $index => $added) { |
|
| 38 | - if ($added === $visitor) { |
|
| 38 | + foreach ($this->visitors as $index => $added) |
|
| 39 | + { |
|
| 40 | + if ($added === $visitor) |
|
| 41 | + { |
|
| 39 | 42 | unset($this->visitors[$index]); |
| 40 | 43 | break; |
| 41 | 44 | } |
@@ -56,22 +59,27 @@ discard block |
||
| 56 | 59 | $context ??= new VisitorContext(); |
| 57 | 60 | |
| 58 | 61 | $ctx = clone $context; |
| 59 | - foreach ($nodes as $index => $node) { |
|
| 60 | - if ($this->stopTraversal) { |
|
| 62 | + foreach ($nodes as $index => $node) |
|
| 63 | + { |
|
| 64 | + if ($this->stopTraversal) |
|
| 65 | + { |
|
| 61 | 66 | break; |
| 62 | 67 | } |
| 63 | 68 | |
| 64 | 69 | $traverseChildren = true; |
| 65 | 70 | $breakVisitorID = null; |
| 66 | 71 | |
| 67 | - if ($node instanceof NodeInterface) { |
|
| 72 | + if ($node instanceof NodeInterface) |
|
| 73 | + { |
|
| 68 | 74 | $ctx = $context->withNode($node); |
| 69 | 75 | } |
| 70 | 76 | |
| 71 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 77 | + foreach ($this->visitors as $visitorID => $visitor) |
|
| 78 | + { |
|
| 72 | 79 | $result = $visitor->enterNode($node, $ctx); |
| 73 | 80 | |
| 74 | - switch (true) { |
|
| 81 | + switch (true) |
|
| 82 | + { |
|
| 75 | 83 | case $result === null: |
| 76 | 84 | break; |
| 77 | 85 | |
@@ -101,17 +109,21 @@ discard block |
||
| 101 | 109 | } |
| 102 | 110 | |
| 103 | 111 | // sub nodes |
| 104 | - if ($traverseChildren && $node instanceof NodeInterface) { |
|
| 112 | + if ($traverseChildren && $node instanceof NodeInterface) |
|
| 113 | + { |
|
| 105 | 114 | $nodes[$index] = $this->traverseNode($node, $ctx); |
| 106 | - if ($this->stopTraversal) { |
|
| 115 | + if ($this->stopTraversal) |
|
| 116 | + { |
|
| 107 | 117 | break; |
| 108 | 118 | } |
| 109 | 119 | } |
| 110 | 120 | |
| 111 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 121 | + foreach ($this->visitors as $visitorID => $visitor) |
|
| 122 | + { |
|
| 112 | 123 | $result = $visitor->leaveNode($node, $ctx); |
| 113 | 124 | |
| 114 | - switch (true) { |
|
| 125 | + switch (true) |
|
| 126 | + { |
|
| 115 | 127 | case $result === null: |
| 116 | 128 | break; |
| 117 | 129 | |
@@ -133,7 +145,8 @@ discard block |
||
| 133 | 145 | ); |
| 134 | 146 | } |
| 135 | 147 | |
| 136 | - if ($breakVisitorID === $visitorID) { |
|
| 148 | + if ($breakVisitorID === $visitorID) |
|
| 149 | + { |
|
| 137 | 150 | break; |
| 138 | 151 | } |
| 139 | 152 | } |
@@ -148,18 +161,22 @@ discard block |
||
| 148 | 161 | private function traverseNode(NodeInterface $node, VisitorContext $context): NodeInterface |
| 149 | 162 | { |
| 150 | 163 | $ctx = clone $context; |
| 151 | - foreach ($node as $name => $_) { |
|
| 164 | + foreach ($node as $name => $_) |
|
| 165 | + { |
|
| 152 | 166 | $_child = &$node->$name; |
| 153 | - if (\is_array($_child)) { |
|
| 167 | + if (\is_array($_child)) |
|
| 168 | + { |
|
| 154 | 169 | $_child = $this->traverse($_child, $ctx); |
| 155 | - if ($this->stopTraversal) { |
|
| 170 | + if ($this->stopTraversal) |
|
| 171 | + { |
|
| 156 | 172 | break; |
| 157 | 173 | } |
| 158 | 174 | |
| 159 | 175 | continue; |
| 160 | 176 | } |
| 161 | 177 | |
| 162 | - if (!$_child instanceof NodeInterface) { |
|
| 178 | + if (!$_child instanceof NodeInterface) |
|
| 179 | + { |
|
| 163 | 180 | continue; |
| 164 | 181 | } |
| 165 | 182 | |
@@ -168,9 +185,11 @@ discard block |
||
| 168 | 185 | $traverseChildren = true; |
| 169 | 186 | $breakVisitorID = null; |
| 170 | 187 | |
| 171 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 188 | + foreach ($this->visitors as $visitorID => $visitor) |
|
| 189 | + { |
|
| 172 | 190 | $result = $visitor->enterNode($_child, $ctx); |
| 173 | - switch (true) { |
|
| 191 | + switch (true) |
|
| 192 | + { |
|
| 174 | 193 | case $result === null: |
| 175 | 194 | break; |
| 176 | 195 | |
@@ -198,17 +217,21 @@ discard block |
||
| 198 | 217 | } |
| 199 | 218 | } |
| 200 | 219 | |
| 201 | - if ($traverseChildren) { |
|
| 220 | + if ($traverseChildren) |
|
| 221 | + { |
|
| 202 | 222 | $_child = $this->traverseNode($_child, $ctx); |
| 203 | - if ($this->stopTraversal) { |
|
| 223 | + if ($this->stopTraversal) |
|
| 224 | + { |
|
| 204 | 225 | break; |
| 205 | 226 | } |
| 206 | 227 | } |
| 207 | 228 | |
| 208 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 229 | + foreach ($this->visitors as $visitorID => $visitor) |
|
| 230 | + { |
|
| 209 | 231 | $result = $visitor->leaveNode($_child, $ctx); |
| 210 | 232 | |
| 211 | - switch (true) { |
|
| 233 | + switch (true) |
|
| 234 | + { |
|
| 212 | 235 | case $result === null: |
| 213 | 236 | break; |
| 214 | 237 | |
@@ -226,7 +249,8 @@ discard block |
||
| 226 | 249 | ); |
| 227 | 250 | } |
| 228 | 251 | |
| 229 | - if ($breakVisitorID === $visitorID) { |
|
| 252 | + if ($breakVisitorID === $visitorID) |
|
| 253 | + { |
|
| 230 | 254 | break; |
| 231 | 255 | } |
| 232 | 256 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | public function __construct(array $visitors = []) |
| 22 | 22 | { |
| 23 | - foreach ($visitors as $visitor) { |
|
| 23 | + foreach ($visitors as $visitor){ |
|
| 24 | 24 | $this->addVisitor($visitor); |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function removeVisitor(VisitorInterface $visitor): void |
| 37 | 37 | { |
| 38 | - foreach ($this->visitors as $index => $added) { |
|
| 39 | - if ($added === $visitor) { |
|
| 38 | + foreach ($this->visitors as $index => $added){ |
|
| 39 | + if ($added === $visitor){ |
|
| 40 | 40 | unset($this->visitors[$index]); |
| 41 | 41 | break; |
| 42 | 42 | } |
@@ -57,22 +57,22 @@ discard block |
||
| 57 | 57 | $context ??= new VisitorContext(); |
| 58 | 58 | |
| 59 | 59 | $ctx = clone $context; |
| 60 | - foreach ($nodes as $index => $node) { |
|
| 61 | - if ($this->stopTraversal) { |
|
| 60 | + foreach ($nodes as $index => $node){ |
|
| 61 | + if ($this->stopTraversal){ |
|
| 62 | 62 | break; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $traverseChildren = true; |
| 66 | 66 | $breakVisitorID = null; |
| 67 | 67 | |
| 68 | - if ($node instanceof NodeInterface) { |
|
| 68 | + if ($node instanceof NodeInterface){ |
|
| 69 | 69 | $ctx = $context->withNode($node); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 72 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 73 | 73 | $result = $visitor->enterNode($node, $ctx); |
| 74 | 74 | |
| 75 | - switch (true) { |
|
| 75 | + switch (true){ |
|
| 76 | 76 | case $result === null: |
| 77 | 77 | break; |
| 78 | 78 | |
@@ -96,23 +96,23 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | default: |
| 98 | 98 | throw new \LogicException( |
| 99 | - 'enterNode() returned invalid value of type ' . \gettype($result), |
|
| 99 | + 'enterNode() returned invalid value of type '.\gettype($result), |
|
| 100 | 100 | ); |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // sub nodes |
| 105 | - if ($traverseChildren && $node instanceof NodeInterface) { |
|
| 105 | + if ($traverseChildren && $node instanceof NodeInterface){ |
|
| 106 | 106 | $nodes[$index] = $this->traverseNode($node, $ctx); |
| 107 | - if ($this->stopTraversal) { |
|
| 107 | + if ($this->stopTraversal){ |
|
| 108 | 108 | break; |
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 112 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 113 | 113 | $result = $visitor->leaveNode($node, $ctx); |
| 114 | 114 | |
| 115 | - switch (true) { |
|
| 115 | + switch (true){ |
|
| 116 | 116 | case $result === null: |
| 117 | 117 | break; |
| 118 | 118 | |
@@ -130,11 +130,11 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | default: |
| 132 | 132 | throw new \LogicException( |
| 133 | - 'leaveNode() returned invalid value of type ' . \gettype($result), |
|
| 133 | + 'leaveNode() returned invalid value of type '.\gettype($result), |
|
| 134 | 134 | ); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ($breakVisitorID === $visitorID) { |
|
| 137 | + if ($breakVisitorID === $visitorID){ |
|
| 138 | 138 | break; |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -149,18 +149,18 @@ discard block |
||
| 149 | 149 | private function traverseNode(NodeInterface $node, VisitorContext $context): NodeInterface |
| 150 | 150 | { |
| 151 | 151 | $ctx = clone $context; |
| 152 | - foreach ($node as $name => $_) { |
|
| 152 | + foreach ($node as $name => $_){ |
|
| 153 | 153 | $_child = &$node->$name; |
| 154 | - if (\is_array($_child)) { |
|
| 154 | + if (\is_array($_child)){ |
|
| 155 | 155 | $_child = $this->traverse($_child, $ctx); |
| 156 | - if ($this->stopTraversal) { |
|
| 156 | + if ($this->stopTraversal){ |
|
| 157 | 157 | break; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | continue; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if (!$_child instanceof NodeInterface) { |
|
| 163 | + if (!$_child instanceof NodeInterface){ |
|
| 164 | 164 | continue; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | $traverseChildren = true; |
| 170 | 170 | $breakVisitorID = null; |
| 171 | 171 | |
| 172 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 172 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 173 | 173 | $result = $visitor->enterNode($_child, $ctx); |
| 174 | - switch (true) { |
|
| 174 | + switch (true){ |
|
| 175 | 175 | case $result === null: |
| 176 | 176 | break; |
| 177 | 177 | |
@@ -194,22 +194,22 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | default: |
| 196 | 196 | throw new \LogicException( |
| 197 | - 'enterNode() returned invalid value of type ' . \gettype($result), |
|
| 197 | + 'enterNode() returned invalid value of type '.\gettype($result), |
|
| 198 | 198 | ); |
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - if ($traverseChildren) { |
|
| 202 | + if ($traverseChildren){ |
|
| 203 | 203 | $_child = $this->traverseNode($_child, $ctx); |
| 204 | - if ($this->stopTraversal) { |
|
| 204 | + if ($this->stopTraversal){ |
|
| 205 | 205 | break; |
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
| 209 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
| 210 | 210 | $result = $visitor->leaveNode($_child, $ctx); |
| 211 | 211 | |
| 212 | - switch (true) { |
|
| 212 | + switch (true){ |
|
| 213 | 213 | case $result === null: |
| 214 | 214 | break; |
| 215 | 215 | |
@@ -223,11 +223,11 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | default: |
| 225 | 225 | throw new \LogicException( |
| 226 | - 'leaveNode() returned invalid value of type ' . \gettype($result), |
|
| 226 | + 'leaveNode() returned invalid value of type '.\gettype($result), |
|
| 227 | 227 | ); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ($breakVisitorID === $visitorID) { |
|
| 230 | + if ($breakVisitorID === $visitorID){ |
|
| 231 | 231 | break; |
| 232 | 232 | } |
| 233 | 233 | } |
@@ -25,15 +25,21 @@ |
||
| 25 | 25 | |
| 26 | 26 | public function patch(array $config): array |
| 27 | 27 | { |
| 28 | - try { |
|
| 28 | + try |
|
| 29 | + { |
|
| 29 | 30 | $_target = &$this->dotGet($config, $this->position); |
| 30 | 31 | |
| 31 | - if ($this->key !== null) { |
|
| 32 | + if ($this->key !== null) |
|
| 33 | + { |
|
| 32 | 34 | $_target = \array_merge([$this->key => $this->value], $_target); |
| 33 | - } else { |
|
| 35 | + } |
|
| 36 | + else |
|
| 37 | + { |
|
| 34 | 38 | \array_unshift($_target, $this->value); |
| 35 | 39 | } |
| 36 | - } catch (DotNotFoundException $e) { |
|
| 40 | + } |
|
| 41 | + catch (DotNotFoundException $e) |
|
| 42 | + { |
|
| 37 | 43 | throw new PatchException($e->getMessage(), $e->getCode(), $e); |
| 38 | 44 | } |
| 39 | 45 | |
@@ -19,21 +19,21 @@ |
||
| 19 | 19 | string $position, |
| 20 | 20 | private readonly ?string $key, |
| 21 | 21 | private mixed $value, |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | $this->position = $position === '.' ? '' : $position; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public function patch(array $config): array |
| 27 | 27 | { |
| 28 | - try { |
|
| 28 | + try{ |
|
| 29 | 29 | $_target = &$this->dotGet($config, $this->position); |
| 30 | 30 | |
| 31 | - if ($this->key !== null) { |
|
| 31 | + if ($this->key !== null){ |
|
| 32 | 32 | $_target = \array_merge([$this->key => $this->value], $_target); |
| 33 | - } else { |
|
| 33 | + }else{ |
|
| 34 | 34 | \array_unshift($_target, $this->value); |
| 35 | 35 | } |
| 36 | - } catch (DotNotFoundException $e) { |
|
| 36 | + }catch (DotNotFoundException $e){ |
|
| 37 | 37 | throw new PatchException($e->getMessage(), $e->getCode(), $e); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -51,8 +51,10 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function injectDependencies(string $code, ClassNode $node, bool $removeTrait = false): string |
| 53 | 53 | { |
| 54 | - if (empty($node->dependencies)) { |
|
| 55 | - if ($removeTrait) { |
|
| 54 | + if (empty($node->dependencies)) |
|
| 55 | + { |
|
| 56 | + if ($removeTrait) |
|
| 57 | + { |
|
| 56 | 58 | $tr = new NodeTraverser(); |
| 57 | 59 | $tr->addVisitor(new RemoveUse()); |
| 58 | 60 | $tr->addVisitor(new RemoveTrait()); |
@@ -66,7 +68,8 @@ discard block |
||
| 66 | 68 | $tr = new NodeTraverser(); |
| 67 | 69 | $tr->addVisitor(new AddUse($node)); |
| 68 | 70 | |
| 69 | - if ($removeTrait) { |
|
| 71 | + if ($removeTrait) |
|
| 72 | + { |
|
| 70 | 73 | $tr->addVisitor(new RemoveUse()); |
| 71 | 74 | $tr->addVisitor(new RemoveTrait()); |
| 72 | 75 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | public function __construct( |
| 29 | 29 | ?Lexer $lexer = null, |
| 30 | 30 | private readonly PrettyPrinterAbstract $printer = new Standard(), |
| 31 | - ) { |
|
| 31 | + ){ |
|
| 32 | 32 | $this->lexer = $lexer ?? new Lexer\Emulative(); |
| 33 | 33 | |
| 34 | 34 | $this->parser = new Parser\Php8($this->lexer); |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function injectDependencies(string $code, ClassNode $node, bool $removeTrait = false): string |
| 45 | 45 | { |
| 46 | - if (empty($node->dependencies)) { |
|
| 47 | - if ($removeTrait) { |
|
| 46 | + if (empty($node->dependencies)){ |
|
| 47 | + if ($removeTrait){ |
|
| 48 | 48 | $tr = new NodeTraverser(); |
| 49 | 49 | $tr->addVisitor(new RemoveUse()); |
| 50 | 50 | $tr->addVisitor(new RemoveTrait()); |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $tr = new NodeTraverser(); |
| 59 | 59 | $tr->addVisitor(new AddUse($node)); |
| 60 | 60 | |
| 61 | - if ($removeTrait) { |
|
| 61 | + if ($removeTrait){ |
|
| 62 | 62 | $tr->addVisitor(new RemoveUse()); |
| 63 | 63 | $tr->addVisitor(new RemoveTrait()); |
| 64 | 64 | } |
@@ -9,10 +9,12 @@ |
||
| 9 | 9 | |
| 10 | 10 | final class UpdateClass |
| 11 | 11 | { |
| 12 | - public function do(OutputInterface $output): void |
|
| 12 | + public function do{ |
|
| 13 | + (OutputInterface $output): void |
|
| 13 | 14 | { |
| 14 | 15 | $output->write('OK'); |
| 15 | 16 | } |
| 17 | + } |
|
| 16 | 18 | |
| 17 | 19 | public function err(OutputInterface $output): void |
| 18 | 20 | { |
@@ -18,9 +18,9 @@ |
||
| 18 | 18 | |
| 19 | 19 | public static function trailingProvider(): \Traversable |
| 20 | 20 | { |
| 21 | - yield ['name7', 7, 'name',]; |
|
| 22 | - yield ['name', 0, 'name',]; |
|
| 23 | - yield ['name0', 0, 'name',]; |
|
| 21 | + yield ['name7', 7, 'name', ]; |
|
| 22 | + yield ['name', 0, 'name', ]; |
|
| 23 | + yield ['name0', 0, 'name', ]; |
|
| 24 | 24 | yield ['name1', 1, 'name']; |
| 25 | 25 | yield ['name-1', 1, 'name-']; |
| 26 | 26 | yield ['name-1', -1, 'name']; |
@@ -22,15 +22,15 @@ |
||
| 22 | 22 | // empty input |
| 23 | 23 | yield [[], 5, 5]; |
| 24 | 24 | // in the gap (not taken) |
| 25 | - yield [[3, 4, 8, 9,], 6, 6]; |
|
| 26 | - yield [[3, 4, 8, 9,], 1, 1]; |
|
| 25 | + yield [[3, 4, 8, 9, ], 6, 6]; |
|
| 26 | + yield [[3, 4, 8, 9, ], 1, 1]; |
|
| 27 | 27 | // in the sequence (taken) |
| 28 | - yield [[3, 4, 8, 9,], 4, 0]; |
|
| 29 | - yield [[0, 1, 4, 5,], 5, 2]; |
|
| 28 | + yield [[3, 4, 8, 9, ], 4, 0]; |
|
| 29 | + yield [[0, 1, 4, 5, ], 5, 2]; |
|
| 30 | 30 | // do not use "1" |
| 31 | - yield [[0, 3, 4, 8,], 4, 2]; |
|
| 31 | + yield [[0, 3, 4, 8, ], 4, 2]; |
|
| 32 | 32 | // full sequence, take next |
| 33 | - yield [[0, 1, 2, 3,], 3, 4]; |
|
| 33 | + yield [[0, 1, 2, 3, ], 3, 4]; |
|
| 34 | 34 | yield [[0], 0, 2]; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -26,14 +26,14 @@ |
||
| 26 | 26 | parent::setUp(); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - protected function bind(string $alias, string|array|callable|object $resolver): void |
|
| 29 | + protected function bind(string $alias, string | array | callable | object $resolver): void |
|
| 30 | 30 | { |
| 31 | 31 | $binder = $this->constructor->get('binder', BinderInterface::class); |
| 32 | 32 | \assert($binder instanceof BinderInterface); |
| 33 | 33 | $binder->bind($alias, $resolver); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - protected function bindSingleton(string $alias, string|array|callable|object $resolver): void |
|
| 36 | + protected function bindSingleton(string $alias, string | array | callable | object $resolver): void |
|
| 37 | 37 | { |
| 38 | 38 | $binder = $this->constructor->get('binder', BinderInterface::class); |
| 39 | 39 | \assert($binder instanceof BinderInterface); |