Passed
Push — 109 ( 64c3cb...e44d1f )
by Max
05:55 queued 03:37
created

The::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 3
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 12
rs 10
c 3
b 0
f 3
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