@@ -37,7 +37,8 @@ |
||
37 | 37 | parent::setUp(); |
38 | 38 | |
39 | 39 | $this->container->bindSingleton(ReaderInterface::class, (new Factory())->create()); |
40 | - $this->container->bindSingleton(SchemaProviderInterface::class, static function (FactoryInterface $factory) { |
|
40 | + $this->container->bindSingleton(SchemaProviderInterface::class, static function (FactoryInterface $factory) |
|
41 | + { |
|
41 | 42 | return $factory->make(SchemaProvider::class, [ |
42 | 43 | 'readers' => [ |
43 | 44 | $factory->make(AttributeReader::class), |
@@ -18,7 +18,8 @@ |
||
18 | 18 | $errors = array_merge($core->callAction($controller, $action, $parameters), $parameters['errors'] ?? []); |
19 | 19 | $errorMapper = new ErrorMapper($parameters['schema']); |
20 | 20 | |
21 | - if ($errors !== []) { |
|
21 | + if ($errors !== []) |
|
22 | + { |
|
22 | 23 | throw new ValidationException( |
23 | 24 | $errorMapper->mapErrors($errors), |
24 | 25 | $parameters['context'] ?? null |
@@ -29,9 +29,11 @@ |
||
29 | 29 | |
30 | 30 | private function validateFilter(FilterInterface $filter, array $data, mixed $context = null): array |
31 | 31 | { |
32 | - if ($filter instanceof HasFilterDefinition) { |
|
32 | + if ($filter instanceof HasFilterDefinition) |
|
33 | + { |
|
33 | 34 | $definition = $filter->filterDefinition(); |
34 | - if ($definition instanceof ShouldBeValidated) { |
|
35 | + if ($definition instanceof ShouldBeValidated) |
|
36 | + { |
|
35 | 37 | /** @var ValidationProviderInterface $validationProvider */ |
36 | 38 | $validationProvider = $this->container->get(ValidationProviderInterface::class); |
37 | 39 |
@@ -33,15 +33,22 @@ |
||
33 | 33 | $setters = []; |
34 | 34 | $class = new \ReflectionClass($filter); |
35 | 35 | |
36 | - foreach ($class->getProperties() as $property) { |
|
36 | + foreach ($class->getProperties() as $property) |
|
37 | + { |
|
37 | 38 | /** @var object $attribute */ |
38 | - foreach ($this->reader->getPropertyMetadata($property) as $attribute) { |
|
39 | - if ($attribute instanceof AbstractInput || $attribute instanceof NestedFilter) { |
|
39 | + foreach ($this->reader->getPropertyMetadata($property) as $attribute) |
|
40 | + { |
|
41 | + if ($attribute instanceof AbstractInput || $attribute instanceof NestedFilter) |
|
42 | + { |
|
40 | 43 | $schema[$property->getName()] = $attribute->getSchema($property); |
41 | - } elseif ($attribute instanceof NestedArray) { |
|
44 | + } |
|
45 | + elseif ($attribute instanceof NestedArray) |
|
46 | + { |
|
42 | 47 | $prefix = $attribute->input->key ?? $attribute->prefix ?? $property->getName(); |
43 | 48 | $schema[$property->getName()] = [$attribute->class, $prefix . '.*']; |
44 | - } elseif ($attribute instanceof Setter) { |
|
49 | + } |
|
50 | + elseif ($attribute instanceof Setter) |
|
51 | + { |
|
45 | 52 | $setters[$property->getName()][] = $attribute; |
46 | 53 | } |
47 | 54 | } |
@@ -11,7 +11,8 @@ |
||
11 | 11 | |
12 | 12 | public function __construct(array $setters = []) |
13 | 13 | { |
14 | - foreach ($setters as $setter) { |
|
14 | + foreach ($setters as $setter) |
|
15 | + { |
|
15 | 16 | $this->register($setter); |
16 | 17 | } |
17 | 18 | } |
@@ -13,7 +13,8 @@ discard block |
||
13 | 13 | |
14 | 14 | public function supports(\ReflectionNamedType $type): bool |
15 | 15 | { |
16 | - if ($this->interfaceExists === null) { |
|
16 | + if ($this->interfaceExists === null) |
|
17 | + { |
|
17 | 18 | $this->interfaceExists = \interface_exists(UuidInterface::class); |
18 | 19 | } |
19 | 20 | |
@@ -27,16 +28,20 @@ discard block |
||
27 | 28 | |
28 | 29 | private function implements(string $haystack, string $interface): bool |
29 | 30 | { |
30 | - if ($haystack === $interface) { |
|
31 | + if ($haystack === $interface) |
|
32 | + { |
|
31 | 33 | return true; |
32 | 34 | } |
33 | 35 | |
34 | - foreach ((array)\class_implements($haystack) as $implements) { |
|
35 | - if ($implements === $interface) { |
|
36 | + foreach ((array)\class_implements($haystack) as $implements) |
|
37 | + { |
|
38 | + if ($implements === $interface) |
|
39 | + { |
|
36 | 40 | return true; |
37 | 41 | } |
38 | 42 | |
39 | - if (self::implements($implements, $interface)) { |
|
43 | + if (self::implements($implements, $interface)) |
|
44 | + { |
|
40 | 45 | return true; |
41 | 46 | } |
42 | 47 | } |
@@ -22,7 +22,8 @@ |
||
22 | 22 | $class = new \ReflectionClass($name); |
23 | 23 | |
24 | 24 | $args = []; |
25 | - if ($constructor = $class->getConstructor()) { |
|
25 | + if ($constructor = $class->getConstructor()) |
|
26 | + { |
|
26 | 27 | $args = $this->resolver->resolveArguments($constructor); |
27 | 28 | } |
28 | 29 |
@@ -106,12 +106,14 @@ |
||
106 | 106 | ?EventDispatcherInterface $dispatcher = null |
107 | 107 | ): FilterProvider { |
108 | 108 | $core = new InterceptableCore(new Core(), $dispatcher); |
109 | - foreach ($config->getInterceptors() as $interceptor) { |
|
109 | + foreach ($config->getInterceptors() as $interceptor) |
|
110 | + { |
|
110 | 111 | $core->addInterceptor($container->get($interceptor)); |
111 | 112 | } |
112 | 113 | |
113 | 114 | $validationCode = new InterceptableCore(new ValidationCore($container), $dispatcher); |
114 | - foreach ($config->getValidationInterceptors() as $interceptor) { |
|
115 | + foreach ($config->getValidationInterceptors() as $interceptor) |
|
116 | + { |
|
115 | 117 | $validationCode->addInterceptor($container->get($interceptor)); |
116 | 118 | } |
117 | 119 |
@@ -42,18 +42,22 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function makeSchema(string $name, array $schema): array |
44 | 44 | { |
45 | - if (empty($schema)) { |
|
45 | + if (empty($schema)) |
|
46 | + { |
|
46 | 47 | throw new SchemaException(\sprintf('Filter `%s` does not define any schema', $name)); |
47 | 48 | } |
48 | 49 | |
49 | 50 | $result = []; |
50 | - foreach ($schema as $field => $definition) { |
|
51 | + foreach ($schema as $field => $definition) |
|
52 | + { |
|
51 | 53 | $optional = false; |
52 | 54 | |
53 | 55 | // short definition |
54 | - if (\is_string($definition)) { |
|
56 | + if (\is_string($definition)) |
|
57 | + { |
|
55 | 58 | // simple scalar field definition |
56 | - if (!\class_exists($definition)) { |
|
59 | + if (!\class_exists($definition)) |
|
60 | + { |
|
57 | 61 | [$source, $origin] = $this->parseDefinition($field, $definition); |
58 | 62 | $result[$field] = [ |
59 | 63 | self::SCHEMA_SOURCE => $source, |
@@ -74,25 +78,30 @@ discard block |
||
74 | 78 | continue; |
75 | 79 | } |
76 | 80 | |
77 | - if (!\is_array($definition) || $definition === []) { |
|
81 | + if (!\is_array($definition) || $definition === []) |
|
82 | + { |
|
78 | 83 | throw new SchemaException( |
79 | 84 | \sprintf('Invalid schema definition at `%s`->`%s`', $name, $field) |
80 | 85 | ); |
81 | 86 | } |
82 | 87 | |
83 | 88 | // complex definition |
84 | - if (!empty($definition[self::ORIGIN])) { |
|
89 | + if (!empty($definition[self::ORIGIN])) |
|
90 | + { |
|
85 | 91 | $origin = $definition[self::ORIGIN]; |
86 | 92 | |
87 | 93 | // [class, 'data:something.*'] vs [class, 'data:something'] |
88 | 94 | $iterate = \str_contains((string)$origin, '.*') || !empty($definition[self::ITERATE]); |
89 | 95 | $origin = \rtrim($origin, '.*'); |
90 | - } else { |
|
96 | + } |
|
97 | + else |
|
98 | + { |
|
91 | 99 | $origin = $field; |
92 | 100 | $iterate = true; |
93 | 101 | } |
94 | 102 | |
95 | - if (!empty($definition[self::OPTIONAL])) { |
|
103 | + if (!empty($definition[self::OPTIONAL])) |
|
104 | + { |
|
96 | 105 | $optional = true; |
97 | 106 | } |
98 | 107 | |
@@ -105,7 +114,8 @@ discard block |
||
105 | 114 | self::SCHEMA_OPTIONAL => $optional, |
106 | 115 | ]; |
107 | 116 | |
108 | - if ($iterate) { |
|
117 | + if ($iterate) |
|
118 | + { |
|
109 | 119 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
110 | 120 | |
111 | 121 | $map[self::SCHEMA_ITERATE_SOURCE] = $source; |
@@ -137,11 +147,13 @@ discard block |
||
137 | 147 | 'path', |
138 | 148 | 'remoteAddress', |
139 | 149 | 'uri', |
140 | - ], true)) { |
|
150 | + ], true)) |
|
151 | + { |
|
141 | 152 | return [$definition, $field]; |
142 | 153 | } |
143 | 154 | |
144 | - if (!\str_contains($definition, ':')) { |
|
155 | + if (!\str_contains($definition, ':')) |
|
156 | + { |
|
145 | 157 | return ['data', empty($definition) ? $field : $definition]; |
146 | 158 | } |
147 | 159 |