Passed
Pull Request — master (#961)
by Maxim
09:14
created
src/Framework/Bootloader/Security/FiltersBootloader.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -93,7 +93,8 @@
 block discarded – undo
93 93
         ?EventDispatcherInterface $dispatcher = null
94 94
     ): FilterProvider {
95 95
         $core = new InterceptableCore(new Core(), $dispatcher);
96
-        foreach ($config->getInterceptors() as $interceptor) {
96
+        foreach ($config->getInterceptors() as $interceptor)
97
+        {
97 98
             $core->addInterceptor($container->get($interceptor));
98 99
         }
99 100
 
Please login to merge, or discard this patch.
src/Filters/src/Model/FilterProvider.php 1 patch
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -34,7 +34,8 @@  discard block
 block discarded – undo
34 34
         $filter = $this->createFilterInstance($name);
35 35
         [$mappingSchema, $errors, $setters, $optionalFilters] = $attributeMapper->map($filter, $input);
36 36
 
37
-        if ($filter instanceof HasFilterDefinition) {
37
+        if ($filter instanceof HasFilterDefinition)
38
+        {
38 39
             $mappingSchema = \array_merge(
39 40
                 $mappingSchema,
40 41
                 $filter->filterDefinition()->mappingSchema()
@@ -48,7 +49,8 @@  discard block
 block discarded – undo
48 49
         \assert($schemaBuilder instanceof Builder);
49 50
 
50 51
         $schema = $schemaBuilder->makeSchema($name, $mappingSchema);
51
-        foreach ($optionalFilters as $optionalFilter) {
52
+        foreach ($optionalFilters as $optionalFilter)
53
+        {
52 54
             $schema[$optionalFilter][Builder::SCHEMA_OPTIONAL] = true;
53 55
         }
54 56
 
@@ -66,7 +68,8 @@  discard block
 block discarded – undo
66 68
         $class = new \ReflectionClass($name);
67 69
 
68 70
         $args = [];
69
-        if ($constructor = $class->getConstructor()) {
71
+        if ($constructor = $class->getConstructor())
72
+        {
70 73
             $args = $this->resolver->resolveArguments($constructor);
71 74
         }
72 75
 
Please login to merge, or discard this patch.
src/Filters/src/Model/Mapper/CasterRegistry.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,8 @@
 block discarded – undo
11 11
 
12 12
     public function __construct(array $casters = [])
13 13
     {
14
-        foreach ($casters as $caster) {
14
+        foreach ($casters as $caster)
15
+        {
15 16
             $this->register($caster);
16 17
         }
17 18
     }
Please login to merge, or discard this patch.
src/Filters/src/Model/Mapper/Mapper.php 1 patch
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,9 +22,12 @@
 block discarded – undo
22 22
     public function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void
23 23
     {
24 24
         $type = $property->getType();
25
-        if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) {
26
-            foreach ($this->registry->getCasters() as $setter) {
27
-                if ($setter->supports($type)) {
25
+        if ($type instanceof \ReflectionNamedType && !$type->isBuiltin())
26
+        {
27
+            foreach ($this->registry->getCasters() as $setter)
28
+            {
29
+                if ($setter->supports($type))
30
+                {
28 31
                     $setter->setValue($filter, $property, $value);
29 32
                     return;
30 33
                 }
Please login to merge, or discard this patch.
src/Filters/src/Attribute/Setter.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,9 +31,12 @@
 block discarded – undo
31 31
 
32 32
     public function updateValue(mixed $value): mixed
33 33
     {
34
-        try {
34
+        try
35
+        {
35 36
             return ($this->filter)($value, ...$this->args);
36
-        } catch (\Throwable $e) {
37
+        }
38
+        catch (\Throwable $e)
39
+        {
37 40
             throw new SetterException($e);
38 41
         }
39 42
     }
Please login to merge, or discard this patch.
src/Filters/src/Model/Interceptor/ValidateFilterInterceptor.php 1 patch
Braces   +11 added lines, -5 removed lines patch added patch discarded remove patch
@@ -34,7 +34,8 @@  discard block
 block discarded – undo
34 34
         $bag = $parameters['filterBag'];
35 35
         $filter = $core->callAction($controller, $action, $parameters);
36 36
 
37
-        if ($filter instanceof HasFilterDefinition) {
37
+        if ($filter instanceof HasFilterDefinition)
38
+        {
38 39
             $this->validateFilter(
39 40
                 $filter->filterDefinition(),
40 41
                 $bag,
@@ -43,7 +44,8 @@  discard block
 block discarded – undo
43 44
             );
44 45
         }
45 46
 
46
-        if (($bag->errors ?? []) !== []) {
47
+        if (($bag->errors ?? []) !== [])
48
+        {
47 49
             $errorMapper = new ErrorMapper($bag->schema);
48 50
             throw new ValidationException($errorMapper->mapErrors($bag->errors), $parameters['context'] ?? null);
49 51
         }
@@ -57,7 +59,8 @@  discard block
 block discarded – undo
57 59
         array $errors,
58 60
         mixed $context
59 61
     ): void {
60
-        if ($definition instanceof ShouldBeValidated) {
62
+        if ($definition instanceof ShouldBeValidated)
63
+        {
61 64
             $errorMapper = new ErrorMapper($bag->schema);
62 65
             $validationProvider = $this->container->get(ValidationProviderInterface::class);
63 66
 
@@ -65,12 +68,15 @@  discard block
 block discarded – undo
65 68
                 ->getValidation($definition::class)
66 69
                 ->validate($bag, $definition->validationRules(), $context);
67 70
 
68
-            if (!$validator->isValid()) {
71
+            if (!$validator->isValid())
72
+            {
69 73
                 throw new ValidationException(
70 74
                     $errorMapper->mapErrors(\array_merge($errors, $validator->getErrors())),
71 75
                     $context
72 76
                 );
73
-            } elseif ($errors !== []) {
77
+            }
78
+            elseif ($errors !== [])
79
+            {
74 80
                 throw new ValidationException($errorMapper->mapErrors($errors), $context);
75 81
             }
76 82
         }
Please login to merge, or discard this patch.
src/Filters/src/Model/Schema/InputMapper.php 1 patch
Braces   +33 added lines, -15 removed lines patch added patch discarded remove patch
@@ -22,16 +22,23 @@  discard block
 block discarded – undo
22 22
         $errors = [];
23 23
         $result = [];
24 24
 
25
-        foreach ($mappingSchema as $field => $map) {
26
-            if (empty($map[Builder::SCHEMA_FILTER])) {
25
+        foreach ($mappingSchema as $field => $map)
26
+        {
27
+            if (empty($map[Builder::SCHEMA_FILTER]))
28
+            {
27 29
                 $value = $input->getValue($map[Builder::SCHEMA_SOURCE], $map[Builder::SCHEMA_ORIGIN]);
28 30
 
29
-                if ($value !== null) {
31
+                if ($value !== null)
32
+                {
30 33
                     /** @var Setter $setter */
31
-                    foreach ($setters[$field] ?? [] as $setter) {
32
-                        try {
34
+                    foreach ($setters[$field] ?? [] as $setter)
35
+                    {
36
+                        try
37
+                        {
33 38
                             $value = $setter->updateValue($value);
34
-                        } catch (SetterException $e) {
39
+                        }
40
+                        catch (SetterException $e)
41
+                        {
35 42
                             $errors[$field] = $e->getMessage();
36 43
                         }
37 44
                     }
@@ -42,12 +49,17 @@  discard block
 block discarded – undo
42 49
             }
43 50
 
44 51
             $nested = $map[Builder::SCHEMA_FILTER];
45
-            if (empty($map[Builder::SCHEMA_ARRAY])) {
52
+            if (empty($map[Builder::SCHEMA_ARRAY]))
53
+            {
46 54
                 // slicing down
47
-                try {
55
+                try
56
+                {
48 57
                     $result[$field] = $this->provider->createFilter($nested, $input->withPrefix($map[Builder::SCHEMA_ORIGIN]));
49
-                } catch (ValidationException $e) {
50
-                    if ($map[Builder::SCHEMA_OPTIONAL]) {
58
+                }
59
+                catch (ValidationException $e)
60
+                {
61
+                    if ($map[Builder::SCHEMA_OPTIONAL])
62
+                    {
51 63
                         $result[$field] = null;
52 64
                         continue;
53 65
                     }
@@ -59,10 +71,14 @@  discard block
 block discarded – undo
59 71
             $values = [];
60 72
 
61 73
             // List of "key" => "location in request"
62
-            foreach ($this->iterate($map, $input) as $index => $origin) {
63
-                try {
74
+            foreach ($this->iterate($map, $input) as $index => $origin)
75
+            {
76
+                try
77
+                {
64 78
                     $values[$index] = $this->provider->createFilter($nested, $input->withPrefix($origin));
65
-                } catch (ValidationException $e) {
79
+                }
80
+                catch (ValidationException $e)
81
+                {
66 82
                     $errors[$field][$index] = $e->errors;
67 83
                 }
68 84
             }
@@ -83,11 +99,13 @@  discard block
 block discarded – undo
83 99
             $schema[Builder::SCHEMA_ITERATE_ORIGIN]
84 100
         );
85 101
 
86
-        if (empty($values) || !\is_array($values)) {
102
+        if (empty($values) || !\is_array($values))
103
+        {
87 104
             return [];
88 105
         }
89 106
 
90
-        foreach (\array_keys($values) as $key) {
107
+        foreach (\array_keys($values) as $key)
108
+        {
91 109
             yield $key => $schema[Builder::SCHEMA_ORIGIN] . '.' . $key;
92 110
         }
93 111
     }
Please login to merge, or discard this patch.
src/Filters/src/Model/Schema/AttributeMapper.php 1 patch
Braces   +53 added lines, -22 removed lines patch added patch discarded remove patch
@@ -39,66 +39,95 @@  discard block
 block discarded – undo
39 39
         $optionalFilters = [];
40 40
         $class = new \ReflectionClass($filter);
41 41
 
42
-        foreach ($class->getProperties() as $property) {
42
+        foreach ($class->getProperties() as $property)
43
+        {
43 44
             /** @var object $attribute */
44
-            foreach ($this->reader->getPropertyMetadata($property) as $attribute) {
45
-                if ($attribute instanceof AbstractInput) {
46
-                    try {
45
+            foreach ($this->reader->getPropertyMetadata($property) as $attribute)
46
+            {
47
+                if ($attribute instanceof AbstractInput)
48
+                {
49
+                    try
50
+                    {
47 51
                         $this->setValue($filter, $property, $attribute->getValue($input, $property));
48
-                    } catch (SetterException $e) {
52
+                    }
53
+                    catch (SetterException $e)
54
+                    {
49 55
                         $errors[$property->getName()] = $e->getMessage();
50 56
                     }
51 57
                     $schema[$property->getName()] = $attribute->getSchema($property);
52
-                } elseif ($attribute instanceof NestedFilter) {
58
+                }
59
+                elseif ($attribute instanceof NestedFilter)
60
+                {
53 61
                     $prefix = $attribute->prefix ?? $property->name;
54
-                    try {
62
+                    try
63
+                    {
55 64
                         $value = $this->provider->createFilter(
56 65
                             $attribute->class,
57 66
                             $input->withPrefix($prefix)
58 67
                         );
59 68
 
60
-                        try {
69
+                        try
70
+                        {
61 71
                             $this->setValue($filter, $property, $value);
62
-                        } catch (SetterException $e) {
72
+                        }
73
+                        catch (SetterException $e)
74
+                        {
63 75
                             $errors[$property->getName()] = $e->getMessage();
64 76
                         }
65
-                    } catch (ValidationException $e) {
66
-                        if ($this->allowsNull($property)) {
77
+                    }
78
+                    catch (ValidationException $e)
79
+                    {
80
+                        if ($this->allowsNull($property))
81
+                        {
67 82
                             $this->setValue($filter, $property, null);
68 83
                             $optionalFilters[] = $property->getName();
69
-                        } else {
84
+                        }
85
+                        else
86
+                        {
70 87
                             $errors[$prefix] = $e->errors;
71 88
                         }
72 89
                     }
73 90
 
74 91
                     $schema[$property->getName()] = $attribute->getSchema($property);
75
-                } elseif ($attribute instanceof NestedArray) {
92
+                }
93
+                elseif ($attribute instanceof NestedArray)
94
+                {
76 95
                     $values = $attribute->getValue($input, $property);
77 96
                     $propertyValues = [];
78 97
 
79 98
                     $prefix = $attribute->input->key ?? $attribute->prefix ?? $property->getName();
80 99
 
81
-                    if (\is_array($values)) {
82
-                        foreach (\array_keys($values) as $key) {
83
-                            try {
100
+                    if (\is_array($values))
101
+                    {
102
+                        foreach (\array_keys($values) as $key)
103
+                        {
104
+                            try
105
+                            {
84 106
                                 $propertyValues[$key] = $this->provider->createFilter(
85 107
                                     $attribute->class,
86 108
                                     $input->withPrefix($prefix . '.' . $key)
87 109
                                 );
88
-                            } catch (ValidationException $e) {
110
+                            }
111
+                            catch (ValidationException $e)
112
+                            {
89 113
                                 /** @psalm-suppress InvalidArrayOffset */
90 114
                                 $errors[$property->getName()][$key] = $e->errors;
91 115
                             }
92 116
                         }
93 117
                     }
94 118
 
95
-                    try {
119
+                    try
120
+                    {
96 121
                         $this->setValue($filter, $property, $propertyValues);
97
-                    } catch (SetterException $e) {
122
+                    }
123
+                    catch (SetterException $e)
124
+                    {
98 125
                         $errors[$property->getName()] = $e->getMessage();
99 126
                     }
100 127
                     $schema[$property->getName()] = [$attribute->class, $prefix . '.*'];
101
-                } elseif ($attribute instanceof Setter) {
128
+                }
129
+                elseif ($attribute instanceof Setter)
130
+                {
102 131
                     $setters[$property->getName()][] = $attribute;
103 132
                 }
104 133
             }
@@ -109,13 +138,15 @@  discard block
 block discarded – undo
109 138
 
110 139
     private function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void
111 140
     {
112
-        if ($value === null) {
141
+        if ($value === null)
142
+        {
113 143
             return;
114 144
         }
115 145
 
116 146
         $setters = $this->reader->getPropertyMetadata($property, Setter::class);
117 147
 
118
-        foreach ($setters as $setter) {
148
+        foreach ($setters as $setter)
149
+        {
119 150
             $value = $setter->updateValue($value);
120 151
         }
121 152
 
Please login to merge, or discard this patch.