@@ -24,7 +24,7 @@ |
||
24 | 24 | 'alias' => $alias, |
25 | 25 | '--description' => 'My sample command description', |
26 | 26 | ]; |
27 | - if ($alias === null) { |
|
27 | + if ($alias === null){ |
|
28 | 28 | unset($input['alias']); |
29 | 29 | } |
30 | 30 |
@@ -24,7 +24,8 @@ |
||
24 | 24 | 'alias' => $alias, |
25 | 25 | '--description' => 'My sample command description', |
26 | 26 | ]; |
27 | - if ($alias === null) { |
|
27 | + if ($alias === null) |
|
28 | + { |
|
28 | 29 | unset($input['alias']); |
29 | 30 | } |
30 | 31 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | ?string $namespace = null, |
23 | 23 | private readonly ?string $alias = null, |
24 | 24 | private readonly ?string $description = null, |
25 | - ) { |
|
25 | + ){ |
|
26 | 26 | parent::__construct($config, $name, $comment, $namespace); |
27 | 27 | } |
28 | 28 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | 'name' => $this->alias, |
70 | 70 | ]; |
71 | 71 | |
72 | - if ($this->description) { |
|
72 | + if ($this->description){ |
|
73 | 73 | $commandDefinition['description'] = $this->description; |
74 | 74 | } |
75 | 75 |
@@ -69,7 +69,8 @@ |
||
69 | 69 | 'name' => $this->alias, |
70 | 70 | ]; |
71 | 71 | |
72 | - if ($this->description) { |
|
72 | + if ($this->description) |
|
73 | + { |
|
73 | 74 | $commandDefinition['description'] = $this->description; |
74 | 75 | } |
75 | 76 |
@@ -33,11 +33,11 @@ |
||
33 | 33 | { |
34 | 34 | $declaration = $this->createDeclaration(ControllerDeclaration::class); |
35 | 35 | |
36 | - foreach ($this->actions as $action) { |
|
36 | + foreach ($this->actions as $action){ |
|
37 | 37 | $declaration->addAction($action); |
38 | 38 | } |
39 | 39 | |
40 | - if ($this->usePrototype) { |
|
40 | + if ($this->usePrototype){ |
|
41 | 41 | $declaration->addPrototypeTrait(); |
42 | 42 | } |
43 | 43 |
@@ -33,11 +33,13 @@ |
||
33 | 33 | { |
34 | 34 | $declaration = $this->createDeclaration(ControllerDeclaration::class); |
35 | 35 | |
36 | - foreach ($this->actions as $action) { |
|
36 | + foreach ($this->actions as $action) |
|
37 | + { |
|
37 | 38 | $declaration->addAction($action); |
38 | 39 | } |
39 | 40 | |
40 | - if ($this->usePrototype) { |
|
41 | + if ($this->usePrototype) |
|
42 | + { |
|
41 | 43 | $declaration->addPrototypeTrait(); |
42 | 44 | } |
43 | 45 |
@@ -33,11 +33,11 @@ |
||
33 | 33 | { |
34 | 34 | $declaration = $this->createDeclaration(FilterDeclaration::class); |
35 | 35 | |
36 | - foreach ($this->properties as $property) { |
|
36 | + foreach ($this->properties as $property){ |
|
37 | 37 | $declaration->addProperty($property); |
38 | 38 | } |
39 | 39 | |
40 | - if ($this->useValidator) { |
|
40 | + if ($this->useValidator){ |
|
41 | 41 | $declaration->addFilterDefinition(); |
42 | 42 | } |
43 | 43 |
@@ -33,11 +33,13 @@ |
||
33 | 33 | { |
34 | 34 | $declaration = $this->createDeclaration(FilterDeclaration::class); |
35 | 35 | |
36 | - foreach ($this->properties as $property) { |
|
36 | + foreach ($this->properties as $property) |
|
37 | + { |
|
37 | 38 | $declaration->addProperty($property); |
38 | 39 | } |
39 | 40 | |
40 | - if ($this->useValidator) { |
|
41 | + if ($this->useValidator) |
|
42 | + { |
|
41 | 43 | $declaration->addFilterDefinition(); |
42 | 44 | } |
43 | 45 |
@@ -70,7 +70,7 @@ |
||
70 | 70 | return new $validationClass(validationRules: [ |
71 | 71 | // Put your validation rules here |
72 | 72 | ]); |
73 | -PHP, |
|
73 | +php, |
|
74 | 74 | ); |
75 | 75 | } |
76 | 76 |
@@ -29,12 +29,12 @@ discard block |
||
29 | 29 | string $name, |
30 | 30 | ?string $comment = null, |
31 | 31 | ?string $namespace = null, |
32 | - ) { |
|
32 | + ){ |
|
33 | 33 | parent::__construct($config, $name, $comment, $namespace); |
34 | 34 | |
35 | - try { |
|
35 | + try{ |
|
36 | 36 | $this->validationConfig = $container->get(ValidationConfig::class); |
37 | - } catch (\Throwable) { |
|
37 | + }catch (\Throwable){ |
|
38 | 38 | // Validation is not configured |
39 | 39 | $this->validationConfig = null; |
40 | 40 | } |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | public function addFilterDefinition(): void |
52 | 52 | { |
53 | 53 | $validation = $this->validationConfig?->getDefaultValidator(); |
54 | - if ($validation === null) { |
|
54 | + if ($validation === null){ |
|
55 | 55 | throw new ValidationException( |
56 | 56 | 'Default Validator is not configured. Read more at https://spiral.dev/docs/validation-factory', |
57 | 57 | ); |
58 | 58 | } |
59 | 59 | |
60 | - if (!\class_exists($validation)) { |
|
60 | + if (!\class_exists($validation)){ |
|
61 | 61 | throw new ValidationException( |
62 | 62 | \sprintf( |
63 | 63 | 'Default Validator "%s" is not class or does not exist.', |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $p = $this->class->addProperty($property->getName()) |
92 | 92 | ->setType($property->getType()); |
93 | 93 | |
94 | - foreach ($property->getAttributes() as $attribute) { |
|
94 | + foreach ($property->getAttributes() as $attribute){ |
|
95 | 95 | $p->addAttribute($attribute->getName(), $attribute->getArguments()); |
96 | 96 | } |
97 | 97 | } |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | { |
109 | 109 | $declaredType = null; |
110 | 110 | |
111 | - if (\str_contains($property, ':')) { |
|
111 | + if (\str_contains($property, ':')){ |
|
112 | 112 | $segments = \explode(':', $property, 3); |
113 | 113 | |
114 | - if (\count($segments) === 3) { |
|
114 | + if (\count($segments) === 3){ |
|
115 | 115 | [$property, $source, $declaredType] = $segments; |
116 | - } else { |
|
116 | + }else{ |
|
117 | 117 | [$property, $source] = $segments; |
118 | 118 | } |
119 | 119 | } |
@@ -32,9 +32,12 @@ discard block |
||
32 | 32 | ) { |
33 | 33 | parent::__construct($config, $name, $comment, $namespace); |
34 | 34 | |
35 | - try { |
|
35 | + try |
|
36 | + { |
|
36 | 37 | $this->validationConfig = $container->get(ValidationConfig::class); |
37 | - } catch (\Throwable) { |
|
38 | + } |
|
39 | + catch (\Throwable) |
|
40 | + { |
|
38 | 41 | // Validation is not configured |
39 | 42 | $this->validationConfig = null; |
40 | 43 | } |
@@ -51,13 +54,15 @@ discard block |
||
51 | 54 | public function addFilterDefinition(): void |
52 | 55 | { |
53 | 56 | $validation = $this->validationConfig?->getDefaultValidator(); |
54 | - if ($validation === null) { |
|
57 | + if ($validation === null) |
|
58 | + { |
|
55 | 59 | throw new ValidationException( |
56 | 60 | 'Default Validator is not configured. Read more at https://spiral.dev/docs/validation-factory', |
57 | 61 | ); |
58 | 62 | } |
59 | 63 | |
60 | - if (!\class_exists($validation)) { |
|
64 | + if (!\class_exists($validation)) |
|
65 | + { |
|
61 | 66 | throw new ValidationException( |
62 | 67 | \sprintf( |
63 | 68 | 'Default Validator "%s" is not class or does not exist.', |
@@ -91,7 +96,8 @@ discard block |
||
91 | 96 | $p = $this->class->addProperty($property->getName()) |
92 | 97 | ->setType($property->getType()); |
93 | 98 | |
94 | - foreach ($property->getAttributes() as $attribute) { |
|
99 | + foreach ($property->getAttributes() as $attribute) |
|
100 | + { |
|
95 | 101 | $p->addAttribute($attribute->getName(), $attribute->getArguments()); |
96 | 102 | } |
97 | 103 | } |
@@ -108,12 +114,16 @@ discard block |
||
108 | 114 | { |
109 | 115 | $declaredType = null; |
110 | 116 | |
111 | - if (\str_contains($property, ':')) { |
|
117 | + if (\str_contains($property, ':')) |
|
118 | + { |
|
112 | 119 | $segments = \explode(':', $property, 3); |
113 | 120 | |
114 | - if (\count($segments) === 3) { |
|
121 | + if (\count($segments) === 3) |
|
122 | + { |
|
115 | 123 | [$property, $source, $declaredType] = $segments; |
116 | - } else { |
|
124 | + } |
|
125 | + else |
|
126 | + { |
|
117 | 127 | [$property, $source] = $segments; |
118 | 128 | } |
119 | 129 | } |
@@ -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 |