2 declare(strict_types=1);
29 foreach ($transformations as $key => $transformation) {
31 $transformationClassName = Transformation::class;
34 sprintf(
'The array MUST contain only "%s" instances', $transformationClassName),
35 'not_a_transformation',
36 $transformationClassName
40 if (
false === is_string($key)) {
42 'The array key MUST be a string',
60 foreach ($from as $key => $value) {
61 if (
false === is_string($key)) {
63 'The array key MUST be a string',
68 if (
false === isset($this->transformations[$key])) {
70 sprintf(
'Could not find transformation for array key "%s"', $key),
71 'array_key_does_not_exist',
76 $transformation = $this->transformations[$key];
77 $transformedValue = $transformation->transform($value);
79 $result[$key] = $transformedValue;
99 $countOfValues = count($values);
100 $countOfTransformations = count($this->transformations);
102 if ($countOfValues !== $countOfTransformations) {
105 'The given values(count: "%s") does not match with the given transformations("%s")',
107 $countOfTransformations
109 'length_does_not_match',
111 $countOfTransformations
trait DeriveApplyToFromTransform