@@ -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 |
@@ -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,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,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 | } |
@@ -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 |