ContextVeil::__call()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 2
b 0
f 1
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace MaxGoryunov\SavingIterator\Src;
4
5
use Closure;
6
7
/**
8
 * Veil which applies context to origin if the condition is met.
9
 * @template T of object origin type.
10
 * @implements Indifferent<T>
11
 * @mixin T
12
 */
13
final class ContextVeil implements Indifferent
14
{
15
16
    /**
17
     * Ctor.
18
     * 
19
     * @phpstan-param T           $origin
20
     * @phpstan-param Reaction<T> $reaction
21
     * @param object   $origin   original element.
22
     * @param Reaction $reaction reaction for the element.
23
     */
24
    public function __construct(
25
        /**
26
         * Original element.
27
         *
28
         * @phpstan-var T
29
         * @var object
30
         */
31
        private object $origin,
32
33
        /**
34
         * Reaction for the element.
35
         *
36
         * @phpstan-var Reaction<T>
37
         * @var Reaction
38
         */
39
        private Reaction $reaction
40
    ) {
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function __call(string $name, array $arguments): mixed
47
    {
48
        $this->origin = $this->reaction->edited($this->origin, $name);
49
        return $this->origin->$name(...$arguments);
50
    }
51
}
52