Passed
Pull Request — master (#1036)
by Maxim
12:01
created
src/Console/tests/Configurator/Attribute/FillPropertiesTest.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
             ->method('getArgument')
38 38
             ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true);
39 39
 
40
-        $command = new #[AsCommand('foo')] class extends Command {
40
+        $command = new #[AsCommand('foo')] class extends Command{
41 41
             #[Argument]
42 42
             public int $intVal;
43 43
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
             ->expects($this->never())
77 77
             ->method('getArgument');
78 78
 
79
-        $command = new #[AsCommand('foo')] class extends Command {
79
+        $command = new #[AsCommand('foo')] class extends Command{
80 80
             #[Argument]
81 81
             public int $arg;
82 82
         };
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
             ->method('getOption')
100 100
             ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true, true);
101 101
 
102
-        $command = new #[AsCommand('foo')] class extends Command {
102
+        $command = new #[AsCommand('foo')] class extends Command{
103 103
             #[Option(mode: InputOption::VALUE_REQUIRED)]
104 104
             public int $intVal;
105 105
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
             ->method('getOption')
143 143
             ->willReturnOnConsecutiveCalls(1, null, 0);
144 144
 
145
-        $command = new #[AsCommand('foo')] class extends Command {
145
+        $command = new #[AsCommand('foo')] class extends Command{
146 146
             #[Option(mode: InputOption::VALUE_REQUIRED)]
147 147
             public Status $required;
148 148
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
             ->expects($this->never())
174 174
             ->method('getOption');
175 175
 
176
-        $command = new #[AsCommand('foo')] class extends Command {
176
+        $command = new #[AsCommand('foo')] class extends Command{
177 177
             #[Option(mode: InputOption::VALUE_REQUIRED)]
178 178
             public int $option;
179 179
         };
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
             ->method('getOption')
198 198
             ->willReturn(null);
199 199
 
200
-        $command = new #[AsCommand('foo')] class extends Command {
200
+        $command = new #[AsCommand('foo')] class extends Command{
201 201
             #[Option(mode: InputOption::VALUE_REQUIRED)]
202 202
             public int $option;
203 203
         };
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
             ->method('getOption')
221 221
             ->willReturn(null);
222 222
 
223
-        $command = new #[AsCommand('foo')] class extends Command {
223
+        $command = new #[AsCommand('foo')] class extends Command{
224 224
             #[Option(mode: InputOption::VALUE_REQUIRED)]
225 225
             public ?int $intVal;
226 226
         };
Please login to merge, or discard this patch.
Braces   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -37,7 +37,8 @@  discard block
 block discarded – undo
37 37
             ->method('getArgument')
38 38
             ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true);
39 39
 
