Passed
Push — feature/40 ( c9d26f...67d730 )
by Max
02:40
created

Let::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 0
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 15
rs 10
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
 */
10
class Let
11
{
12
13
    /**
14
     * Ctor.
15
     * 
16
     * @param mixed   $subject
17
     * @param Closure $context
18
     */
19
    public function __construct(
20
        /**
21
         * Element to be put into the context.
22
         * 
23
         * @var mixed
24
         */
25
        private mixed $subject,
26
27
        /**
28
         * Context for the element.
29
         * 
30
         * @var Closure
31
         */
32
        private Closure $context
33
    ) {
34
    }
35
36
    /**
37
     * Returns result of applying context to element.
38
     *
39
     * @return mixed
40
     */
41
    public function value(): mixed
42
    {
43
        return ($this->context)($this->subject);
44
    }
45
}
46