| Total Complexity | 6 |
| Total Lines | 57 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | class ContextualizedTransformation implements HasContext, Transformation |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var Context |
||
| 24 | */ |
||
| 25 | private $context; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var Transformation|callable |
||
| 29 | */ |
||
| 30 | private $transformation; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param Context|null $context |
||
| 34 | * @param Transformation|callable|null $transformation |
||
| 35 | */ |
||
| 36 | public function __construct(Context $context = null, callable $transformation = null) |
||
| 40 | } |
||
| 41 | |||
| 42 | public function __clone() |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param mixed $data |
||
| 49 | * @param Transformation|callable|null $transformation |
||
| 50 | * |
||
| 51 | * @return mixed |
||
| 52 | */ |
||
| 53 | public function __invoke($data, callable $transformation = null) |
||
| 54 | { |
||
| 55 | if ($transformation) { |
||
| 56 | $clone = clone $this; |
||
| 57 | $clone->transformation = $transformation; |
||
| 58 | |||
| 59 | return $clone($data); |
||
| 60 | } |
||
| 61 | |||
| 62 | $this->context->push($data); |
||
| 63 | |||
| 64 | $result = ($this->transformation)($data, $this); |
||
| 65 | |||
| 66 | $this->context->pop(); |
||
| 67 | |||
| 68 | return $result; |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return Context |
||
| 73 | */ |
||
| 74 | public function getContext(): Context |
||
| 77 | } |
||
| 78 | } |
||
| 79 |