ContextVeil   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
eloc 3
c 3
b 0
f 2
dl 0
loc 37
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A __call() 0 4 1
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