|
20 | 20 | * @author Walmir Silva <walmir.silva@kariricode.org> |
21 | 21 | * @since 3.1.0 ARFA 1.3 |
22 | 22 | */ |
23 | | -final class TransformerEngine |
| 23 | +final readonly class TransformerEngine |
24 | 24 | { |
25 | 25 | public function __construct( |
26 | | - private readonly RuleRegistry $registry, |
27 | | - private readonly ?TransformerConfiguration $configuration = null, |
28 | | - ) {} |
| 26 | + private RuleRegistry $registry, |
| 27 | + private ?TransformerConfiguration $configuration = null, |
| 28 | + ) { |
| 29 | + } |
29 | 30 |
|
30 | 31 | /** |
31 | 32 | * @param array<string, mixed> $data |
@@ -59,34 +60,40 @@ public function transform(array $data, array $fieldRules): TransformationResult |
59 | 60 | return $result; |
60 | 61 | } |
61 | 62 |
|
| 63 | + /** @param array<string, mixed> $data */ |
62 | 64 | private function resolveValue(array $data, string $field): mixed |
63 | 65 | { |
64 | | - if (array_key_exists($field, $data)) { |
| 66 | + if (\array_key_exists($field, $data)) { |
65 | 67 | return $data[$field]; |
66 | 68 | } |
67 | 69 | $segments = explode('.', $field); |
68 | 70 | $current = $data; |
69 | 71 | foreach ($segments as $segment) { |
70 | | - if (!is_array($current) || !array_key_exists($segment, $current)) { |
| 72 | + if (! \is_array($current) || ! \array_key_exists($segment, $current)) { |
71 | 73 | return null; |
72 | 74 | } |
73 | 75 | $current = $current[$segment]; |
74 | 76 | } |
| 77 | + |
75 | 78 | return $current; |
76 | 79 | } |
77 | 80 |
|
78 | | - /** @return array{0: TransformationRule, 1: array<string, mixed>} */ |
| 81 | + /** |
| 82 | + * @param string|array{0: string|TransformationRule, 1: array<string, mixed>}|TransformationRule $definition |
| 83 | + * @return array{0: TransformationRule, 1: array<string, mixed>} |
| 84 | + */ |
79 | 85 | private function resolveRule(string|array|TransformationRule $definition): array |
80 | 86 | { |
81 | 87 | if ($definition instanceof TransformationRule) { |
82 | 88 | return [$definition, []]; |
83 | 89 | } |
84 | | - if (is_string($definition)) { |
| 90 | + if (\is_string($definition)) { |
85 | 91 | return [$this->registry->resolve($definition), []]; |
86 | 92 | } |
87 | 93 | $ruleRef = $definition[0]; |
88 | 94 | $params = $definition[1] ?? []; |
89 | 95 | $rule = $ruleRef instanceof TransformationRule ? $ruleRef : $this->registry->resolve($ruleRef); |
| 96 | + |
90 | 97 | return [$rule, $params]; |
91 | 98 | } |
92 | 99 | } |
0 commit comments