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

Let::act()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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