@@ -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 |
@@ -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 | }; |