@@ -15,15 +15,15 @@ |
||
15 | 15 | public function __construct( |
16 | 16 | protected ?string $message = null, |
17 | 17 | ?callable $callback = null |
18 | - ) { |
|
19 | - if ($callback !== null) { |
|
18 | + ){ |
|
19 | + if ($callback !== null){ |
|
20 | 20 | $this->callback = $callback(...); |
21 | 21 | } |
22 | 22 | } |
23 | 23 | |
24 | 24 | public function getMessage(SetterException $exception, mixed $value = null): ?string |
25 | 25 | { |
26 | - if ($this->callback instanceof \Closure) { |
|
26 | + if ($this->callback instanceof \Closure){ |
|
27 | 27 | return ($this->callback)($exception, $value); |
28 | 28 | } |
29 | 29 |
@@ -16,14 +16,16 @@ |
||
16 | 16 | protected ?string $message = null, |
17 | 17 | ?callable $callback = null |
18 | 18 | ) { |
19 | - if ($callback !== null) { |
|
19 | + if ($callback !== null) |
|
20 | + { |
|
20 | 21 | $this->callback = $callback(...); |
21 | 22 | } |
22 | 23 | } |
23 | 24 | |
24 | 25 | public function getMessage(SetterException $exception, mixed $value = null): ?string |
25 | 26 | { |
26 | - if ($this->callback instanceof \Closure) { |
|
27 | + if ($this->callback instanceof \Closure) |
|
28 | + { |
|
27 | 29 | return ($this->callback)($exception, $value); |
28 | 30 | } |
29 | 31 |
@@ -9,8 +9,8 @@ |
||
9 | 9 | public function __construct(\Throwable $previous = null, ?string $message = null) |
10 | 10 | { |
11 | 11 | parent::__construct( |
12 | - message: $message ?? 'Unable to set value. The given data was invalid.', |
|
13 | - previous: $previous, |
|
12 | + message : $message ?? 'Unable to set value. The given data was invalid.', |
|
13 | + previous : $previous, |
|
14 | 14 | ); |
15 | 15 | } |
16 | 16 | } |
@@ -26,9 +26,9 @@ |
||
26 | 26 | */ |
27 | 27 | $enum = $type->getName(); |
28 | 28 | |
29 | - try { |
|
29 | + try{ |
|
30 | 30 | $property->setValue($filter, $value instanceof $enum ? $value : $enum::from($value)); |
31 | - } catch (\Throwable $e) { |
|
31 | + }catch (\Throwable $e){ |
|
32 | 32 | throw new SetterException( |
33 | 33 | previous: $e, |
34 | 34 | message: \sprintf('Unable to set enum value. %s', $e->getMessage()), |
@@ -26,9 +26,12 @@ |
||
26 | 26 | */ |
27 | 27 | $enum = $type->getName(); |
28 | 28 | |
29 | - try { |
|
29 | + try |
|
30 | + { |
|
30 | 31 | $property->setValue($filter, $value instanceof $enum ? $value : $enum::from($value)); |
31 | - } catch (\Throwable $e) { |
|
32 | + } |
|
33 | + catch (\Throwable $e) |
|
34 | + { |
|
32 | 35 | throw new SetterException( |
33 | 36 | previous: $e, |
34 | 37 | message: \sprintf('Unable to set enum value. %s', $e->getMessage()), |
@@ -16,9 +16,9 @@ |
||
16 | 16 | |
17 | 17 | public function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void |
18 | 18 | { |
19 | - try { |
|
19 | + try{ |
|
20 | 20 | $property->setValue($filter, $value); |
21 | - } catch (\Throwable $e) { |
|
21 | + }catch (\Throwable $e){ |
|
22 | 22 | throw new SetterException( |
23 | 23 | previous: $e, |
24 | 24 | message: \sprintf('Unable to set value. %s', $e->getMessage()), |
@@ -16,9 +16,12 @@ |
||
16 | 16 | |
17 | 17 | public function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void |
18 | 18 | { |
19 | - try { |
|
19 | + try |
|
20 | + { |
|
20 | 21 | $property->setValue($filter, $value); |
21 | - } catch (\Throwable $e) { |
|
22 | + } |
|
23 | + catch (\Throwable $e) |
|
24 | + { |
|
22 | 25 | throw new SetterException( |
23 | 26 | previous: $e, |
24 | 27 | message: \sprintf('Unable to set value. %s', $e->getMessage()), |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | public function supports(\ReflectionNamedType $type): bool |
17 | 17 | { |
18 | - if ($this->interfaceExists === null) { |
|
18 | + if ($this->interfaceExists === null){ |
|
19 | 19 | $this->interfaceExists = \interface_exists(UuidInterface::class); |
20 | 20 | } |
21 | 21 | |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | |
25 | 25 | public function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void |
26 | 26 | { |
27 | - try { |
|
27 | + try{ |
|
28 | 28 | $property->setValue($filter, $value instanceof UuidInterface ? $value : Uuid::fromString($value)); |
29 | - } catch (\Throwable $e) { |
|
29 | + }catch (\Throwable $e){ |
|
30 | 30 | throw new SetterException( |
31 | 31 | previous: $e, |
32 | 32 | message: \sprintf('Unable to set UUID value. %s', $e->getMessage()), |
@@ -36,16 +36,16 @@ discard block |
||
36 | 36 | |
37 | 37 | private function implements(string $haystack, string $interface): bool |
38 | 38 | { |
39 | - if ($haystack === $interface) { |
|
39 | + if ($haystack === $interface){ |
|
40 | 40 | return true; |
41 | 41 | } |
42 | 42 | |
43 | - foreach ((array)\class_implements($haystack) as $implements) { |
|
44 | - if ($implements === $interface) { |
|
43 | + foreach ((array)\class_implements($haystack) as $implements){ |
|
44 | + if ($implements === $interface){ |
|
45 | 45 | return true; |
46 | 46 | } |
47 | 47 | |
48 | - if (self::implements($implements, $interface)) { |
|
48 | + if (self::implements($implements, $interface)){ |
|
49 | 49 | return true; |
50 | 50 | } |
51 | 51 | } |
@@ -15,7 +15,8 @@ discard block |
||
15 | 15 | |
16 | 16 | public function supports(\ReflectionNamedType $type): bool |
17 | 17 | { |
18 | - if ($this->interfaceExists === null) { |
|
18 | + if ($this->interfaceExists === null) |
|
19 | + { |
|
19 | 20 | $this->interfaceExists = \interface_exists(UuidInterface::class); |
20 | 21 | } |
21 | 22 | |
@@ -24,9 +25,12 @@ discard block |
||
24 | 25 | |
25 | 26 | public function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void |
26 | 27 | { |
27 | - try { |
|
28 | + try |
|
29 | + { |
|
28 | 30 | $property->setValue($filter, $value instanceof UuidInterface ? $value : Uuid::fromString($value)); |
29 | - } catch (\Throwable $e) { |
|
31 | + } |
|
32 | + catch (\Throwable $e) |
|
33 | + { |
|
30 | 34 | throw new SetterException( |
31 | 35 | previous: $e, |
32 | 36 | message: \sprintf('Unable to set UUID value. %s', $e->getMessage()), |
@@ -36,16 +40,20 @@ discard block |
||
36 | 40 | |
37 | 41 | private function implements(string $haystack, string $interface): bool |
38 | 42 | { |
39 | - if ($haystack === $interface) { |
|
43 | + if ($haystack === $interface) |
|
44 | + { |
|
40 | 45 | return true; |
41 | 46 | } |
42 | 47 | |
43 | - foreach ((array)\class_implements($haystack) as $implements) { |
|
44 | - if ($implements === $interface) { |
|
48 | + foreach ((array)\class_implements($haystack) as $implements) |
|
49 | + { |
|
50 | + if ($implements === $interface) |
|
51 | + { |
|
45 | 52 | return true; |
46 | 53 | } |
47 | 54 | |
48 | - if (self::implements($implements, $interface)) { |
|
55 | + if (self::implements($implements, $interface)) |
|
56 | + { |
|
49 | 57 | return true; |
50 | 58 | } |
51 | 59 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | private readonly FilterProviderInterface $provider, |
27 | 27 | private readonly ReaderInterface $reader, |
28 | 28 | private readonly Mapper $mapper |
29 | - ) { |
|
29 | + ){ |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -40,54 +40,54 @@ discard block |
||
40 | 40 | $optionalFilters = []; |
41 | 41 | $class = new \ReflectionClass($filter); |
42 | 42 | |
43 | - foreach ($class->getProperties() as $property) { |
|
43 | + foreach ($class->getProperties() as $property){ |
|
44 | 44 | /** @var object $attribute */ |
45 | - foreach ($this->reader->getPropertyMetadata($property) as $attribute) { |
|
46 | - if ($attribute instanceof AbstractInput) { |
|
45 | + foreach ($this->reader->getPropertyMetadata($property) as $attribute){ |
|
46 | + if ($attribute instanceof AbstractInput){ |
|
47 | 47 | $value = $attribute->getValue($input, $property); |
48 | - try { |
|
48 | + try{ |
|
49 | 49 | $this->setValue($filter, $property, $value); |
50 | - } catch (SetterException $e) { |
|
50 | + }catch (SetterException $e){ |
|
51 | 51 | $errors[$property->getName()] = $this->createErrorMessage($e, $property, $value); |
52 | 52 | } |
53 | 53 | $schema[$property->getName()] = $attribute->getSchema($property); |
54 | - } elseif ($attribute instanceof NestedFilter) { |
|
54 | + } elseif ($attribute instanceof NestedFilter){ |
|
55 | 55 | $prefix = $attribute->prefix ?? $property->name; |
56 | - try { |
|
56 | + try{ |
|
57 | 57 | $value = $this->provider->createFilter( |
58 | 58 | $attribute->class, |
59 | 59 | $input->withPrefix($prefix) |
60 | 60 | ); |
61 | 61 | |
62 | - try { |
|
62 | + try{ |
|
63 | 63 | $this->setValue($filter, $property, $value); |
64 | - } catch (SetterException $e) { |
|
64 | + }catch (SetterException $e){ |
|
65 | 65 | $errors[$property->getName()] = $this->createErrorMessage($e, $property, $value); |
66 | 66 | } |
67 | - } catch (ValidationException $e) { |
|
68 | - if ($this->allowsNull($property)) { |
|
67 | + }catch (ValidationException $e){ |
|
68 | + if ($this->allowsNull($property)){ |
|
69 | 69 | $this->setValue($filter, $property, null); |
70 | 70 | $optionalFilters[] = $property->getName(); |
71 | - } else { |
|
71 | + }else{ |
|
72 | 72 | $errors[$prefix] = $e->errors; |
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | 76 | $schema[$property->getName()] = $attribute->getSchema($property); |
77 | - } elseif ($attribute instanceof NestedArray) { |
|
77 | + } elseif ($attribute instanceof NestedArray){ |
|
78 | 78 | $values = $attribute->getValue($input, $property); |
79 | 79 | $propertyValues = []; |
80 | 80 | |
81 | 81 | $prefix = $attribute->input->key ?? $attribute->prefix ?? $property->getName(); |
82 | 82 | |
83 | - if (\is_array($values)) { |
|
84 | - foreach (\array_keys($values) as $key) { |
|
85 | - try { |
|
83 | + if (\is_array($values)){ |
|
84 | + foreach (\array_keys($values) as $key){ |
|
85 | + try{ |
|
86 | 86 | $propertyValues[$key] = $this->provider->createFilter( |
87 | 87 | $attribute->class, |
88 | - $input->withPrefix($prefix . '.' . $key) |
|
88 | + $input->withPrefix($prefix.'.'.$key) |
|
89 | 89 | ); |
90 | - } catch (ValidationException $e) { |
|
90 | + }catch (ValidationException $e){ |
|
91 | 91 | /** @psalm-suppress InvalidArrayOffset */ |
92 | 92 | $errors[$property->getName()][$key] = $e->errors; |
93 | 93 | } |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | $this->setValue($filter, $property, $propertyValues); |
98 | - $schema[$property->getName()] = [$attribute->class, $prefix . '.*']; |
|
99 | - } elseif ($attribute instanceof Setter) { |
|
98 | + $schema[$property->getName()] = [$attribute->class, $prefix.'.*']; |
|
99 | + } elseif ($attribute instanceof Setter){ |
|
100 | 100 | $setters[$property->getName()][] = $attribute; |
101 | 101 | } |
102 | 102 | } |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | |
108 | 108 | private function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void |
109 | 109 | { |
110 | - if ($value === null) { |
|
110 | + if ($value === null){ |
|
111 | 111 | return; |
112 | 112 | } |
113 | 113 | |
114 | 114 | $setters = $this->reader->getPropertyMetadata($property, Setter::class); |
115 | 115 | |
116 | - foreach ($setters as $setter) { |
|
116 | + foreach ($setters as $setter){ |
|
117 | 117 | $value = $setter->updateValue($value); |
118 | 118 | } |
119 | 119 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | ): string { |
135 | 135 | $attribute = $this->reader->firstPropertyMetadata($property, CastingErrorMessage::class); |
136 | 136 | |
137 | - if ($attribute === null) { |
|
137 | + if ($attribute === null){ |
|
138 | 138 | return $exception->getMessage(); |
139 | 139 | } |
140 | 140 |
@@ -40,54 +40,78 @@ discard block |
||
40 | 40 | $optionalFilters = []; |
41 | 41 | $class = new \ReflectionClass($filter); |
42 | 42 | |
43 | - foreach ($class->getProperties() as $property) { |
|
43 | + foreach ($class->getProperties() as $property) |
|
44 | + { |
|
44 | 45 | /** @var object $attribute */ |
45 | - foreach ($this->reader->getPropertyMetadata($property) as $attribute) { |
|
46 | - if ($attribute instanceof AbstractInput) { |
|
46 | + foreach ($this->reader->getPropertyMetadata($property) as $attribute) |
|
47 | + { |
|
48 | + if ($attribute instanceof AbstractInput) |
|
49 | + { |
|
47 | 50 | $value = $attribute->getValue($input, $property); |
48 | - try { |
|
51 | + try |
|
52 | + { |
|
49 | 53 | $this->setValue($filter, $property, $value); |
50 | - } catch (SetterException $e) { |
|
54 | + } |
|
55 | + catch (SetterException $e) |
|
56 | + { |
|
51 | 57 | $errors[$property->getName()] = $this->createErrorMessage($e, $property, $value); |
52 | 58 | } |
53 | 59 | $schema[$property->getName()] = $attribute->getSchema($property); |
54 | - } elseif ($attribute instanceof NestedFilter) { |
|
60 | + } |
|
61 | + elseif ($attribute instanceof NestedFilter) |
|
62 | + { |
|
55 | 63 | $prefix = $attribute->prefix ?? $property->name; |
56 | - try { |
|
64 | + try |
|
65 | + { |
|
57 | 66 | $value = $this->provider->createFilter( |
58 | 67 | $attribute->class, |
59 | 68 | $input->withPrefix($prefix) |
60 | 69 | ); |
61 | 70 | |
62 | - try { |
|
71 | + try |
|
72 | + { |
|
63 | 73 | $this->setValue($filter, $property, $value); |
64 | - } catch (SetterException $e) { |
|
74 | + } |
|
75 | + catch (SetterException $e) |
|
76 | + { |
|
65 | 77 | $errors[$property->getName()] = $this->createErrorMessage($e, $property, $value); |
66 | 78 | } |
67 | - } catch (ValidationException $e) { |
|
68 | - if ($this->allowsNull($property)) { |
|
79 | + } |
|
80 | + catch (ValidationException $e) |
|
81 | + { |
|
82 | + if ($this->allowsNull($property)) |
|
83 | + { |
|
69 | 84 | $this->setValue($filter, $property, null); |
70 | 85 | $optionalFilters[] = $property->getName(); |
71 | - } else { |
|
86 | + } |
|
87 | + else |
|
88 | + { |
|
72 | 89 | $errors[$prefix] = $e->errors; |
73 | 90 | } |
74 | 91 | } |
75 | 92 | |
76 | 93 | $schema[$property->getName()] = $attribute->getSchema($property); |
77 | - } elseif ($attribute instanceof NestedArray) { |
|
94 | + } |
|
95 | + elseif ($attribute instanceof NestedArray) |
|
96 | + { |
|
78 | 97 | $values = $attribute->getValue($input, $property); |
79 | 98 | $propertyValues = []; |
80 | 99 | |
81 | 100 | $prefix = $attribute->input->key ?? $attribute->prefix ?? $property->getName(); |
82 | 101 | |
83 | - if (\is_array($values)) { |
|
84 | - foreach (\array_keys($values) as $key) { |
|
85 | - try { |
|
102 | + if (\is_array($values)) |
|
103 | + { |
|
104 | + foreach (\array_keys($values) as $key) |
|
105 | + { |
|
106 | + try |
|
107 | + { |
|
86 | 108 | $propertyValues[$key] = $this->provider->createFilter( |
87 | 109 | $attribute->class, |
88 | 110 | $input->withPrefix($prefix . '.' . $key) |
89 | 111 | ); |
90 | - } catch (ValidationException $e) { |
|
112 | + } |
|
113 | + catch (ValidationException $e) |
|
114 | + { |
|
91 | 115 | /** @psalm-suppress InvalidArrayOffset */ |
92 | 116 | $errors[$property->getName()][$key] = $e->errors; |
93 | 117 | } |
@@ -96,7 +120,9 @@ discard block |
||
96 | 120 | |
97 | 121 | $this->setValue($filter, $property, $propertyValues); |
98 | 122 | $schema[$property->getName()] = [$attribute->class, $prefix . '.*']; |
99 | - } elseif ($attribute instanceof Setter) { |
|
123 | + } |
|
124 | + elseif ($attribute instanceof Setter) |
|
125 | + { |
|
100 | 126 | $setters[$property->getName()][] = $attribute; |
101 | 127 | } |
102 | 128 | } |
@@ -107,13 +133,15 @@ discard block |
||
107 | 133 | |
108 | 134 | private function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void |
109 | 135 | { |
110 | - if ($value === null) { |
|
136 | + if ($value === null) |
|
137 | + { |
|
111 | 138 | return; |
112 | 139 | } |
113 | 140 | |
114 | 141 | $setters = $this->reader->getPropertyMetadata($property, Setter::class); |
115 | 142 | |
116 | - foreach ($setters as $setter) { |
|
143 | + foreach ($setters as $setter) |
|
144 | + { |
|
117 | 145 | $value = $setter->updateValue($value); |
118 | 146 | } |
119 | 147 | |
@@ -134,7 +162,8 @@ discard block |
||
134 | 162 | ): string { |
135 | 163 | $attribute = $this->reader->firstPropertyMetadata($property, CastingErrorMessage::class); |
136 | 164 | |
137 | - if ($attribute === null) { |
|
165 | + if ($attribute === null) |
|
166 | + { |
|
138 | 167 | return $exception->getMessage(); |
139 | 168 | } |
140 | 169 |