Passed
Push — master ( d9297f...af2311 )
by Max
01:55 queued 01:05
created

The::act()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MaxGoryunov\SavingIterator\Fakes;
4
5
use Closure;
6
7
/**
8
 * Class for applying contexts to elements without changing them.
9
 * @todo #92:30min Remove extension of SurveyEnvelope because it is not needed
10
 *  anymore.
11
 * @template T subject type
12
 * @extends SurveyEnvelope<T, T>
13
 * @implements Block<mixed>
14
 */
15
class The extends SurveyEnvelope implements Block
16
{
17
18
    /**
19
     * Subject for a context.
20
     *
21
     * @var mixed
22
     */
23
    private mixed $subject;
24
25
    /**
26
     * Ctor.
27
     *
28
     * @phpstan-param T                 $subject repeating element
29
     * @phpstan-param Closure(T): mixed $context context for element
30
     * @param mixed $subject
31
     * @param Closure $context
32
     */
33
    public function __construct(mixed $subject, Closure $context)
34
    {
35
        parent::__construct(
36
            $subject,
37
            $context,
38
            function (mixed $subject, Closure $context): mixed
39
            {
40
                $context($subject);
41
                return $subject;
42
            }
43
        );
44
        $this->subject = $subject;
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function act(Closure $context): mixed
51
    {
52
        $context($this->subject);
53
        return $this->subject;
54
    }
55
}
56