Test Failed
Push — master ( a309d2...0e4b58 )
by butschster
17:34 queued 09:02
created
src/Scaffolder/src/Command/AbstractCommand.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
         ContainerInterface $container,
23 23
         private readonly FactoryInterface $factory,
24 24
         private readonly DirectoriesInterface $dirs,
25
-    ) {
25
+    ){
26 26
         $this->setContainer($container);
27 27
 
28 28
         parent::__construct();
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         $className = $declaration->getClass()->getName();
63 63
         $relativeFilename = \str_replace($rootDirectory, '', $filename);
64 64
 
65
-        if ($this->files->exists($filename)) {
65
+        if ($this->files->exists($filename)){
66 66
             $this->writeln(
67 67
                 \sprintf("<fg=red>Unable to create '<comment>%s</comment>' declaration, ", $className)
68 68
                 . \sprintf("file '<comment>%s</comment>' already exists.</fg=red>", $relativeFilename),
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
             . \sprintf("has been successfully written into '<comment>%s</comment>'.", $relativeFilename),
80 80
         );
81 81
 
82
-        if ($declaration instanceof HasInstructions && \count($declaration->getInstructions()) > 0) {
82
+        if ($declaration instanceof HasInstructions && \count($declaration->getInstructions()) > 0){
83 83
             $this->newLine();
84 84
             $this->writeln('<fg=green>Next steps:</fg=green>');
85 85
 
86
-            foreach ($declaration->getInstructions() as $i => $instruction) {
86
+            foreach ($declaration->getInstructions() as $i => $instruction){
87 87
                 $this->writeln(\sprintf('%d. %s', (string)(++$i), $instruction));
88 88
             }
89 89
         }
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -62,7 +62,8 @@  discard block
 block discarded – undo
62 62
         $className = $declaration->getClass()->getName();
63 63
         $relativeFilename = \str_replace($rootDirectory, '', $filename);
64 64
 
65
-        if ($this->files->exists($filename)) {
65
+        if ($this->files->exists($filename))
66
+        {
66 67
             $this->writeln(
67 68
                 \sprintf("<fg=red>Unable to create '<comment>%s</comment>' declaration, ", $className)
68 69
                 . \sprintf("file '<comment>%s</comment>' already exists.</fg=red>", $relativeFilename),
@@ -79,11 +80,13 @@  discard block
 block discarded – undo
79 80
             . \sprintf("has been successfully written into '<comment>%s</comment>'.", $relativeFilename),
80 81
         );
81 82
 
82
-        if ($declaration instanceof HasInstructions && \count($declaration->getInstructions()) > 0) {
83
+        if ($declaration instanceof HasInstructions && \count($declaration->getInstructions()) > 0)
84
+        {
83 85
             $this->newLine();
84 86
             $this->writeln('<fg=green>Next steps:</fg=green>');
85 87
 
86
-            foreach ($declaration->getInstructions() as $i => $instruction) {
88
+            foreach ($declaration->getInstructions() as $i => $instruction)
89
+            {
87 90
                 $this->writeln(\sprintf('%d. %s', (string)(++$i), $instruction));
88 91
             }
89 92
         }
Please login to merge, or discard this patch.
src/Scaffolder/src/Declaration/ConfigDeclaration.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
         protected ?string $comment = null,
36 36
         private readonly string $directory = '',
37 37
         ?string $namespace = null,
38
-    ) {
38
+    ){
39 39
         parent::__construct($config, $name, $comment, $namespace);
40 40
     }
41 41
 
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
         $this->class->addConstant('CONFIG', $configName)->setPublic();
46 46
 
47 47
         $filename = $this->makeConfigFilename($configName);
48
-        if ($reverse) {
49
-            if (!$this->files->exists($filename)) {
48
+        if ($reverse){
49
+            if (!$this->files->exists($filename)){
50 50
                 throw new ScaffolderException(\sprintf("Config filename %s doesn't exist", $filename));
51 51
             }
52 52
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             $this->declareGetters($defaultsFromFile);
55 55
 
56 56
             $this->class->getProperty('config')->setValue($this->defaultValues->get($defaultsFromFile));
57
-        } elseif (!$this->files->exists($filename)) {
57
+        } elseif (!$this->files->exists($filename)){
58 58
             $this->touchConfigFile($filename);
59 59
         }
60 60
     }
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 
111 111
         $this->files->write(
112 112
             $filename,
113
-            $file->render() . PHP_EOL . (new Dumper())->dump(new Literal('return [];')),
113
+            $file->render().PHP_EOL.(new Dumper())->dump(new Literal('return [];')),
114 114
             FilesInterface::READONLY,
115 115
             true,
116 116
         );
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
         $getters = [];
129 129
         $gettersByKey = [];
130 130
 
131
-        foreach ($defaults as $key => $value) {
131
+        foreach ($defaults as $key => $value){
132 132
             $key = (string)$key;
133 133
             $getter = $this->makeGetterName($key);
134 134
             $getters[] = $getter;
@@ -136,19 +136,19 @@  discard block
 block discarded – undo
136 136
             $method = $this->class->addMethod($getter)->setPublic();
137 137
             $method->setBody(\sprintf('return $this->config[\'%s\'];', $key));
138 138
 
139
-            if (\is_array($value)) {
139
+            if (\is_array($value)){
140 140
                 $gettersByKey[] = ['key' => $key, 'value' => $value];
141 141
             }
142 142
 
143 143
             $returnTypeHint = $this->typeHints->getHint(\gettype($value));
144
-            if ($returnTypeHint !== null) {
144
+            if ($returnTypeHint !== null){
145 145
                 $method->setReturnType($returnTypeHint);
146 146
             }
147 147
         }
148 148
 
149
-        foreach ($gettersByKey as $item) {
149
+        foreach ($gettersByKey as $item){
150 150
             $method = $this->declareGettersByKey($getters, $item['key'], $item['value']);
151
-            if ($method !== null) {
151
+            if ($method !== null){
152 152
                 $getters[] = $method->getName();
153 153
             }
154 154
         }
@@ -157,30 +157,30 @@  discard block
 block discarded – undo
157 157
     private function declareGettersByKey(array $methodNames, string $key, array $value): ?Method
158 158
     {
159 159
         //Won't create if there's less than 2 sub-items
160
-        if (\count($value) < 2) {
160
+        if (\count($value) < 2){
161 161
             return null;
162 162
         }
163 163
 
164 164
         $singularKey = $this->singularize($key);
165 165
         $name = $this->makeGetterName($singularKey);
166
-        if (\in_array($name, $methodNames, true)) {
166
+        if (\in_array($name, $methodNames, true)){
167 167
             $name = $this->makeGetterName($singularKey, 'get', 'by');
168 168
         }
169 169
 
170 170
         //Name conflict, won't merge
171
-        if (\in_array($name, $methodNames, true)) {
171
+        if (\in_array($name, $methodNames, true)){
172 172
             return null;
173 173
         }
174 174
 
175 175
         $keyType = defineArrayType(\array_keys($value), '-mixed-');
176 176
         $valueType = defineArrayType(\array_values($value), '-mixed-');
177 177
         //We need a fixed structure here
178
-        if ($keyType === '-mixed-' || $valueType === '-mixed-') {
178
+        if ($keyType === '-mixed-' || $valueType === '-mixed-'){
179 179
             return null;
180 180
         }
181 181
 
182 182
         //Won't create for associated arrays
183
-        if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value)) {
183
+        if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value)){
184 184
             return null;
185 185
         }
186 186
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 
191 191
         $param = $method->addParameter($singularKey);
192 192
         $paramTypeHint = $this->typeHints->getHint($keyType);
193
-        if ($paramTypeHint !== null) {
193
+        if ($paramTypeHint !== null){
194 194
             $param->setType($paramTypeHint);
195 195
         }
196 196
 
@@ -200,13 +200,13 @@  discard block
 block discarded – undo
200 200
     private function makeGetterName(string $name, string $prefix = 'get', string $postfix = ''): string
201 201
     {
202 202
         $chunks = [];
203
-        if (!empty($prefix)) {
203
+        if (!empty($prefix)){
204 204
             $chunks[] = $prefix;
205 205
         }
206 206
 
207 207
         $name = $this->slugify->slugify($name, ['lowercase' => false]);
208 208
         $chunks[] = \count($chunks) !== 0 ? $this->classify($name) : $name;
209
-        if (!empty($postfix)) {
209
+        if (!empty($postfix)){
210 210
             $chunks[] = \ucfirst($postfix);
211 211
         }
212 212
 
Please login to merge, or discard this patch.
Braces   +33 added lines, -16 removed lines patch added patch discarded remove patch
@@ -45,8 +45,10 @@  discard block
 block discarded – undo
45 45
         $this->class->addConstant('CONFIG', $configName)->setPublic();
46 46
 
47 47
         $filename = $this->makeConfigFilename($configName);
48
-        if ($reverse) {
49
-            if (!$this->files->exists($filename)) {
48
+        if ($reverse)
49
+        {
50
+            if (!$this->files->exists($filename))
51
+            {
50 52
                 throw new ScaffolderException(\sprintf("Config filename %s doesn't exist", $filename));
51 53
             }
52 54
 
@@ -54,7 +56,9 @@  discard block
 block discarded – undo
54 56
             $this->declareGetters($defaultsFromFile);
55 57
 
56 58
             $this->class->getProperty('config')->setValue($this->defaultValues->get($defaultsFromFile));
57
-        } elseif (!$this->files->exists($filename)) {
59
+        }
60
+        elseif (!$this->files->exists($filename))
61
+        {
58 62
             $this->touchConfigFile($filename);
59 63
         }
60 64
     }
@@ -128,7 +132,8 @@  discard block
 block discarded – undo
128 132
         $getters = [];
129 133
         $gettersByKey = [];
130 134
 
131
-        foreach ($defaults as $key => $value) {
135
+        foreach ($defaults as $key => $value)
136
+        {
132 137
             $key = (string)$key;
133 138
             $getter = $this->makeGetterName($key);
134 139
             $getters[] = $getter;
@@ -136,19 +141,23 @@  discard block
 block discarded – undo
136 141
             $method = $this->class->addMethod($getter)->setPublic();
137 142
             $method->setBody(\sprintf('return $this->config[\'%s\'];', $key));
138 143
 
139
-            if (\is_array($value)) {
144
+            if (\is_array($value))
145
+            {
140 146
                 $gettersByKey[] = ['key' => $key, 'value' => $value];
141 147
             }
142 148
 
143 149
             $returnTypeHint = $this->typeHints->getHint(\gettype($value));
144
-            if ($returnTypeHint !== null) {
150
+            if ($returnTypeHint !== null)
151
+            {
145 152
                 $method->setReturnType($returnTypeHint);
146 153
             }
147 154
         }
148 155
 
149
-        foreach ($gettersByKey as $item) {
156
+        foreach ($gettersByKey as $item)
157
+        {
150 158
             $method = $this->declareGettersByKey($getters, $item['key'], $item['value']);
151
-            if ($method !== null) {
159
+            if ($method !== null)
160
+            {
152 161
                 $getters[] = $method->getName();
153 162
             }
154 163
         }
@@ -157,30 +166,35 @@  discard block
 block discarded – undo
157 166
     private function declareGettersByKey(array $methodNames, string $key, array $value): ?Method
158 167
     {
159 168
         //Won't create if there's less than 2 sub-items
160
-        if (\count($value) < 2) {
169
+        if (\count($value) < 2)
170
+        {
161 171
             return null;
162 172
         }
163 173
 
164 174
         $singularKey = $this->singularize($key);
165 175
         $name = $this->makeGetterName($singularKey);
166
-        if (\in_array($name, $methodNames, true)) {
176
+        if (\in_array($name, $methodNames, true))
177
+        {
167 178
             $name = $this->makeGetterName($singularKey, 'get', 'by');
168 179
         }
169 180
 
170 181
         //Name conflict, won't merge
171
-        if (\in_array($name, $methodNames, true)) {
182
+        if (\in_array($name, $methodNames, true))
183
+        {
172 184
             return null;
173 185
         }
174 186
 
175 187
         $keyType = defineArrayType(\array_keys($value), '-mixed-');
176 188
         $valueType = defineArrayType(\array_values($value), '-mixed-');
177 189
         //We need a fixed structure here
178
-        if ($keyType === '-mixed-' || $valueType === '-mixed-') {
190
+        if ($keyType === '-mixed-' || $valueType === '-mixed-')
191
+        {
179 192
             return null;
180 193
         }
181 194
 
182 195
         //Won't create for associated arrays
183
-        if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value)) {
196
+        if ($this->typeAnnotations->mapType($keyType) === 'int' && \array_is_list($value))
197
+        {
184 198
             return null;
185 199
         }
186 200
 
@@ -190,7 +204,8 @@  discard block
 block discarded – undo
190 204
 
191 205
         $param = $method->addParameter($singularKey);
192 206
         $paramTypeHint = $this->typeHints->getHint($keyType);
193
-        if ($paramTypeHint !== null) {
207
+        if ($paramTypeHint !== null)
208
+        {
194 209
             $param->setType($paramTypeHint);
195 210
         }
196 211
 
@@ -200,13 +215,15 @@  discard block
 block discarded – undo
200 215
     private function makeGetterName(string $name, string $prefix = 'get', string $postfix = ''): string
201 216
     {
202 217
         $chunks = [];
203
-        if (!empty($prefix)) {
218
+        if (!empty($prefix))
219
+        {
204 220
             $chunks[] = $prefix;
205 221
         }
206 222
 
207 223
         $name = $this->slugify->slugify($name, ['lowercase' => false]);
208 224
         $chunks[] = \count($chunks) !== 0 ? $this->classify($name) : $name;
209
-        if (!empty($postfix)) {
225
+        if (!empty($postfix))
226
+        {
210 227
             $chunks[] = \ucfirst($postfix);
211 228
         }
212 229
 
Please login to merge, or discard this patch.
src/Scaffolder/src/Declaration/FilterDeclaration.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
         string $name,
29 29
         ?string $comment = null,
30 30
         ?string $namespace = null,
31
-    ) {
31
+    ){
32 32
         parent::__construct($config, $name, $comment, $namespace);
33 33
 
34
-        try {
34
+        try{
35 35
             $this->validationConfig = $container->get(ValidationConfig::class);
36
-        } catch (\Throwable $e) {
36
+        }catch (\Throwable $e){
37 37
             // Validation is not configured
38 38
             $this->validationConfig = null;
39 39
         }
@@ -50,13 +50,13 @@  discard block
 block discarded – undo
50 50
     public function addFilterDefinition(): void
51 51
     {
52 52
         $validation = $this->validationConfig?->getDefaultValidator();
53
-        if ($validation === null) {
53
+        if ($validation === null){
54 54
             throw new ValidationException(
55 55
                 'Default Validator is not configured. Read more at https://spiral.dev/docs/validation-factory'
56 56
             );
57 57
         }
58 58
 
59
-        if (!\class_exists($validation)) {
59
+        if (!\class_exists($validation)){
60 60
             throw new ValidationException(
61 61
                 \sprintf(
62 62
                     'Default Validator "%s" is not class or does not exist.',
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         $p = $this->class->addProperty($property->getName())
91 91
             ->setType($property->getType());
92 92
 
93
-        foreach ($property->getAttributes() as $attribute) {
93
+        foreach ($property->getAttributes() as $attribute){
94 94
             $p->addAttribute($attribute->getName(), $attribute->getArguments());
95 95
         }
96 96
     }
@@ -99,12 +99,12 @@  discard block
 block discarded – undo
99 99
     {
100 100
         $declaredType = null;
101 101
 
102
-        if (\str_contains($property, ':')) {
102
+        if (\str_contains($property, ':')){
103 103
             $segments = \explode(':', $property, 3);
104 104
 
105
-            if (\count($segments) === 3) {
105
+            if (\count($segments) === 3){
106 106
                 [$property, $source, $declaredType] = $segments;
107
-            } else {
107
+            }else{
108 108
                 [$property, $source] = $segments;
109 109
             }
110 110
         }
Please login to merge, or discard this patch.
Braces   +18 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,9 +31,12 @@  discard block
 block discarded – undo
31 31
     ) {
32 32
         parent::__construct($config, $name, $comment, $namespace);
33 33
 
34
-        try {
34
+        try
35
+        {
35 36
             $this->validationConfig = $container->get(ValidationConfig::class);
36
-        } catch (\Throwable $e) {
37
+        }
38
+        catch (\Throwable $e)
39
+        {
37 40
             // Validation is not configured
38 41
             $this->validationConfig = null;
39 42
         }
@@ -50,13 +53,15 @@  discard block
 block discarded – undo
50 53
     public function addFilterDefinition(): void
51 54
     {
52 55
         $validation = $this->validationConfig?->getDefaultValidator();
53
-        if ($validation === null) {
56
+        if ($validation === null)
57
+        {
54 58
             throw new ValidationException(
55 59
                 'Default Validator is not configured. Read more at https://spiral.dev/docs/validation-factory'
56 60
             );
57 61
         }
58 62
 
59
-        if (!\class_exists($validation)) {
63
+        if (!\class_exists($validation))
64
+        {
60 65
             throw new ValidationException(
61 66
                 \sprintf(
62 67
                     'Default Validator "%s" is not class or does not exist.',
@@ -90,7 +95,8 @@  discard block
 block discarded – undo
90 95
         $p = $this->class->addProperty($property->getName())
91 96
             ->setType($property->getType());
92 97
 
93
-        foreach ($property->getAttributes() as $attribute) {
98
+        foreach ($property->getAttributes() as $attribute)
99
+        {
94 100
             $p->addAttribute($attribute->getName(), $attribute->getArguments());
95 101
         }
96 102
     }
@@ -99,12 +105,16 @@  discard block
 block discarded – undo
99 105
     {
100 106
         $declaredType = null;
101 107
 
102
-        if (\str_contains($property, ':')) {
108
+        if (\str_contains($property, ':'))
109
+        {
103 110
             $segments = \explode(':', $property, 3);
104 111
 
105
-            if (\count($segments) === 3) {
112
+            if (\count($segments) === 3)
113
+            {
106 114
                 [$property, $source, $declaredType] = $segments;
107
-            } else {
115
+            }
116
+            else
117
+            {
108 118
                 [$property, $source] = $segments;
109 119
             }
110 120
         }
Please login to merge, or discard this patch.