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

Let   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
dl 0
loc 34
rs 10
c 1
b 0
f 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A act() 0 3 1
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