@@ -26,7 +26,8 @@ discard block |
||
26 | 26 | public function testRequired(): void |
27 | 27 | { |
28 | 28 | $result = $this->parser->parse(new \ReflectionClass( |
29 | - new #[AsCommand(name: 'foo')] class { |
|
29 | + new #[AsCommand(name: 'foo')] class |
|
30 | + { |
|
30 | 31 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
31 | 32 | private int $option; |
32 | 33 | } |
@@ -44,7 +45,8 @@ discard block |
||
44 | 45 | public function testDefaultValue(): void |
45 | 46 | { |
46 | 47 | $result = $this->parser->parse(new \ReflectionClass( |
47 | - new #[AsCommand(name: 'foo')] class { |
|
48 | + new #[AsCommand(name: 'foo')] class |
|
49 | + { |
|
48 | 50 | #[Option(mode: InputOption::VALUE_OPTIONAL)] |
49 | 51 | private string $option = 'some'; |
50 | 52 | } |
@@ -62,7 +64,8 @@ discard block |
||
62 | 64 | public function testNullable(): void |
63 | 65 | { |
64 | 66 | $result = $this->parser->parse(new \ReflectionClass( |
65 | - new #[AsCommand(name: 'foo')] class { |
|
67 | + new #[AsCommand(name: 'foo')] class |
|
68 | + { |
|
66 | 69 | #[Option(mode: InputOption::VALUE_OPTIONAL)] |
67 | 70 | private ?string $option; |
68 | 71 | } |
@@ -80,7 +83,8 @@ discard block |
||
80 | 83 | public function testWithName(): void |
81 | 84 | { |
82 | 85 | $result = $this->parser->parse(new \ReflectionClass( |
83 | - new #[AsCommand(name: 'foo')] class { |
|
86 | + new #[AsCommand(name: 'foo')] class |
|
87 | + { |
|
84 | 88 | #[Option(name: 'customName', mode: InputOption::VALUE_OPTIONAL)] |
85 | 89 | private ?string $option; |
86 | 90 | } |
@@ -98,7 +102,8 @@ discard block |
||
98 | 102 | public function testWithShortcut(): void |
99 | 103 | { |
100 | 104 | $result = $this->parser->parse(new \ReflectionClass( |
101 | - new #[AsCommand(name: 'foo')] class { |
|
105 | + new #[AsCommand(name: 'foo')] class |
|
106 | + { |
|
102 | 107 | #[Option(shortcut: 't', mode: InputOption::VALUE_OPTIONAL)] |
103 | 108 | private ?string $option; |
104 | 109 | } |
@@ -116,7 +121,8 @@ discard block |
||
116 | 121 | public function testWithDescription(): void |
117 | 122 | { |
118 | 123 | $result = $this->parser->parse(new \ReflectionClass( |
119 | - new #[AsCommand(name: 'foo')] class { |
|
124 | + new #[AsCommand(name: 'foo')] class |
|
125 | + { |
|
120 | 126 | #[Option(description: 'Some description', mode: InputOption::VALUE_OPTIONAL)] |
121 | 127 | private ?string $option; |
122 | 128 | } |
@@ -134,7 +140,8 @@ discard block |
||
134 | 140 | public function testModeOptionalArray(): void |
135 | 141 | { |
136 | 142 | $result = $this->parser->parse(new \ReflectionClass( |
137 | - new #[AsCommand(name: 'foo')] class { |
|
143 | + new #[AsCommand(name: 'foo')] class |
|
144 | + { |
|
138 | 145 | #[Option(mode: InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY)] |
139 | 146 | private array $option = []; |
140 | 147 | } |
@@ -152,7 +159,8 @@ discard block |
||
152 | 159 | public function testModeRequiredArray(): void |
153 | 160 | { |
154 | 161 | $result = $this->parser->parse(new \ReflectionClass( |
155 | - new #[AsCommand(name: 'foo')] class { |
|
162 | + new #[AsCommand(name: 'foo')] class |
|
163 | + { |
|
156 | 164 | #[Option(mode: InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY)] |
157 | 165 | private array $option = []; |
158 | 166 | } |
@@ -170,7 +178,8 @@ discard block |
||
170 | 178 | public function testModeValueNegatable(): void |
171 | 179 | { |
172 | 180 | $result = $this->parser->parse(new \ReflectionClass( |
173 | - new #[AsCommand(name: 'foo')] class { |
|
181 | + new #[AsCommand(name: 'foo')] class |
|
182 | + { |
|
174 | 183 | #[Option(mode: InputOption::VALUE_NEGATABLE)] |
175 | 184 | private bool $option; |
176 | 185 | } |
@@ -188,7 +197,8 @@ discard block |
||
188 | 197 | public function testModeValueNone(): void |
189 | 198 | { |
190 | 199 | $result = $this->parser->parse(new \ReflectionClass( |
191 | - new #[AsCommand(name: 'foo')] class { |
|
200 | + new #[AsCommand(name: 'foo')] class |
|
201 | + { |
|
192 | 202 | #[Option(mode: InputOption::VALUE_NONE)] |
193 | 203 | private bool $option; |
194 | 204 | } |
@@ -206,7 +216,8 @@ discard block |
||
206 | 216 | public function testGuessedRequiredOption(): void |
207 | 217 | { |
208 | 218 | $result = $this->parser->parse(new \ReflectionClass( |
209 | - new #[AsCommand(name: 'foo')] class { |
|
219 | + new #[AsCommand(name: 'foo')] class |
|
220 | + { |
|
210 | 221 | #[Option] |
211 | 222 | private int $int; |
212 | 223 | |
@@ -234,7 +245,8 @@ discard block |
||
234 | 245 | public function testGuessedOptionalOption(): void |
235 | 246 | { |
236 | 247 | $result = $this->parser->parse(new \ReflectionClass( |
237 | - new #[AsCommand(name: 'foo')] class { |
|
248 | + new #[AsCommand(name: 'foo')] class |
|
249 | + { |
|
238 | 250 | #[Option] |
239 | 251 | private ?int $int; |
240 | 252 | |
@@ -265,7 +277,8 @@ discard block |
||
265 | 277 | public function testGuessedOptionalOptionFromPropertiesWithDefaultValue(): void |
266 | 278 | { |
267 | 279 | $result = $this->parser->parse(new \ReflectionClass( |
268 | - new #[AsCommand(name: 'foo')] class { |
|
280 | + new #[AsCommand(name: 'foo')] class |
|
281 | + { |
|
269 | 282 | #[Option] |
270 | 283 | private int $int = 1; |
271 | 284 | |
@@ -296,7 +309,8 @@ discard block |
||
296 | 309 | public function testGuessedArrayOption(): void |
297 | 310 | { |
298 | 311 | $result = $this->parser->parse(new \ReflectionClass( |
299 | - new #[AsCommand(name: 'foo')] class { |
|
312 | + new #[AsCommand(name: 'foo')] class |
|
313 | + { |
|
300 | 314 | #[Option] |
301 | 315 | private array $array; |
302 | 316 | } |
@@ -310,7 +324,8 @@ discard block |
||
310 | 324 | public function testGuessedOptionalArrayOption(): void |
311 | 325 | { |
312 | 326 | $result = $this->parser->parse(new \ReflectionClass( |
313 | - new #[AsCommand(name: 'foo')] class { |
|
327 | + new #[AsCommand(name: 'foo')] class |
|
328 | + { |
|
314 | 329 | #[Option] |
315 | 330 | private ?array $array; |
316 | 331 | } |
@@ -325,7 +340,8 @@ discard block |
||
325 | 340 | public function testGuessedOptionalArrayOptionFromPropertyWithDefaultValue(): void |
326 | 341 | { |
327 | 342 | $result = $this->parser->parse(new \ReflectionClass( |
328 | - new #[AsCommand(name: 'foo')] class { |
|
343 | + new #[AsCommand(name: 'foo')] class |
|
344 | + { |
|
329 | 345 | #[Option] |
330 | 346 | private array $array = []; |
331 | 347 | } |
@@ -340,7 +356,8 @@ discard block |
||
340 | 356 | public function testWithSuggestedValue(): void |
341 | 357 | { |
342 | 358 | $result = $this->parser->parse(new \ReflectionClass( |
343 | - new #[AsCommand(name: 'foo')] class { |
|
359 | + new #[AsCommand(name: 'foo')] class |
|
360 | + { |
|
344 | 361 | #[Option(mode: InputOption::VALUE_REQUIRED, suggestedValues: [1, 0])] |
345 | 362 | private int $option; |
346 | 363 | } |
@@ -366,7 +383,8 @@ discard block |
||
366 | 383 | public function testUnionTypeWithBuiltInAndNot(): void |
367 | 384 | { |
368 | 385 | $result = $this->parser->parse(new \ReflectionClass( |
369 | - new #[AsCommand(name: 'foo')] class { |
|
386 | + new #[AsCommand(name: 'foo')] class |
|
387 | + { |
|
370 | 388 | #[Option(mode: InputOption::VALUE_OPTIONAL)] |
371 | 389 | private int|\stdClass $option; |
372 | 390 | } |
@@ -385,7 +403,8 @@ discard block |
||
385 | 403 | { |
386 | 404 | $this->expectException(ConfiguratorException::class); |
387 | 405 | $this->parser->parse(new \ReflectionClass( |
388 | - new #[AsCommand(name: 'foo')] class { |
|
406 | + new #[AsCommand(name: 'foo')] class |
|
407 | + { |
|
389 | 408 | #[Option] |
390 | 409 | private \stdClass $option; |
391 | 410 | } |
@@ -396,7 +415,8 @@ discard block |
||
396 | 415 | { |
397 | 416 | $this->expectException(ConfiguratorException::class); |
398 | 417 | $this->parser->parse(new \ReflectionClass( |
399 | - new #[AsCommand(name: 'foo')] class { |
|
418 | + new #[AsCommand(name: 'foo')] class |
|
419 | + { |
|
400 | 420 | #[Option] |
401 | 421 | private \stdClass&\Traversable $option; |
402 | 422 | } |
@@ -407,7 +427,8 @@ discard block |
||
407 | 427 | { |
408 | 428 | $this->expectException(ConfiguratorException::class); |
409 | 429 | $this->parser->parse(new \ReflectionClass( |
410 | - new #[AsCommand(name: 'foo')] class { |
|
430 | + new #[AsCommand(name: 'foo')] class |
|
431 | + { |
|
411 | 432 | #[Option] |
412 | 433 | private object $object; |
413 | 434 | } |
@@ -25,7 +25,8 @@ discard block |
||
25 | 25 | public function testRequired(): void |
26 | 26 | { |
27 | 27 | $result = $this->parser->parse(new \ReflectionClass( |
28 | - new #[AsCommand(name: 'foo')] class { |
|
28 | + new #[AsCommand(name: 'foo')] class |
|
29 | + { |
|
29 | 30 | #[Argument] |
30 | 31 | private int $arg; |
31 | 32 | } |
@@ -41,7 +42,8 @@ discard block |
||
41 | 42 | public function testWithDefaultValue(): void |
42 | 43 | { |
43 | 44 | $result = $this->parser->parse(new \ReflectionClass( |
44 | - new #[AsCommand(name: 'foo')] class { |
|
45 | + new #[AsCommand(name: 'foo')] class |
|
46 | + { |
|
45 | 47 | #[Argument] |
46 | 48 | private int $arg = 1; |
47 | 49 | } |
@@ -57,7 +59,8 @@ discard block |
||
57 | 59 | public function testNullable(): void |
58 | 60 | { |
59 | 61 | $result = $this->parser->parse(new \ReflectionClass( |
60 | - new #[AsCommand(name: 'foo')] class { |
|
62 | + new #[AsCommand(name: 'foo')] class |
|
63 | + { |
|
61 | 64 | #[Argument] |
62 | 65 | private ?int $arg; |
63 | 66 | } |
@@ -73,7 +76,8 @@ discard block |
||
73 | 76 | public function testWithName(): void |
74 | 77 | { |
75 | 78 | $result = $this->parser->parse(new \ReflectionClass( |
76 | - new #[AsCommand(name: 'foo')] class { |
|
79 | + new #[AsCommand(name: 'foo')] class |
|
80 | + { |
|
77 | 81 | #[Argument(name: 'customName')] |
78 | 82 | private int $arg; |
79 | 83 | } |
@@ -89,7 +93,8 @@ discard block |
||
89 | 93 | public function testWithDescription(): void |
90 | 94 | { |
91 | 95 | $result = $this->parser->parse(new \ReflectionClass( |
92 | - new #[AsCommand(name: 'foo')] class { |
|
96 | + new #[AsCommand(name: 'foo')] class |
|
97 | + { |
|
93 | 98 | #[Argument(description: 'Some description')] |
94 | 99 | private int $arg; |
95 | 100 | } |
@@ -105,7 +110,8 @@ discard block |
||
105 | 110 | public function testWithSuggestedValue(): void |
106 | 111 | { |
107 | 112 | $result = $this->parser->parse(new \ReflectionClass( |
108 | - new #[AsCommand(name: 'foo')] class { |
|
113 | + new #[AsCommand(name: 'foo')] class |
|
114 | + { |
|
109 | 115 | #[Argument(suggestedValues: [1, 0])] |
110 | 116 | private int $arg; |
111 | 117 | } |
@@ -129,7 +135,8 @@ discard block |
||
129 | 135 | public function testArrayRequired(): void |
130 | 136 | { |
131 | 137 | $result = $this->parser->parse(new \ReflectionClass( |
132 | - new #[AsCommand(name: 'foo')] class { |
|
138 | + new #[AsCommand(name: 'foo')] class |
|
139 | + { |
|
133 | 140 | #[Argument] |
134 | 141 | private array $arg; |
135 | 142 | } |
@@ -145,7 +152,8 @@ discard block |
||
145 | 152 | public function testArrayNotRequired(): void |
146 | 153 | { |
147 | 154 | $result = $this->parser->parse(new \ReflectionClass( |
148 | - new #[AsCommand(name: 'foo')] class { |
|
155 | + new #[AsCommand(name: 'foo')] class |
|
156 | + { |
|
149 | 157 | #[Argument] |
150 | 158 | private ?array $arg; |
151 | 159 | } |
@@ -161,7 +169,8 @@ discard block |
||
161 | 169 | public function testArrayShouldBeLast(): void |
162 | 170 | { |
163 | 171 | $result = $this->parser->parse(new \ReflectionClass( |
164 | - new #[AsCommand(name: 'foo')] class { |
|
172 | + new #[AsCommand(name: 'foo')] class |
|
173 | + { |
|
165 | 174 | #[Argument] |
166 | 175 | private ?array $arg; |
167 | 176 | |
@@ -180,7 +189,8 @@ discard block |
||
180 | 189 | public function testUnionTypeWithBuiltInAndNot(): void |
181 | 190 | { |
182 | 191 | $result = $this->parser->parse(new \ReflectionClass( |
183 | - new #[AsCommand(name: 'foo')] class { |
|
192 | + new #[AsCommand(name: 'foo')] class |
|
193 | + { |
|
184 | 194 | #[Argument] |
185 | 195 | private int|\stdClass $arg; |
186 | 196 | } |
@@ -197,7 +207,8 @@ discard block |
||
197 | 207 | { |
198 | 208 | $this->expectException(ConfiguratorException::class); |
199 | 209 | $this->parser->parse(new \ReflectionClass( |
200 | - new #[AsCommand(name: 'foo')] class { |
|
210 | + new #[AsCommand(name: 'foo')] class |
|
211 | + { |
|
201 | 212 | #[Argument] |
202 | 213 | private \stdClass $arg; |
203 | 214 | } |
@@ -208,7 +219,8 @@ discard block |
||
208 | 219 | { |
209 | 220 | $this->expectException(ConfiguratorException::class); |
210 | 221 | $this->parser->parse(new \ReflectionClass( |
211 | - new #[AsCommand(name: 'foo')] class { |
|
222 | + new #[AsCommand(name: 'foo')] class |
|
223 | + { |
|
212 | 224 | #[Argument] |
213 | 225 | private \stdClass&\Traversable $arg; |
214 | 226 | } |
@@ -219,7 +231,8 @@ discard block |
||
219 | 231 | { |
220 | 232 | $this->expectException(ConfiguratorException::class); |
221 | 233 | $this->parser->parse(new \ReflectionClass( |
222 | - new #[AsCommand(name: 'foo')] class { |
|
234 | + new #[AsCommand(name: 'foo')] class |
|
235 | + { |
|
223 | 236 | #[Argument] |
224 | 237 | private array $arg; |
225 | 238 | |
@@ -233,7 +246,8 @@ discard block |
||
233 | 246 | { |
234 | 247 | $this->expectException(ConfiguratorException::class); |
235 | 248 | $this->parser->parse(new \ReflectionClass( |
236 | - new #[AsCommand(name: 'foo')] class { |
|
249 | + new #[AsCommand(name: 'foo')] class |
|
250 | + { |
|
237 | 251 | #[Argument] |
238 | 252 | private object $arg; |
239 | 253 | } |
@@ -19,10 +19,10 @@ |
||
19 | 19 | */ |
20 | 20 | public function __construct( |
21 | 21 | public readonly ?string $name = null, |
22 | - public readonly string|array|null $shortcut = null, |
|
22 | + public readonly string | array | null $shortcut = null, |
|
23 | 23 | public readonly ?string $description = null, |
24 | 24 | public readonly ?int $mode = null, |
25 | - public readonly \Closure|array $suggestedValues = [] |
|
26 | - ) { |
|
25 | + public readonly \Closure | array $suggestedValues = [] |
|
26 | + ){ |
|
27 | 27 | } |
28 | 28 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | { |
25 | 25 | public function __construct( |
26 | 26 | private readonly ReaderInterface $reader = new AttributeReader() |
27 | - ) { |
|
27 | + ){ |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | public function hasCommandAttribute(\ReflectionClass $reflection): bool |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | { |
38 | 38 | $attribute = $this->reader->firstClassMetadata($reflection, AsCommand::class); |
39 | 39 | |
40 | - if ($attribute === null) { |
|
40 | + if ($attribute === null){ |
|
41 | 41 | $attribute = $reflection->getAttributes(SymfonyAsCommand::class)[0]->newInstance(); |
42 | 42 | } |
43 | 43 | |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | { |
55 | 55 | $reflection = new \ReflectionClass($command); |
56 | 56 | |
57 | - foreach ($reflection->getProperties() as $property) { |
|
57 | + foreach ($reflection->getProperties() as $property){ |
|
58 | 58 | $attribute = $this->reader->firstPropertyMetadata($property, Argument::class); |
59 | - if ($attribute === null) { |
|
59 | + if ($attribute === null){ |
|
60 | 60 | continue; |
61 | 61 | } |
62 | 62 | |
63 | - if ($input->hasArgument($attribute->name ?? $property->getName())) { |
|
63 | + if ($input->hasArgument($attribute->name ?? $property->getName())){ |
|
64 | 64 | $property->setValue( |
65 | 65 | $command, |
66 | 66 | $this->typecast($input->getArgument($attribute->name ?? $property->getName()), $property) |
@@ -68,16 +68,16 @@ discard block |
||
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | - foreach ($reflection->getProperties() as $property) { |
|
71 | + foreach ($reflection->getProperties() as $property){ |
|
72 | 72 | $attribute = $this->reader->firstPropertyMetadata($property, Option::class); |
73 | - if ($attribute === null) { |
|
73 | + if ($attribute === null){ |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | - if ($input->hasOption($attribute->name ?? $property->getName())) { |
|
77 | + if ($input->hasOption($attribute->name ?? $property->getName())){ |
|
78 | 78 | $value = $this->typecast($input->getOption($attribute->name ?? $property->getName()), $property); |
79 | 79 | |
80 | - if ($value !== null || $this->getPropertyType($property)->allowsNull()) { |
|
80 | + if ($value !== null || $this->getPropertyType($property)->allowsNull()){ |
|
81 | 81 | $property->setValue($command, $value); |
82 | 82 | } |
83 | 83 | } |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | { |
89 | 89 | $result = []; |
90 | 90 | $arrayArgument = null; |
91 | - foreach ($reflection->getProperties() as $property) { |
|
91 | + foreach ($reflection->getProperties() as $property){ |
|
92 | 92 | $attribute = $this->reader->firstPropertyMetadata($property, Argument::class); |
93 | - if ($attribute === null) { |
|
93 | + if ($attribute === null){ |
|
94 | 94 | continue; |
95 | 95 | } |
96 | 96 | |
@@ -108,24 +108,24 @@ discard block |
||
108 | 108 | $argument = new InputArgument( |
109 | 109 | name: $attribute->name ?? $property->getName(), |
110 | 110 | mode: $mode, |
111 | - description: (string) $attribute->description, |
|
111 | + description: (string)$attribute->description, |
|
112 | 112 | default: $property->hasDefaultValue() ? $property->getDefaultValue() : null, |
113 | - suggestedValues: $attribute->suggestedValues |
|
113 | + suggestedValues : $attribute->suggestedValues |
|
114 | 114 | ); |
115 | 115 | |
116 | - if ($arrayArgument !== null && $isArray) { |
|
116 | + if ($arrayArgument !== null && $isArray){ |
|
117 | 117 | throw new ConfiguratorException('There must be only one array argument!'); |
118 | 118 | } |
119 | 119 | |
120 | 120 | // It must be used at the end of the argument list. |
121 | - if ($isArray) { |
|
121 | + if ($isArray){ |
|
122 | 122 | $arrayArgument = $argument; |
123 | 123 | continue; |
124 | 124 | } |
125 | 125 | $result[] = $argument; |
126 | 126 | } |
127 | 127 | |
128 | - if ($arrayArgument !== null) { |
|
128 | + if ($arrayArgument !== null){ |
|
129 | 129 | $result[] = $arrayArgument; |
130 | 130 | } |
131 | 131 | |
@@ -135,21 +135,21 @@ discard block |
||
135 | 135 | private function parseOptions(\ReflectionClass $reflection): array |
136 | 136 | { |
137 | 137 | $result = []; |
138 | - foreach ($reflection->getProperties() as $property) { |
|
138 | + foreach ($reflection->getProperties() as $property){ |
|
139 | 139 | $attribute = $this->reader->firstPropertyMetadata($property, Option::class); |
140 | - if ($attribute === null) { |
|
140 | + if ($attribute === null){ |
|
141 | 141 | continue; |
142 | 142 | } |
143 | 143 | |
144 | 144 | $type = $this->getPropertyType($property); |
145 | 145 | $mode = $attribute->mode; |
146 | 146 | |
147 | - if ($mode === null) { |
|
147 | + if ($mode === null){ |
|
148 | 148 | $mode = $this->guessOptionMode($type, $property); |
149 | 149 | } |
150 | 150 | |
151 | - if ($mode === InputOption::VALUE_NONE || $attribute->mode === InputOption::VALUE_NEGATABLE) { |
|
152 | - if ($type->getName() !== 'bool') { |
|
151 | + if ($mode === InputOption::VALUE_NONE || $attribute->mode === InputOption::VALUE_NEGATABLE){ |
|
152 | + if ($type->getName() !== 'bool'){ |
|
153 | 153 | throw new ConfiguratorException( |
154 | 154 | 'Options properties with mode `VALUE_NONE` or `VALUE_NEGATABLE` must be bool!' |
155 | 155 | ); |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | name: $attribute->name ?? $property->getName(), |
163 | 163 | shortcut: $attribute->shortcut, |
164 | 164 | mode: $mode, |
165 | - description: (string) $attribute->description, |
|
165 | + description: (string)$attribute->description, |
|
166 | 166 | default: $hasDefaultValue ? $property->getDefaultValue() : null, |
167 | - suggestedValues: $attribute->suggestedValues |
|
167 | + suggestedValues : $attribute->suggestedValues |
|
168 | 168 | ); |
169 | 169 | } |
170 | 170 | |
@@ -175,23 +175,23 @@ discard block |
||
175 | 175 | { |
176 | 176 | $type = $property->hasType() ? $property->getType() : null; |
177 | 177 | |
178 | - if (!$type instanceof \ReflectionNamedType || $value === null) { |
|
178 | + if (!$type instanceof \ReflectionNamedType || $value === null){ |
|
179 | 179 | return $value; |
180 | 180 | } |
181 | 181 | |
182 | 182 | return match ($type->getName()) { |
183 | - 'int' => (int) $value, |
|
184 | - 'string' => (string) $value, |
|
185 | - 'bool' => (bool) $value, |
|
186 | - 'float' => (float) $value, |
|
187 | - 'array' => (array) $value, |
|
183 | + 'int' => (int)$value, |
|
184 | + 'string' => (string)$value, |
|
185 | + 'bool' => (bool)$value, |
|
186 | + 'float' => (float)$value, |
|
187 | + 'array' => (array)$value, |
|
188 | 188 | default => $value |
189 | 189 | }; |
190 | 190 | } |
191 | 191 | |
192 | 192 | private function getPropertyType(\ReflectionProperty $property): \ReflectionNamedType |
193 | 193 | { |
194 | - if (!$property->hasType()) { |
|
194 | + if (!$property->hasType()){ |
|
195 | 195 | throw new ConfiguratorException( |
196 | 196 | \sprintf('Please, specify the type for the `%s` property!', $property->getName()) |
197 | 197 | ); |
@@ -199,19 +199,19 @@ discard block |
||
199 | 199 | |
200 | 200 | $type = $property->getType(); |
201 | 201 | |
202 | - if ($type instanceof \ReflectionIntersectionType) { |
|
202 | + if ($type instanceof \ReflectionIntersectionType){ |
|
203 | 203 | throw new ConfiguratorException(\sprintf('Invalid type for the `%s` property.', $property->getName())); |
204 | 204 | } |
205 | 205 | |
206 | - if ($type instanceof \ReflectionUnionType) { |
|
207 | - foreach ($type->getTypes() as $type) { |
|
208 | - if ($type->isBuiltin()) { |
|
206 | + if ($type instanceof \ReflectionUnionType){ |
|
207 | + foreach ($type->getTypes() as $type){ |
|
208 | + if ($type->isBuiltin()){ |
|
209 | 209 | return $type; |
210 | 210 | } |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | - if ($type instanceof \ReflectionNamedType && $type->isBuiltin() && $type->getName() !== 'object') { |
|
214 | + if ($type instanceof \ReflectionNamedType && $type->isBuiltin() && $type->getName() !== 'object'){ |
|
215 | 215 | return $type; |
216 | 216 | } |
217 | 217 |
@@ -37,7 +37,8 @@ discard block |
||
37 | 37 | { |
38 | 38 | $attribute = $this->reader->firstClassMetadata($reflection, AsCommand::class); |
39 | 39 | |
40 | - if ($attribute === null) { |
|
40 | + if ($attribute === null) |
|
41 | + { |
|
41 | 42 | $attribute = $reflection->getAttributes(SymfonyAsCommand::class)[0]->newInstance(); |
42 | 43 | } |
43 | 44 | |
@@ -54,13 +55,16 @@ discard block |
||
54 | 55 | { |
55 | 56 | $reflection = new \ReflectionClass($command); |
56 | 57 | |
57 | - foreach ($reflection->getProperties() as $property) { |
|
58 | + foreach ($reflection->getProperties() as $property) |
|
59 | + { |
|
58 | 60 | $attribute = $this->reader->firstPropertyMetadata($property, Argument::class); |
59 | - if ($attribute === null) { |
|
61 | + if ($attribute === null) |
|
62 | + { |
|
60 | 63 | continue; |
61 | 64 | } |
62 | 65 | |
63 | - if ($input->hasArgument($attribute->name ?? $property->getName())) { |
|
66 | + if ($input->hasArgument($attribute->name ?? $property->getName())) |
|
67 | + { |
|
64 | 68 | $property->setValue( |
65 | 69 | $command, |
66 | 70 | $this->typecast($input->getArgument($attribute->name ?? $property->getName()), $property) |
@@ -68,16 +72,20 @@ discard block |
||
68 | 72 | } |
69 | 73 | } |
70 | 74 | |
71 | - foreach ($reflection->getProperties() as $property) { |
|
75 | + foreach ($reflection->getProperties() as $property) |
|
76 | + { |
|
72 | 77 | $attribute = $this->reader->firstPropertyMetadata($property, Option::class); |
73 | - if ($attribute === null) { |
|
78 | + if ($attribute === null) |
|
79 | + { |
|
74 | 80 | continue; |
75 | 81 | } |
76 | 82 | |
77 | - if ($input->hasOption($attribute->name ?? $property->getName())) { |
|
83 | + if ($input->hasOption($attribute->name ?? $property->getName())) |
|
84 | + { |
|
78 | 85 | $value = $this->typecast($input->getOption($attribute->name ?? $property->getName()), $property); |
79 | 86 | |
80 | - if ($value !== null || $this->getPropertyType($property)->allowsNull()) { |
|
87 | + if ($value !== null || $this->getPropertyType($property)->allowsNull()) |
|
88 | + { |
|
81 | 89 | $property->setValue($command, $value); |
82 | 90 | } |
83 | 91 | } |
@@ -88,9 +96,11 @@ discard block |
||
88 | 96 | { |
89 | 97 | $result = []; |
90 | 98 | $arrayArgument = null; |
91 | - foreach ($reflection->getProperties() as $property) { |
|
99 | + foreach ($reflection->getProperties() as $property) |
|
100 | + { |
|
92 | 101 | $attribute = $this->reader->firstPropertyMetadata($property, Argument::class); |
93 | - if ($attribute === null) { |
|
102 | + if ($attribute === null) |
|
103 | + { |
|
94 | 104 | continue; |
95 | 105 | } |
96 | 106 | |
@@ -113,19 +123,22 @@ discard block |
||
113 | 123 | suggestedValues: $attribute->suggestedValues |
114 | 124 | ); |
115 | 125 | |
116 | - if ($arrayArgument !== null && $isArray) { |
|
126 | + if ($arrayArgument !== null && $isArray) |
|
127 | + { |
|
117 | 128 | throw new ConfiguratorException('There must be only one array argument!'); |
118 | 129 | } |
119 | 130 | |
120 | 131 | // It must be used at the end of the argument list. |
121 | - if ($isArray) { |
|
132 | + if ($isArray) |
|
133 | + { |
|
122 | 134 | $arrayArgument = $argument; |
123 | 135 | continue; |
124 | 136 | } |
125 | 137 | $result[] = $argument; |
126 | 138 | } |
127 | 139 | |
128 | - if ($arrayArgument !== null) { |
|
140 | + if ($arrayArgument !== null) |
|
141 | + { |
|
129 | 142 | $result[] = $arrayArgument; |
130 | 143 | } |
131 | 144 | |
@@ -135,21 +148,26 @@ discard block |
||
135 | 148 | private function parseOptions(\ReflectionClass $reflection): array |
136 | 149 | { |
137 | 150 | $result = []; |
138 | - foreach ($reflection->getProperties() as $property) { |
|
151 | + foreach ($reflection->getProperties() as $property) |
|
152 | + { |
|
139 | 153 | $attribute = $this->reader->firstPropertyMetadata($property, Option::class); |
140 | - if ($attribute === null) { |
|
154 | + if ($attribute === null) |
|
155 | + { |
|
141 | 156 | continue; |
142 | 157 | } |
143 | 158 | |
144 | 159 | $type = $this->getPropertyType($property); |
145 | 160 | $mode = $attribute->mode; |
146 | 161 | |
147 | - if ($mode === null) { |
|
162 | + if ($mode === null) |
|
163 | + { |
|
148 | 164 | $mode = $this->guessOptionMode($type, $property); |
149 | 165 | } |
150 | 166 | |
151 | - if ($mode === InputOption::VALUE_NONE || $attribute->mode === InputOption::VALUE_NEGATABLE) { |
|
152 | - if ($type->getName() !== 'bool') { |
|
167 | + if ($mode === InputOption::VALUE_NONE || $attribute->mode === InputOption::VALUE_NEGATABLE) |
|
168 | + { |
|
169 | + if ($type->getName() !== 'bool') |
|
170 | + { |
|
153 | 171 | throw new ConfiguratorException( |
154 | 172 | 'Options properties with mode `VALUE_NONE` or `VALUE_NEGATABLE` must be bool!' |
155 | 173 | ); |
@@ -175,7 +193,8 @@ discard block |
||
175 | 193 | { |
176 | 194 | $type = $property->hasType() ? $property->getType() : null; |
177 | 195 | |
178 | - if (!$type instanceof \ReflectionNamedType || $value === null) { |
|
196 | + if (!$type instanceof \ReflectionNamedType || $value === null) |
|
197 | + { |
|
179 | 198 | return $value; |
180 | 199 | } |
181 | 200 | |
@@ -191,7 +210,8 @@ discard block |
||
191 | 210 | |
192 | 211 | private function getPropertyType(\ReflectionProperty $property): \ReflectionNamedType |
193 | 212 | { |
194 | - if (!$property->hasType()) { |
|
213 | + if (!$property->hasType()) |
|
214 | + { |
|
195 | 215 | throw new ConfiguratorException( |
196 | 216 | \sprintf('Please, specify the type for the `%s` property!', $property->getName()) |
197 | 217 | ); |
@@ -199,19 +219,24 @@ discard block |
||
199 | 219 | |
200 | 220 | $type = $property->getType(); |
201 | 221 | |
202 | - if ($type instanceof \ReflectionIntersectionType) { |
|
222 | + if ($type instanceof \ReflectionIntersectionType) |
|
223 | + { |
|
203 | 224 | throw new ConfiguratorException(\sprintf('Invalid type for the `%s` property.', $property->getName())); |
204 | 225 | } |
205 | 226 | |
206 | - if ($type instanceof \ReflectionUnionType) { |
|
207 | - foreach ($type->getTypes() as $type) { |
|
208 | - if ($type->isBuiltin()) { |
|
227 | + if ($type instanceof \ReflectionUnionType) |
|
228 | + { |
|
229 | + foreach ($type->getTypes() as $type) |
|
230 | + { |
|
231 | + if ($type->isBuiltin()) |
|
232 | + { |
|
209 | 233 | return $type; |
210 | 234 | } |
211 | 235 | } |
212 | 236 | } |
213 | 237 | |
214 | - if ($type instanceof \ReflectionNamedType && $type->isBuiltin() && $type->getName() !== 'object') { |
|
238 | + if ($type instanceof \ReflectionNamedType && $type->isBuiltin() && $type->getName() !== 'object') |
|
239 | + { |
|
215 | 240 | return $type; |
216 | 241 | } |
217 | 242 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | ->method('getArgument') |
37 | 37 | ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true); |
38 | 38 | |
39 | - $command = new #[AsCommand('foo')] class extends Command { |
|
39 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
40 | 40 | #[Argument] |
41 | 41 | public int $intVal; |
42 | 42 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | ->expects($this->never()) |
76 | 76 | ->method('getArgument'); |
77 | 77 | |
78 | - $command = new #[AsCommand('foo')] class extends Command { |
|
78 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
79 | 79 | #[Argument] |
80 | 80 | public int $arg; |
81 | 81 | }; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | ->method('getOption') |
99 | 99 | ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true, true); |
100 | 100 | |
101 | - $command = new #[AsCommand('foo')] class extends Command { |
|
101 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
102 | 102 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
103 | 103 | public int $intVal; |
104 | 104 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | ->expects($this->never()) |
142 | 142 | ->method('getOption'); |
143 | 143 | |
144 | - $command = new #[AsCommand('foo')] class extends Command { |
|
144 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
145 | 145 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
146 | 146 | public int $option; |
147 | 147 | }; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | ->method('getOption') |
166 | 166 | ->willReturn(null); |
167 | 167 | |
168 | - $command = new #[AsCommand('foo')] class extends Command { |
|
168 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
169 | 169 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
170 | 170 | public int $option; |
171 | 171 | }; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | ->method('getOption') |
189 | 189 | ->willReturn(null); |
190 | 190 | |
191 | - $command = new #[AsCommand('foo')] class extends Command { |
|
191 | + $command = new #[AsCommand('foo')] class extends Command{ |
|
192 | 192 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
193 | 193 | public ?int $intVal; |
194 | 194 | }; |
@@ -36,7 +36,8 @@ discard block |
||
36 | 36 | ->method('getArgument') |
37 | 37 | ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true); |
38 | 38 | |
39 | - $command = new #[AsCommand('foo')] class extends Command { |
|
39 | + $command = new #[AsCommand('foo')] class extends Command |
|
40 | + { |
|
40 | 41 | #[Argument] |
41 | 42 | public int $intVal; |
42 | 43 | |
@@ -75,7 +76,8 @@ discard block |
||
75 | 76 | ->expects($this->never()) |
76 | 77 | ->method('getArgument'); |
77 | 78 | |
78 | - $command = new #[AsCommand('foo')] class extends Command { |
|
79 | + $command = new #[AsCommand('foo')] class extends Command |
|
80 | + { |
|
79 | 81 | #[Argument] |
80 | 82 | public int $arg; |
81 | 83 | }; |
@@ -98,7 +100,8 @@ discard block |
||
98 | 100 | ->method('getOption') |
99 | 101 | ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true, true); |
100 | 102 | |
101 | - $command = new #[AsCommand('foo')] class extends Command { |
|
103 | + $command = new #[AsCommand('foo')] class extends Command |
|
104 | + { |
|
102 | 105 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
103 | 106 | public int $intVal; |
104 | 107 | |
@@ -141,7 +144,8 @@ discard block |
||
141 | 144 | ->expects($this->never()) |
142 | 145 | ->method('getOption'); |
143 | 146 | |
144 | - $command = new #[AsCommand('foo')] class extends Command { |
|
147 | + $command = new #[AsCommand('foo')] class extends Command |
|
148 | + { |
|
145 | 149 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
146 | 150 | public int $option; |
147 | 151 | }; |
@@ -165,7 +169,8 @@ discard block |
||
165 | 169 | ->method('getOption') |
166 | 170 | ->willReturn(null); |
167 | 171 | |
168 | - $command = new #[AsCommand('foo')] class extends Command { |
|
172 | + $command = new #[AsCommand('foo')] class extends Command |
|
173 | + { |
|
169 | 174 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
170 | 175 | public int $option; |
171 | 176 | }; |
@@ -188,7 +193,8 @@ discard block |
||
188 | 193 | ->method('getOption') |
189 | 194 | ->willReturn(null); |
190 | 195 | |
191 | - $command = new #[AsCommand('foo')] class extends Command { |
|
196 | + $command = new #[AsCommand('foo')] class extends Command |
|
197 | + { |
|
192 | 198 | #[Option(mode: InputOption::VALUE_REQUIRED)] |
193 | 199 | public ?int $intVal; |
194 | 200 | }; |