Test Failed
Pull Request — master (#872)
by Maxim
10:54 queued 03:52
created
src/Console/src/Configurator/Attribute/Parser.php 2 patches
Spacing   +33 added lines, -33 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,13 +68,13 @@  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
                 $property->setValue(
79 79
                     $command,
80 80
                     $this->typecast($input->getOption($attribute->name ?? $property->getName()), $property)
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
     {
88 88
         $result = [];
89 89
         $arrayArgument = null;
90
-        foreach ($reflection->getProperties() as $property) {
90
+        foreach ($reflection->getProperties() as $property){
91 91
             $attribute = $this->reader->firstPropertyMetadata($property, Argument::class);
92
-            if ($attribute === null) {
92
+            if ($attribute === null){
93 93
                 continue;
94 94
             }
95 95
 
@@ -107,24 +107,24 @@  discard block
 block discarded – undo
107 107
             $argument = new InputArgument(
108 108
                 name: $attribute->name ?? $property->getName(),
109 109
                 mode: $mode,
110
-                description: (string) $attribute->description,
110
+                description: (string)$attribute->description,
111 111
                 default: $property->hasDefaultValue() ? $property->getDefaultValue() : null,
112
-                suggestedValues: $attribute->suggestedValues
112
+                suggestedValues : $attribute->suggestedValues
113 113
             );
114 114
 
115
-            if ($arrayArgument !== null && $isArray) {
115
+            if ($arrayArgument !== null && $isArray){
116 116
                 throw new ConfiguratorException('There must be only one array argument!');
117 117
             }
118 118
 
119 119
             // It must be used at the end of the argument list.
120
-            if ($isArray) {
120
+            if ($isArray){
121 121
                 $arrayArgument = $argument;
122 122
                 continue;
123 123
             }
124 124
             $result[] = $argument;
125 125
         }
126 126
 
127
-        if ($arrayArgument !== null) {
127
+        if ($arrayArgument !== null){
128 128
             $result[] = $arrayArgument;
129 129
         }
130 130
 
@@ -134,16 +134,16 @@  discard block
 block discarded – undo
134 134
     private function parseOptions(\ReflectionClass $reflection): array
135 135
     {
136 136
         $result = [];
137
-        foreach ($reflection->getProperties() as $property) {
137
+        foreach ($reflection->getProperties() as $property){
138 138
             $attribute = $this->reader->firstPropertyMetadata($property, Option::class);
139
-            if ($attribute === null) {
139
+            if ($attribute === null){
140 140
                 continue;
141 141
             }
142 142
 
143 143
             $type = $this->getPropertyType($property);
144 144
 
145
-            if ($attribute->mode === InputOption::VALUE_NONE || $attribute->mode === InputOption::VALUE_NEGATABLE) {
146
-                if ($type->getName() !== 'bool') {
145
+            if ($attribute->mode === InputOption::VALUE_NONE || $attribute->mode === InputOption::VALUE_NEGATABLE){
146
+                if ($type->getName() !== 'bool'){
147 147
                     throw new ConfiguratorException(
148 148
                         'Options properties with mode `VALUE_NONE` or `VALUE_NEGATABLE` must be bool!'
149 149
                     );
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
                 name: $attribute->name ?? $property->getName(),
157 157
                 shortcut: $attribute->shortcut,
158 158
                 mode: $attribute->mode,
159
-                description: (string) $attribute->description,
159
+                description: (string)$attribute->description,
160 160
                 default: $hasDefaultValue ? $property->getDefaultValue() : null,
161
-                suggestedValues: $attribute->suggestedValues
161
+                suggestedValues : $attribute->suggestedValues
162 162
             );
163 163
         }
164 164
 
@@ -169,23 +169,23 @@  discard block
 block discarded – undo
169 169
     {
170 170
         $type = $property->hasType() ? $property->getType() : null;
171 171
 
172
-        if (!$type instanceof \ReflectionNamedType) {
172
+        if (!$type instanceof \ReflectionNamedType){
173 173
             return $value;
174 174
         }
175 175
 
176 176
         return match ($type->getName()) {
177
-            'int' => (int) $value,
178
-            'string' => (string) $value,
179
-            'bool' => (bool) $value,
180
-            'float' => (float) $value,
181
-            'array' => (array) $value,
177
+            'int' => (int)$value,
178
+            'string' => (string)$value,
179
+            'bool' => (bool)$value,
180
+            'float' => (float)$value,
181
+            'array' => (array)$value,
182 182
             default => $value
183 183
         };
184 184
     }
185 185
 
186 186
     private function getPropertyType(\ReflectionProperty $property): \ReflectionNamedType
187 187
     {
188
-        if (!$property->hasType()) {
188
+        if (!$property->hasType()){
189 189
             throw new ConfiguratorException(
190 190
                 \sprintf('Please, specify the type for the `%s` property!', $property->getName())
191 191
             );
@@ -193,19 +193,19 @@  discard block
 block discarded – undo
193 193
 
194 194
         $type = $property->getType();
195 195
 
196
-        if ($type instanceof \ReflectionIntersectionType) {
196
+        if ($type instanceof \ReflectionIntersectionType){
197 197
             throw new ConfiguratorException(\sprintf('Invalid type for the `%s` property.', $property->getName()));
198 198
         }
199 199
 
200
-        if ($type instanceof \ReflectionUnionType) {
201
-            foreach ($type->getTypes() as $type) {
202
-                if ($type->isBuiltin()) {
200
+        if ($type instanceof \ReflectionUnionType){
201
+            foreach ($type->getTypes() as $type){
202
+                if ($type->isBuiltin()){
203 203
                     return $type;
204 204
                 }
205 205
             }
206 206
         }
207 207
 
208
-        if ($type instanceof \ReflectionNamedType && $type->isBuiltin()) {
208
+        if ($type instanceof \ReflectionNamedType && $type->isBuiltin()){
209 209
             return $type;
210 210
         }
211 211
 
Please login to merge, or discard this patch.
Braces   +46 added lines, -23 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,13 +72,16 @@  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
                 $property->setValue(
79 86
                     $command,
80 87
                     $this->typecast($input->getOption($attribute->name ?? $property->getName()), $property)
@@ -87,9 +94,11 @@  discard block
 block discarded – undo
87 94
     {
88 95
         $result = [];
89 96
         $arrayArgument = null;
90
-        foreach ($reflection->getProperties() as $property) {
97
+        foreach ($reflection->getProperties() as $property)
98
+        {
91 99
             $attribute = $this->reader->firstPropertyMetadata($property, Argument::class);
92
-            if ($attribute === null) {
100
+            if ($attribute === null)
101
+            {
93 102
                 continue;
94 103
             }
95 104
 
@@ -112,19 +121,22 @@  discard block
 block discarded – undo
112 121
                 suggestedValues: $attribute->suggestedValues
113 122
             );
114 123
 
115
-            if ($arrayArgument !== null && $isArray) {
124
+            if ($arrayArgument !== null && $isArray)
125
+            {
116 126
                 throw new ConfiguratorException('There must be only one array argument!');
117 127
             }
118 128
 
119 129
             // It must be used at the end of the argument list.
120
-            if ($isArray) {
130
+            if ($isArray)
131
+            {
121 132
                 $arrayArgument = $argument;
122 133
                 continue;
123 134
             }
124 135
             $result[] = $argument;
125 136
         }
126 137
 
127
-        if ($arrayArgument !== null) {
138
+        if ($arrayArgument !== null)
139
+        {
128 140
             $result[] = $arrayArgument;
129 141
         }
130 142
 
@@ -134,16 +146,20 @@  discard block
 block discarded – undo
134 146
     private function parseOptions(\ReflectionClass $reflection): array
135 147
     {
136 148
         $result = [];
137
-        foreach ($reflection->getProperties() as $property) {
149
+        foreach ($reflection->getProperties() as $property)
150
+        {
138 151
             $attribute = $this->reader->firstPropertyMetadata($property, Option::class);
139
-            if ($attribute === null) {
152
+            if ($attribute === null)
153
+            {
140 154
                 continue;
141 155
             }
142 156
 
143 157
             $type = $this->getPropertyType($property);
144 158
 
145
-            if ($attribute->mode === InputOption::VALUE_NONE || $attribute->mode === InputOption::VALUE_NEGATABLE) {
146
-                if ($type->getName() !== 'bool') {
159
+            if ($attribute->mode === InputOption::VALUE_NONE || $attribute->mode === InputOption::VALUE_NEGATABLE)
160
+            {
161
+                if ($type->getName() !== 'bool')
162
+                {
147 163
                     throw new ConfiguratorException(
148 164
                         'Options properties with mode `VALUE_NONE` or `VALUE_NEGATABLE` must be bool!'
149 165
                     );
@@ -169,7 +185,8 @@  discard block
 block discarded – undo
169 185
     {
170 186
         $type = $property->hasType() ? $property->getType() : null;
171 187
 
172
-        if (!$type instanceof \ReflectionNamedType) {
188
+        if (!$type instanceof \ReflectionNamedType)
189
+        {
173 190
             return $value;
174 191
         }
175 192
 
@@ -185,7 +202,8 @@  discard block
 block discarded – undo
185 202
 
186 203
     private function getPropertyType(\ReflectionProperty $property): \ReflectionNamedType
187 204
     {
188
-        if (!$property->hasType()) {
205
+        if (!$property->hasType())
206
+        {
189 207
             throw new ConfiguratorException(
190 208
                 \sprintf('Please, specify the type for the `%s` property!', $property->getName())
191 209
             );
@@ -193,19 +211,24 @@  discard block
 block discarded – undo
193 211
 
194 212
         $type = $property->getType();
195 213
 
196
-        if ($type instanceof \ReflectionIntersectionType) {
214
+        if ($type instanceof \ReflectionIntersectionType)
215
+        {
197 216
             throw new ConfiguratorException(\sprintf('Invalid type for the `%s` property.', $property->getName()));
198 217
         }
199 218
 
200
-        if ($type instanceof \ReflectionUnionType) {
201
-            foreach ($type->getTypes() as $type) {
202
-                if ($type->isBuiltin()) {
219
+        if ($type instanceof \ReflectionUnionType)
220
+        {
221
+            foreach ($type->getTypes() as $type)
222
+            {
223
+                if ($type->isBuiltin())
224
+                {
203 225
                     return $type;
204 226
                 }
205 227
             }
206 228
         }
207 229
 
208
-        if ($type instanceof \ReflectionNamedType && $type->isBuiltin()) {
230
+        if ($type instanceof \ReflectionNamedType && $type->isBuiltin())
231
+        {
209 232
             return $type;
210 233
         }
211 234
 
Please login to merge, or discard this patch.
src/Console/src/PromptArguments.php 2 patches
Braces   +18 added lines, -9 removed lines patch added patch discarded remove patch
@@ -24,13 +24,16 @@  discard block
 block discarded – undo
24 24
     {
25 25
         $io = new SymfonyStyle($input, $output);
26 26
 
27
-        foreach ($command->getDefinition()->getArguments() as $argument) {
27
+        foreach ($command->getDefinition()->getArguments() as $argument)
28
+        {
28 29
             // Skip default argument "the command to execute"
29
-            if ($argument->getName() === 'command') {
30
+            if ($argument->getName() === 'command')
31
+            {
30 32
                 continue;
31 33
             }
32 34
 
33
-            if ($argument->isRequired() && $input->getArgument($argument->getName()) === null) {
35
+            if ($argument->isRequired() && $input->getArgument($argument->getName()) === null)
36
+            {
34 37
                 $input->setArgument(
35 38
                     $argument->getName(),
36 39
                     $io->ask($this->getQuestion($command, $argument))
@@ -43,25 +46,31 @@  discard block
 block discarded – undo
43 46
     {
44 47
         $reflection = new \ReflectionClass($command);
45 48
 
46
-        foreach ($this->reader->getClassMetadata($reflection, Question::class) as $question) {
47
-            if ($question->argument === null) {
49
+        foreach ($this->reader->getClassMetadata($reflection, Question::class) as $question)
50
+        {
51
+            if ($question->argument === null)
52
+            {
48 53
                 throw new ConsoleException(
49 54
                     'When using a `Question` attribute on a console command class, the argument parameter is required.'
50 55
                 );
51 56
             }
52 57
 
53
-            if ($argument->getName() === $question->argument) {
58
+            if ($argument->getName() === $question->argument)
59
+            {
54 60
                 return $question->question;
55 61
             }
56 62
         }
57 63
 
58
-        foreach ($reflection->getProperties() as $property) {
64
+        foreach ($reflection->getProperties() as $property)
65
+        {
59 66
             $question = $this->reader->firstPropertyMetadata($property, Question::class);
60
-            if ($question === null) {
67
+            if ($question === null)
68
+            {
61 69
                 continue;
62 70
             }
63 71
 
64
-            if ($argument->getName() === ($question->argument ?? $property->getName())) {
72
+            if ($argument->getName() === ($question->argument ?? $property->getName()))
73
+            {
65 74
                 return $question->question;
66 75
             }
67 76
         }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -20,20 +20,20 @@  discard block
 block discarded – undo
20 20
 {
21 21
     public function __construct(
22 22
         private readonly ReaderInterface $reader = new AttributeReader()
23
-    ) {
23
+    ){
24 24
     }
25 25
 
26 26
     public function promptMissedArguments(Command $command, InputInterface $input, OutputInterface $output): void
27 27
     {
28 28
         $io = new SymfonyStyle($input, $output);
29 29
 
30
-        foreach ($command->getDefinition()->getArguments() as $argument) {
30
+        foreach ($command->getDefinition()->getArguments() as $argument){
31 31
             // Skip default argument "the command to execute"
32
-            if ($argument->getName() === 'command') {
32
+            if ($argument->getName() === 'command'){
33 33
                 continue;
34 34
             }
35 35
 
36
-            if ($argument->isRequired() && $input->getArgument($argument->getName()) === null) {
36
+            if ($argument->isRequired() && $input->getArgument($argument->getName()) === null){
37 37
                 $input->setArgument(
38 38
                     $argument->getName(),
39 39
                     $io->ask($this->getQuestion($command, $argument))
@@ -46,25 +46,25 @@  discard block
 block discarded – undo
46 46
     {
47 47
         $reflection = new \ReflectionClass($command);
48 48
 
49
-        foreach ($this->reader->getClassMetadata($reflection, Question::class) as $question) {
50
-            if ($question->argument === null) {
49
+        foreach ($this->reader->getClassMetadata($reflection, Question::class) as $question){
50
+            if ($question->argument === null){
51 51
                 throw new ConsoleException(
52 52
                     'When using a `Question` attribute on a console command class, the argument parameter is required.'
53 53
                 );
54 54
             }
55 55
 
56
-            if ($argument->getName() === $question->argument) {
56
+            if ($argument->getName() === $question->argument){
57 57
                 return $question->question;
58 58
             }
59 59
         }
60 60
 
61
-        foreach ($reflection->getProperties() as $property) {
61
+        foreach ($reflection->getProperties() as $property){
62 62
             $question = $this->reader->firstPropertyMetadata($property, Question::class);
63
-            if ($question === null) {
63
+            if ($question === null){
64 64
                 continue;
65 65
             }
66 66
 
67
-            if ($argument->getName() === ($question->argument ?? $property->getName())) {
67
+            if ($argument->getName() === ($question->argument ?? $property->getName())){
68 68
                 return $question->question;
69 69
             }
70 70
         }
Please login to merge, or discard this patch.
src/Console/src/Configurator/Signature/Parser.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -24,8 +24,8 @@  discard block
 block discarded – undo
24 24
     {
25 25
         $name = $this->parseName($signature);
26 26
 
27
-        if (\preg_match_all('/\{\s*(.*?)\s*\}/', $signature, $matches)) {
28
-            if (\count($matches[1])) {
27
+        if (\preg_match_all('/\{\s*(.*?)\s*\}/', $signature, $matches)){
28
+            if (\count($matches[1])){
29 29
                 return new CommandDefinition($name, ...$this->parseParameters($matches[1]));
30 30
             }
31 31
         }
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      */
41 41
     private function parseName(string $signature): string
42 42
     {
43
-        if (!\preg_match('/\S+/', $signature, $matches)) {
43
+        if (!\preg_match('/\S+/', $signature, $matches)){
44 44
             throw new InvalidArgumentException('Unable to determine command name from signature.');
45 45
         }
46 46
 
@@ -57,10 +57,10 @@  discard block
 block discarded – undo
57 57
         $arguments = [];
58 58
         $options = [];
59 59
 
60
-        foreach ($tokens as $token) {
61
-            if (\preg_match('/-{2,}(.*)/', $token, $matches)) {
60
+        foreach ($tokens as $token){
61
+            if (\preg_match('/-{2,}(.*)/', $token, $matches)){
62 62
                 $options[] = $this->parseOption($matches[1]);
63
-            } else {
63
+            }else{
64 64
                 $arguments[] = $this->parseArgument($token);
65 65
             }
66 66
         }
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         $matches = \preg_split('/\s*\|\s*/', $token, 2);
124 124
         $shortcut = null;
125 125
 
126
-        if (isset($matches[1])) {
126
+        if (isset($matches[1])){
127 127
             [$shortcut, $token] = $matches;
128 128
         }
129 129
 
Please login to merge, or discard this patch.
Braces   +15 added lines, -7 removed lines patch added patch discarded remove patch
@@ -24,8 +24,10 @@  discard block
 block discarded – undo
24 24
     {
25 25
         $name = $this->parseName($signature);
26 26
 
27
-        if (\preg_match_all('/\{\s*(.*?)\s*\}/', $signature, $matches)) {
28
-            if (\count($matches[1])) {
27
+        if (\preg_match_all('/\{\s*(.*?)\s*\}/', $signature, $matches))
28
+        {
29
+            if (\count($matches[1]))
30
+            {
29 31
                 return new CommandDefinition($name, ...$this->parseParameters($matches[1]));
30 32
             }
31 33
         }
@@ -40,7 +42,8 @@  discard block
 block discarded – undo
40 42
      */
41 43
     private function parseName(string $signature): string
42 44
     {
43
-        if (!\preg_match('/\S+/', $signature, $matches)) {
45
+        if (!\preg_match('/\S+/', $signature, $matches))
46
+        {
44 47
             throw new InvalidArgumentException('Unable to determine command name from signature.');
45 48
         }
46 49
 
@@ -57,10 +60,14 @@  discard block
 block discarded – undo
57 60
         $arguments = [];
58 61
         $options = [];
59 62
 
60
-        foreach ($tokens as $token) {
61
-            if (\preg_match('/-{2,}(.*)/', $token, $matches)) {
63
+        foreach ($tokens as $token)
64
+        {
65
+            if (\preg_match('/-{2,}(.*)/', $token, $matches))
66
+            {
62 67
                 $options[] = $this->parseOption($matches[1]);
63
-            } else {
68
+            }
69
+            else
70
+            {
64 71
                 $arguments[] = $this->parseArgument($token);
65 72
             }
66 73
         }
@@ -123,7 +130,8 @@  discard block
 block discarded – undo
123 130
         $matches = \preg_split('/\s*\|\s*/', $token, 2);
124 131
         $shortcut = null;
125 132
 
126
-        if (isset($matches[1])) {
133
+        if (isset($matches[1]))
134
+        {
127 135
             [$shortcut, $token] = $matches;
128 136
         }
129 137
 
Please login to merge, or discard this patch.