Passed
Push — feature/40 ( c9d26f...67d730 )
by Max
02:40
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 2
c 1
b 0
f 1
dl 0
loc 34
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A value() 0 3 1
A __construct() 0 15 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
 */
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