@@ -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 |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | string $name, |
29 | 29 | ?string $comment = null, |
30 | 30 | ?string $namespace = null, |
31 | - ) { |
|
31 | + ){ |
|
32 | 32 | parent::__construct($config, $name, $comment, $namespace); |
33 | 33 | |
34 | - try { |
|
34 | + try{ |
|
35 | 35 | $this->validationConfig = $container->get(ValidationConfig::class); |
36 | - } catch (\Throwable) { |
|
36 | + }catch (\Throwable){ |
|
37 | 37 | // Validation is not configured |
38 | 38 | $this->validationConfig = null; |
39 | 39 | } |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | public function addFilterDefinition(): void |
51 | 51 | { |
52 | 52 | $validation = $this->validationConfig?->getDefaultValidator(); |
53 | - if ($validation === null) { |
|
53 | + if ($validation === null){ |
|
54 | 54 | throw new ValidationException( |
55 | 55 | 'Default Validator is not configured. Read more at https://spiral.dev/docs/validation-factory' |
56 | 56 | ); |
57 | 57 | } |
58 | 58 | |
59 | - if (!\class_exists($validation)) { |
|
59 | + if (!\class_exists($validation)){ |
|
60 | 60 | throw new ValidationException( |
61 | 61 | \sprintf( |
62 | 62 | 'Default Validator "%s" is not class or does not exist.', |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $p = $this->class->addProperty($property->getName()) |
91 | 91 | ->setType($property->getType()); |
92 | 92 | |
93 | - foreach ($property->getAttributes() as $attribute) { |
|
93 | + foreach ($property->getAttributes() as $attribute){ |
|
94 | 94 | $p->addAttribute($attribute->getName(), $attribute->getArguments()); |
95 | 95 | } |
96 | 96 | } |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | { |
108 | 108 | $declaredType = null; |
109 | 109 | |
110 | - if (\str_contains($property, ':')) { |
|
110 | + if (\str_contains($property, ':')){ |
|
111 | 111 | $segments = \explode(':', $property, 3); |
112 | 112 | |
113 | - if (\count($segments) === 3) { |
|
113 | + if (\count($segments) === 3){ |
|
114 | 114 | [$property, $source, $declaredType] = $segments; |
115 | - } else { |
|
115 | + }else{ |
|
116 | 116 | [$property, $source] = $segments; |
117 | 117 | } |
118 | 118 | } |
@@ -31,9 +31,12 @@ discard block |
||
31 | 31 | ) { |
32 | 32 | parent::__construct($config, $name, $comment, $namespace); |
33 | 33 | |
34 | - try { |
|
34 | + try |
|
35 | + { |
|
35 | 36 | $this->validationConfig = $container->get(ValidationConfig::class); |
36 | - } catch (\Throwable) { |
|
37 | + } |
|
38 | + catch (\Throwable) |
|
39 | + { |
|
37 | 40 | // Validation is not configured |
38 | 41 | $this->validationConfig = null; |
39 | 42 | } |
@@ -50,13 +53,15 @@ discard block |
||
50 | 53 | public function addFilterDefinition(): void |
51 | 54 | { |
52 | 55 | $validation = $this->validationConfig?->getDefaultValidator(); |
53 | - if ($validation === null) { |
|
56 | + if ($validation === null) |
|
57 | + { |
|
54 | 58 | throw new ValidationException( |
55 | 59 | 'Default Validator is not configured. Read more at https://spiral.dev/docs/validation-factory' |
56 | 60 | ); |
57 | 61 | } |
58 | 62 | |
59 | - if (!\class_exists($validation)) { |
|
63 | + if (!\class_exists($validation)) |
|
64 | + { |
|
60 | 65 | throw new ValidationException( |
61 | 66 | \sprintf( |
62 | 67 | 'Default Validator "%s" is not class or does not exist.', |
@@ -90,7 +95,8 @@ discard block |
||
90 | 95 | $p = $this->class->addProperty($property->getName()) |
91 | 96 | ->setType($property->getType()); |
92 | 97 | |
93 | - foreach ($property->getAttributes() as $attribute) { |
|
98 | + foreach ($property->getAttributes() as $attribute) |
|
99 | + { |
|
94 | 100 | $p->addAttribute($attribute->getName(), $attribute->getArguments()); |
95 | 101 | } |
96 | 102 | } |
@@ -107,12 +113,16 @@ discard block |
||
107 | 113 | { |
108 | 114 | $declaredType = null; |
109 | 115 | |
110 | - if (\str_contains($property, ':')) { |
|
116 | + if (\str_contains($property, ':')) |
|
117 | + { |
|
111 | 118 | $segments = \explode(':', $property, 3); |
112 | 119 | |
113 | - if (\count($segments) === 3) { |
|
120 | + if (\count($segments) === 3) |
|
121 | + { |
|
114 | 122 | [$property, $source, $declaredType] = $segments; |
115 | - } else { |
|
123 | + } |
|
124 | + else |
|
125 | + { |
|
116 | 126 | [$property, $source] = $segments; |
117 | 127 | } |
118 | 128 | } |
@@ -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 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | protected ?string $comment = null, |
36 | 36 | private readonly string $directory = '', |
37 | 37 | ?string $namespace = null, |
38 | - ) { |
|
38 | + ){ |
|
39 | 39 | parent::__construct($config, $name, $comment, $namespace); |
40 | 40 | } |
41 | 41 | |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | $this->class->addConstant('CONFIG', $configName)->setPublic(); |
46 | 46 | |
47 | 47 | $filename = $this->makeConfigFilename($configName); |
48 | - if ($reverse) { |
|
49 | - if (!$this->files->exists($filename)) { |
|
48 | + if ($reverse){ |
|
49 | + if (!$this->files->exists($filename)){ |
|
50 | 50 | throw new ScaffolderException(\sprintf("Config filename %s doesn't exist", $filename)); |
51 | 51 | } |
52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $this->declareGetters($defaultsFromFile); |
55 | 55 | |
56 | 56 | $this->class->getProperty('config')->setValue($this->defaultValues->get($defaultsFromFile)); |
57 | - } elseif (!$this->files->exists($filename)) { |
|
57 | + } elseif (!$this->files->exists($filename)){ |
|
58 | 58 | $this->touchConfigFile($filename); |
59 | 59 | } |
60 | 60 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | $this->files->write( |
112 | 112 | $filename, |
113 | - $file->render() . PHP_EOL . (new Dumper())->dump(new Literal('return [];')), |
|
113 | + $file->render().PHP_EOL.(new Dumper())->dump(new Literal('return [];')), |
|
114 | 114 | FilesInterface::READONLY, |
115 | 115 | true, |
116 | 116 | ); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $getters = []; |
129 | 129 | $gettersByKey = []; |
130 | 130 | |
131 | - foreach ($defaults as $key => $value) { |
|
131 | + foreach ($defaults as $key => $value){ |
|
132 | 132 | $key = (string)$key; |
133 | 133 | $getter = $this->makeGetterName($key); |
134 | 134 | $getters[] = $getter; |
@@ -136,19 +136,19 @@ discard block |
||
136 | 136 | $method = $this->class->addMethod($getter)->setPublic(); |
137 | 137 | $method->setBody(\sprintf('return $this->config[\'%s\'];', $key)); |
138 | 138 | |
139 | - if (\is_array($value)) { |
|
139 | + if (\is_array($value)){ |
|
140 | 140 | $gettersByKey[] = ['key' => $key, 'value' => $value]; |
141 | 141 | } |
142 | 142 | |
143 | 143 | $returnTypeHint = $this->typeHints->getHint(\gettype($value)); |
144 | - if ($returnTypeHint !== null) { |
|
144 | + if ($returnTypeHint !== null){ |
|
145 | 145 | $method->setReturnType($returnTypeHint); |
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | - foreach ($gettersByKey as $item) { |
|
149 | + foreach ($gettersByKey as $item){ |
|
150 | 150 | $method = $this->declareGettersByKey($getters, $item['key'], $item['value']); |
151 | - if ($method !== null) { |
|
151 | + if ($method !== null){ |
|
152 | 152 | $getters[] = $method->getName(); |
153 | 153 | } |
154 | 154 | } |
@@ -157,30 +157,30 @@ discard block |
||
157 | 157 | private function declareGettersByKey(array $methodNames, string $key, array $value): ?Method |
158 | 158 | { |
159 | 159 | //Won't create if there's less than 2 sub-items |
160 | - if (\count($value) < 2) { |
|
160 | + if (\count($value) < 2){ |
|
161 | 161 | return null; |
162 | 162 | } |
163 | 163 | |
164 | 164 | $singularKey = $this->singularize($key); |
165 | 165 | $name = $this->makeGetterName($singularKey); |
166 | - if (\in_array($name, $methodNames, true)) { |
|
166 | + if (\in_array($name, $methodNames, true)){ |
|
167 | 167 | $name = $this->makeGetterName($singularKey, 'get', 'by'); |
168 | 168 | } |
169 | 169 | |
170 | 170 | //Name conflict, won't merge |
171 | - if (\in_array($name, $methodNames, true)) { |
|
171 | + if (\in_array($name, $methodNames, true)){ |
|
172 | 172 | return null; |
173 | 173 | } |
174 | 174 | |
175 | 175 | $keyType = defineArrayType(\array_keys($value), '-mixed-'); |
176 | 176 | $valueType = defineArrayType(\array_values($value), '-mixed-'); |
177 | 177 | //We need a fixed structure here |
178 | - if ($keyType === '-mixed-' || $valueType === '-mixed-') { |
|
178 | + if ($keyType === '-mixed-' || $valueType === '-mixed-'){ |
|
179 | 179 | return null; |
180 | 180 | } |
181 | 181 | |
182 | 182 | //Won't create for associated arrays |
183 | - if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value)) { |
|
183 | + if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value)){ |
|
184 | 184 | return null; |
185 | 185 | } |
186 | 186 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | |
191 | 191 | $param = $method->addParameter($singularKey); |
192 | 192 | $paramTypeHint = $this->typeHints->getHint($keyType); |
193 | - if ($paramTypeHint !== null) { |
|
193 | + if ($paramTypeHint !== null){ |
|
194 | 194 | $param->setType($paramTypeHint); |
195 | 195 | } |
196 | 196 | |
@@ -200,13 +200,13 @@ discard block |
||
200 | 200 | private function makeGetterName(string $name, string $prefix = 'get', string $postfix = ''): string |
201 | 201 | { |
202 | 202 | $chunks = []; |
203 | - if (!empty($prefix)) { |
|
203 | + if (!empty($prefix)){ |
|
204 | 204 | $chunks[] = $prefix; |
205 | 205 | } |
206 | 206 | |
207 | 207 | $name = $this->slugify->slugify($name, ['lowercase' => false]); |
208 | 208 | $chunks[] = \count($chunks) !== 0 ? $this->classify($name) : $name; |
209 | - if (!empty($postfix)) { |
|
209 | + if (!empty($postfix)){ |
|
210 | 210 | $chunks[] = \ucfirst($postfix); |
211 | 211 | } |
212 | 212 |
@@ -45,8 +45,10 @@ discard block |
||
45 | 45 | $this->class->addConstant('CONFIG', $configName)->setPublic(); |
46 | 46 | |
47 | 47 | $filename = $this->makeConfigFilename($configName); |
48 | - if ($reverse) { |
|
49 | - if (!$this->files->exists($filename)) { |
|
48 | + if ($reverse) |
|
49 | + { |
|
50 | + if (!$this->files->exists($filename)) |
|
51 | + { |
|
50 | 52 | throw new ScaffolderException(\sprintf("Config filename %s doesn't exist", $filename)); |
51 | 53 | } |
52 | 54 | |
@@ -54,7 +56,9 @@ discard block |
||
54 | 56 | $this->declareGetters($defaultsFromFile); |
55 | 57 | |
56 | 58 | $this->class->getProperty('config')->setValue($this->defaultValues->get($defaultsFromFile)); |
57 | - } elseif (!$this->files->exists($filename)) { |
|
59 | + } |
|
60 | + elseif (!$this->files->exists($filename)) |
|
61 | + { |
|
58 | 62 | $this->touchConfigFile($filename); |
59 | 63 | } |
60 | 64 | } |
@@ -128,7 +132,8 @@ discard block |
||
128 | 132 | $getters = []; |
129 | 133 | $gettersByKey = []; |
130 | 134 | |
131 | - foreach ($defaults as $key => $value) { |
|
135 | + foreach ($defaults as $key => $value) |
|
136 | + { |
|
132 | 137 | $key = (string)$key; |
133 | 138 | $getter = $this->makeGetterName($key); |
134 | 139 | $getters[] = $getter; |
@@ -136,19 +141,23 @@ discard block |
||
136 | 141 | $method = $this->class->addMethod($getter)->setPublic(); |
137 | 142 | $method->setBody(\sprintf('return $this->config[\'%s\'];', $key)); |
138 | 143 | |
139 | - if (\is_array($value)) { |
|
144 | + if (\is_array($value)) |
|
145 | + { |
|
140 | 146 | $gettersByKey[] = ['key' => $key, 'value' => $value]; |
141 | 147 | } |
142 | 148 | |
143 | 149 | $returnTypeHint = $this->typeHints->getHint(\gettype($value)); |
144 | - if ($returnTypeHint !== null) { |
|
150 | + if ($returnTypeHint !== null) |
|
151 | + { |
|
145 | 152 | $method->setReturnType($returnTypeHint); |
146 | 153 | } |
147 | 154 | } |
148 | 155 | |
149 | - foreach ($gettersByKey as $item) { |
|
156 | + foreach ($gettersByKey as $item) |
|
157 | + { |
|
150 | 158 | $method = $this->declareGettersByKey($getters, $item['key'], $item['value']); |
151 | - if ($method !== null) { |
|
159 | + if ($method !== null) |
|
160 | + { |
|
152 | 161 | $getters[] = $method->getName(); |
153 | 162 | } |
154 | 163 | } |
@@ -157,30 +166,35 @@ discard block |
||
157 | 166 | private function declareGettersByKey(array $methodNames, string $key, array $value): ?Method |
158 | 167 | { |
159 | 168 | //Won't create if there's less than 2 sub-items |
160 | - if (\count($value) < 2) { |
|
169 | + if (\count($value) < 2) |
|
170 | + { |
|
161 | 171 | return null; |
162 | 172 | } |
163 | 173 | |
164 | 174 | $singularKey = $this->singularize($key); |
165 | 175 | $name = $this->makeGetterName($singularKey); |
166 | - if (\in_array($name, $methodNames, true)) { |
|
176 | + if (\in_array($name, $methodNames, true)) |
|
177 | + { |
|
167 | 178 | $name = $this->makeGetterName($singularKey, 'get', 'by'); |
168 | 179 | } |
169 | 180 | |
170 | 181 | //Name conflict, won't merge |
171 | - if (\in_array($name, $methodNames, true)) { |
|
182 | + if (\in_array($name, $methodNames, true)) |
|
183 | + { |
|
172 | 184 | return null; |
173 | 185 | } |
174 | 186 | |
175 | 187 | $keyType = defineArrayType(\array_keys($value), '-mixed-'); |
176 | 188 | $valueType = defineArrayType(\array_values($value), '-mixed-'); |
177 | 189 | //We need a fixed structure here |
178 | - if ($keyType === '-mixed-' || $valueType === '-mixed-') { |
|
190 | + if ($keyType === '-mixed-' || $valueType === '-mixed-') |
|
191 | + { |
|
179 | 192 | return null; |
180 | 193 | } |
181 | 194 | |
182 | 195 | //Won't create for associated arrays |
183 | - if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value)) { |
|
196 | + if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value)) |
|
197 | + { |
|
184 | 198 | return null; |
185 | 199 | } |
186 | 200 | |
@@ -190,7 +204,8 @@ discard block |
||
190 | 204 | |
191 | 205 | $param = $method->addParameter($singularKey); |
192 | 206 | $paramTypeHint = $this->typeHints->getHint($keyType); |
193 | - if ($paramTypeHint !== null) { |
|
207 | + if ($paramTypeHint !== null) |
|
208 | + { |
|
194 | 209 | $param->setType($paramTypeHint); |
195 | 210 | } |
196 | 211 | |
@@ -200,13 +215,15 @@ discard block |
||
200 | 215 | private function makeGetterName(string $name, string $prefix = 'get', string $postfix = ''): string |
201 | 216 | { |
202 | 217 | $chunks = []; |
203 | - if (!empty($prefix)) { |
|
218 | + if (!empty($prefix)) |
|
219 | + { |
|
204 | 220 | $chunks[] = $prefix; |
205 | 221 | } |
206 | 222 | |
207 | 223 | $name = $this->slugify->slugify($name, ['lowercase' => false]); |
208 | 224 | $chunks[] = \count($chunks) !== 0 ? $this->classify($name) : $name; |
209 | - if (!empty($postfix)) { |
|
225 | + if (!empty($postfix)) |
|
226 | + { |
|
210 | 227 | $chunks[] = \ucfirst($postfix); |
211 | 228 | } |
212 | 229 |
@@ -10,7 +10,7 @@ |
||
10 | 10 | { |
11 | 11 | public function __construct( |
12 | 12 | private readonly ExceptionReporterInterface $reporter |
13 | - ) { |
|
13 | + ){ |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | public function handle(string $driver, string $queue, string $job, mixed $payload, \Throwable $e): void |
@@ -13,6 +13,6 @@ |
||
13 | 13 | public readonly string $id, |
14 | 14 | public readonly mixed $payload, |
15 | 15 | public readonly array $headers = [] |
16 | - ) { |
|
16 | + ){ |
|
17 | 17 | } |
18 | 18 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | |
14 | 14 | final class ContainerRegistryT extends TestCase |
15 | 15 | { |
16 | - private ContainerInterface|m\MockInterface $container; |
|
16 | + private ContainerInterface | m\MockInterface $container; |
|
17 | 17 | private ContainerRegistry $registry; |
18 | 18 | |
19 | 19 | protected function setUp(): void |
@@ -24,7 +24,7 @@ |
||
24 | 24 | $handler = m::mock(FailedJobHandlerInterface::class) |
25 | 25 | ); |
26 | 26 | |
27 | - if (!\is_array($payload)) { |
|
27 | + if (!\is_array($payload)){ |
|
28 | 28 | $this->markTestIncomplete('FailedJobHandlerInterface does not support non-array payloads'); |
29 | 29 | return; |
30 | 30 | } |
@@ -24,7 +24,8 @@ |
||
24 | 24 | $handler = m::mock(FailedJobHandlerInterface::class) |
25 | 25 | ); |
26 | 26 | |
27 | - if (!\is_array($payload)) { |
|
27 | + if (!\is_array($payload)) |
|
28 | + { |
|
28 | 29 | $this->markTestIncomplete('FailedJobHandlerInterface does not support non-array payloads'); |
29 | 30 | return; |
30 | 31 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | /** @param TNode[] $nodes */ |
18 | 18 | public function __construct( |
19 | 19 | public array $nodes |
20 | - ) { |
|
20 | + ){ |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public function getIterator(): \Generator |