Passed
Push — master ( 130115...2db6a6 )
by Max
57s queued 14s
created

SurveyEnvelope::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
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace MaxGoryunov\SavingIterator\Fakes;
4
5
use Closure;
6
use MaxGoryunov\SavingIterator\Src\Scalar;
7
8
/**
9
 * Class for wrapping divergent program flows. It allows to structure a program
10
 * in such a way that there will be no need for a variable if it exists only in
11
 * order to be used in two places.
12
 * @template X subject type
13
 * @template Y result type
14
 * @implements Block<Y>
15
 */
16
abstract class SurveyEnvelope implements Block
17
{
18
19
    /**
20
     * Ctor.
21
     * 
22
     * @phpstan-param X                                $subject
23
     * @phpstan-param Closure(X, Closure(X): mixed): Y $usage
24
     * @param mixed   $subject element to be used in some context
25
     * @param Closure $usage   way of combining element and context
26
     */
27
    public function __construct(
28
        /**
29
         * Element to be used in some context.
30
         * 
31
         * @phpstan-var X
32
         * @var mixed
33
         */
34
        private mixed $subject,
35
36
        /**
37
         * way of combining element and context.
38
         * 
39
         * @phpstan-var Closure(X, Closure(X): mixed): Y
40
         * @var Closure
41
         */
42
        private Closure $usage
43
    ) {
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public final function act(Closure $context): mixed
50
    {
51
        return ($this->usage)($this->subject, $context);
52
    }
53
}
54