40
-        $command = new #[AsCommand('foo')] class extends Command {
40
+        $command = new #[AsCommand('foo')] class extends Command
41
+        {
41 42
             #[Argument]
42 43
             public int $intVal;
43 44
 
@@ -76,7 +77,8 @@  discard block
 block discarded – undo
76 77
             ->expects($this->never())
77 78
             ->method('getArgument');
78 79
 
79
-        $command = new #[AsCommand('foo')] class extends Command {
80
+        $command = new #[AsCommand('foo')] class extends Command
81
+        {
80 82
             #[Argument]
81 83
             public int $arg;
82 84
         };
@@ -99,7 +101,8 @@  discard block
 block discarded – undo
99 101
             ->method('getOption')
100 102
             ->willReturnOnConsecutiveCalls(5, 'foo', ['foo', 'bar'], 0.5, true, true);
101 103
 
102
-        $command = new #[AsCommand('foo')] class extends Command {
104
+        $command = new #[AsCommand('foo')] class extends Command
105
+        {
103 106
             #[Option(mode: InputOption::VALUE_REQUIRED)]
104 107
             public int $intVal;
105 108
 
@@ -142,7 +145,8 @@  discard block
 block discarded – undo
142 145
             ->method('getOption')
143 146
             ->willReturnOnConsecutiveCalls(1, null, 0);
144 147
 
145
-        $command = new #[AsCommand('foo')] class extends Command {
148
+        $command = new #[AsCommand('foo')] class extends Command
149
+        {
146 150
             #[Option(mode: InputOption::VALUE_REQUIRED)]
147 151
             public Status $required;
148 152
 
@@ -173,7 +177,8 @@  discard block
 block discarded – undo
173 177
             ->expects($this->never())
174 178
             ->method('getOption');
175 179
 
176
-        $command = new #[AsCommand('foo')] class extends Command {
180
+        $command = new #[AsCommand('foo')] class extends Command
181
+        {
177 182
             #[Option(mode: InputOption::VALUE_REQUIRED)]
178 183
             public int $option;
179 184
         };
@@ -197,7 +202,8 @@  discard block
 block discarded – undo
197 202
             ->method('getOption')
198 203
             ->willReturn(null);
199 204
 
200
-        $command = new #[AsCommand('foo')] class extends Command {
205
+        $command = new #[AsCommand('foo')] class extends Command
206
+        {
201 207
             #[Option(mode: InputOption::VALUE_REQUIRED)]
202 208
             public int $option;
203 209
         };
@@ -220,7 +226,8 @@  discard block
 block discarded – undo
220 226
             ->method('getOption')
221 227
             ->willReturn(null);
222 228
 
223
-        $command = new #[AsCommand('foo')] class extends Command {
229
+        $command = new #[AsCommand('foo')] class extends Command
230
+        {
224 231
             #[Option(mode: InputOption::VALUE_REQUIRED)]
225 232
             public ?int $intVal;
226 233
         };
Please login to merge, or discard this patch.
src/Console/src/Configurator/Attribute/Parser.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 || $mode === InputOption::VALUE_NEGATABLE) {
152
-                if ($type->getName() !== 'bool') {
151
+            if ($mode === InputOption::VALUE_NONE || $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
 block discarded – undo
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,18 +175,18 @@  discard block
 block discarded – undo
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
         $typeName = $type->getName();
183 183
 
184 184
         return match (true) {
185
-            $typeName === 'int' => (int) $value,
186
-            $typeName === 'string' => (string) $value,
187
-            $typeName === 'bool' => (bool) $value,
188
-            $typeName === 'float' => (float) $value,
189
-            $typeName === 'array' => (array) $value,
185
+            $typeName === 'int' => (int)$value,
186
+            $typeName === 'string' => (string)$value,
187
+            $typeName === 'bool' => (bool)$value,
188
+            $typeName === 'float' => (float)$value,
189
+            $typeName === 'array' => (array)$value,
190 190
             \enum_exists($typeName) => $typeName::from($value),
191 191
             default => $value
192 192
         };
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 
195 195
     private function getPropertyType(\ReflectionProperty $property): \ReflectionNamedType
196 196
     {
197
-        if (!$property->hasType()) {
197
+        if (!$property->hasType()){
198 198
             throw new ConfiguratorException(
199 199
                 \sprintf('Please, specify the type for the `%s` property!', $property->getName())
200 200
             );
@@ -202,23 +202,23 @@  discard block
 block discarded – undo
202 202
 
203 203
         $type = $property->getType();
204 204
 
205
-        if ($type instanceof \ReflectionIntersectionType) {
205
+        if ($type instanceof \ReflectionIntersectionType){
206 206
             throw new ConfiguratorException(\sprintf('Invalid type for the `%s` property.', $property->getName()));
207 207
         }
208 208
 
209
-        if ($type instanceof \ReflectionUnionType) {
210
-            foreach ($type->getTypes() as $type) {
211
-                if ($type instanceof \ReflectionNamedType && $type->isBuiltin()) {
209
+        if ($type instanceof \ReflectionUnionType){
210
+            foreach ($type->getTypes() as $type){
211
+                if ($type instanceof \ReflectionNamedType && $type->isBuiltin()){
212 212
                     return $type;
213 213
                 }
214 214
             }
215 215
         }
216 216
 
217
-        if (!$type->isBuiltin() && \enum_exists($type->getName())) {
217
+        if (!$type->isBuiltin() && \enum_exists($type->getName())){
218 218
             return $type;
219 219
         }
220 220
 
221
-        if ($type instanceof \ReflectionNamedType && $type->isBuiltin() && $type->getName() !== 'object') {
221
+        if ($type instanceof \ReflectionNamedType && $type->isBuiltin() && $type->getName() !== 'object'){
222 222
             return $type;
223 223
         }
224 224
 
Please login to merge, or discard this patch.
Braces   +52 added lines, -26 removed lines patch added patch discarded remove patch
@@ -37,7 +37,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 || $mode === InputOption::VALUE_NEGATABLE) {
152
-                if ($type->getName() !== 'bool') {
167
+            if ($mode === InputOption::VALUE_NONE || $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
 block discarded – undo
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
 
@@ -194,7 +213,8 @@  discard block
 block discarded – undo
194 213
 
195 214
     private function getPropertyType(\ReflectionProperty $property): \ReflectionNamedType
196 215
     {
197
-        if (!$property->hasType()) {
216
+        if (!$property->hasType())
217
+        {
198 218
             throw new ConfiguratorException(
199 219
                 \sprintf('Please, specify the type for the `%s` property!', $property->getName())
200 220
             );
@@ -202,23 +222,29 @@  discard block
 block discarded – undo
202 222
 
203 223
         $type = $property->getType();
204 224
 
205
-        if ($type instanceof \ReflectionIntersectionType) {
225
+        if ($type instanceof \ReflectionIntersectionType)
226
+        {
206 227
             throw new ConfiguratorException(\sprintf('Invalid type for the `%s` property.', $property->getName()));
207 228
         }
208 229
 
209
-        if ($type instanceof \ReflectionUnionType) {
210
-            foreach ($type->getTypes() as $type) {
211
-                if ($type instanceof \ReflectionNamedType && $type->isBuiltin()) {
230
+        if ($type instanceof \ReflectionUnionType)
231
+        {
232
+            foreach ($type->getTypes() as $type)
233
+            {
234
+                if ($type instanceof \ReflectionNamedType && $type->isBuiltin())
235
+                {
212 236
                     return $type;
213 237
                 }
214 238
             }
215 239
         }
216 240
 
217
-        if (!$type->isBuiltin() && \enum_exists($type->getName())) {
241
+        if (!$type->isBuiltin() && \enum_exists($type->getName()))
242
+        {
218 243
             return $type;
219 244
         }
220 245
 
221
-        if ($type instanceof \ReflectionNamedType && $type->isBuiltin() && $type->getName() !== 'object') {
246
+        if ($type instanceof \ReflectionNamedType && $type->isBuiltin() && $type->getName() !== 'object')
247
+        {
222 248
             return $type;
223 249
         }
224 250
 
Please login to merge, or discard this patch.