19declare(strict_types=1);
27use InvalidArgumentException;
56 if (!is_array($from)) {
57 throw new InvalidArgumentException(__METHOD__ .
" argument is not an array.");
60 if (count($from) !== count($this->labels)) {
61 throw new InvalidArgumentException(__METHOD__ .
" number of items in arrays are not equal.");
64 return array_combine($this->labels, $from);
72 $dataValue = $result->
value();
73 if (
false === is_array($dataValue)) {
74 $exception =
new InvalidArgumentException(__METHOD__ .
" argument is not an array.");
75 return $this->
factory->error($exception);
78 if (count($dataValue) !== count($this->labels)) {
79 $exception =
new InvalidArgumentException(__METHOD__ .
" number of items in arrays are not equal.");
80 return $this->
factory->error($exception);
83 $value = array_combine($this->labels, $dataValue);
84 $result = $this->
factory->ok($value);
Adds to any array keys for each value.
applyTo(Result $result)
@inheritDoc
transform($from)
@inheritDoc
__construct(array $labels, Factory $factory)
trait DeriveInvokeFromTransform
A result encapsulates a value or an error and simplifies the handling of those.
value()
Get the encapsulated value.