Passed
Pull Request — master (#737)
by butschster
06:36
created
src/Attributes/tests/TestCase.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      */
25 25
     protected function iterableToArray(iterable $iterable): array
26 26
     {
27
-        if ($iterable instanceof \Traversable) {
27
+        if ($iterable instanceof \Traversable){
28 28
             return \iterator_to_array($iterable, false);
29 29
         }
30 30
 
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
     {
50 50
         $instance = new $class();
51 51
 
52
-        foreach ($fields as $field => $value) {
52
+        foreach ($fields as $field => $value){
53 53
             $instance->$field = $value;
54 54
         }
55 55
 
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
      * @param string $message
66 66
      *   Expected message.
67 67
      */
68
-    public function expectExceptionMessageEquals(string $message) {
68
+    public function expectExceptionMessageEquals(string $message){
69 69
         // The "contains" check produces a more readable message.
70 70
         $this->expectExceptionMessage($message);
71 71
         // The regex check is the only way to check exact equality.
72 72
         $this->expectExceptionMessageMatches(
73
-            '@^' . preg_quote($message, '@') . '$@'
73
+            '@^'.preg_quote($message, '@').'$@'
74 74
         );
75 75
     }
76 76
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      * @throws \ReflectionException
88 88
      *   The class does not exist.
89 89
      */
90
-    public static function assertExceptionSource(\Throwable $e, string $class, string $search) {
90
+    public static function assertExceptionSource(\Throwable $e, string $class, string $search){
91 91
         $rc = new \ReflectionClass($class);
92 92
         $file = $rc->getFileName();
93 93
         self::assertSame($file, $e->getFile(), 'Exception file');
Please login to merge, or discard this patch.
src/Attributes/tests/Instantiator/NamedArgumentsInstantiatorTestCase.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -73,23 +73,23 @@  discard block
 block discarded – undo
73 73
 
74 74
     public function testUnknownSequentialAfterNamed()
75 75
     {
76
-        if (PHP_VERSION_ID < 80000) {
76
+        if (PHP_VERSION_ID < 80000){
77 77
             $this->expectException(\BadMethodCallException::class);
78
-        } else {
78
+        }else{
79 79
             $this->expectException(\Error::class);
80 80
         }
81 81
         /* @see NamedArgumentsInstantiator::ERROR_POSITIONAL_AFTER_NAMED */
82 82
         $this->expectExceptionMessageEquals('Cannot use positional argument after named argument');
83 83
 
84
-        try {
84
+        try{
85 85
             $this->new($class = NamedArgumentConstructorFixture::class, [
86 86
                 'a' => 'A',
87 87
                 5 => 'five',
88 88
             ]);
89
-        } catch (\Throwable $e) {
90
-            if (PHP_VERSION_ID < 80000) {
89
+        }catch (\Throwable $e){
90
+            if (PHP_VERSION_ID < 80000){
91 91
                 self::assertExceptionSource($e, $class, 'function __construct');
92
-            } else {
92
+            }else{
93 93
                 self::assertExceptionSource($e, $class, 'class ');
94 94
             }
95 95
             throw $e;
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 
99 99
     public function testKnownSequentialAfterNamed()
100 100
     {
101
-        if (PHP_VERSION_ID < 80000) {
101
+        if (PHP_VERSION_ID < 80000){
102 102
             $this->expectException(\BadMethodCallException::class);
103
-        } else {
103
+        }else{
104 104
             $this->expectException(\Error::class);
105 105
         }
106 106
         /* @see NamedArgumentsInstantiator::ERROR_POSITIONAL_AFTER_NAMED */
@@ -123,15 +123,15 @@  discard block
 block discarded – undo
123 123
             )
124 124
         );
125 125
 
126
-        try {
126
+        try{
127 127
             $this->new($class = NamedRequiredArgumentConstructorFixture::class, [
128 128
                 'a',
129 129
                 'c' => 'C',
130 130
             ]);
131
-        } catch (\Throwable $e) {
132
-            if (PHP_VERSION_ID < 80000) {
131
+        }catch (\Throwable $e){
132
+            if (PHP_VERSION_ID < 80000){
133 133
                 self::assertExceptionSource($e, $class, 'function __construct');
134
-            } else {
134
+            }else{
135 135
                 self::assertExceptionSource($e, $class, 'class ');
136 136
             }
137 137
             throw $e;
@@ -140,22 +140,22 @@  discard block
 block discarded – undo
140 140
 
141 141
     public function testUnknownArg()
142 142
     {
143
-        if (PHP_VERSION_ID < 80000) {
143
+        if (PHP_VERSION_ID < 80000){
144 144
             $this->expectException(\BadMethodCallException::class);
145
-        } else {
145
+        }else{
146 146
             $this->expectException(\Error::class);
147 147
         }
148 148
         /* @see NamedArgumentsInstantiator::ERROR_UNKNOWN_ARGUMENT */
149 149
         $this->expectExceptionMessageEquals('Unknown named parameter $d');
150 150
 
151
-        try {
151
+        try{
152 152
             $this->new($class = NamedArgumentConstructorFixture::class, [
153 153
                 'd' => 'D',
154 154
             ]);
155
-        } catch (\Throwable $e) {
156
-            if (PHP_VERSION_ID < 80000) {
155
+        }catch (\Throwable $e){
156
+            if (PHP_VERSION_ID < 80000){
157 157
                 self::assertExceptionSource($e, $class, 'function __construct');
158
-            } else {
158
+            }else{
159 159
                 self::assertExceptionSource($e, $class, 'class ');
160 160
             }
161 161
             throw $e;
@@ -164,9 +164,9 @@  discard block
 block discarded – undo
164 164
 
165 165
     public function testOverwriteArg()
166 166
     {
167
-        if (PHP_VERSION_ID < 80000) {
167
+        if (PHP_VERSION_ID < 80000){
168 168
             $this->expectException(\BadMethodCallException::class);
169
-        } else {
169
+        }else{
170 170
             $this->expectException(\Error::class);
171 171
         }
172 172
         /* @see NamedArgumentsInstantiator::ERROR_OVERWRITE_ARGUMENT */
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
 
196 196
     public function testVariadicPositionalAfterNamed()
197 197
     {
198
-        if (PHP_VERSION_ID < 80000) {
198
+        if (PHP_VERSION_ID < 80000){
199 199
             $this->expectException(\BadMethodCallException::class);
200
-        } else {
200
+        }else{
201 201
             $this->expectException(\Error::class);
202 202
         }
203 203
         /* @see NamedArgumentsInstantiator::ERROR_POSITIONAL_AFTER_NAMED */
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
     public function testVariadicMixed()
215 215
     {
216
-        if (PHP_VERSION_ID < 80000) {
216
+        if (PHP_VERSION_ID < 80000){
217 217
             $this->expectException(\BadMethodCallException::class);
218 218
             /* @see NamedArgumentsInstantiator::ERROR_NAMED_ARG_TO_VARIADIC */
219 219
             $this->expectExceptionMessageEquals('Cannot pass named argument $x to variadic parameter ...$args in PHP < 8');
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 
235 235
     public function testVariadicNamed()
236 236
     {
237
-        if (PHP_VERSION_ID < 80000) {
237
+        if (PHP_VERSION_ID < 80000){
238 238
             $this->expectException(\BadMethodCallException::class);
239 239
             /* @see NamedArgumentsInstantiator::ERROR_NAMED_ARG_TO_VARIADIC */
240 240
             $this->expectExceptionMessageEquals('Cannot pass named argument $x to variadic parameter ...$args in PHP < 8');
Please login to merge, or discard this patch.
src/Attributes/src/Internal/Instantiator/NamedArgumentsInstantiator.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -49,17 +49,17 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function instantiate(\ReflectionClass $attr, array $arguments, \Reflector $context = null): object
51 51
     {
52
-        if ($this->isNamedArgumentsSupported()) {
53
-            try {
52
+        if ($this->isNamedArgumentsSupported()){
53
+            try{
54 54
                 return $attr->newInstanceArgs($arguments);
55
-            } catch (\Throwable $e) {
55
+            }catch (\Throwable $e){
56 56
                 throw Exception::withLocation($e, $attr->getFileName(), $attr->getStartLine());
57 57
             }
58 58
         }
59 59
 
60 60
         $constructor = $this->getConstructor($attr);
61 61
 
62
-        if ($constructor === null) {
62
+        if ($constructor === null){
63 63
             return $attr->newInstanceWithoutConstructor();
64 64
         }
65 65
 
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
      */
79 79
     private function resolveParameters(\ReflectionClass $ctx, \ReflectionMethod $constructor, array $arguments): array
80 80
     {
81
-        try {
81
+        try{
82 82
             return $this->doResolveParameters($ctx, $constructor, $arguments);
83
-        } catch (\Throwable $e) {
83
+        }catch (\Throwable $e){
84 84
             throw Exception::withLocation($e, $constructor->getFileName(), $constructor->getStartLine());
85 85
         }
86 86
     }
@@ -93,16 +93,16 @@  discard block
 block discarded – undo
93 93
     {
94 94
         $namedArgsBegin = $this->analyzeKeys($arguments);
95 95
 
96
-        if ($namedArgsBegin === null) {
96
+        if ($namedArgsBegin === null){
97 97
             // Only numeric / positional keys exist.
98 98
             return $arguments;
99 99
         }
100 100
 
101
-        if ($namedArgsBegin === 0) {
101
+        if ($namedArgsBegin === 0){
102 102
             // Only named keys exist.
103 103
             $passed = [];
104 104
             $named = $arguments;
105
-        } else {
105
+        }else{
106 106
             // Numeric/positional keys followed by named keys.
107 107
             // No need to preserve numeric keys.
108 108
             $passed = array_slice($arguments, 0, $namedArgsBegin);
@@ -138,11 +138,11 @@  discard block
 block discarded – undo
138 138
         $arguments = array_merge($arguments);
139 139
 
140 140
         $i = 0;
141
-        foreach ($arguments as $k => $_) {
142
-            if ($k !== $i) {
141
+        foreach ($arguments as $k => $_){
142
+            if ($k !== $i){
143 143
                 // This must be a string key.
144 144
                 // Any further numeric keys are illegal.
145
-                if (\array_key_exists($i, $arguments)) {
145
+                if (\array_key_exists($i, $arguments)){
146 146
                     throw new \BadMethodCallException(self::ERROR_POSITIONAL_AFTER_NAMED);
147 147
                 }
148 148
                 return $i;
@@ -179,25 +179,25 @@  discard block
 block discarded – undo
179 179
     {
180 180
         // Analyze parameters.
181 181
         $n = count($parameters);
182
-        if ($n > 0 && end($parameters)->isVariadic()) {
182
+        if ($n > 0 && end($parameters)->isVariadic()){
183 183
             $variadicParameter = end($parameters);
184 184
             // Don't include the variadic parameter in the mapping process.
185 185
             --$n;
186
-        } else {
186
+        }else{
187 187
             $variadicParameter = null;
188 188
         }
189 189
 
190 190
         // Process parameters that are not already filled with positional args.
191 191
         // This loop will do nothing if $namedArgsBegin >= $n. That's ok.
192
-        for ($i = $namedArgsBegin; $i < $n; ++$i) {
192
+        for ($i = $namedArgsBegin; $i < $n; ++$i){
193 193
             $parameter = $parameters[$i];
194 194
             $k = $parameter->getName();
195
-            if (array_key_exists($k, $named)) {
195
+            if (array_key_exists($k, $named)){
196 196
                 $passed[] = $named[$k];
197 197
                 unset($named[$k]);
198
-            } elseif ($parameter->isDefaultValueAvailable()) {
198
+            } elseif ($parameter->isDefaultValueAvailable()){
199 199
                 $passed[] = $parameter->getDefaultValue();
200
-            } else {
200
+            }else{
201 201
                 $message = \vsprintf(self::ERROR_ARGUMENT_NOT_PASSED, [
202 202
                     $ctx->getName(),
203 203
                     $parameter->getPosition() + 1,
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             }
209 209
         }
210 210
 
211
-        if ($named === []) {
211
+        if ($named === []){
212 212
             // No unknown argument names exist.
213 213
             return $passed;
214 214
         }
@@ -218,11 +218,11 @@  discard block
 block discarded – undo
218 218
         $badArgName = key($named);
219 219
 
220 220
         // Check collision with positional arguments.
221
-        foreach ($parameters as $i => $parameter) {
222
-            if ($i >= $namedArgsBegin) {
221
+        foreach ($parameters as $i => $parameter){
222
+            if ($i >= $namedArgsBegin){
223 223
                 break;
224 224
             }
225
-            if ($parameter->getName() === $badArgName) {
225
+            if ($parameter->getName() === $badArgName){
226 226
                 // The named argument overwrites a positional argument.
227 227
                 $message = \sprintf(self::ERROR_OVERWRITE_ARGUMENT, $badArgName);
228 228
                 throw new \BadMethodCallException($message);
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
         }
231 231
 
232 232
         // Special handling if a variadic parameter is present.
233
-        if ($variadicParameter !== null) {
233
+        if ($variadicParameter !== null){
234 234
             // The last parameter is variadic.
235 235
             // Since PHP 8+, variadic parameters can consume named arguments.
236 236
             // However, this code only runs if PHP < 8.
Please login to merge, or discard this patch.
src/Framework/Domain/FilterWithRendererInterceptor.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
         ReaderInterface $reader,
31 31
         ?RenderErrors $renderErrors = null,
32 32
         int $strategy = self::STRATEGY_JSON_RESPONSE
33
-    ) {
33
+    ){
34 34
         parent::__construct($container, $strategy);
35 35
 
36 36
         $this->reader = $reader;
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
     {
50 50
         parent::buildCache($parameter, $class, $key);
51 51
 
52
-        if (null !== ($renderWith = $this->reader->firstClassMetadata($class, RenderWith::class))) {
52
+        if (null !== ($renderWith = $this->reader->firstClassMetadata($class, RenderWith::class))){
53 53
             $this->renderersCache[$class->getName()] = $this->container->get($renderWith->getRenderer());
54 54
         }
55 55
     }
Please login to merge, or discard this patch.
src/Framework/Domain/DefaultFilterErrorsRenderer.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
      */
26 26
     public function render(FilterInterface $filter)
27 27
     {
28
-        switch ($this->strategy) {
28
+        switch ($this->strategy){
29 29
             case FilterInterceptor::STRATEGY_JSON_RESPONSE:
30 30
                 return [
31 31
                     'status' => 400,
Please login to merge, or discard this patch.
src/Framework/Domain/FilterInterceptor.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -37,20 +37,20 @@  discard block
 block discarded – undo
37 37
      */
38 38
     public function process(string $controller, string $action, array $parameters, CoreInterface $core)
39 39
     {
40
-        foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) {
41
-            if (isset($parameters[$parameter])) {
40
+        foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass){
41
+            if (isset($parameters[$parameter])){
42 42
                 continue;
43 43
             }
44 44
 
45 45
             /** @var FilterInterface $filter */
46 46
             $filter = $this->container->get($filterClass);
47 47
 
48
-            if (isset($parameters['@context'])) {
48
+            if (isset($parameters['@context'])){
49 49
                 // other interceptors can define the validation contex
50 50
                 $filter->setContext($parameters['@context']);
51 51
             }
52 52
 
53
-            if (!$filter->isValid()) {
53
+            if (!$filter->isValid()){
54 54
                 return $this->renderInvalid($filter);
55 55
             }
56 56
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
      */
69 69
     protected function renderInvalid(FilterInterface $filter)
70 70
     {
71
-        switch ($this->strategy) {
71
+        switch ($this->strategy){
72 72
             case self::STRATEGY_JSON_RESPONSE:
73 73
                 return [
74 74
                     'status' => 400,
@@ -87,25 +87,25 @@  discard block
 block discarded – undo
87 87
     private function getDeclaredFilters(string $controller, string $action): array
88 88
     {
89 89
         $key = sprintf('%s:%s', $controller, $action);
90
-        if (array_key_exists($key, $this->cache)) {
90
+        if (array_key_exists($key, $this->cache)){
91 91
             return $this->cache[$key];
92 92
         }
93 93
 
94 94
         $this->cache[$key] = [];
95
-        try {
95
+        try{
96 96
             $method = new \ReflectionMethod($controller, $action);
97
-        } catch (\ReflectionException $e) {
97
+        }catch (\ReflectionException $e){
98 98
             return [];
99 99
         }
100 100
 
101
-        foreach ($method->getParameters() as $parameter) {
101
+        foreach ($method->getParameters() as $parameter){
102 102
             $class = $this->getParameterClass($parameter);
103 103
 
104
-            if ($class === null) {
104
+            if ($class === null){
105 105
                 continue;
106 106
             }
107 107
 
108
-            if ($class->implementsInterface(FilterInterface::class)) {
108
+            if ($class->implementsInterface(FilterInterface::class)){
109 109
                 $this->buildCache($parameter, $class, $key);
110 110
             }
111 111
         }
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
     {
124 124
         $type = $parameter->getType();
125 125
 
126
-        if (!$type instanceof \ReflectionNamedType) {
126
+        if (!$type instanceof \ReflectionNamedType){
127 127
             return null;
128 128
         }
129 129
 
130
-        if ($type->isBuiltin()) {
130
+        if ($type->isBuiltin()){
131 131
             return null;
132 132
         }
133 133
 
Please login to merge, or discard this patch.