Passed
Push — feature/51 ( 15fa2a...ffcada )
by Max
02:36
created

The::value()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
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 applying contexts to elements without changing them.
10
 * @template T subject type.
11
 * @implements Scalar<T>
12
 * 
13
 * @todo #44:20min Classes Let and The do not have proper type hints in
14
 *  constructor and methods. Workarounds with `@var` tags must be removed
15
 *  after that. 
16
 */
17
class The implements Scalar
18
{
19
20
    /**
21
     * Ctor.
22
     * 
23
     * @param T                 $subject
24
     * @param Closure(T): mixed $context
25
     */
26
    public function __construct(
27
        /**
28
         * Element to be put into the context.
29
         * 
30
         * @var T
31
         */
32
        private mixed $subject,
33
34
        /**
35
         * Context for the element.
36
         * 
37
         * @var Closure(T): mixed
38
         */
39
        private Closure $context
40
    ) {
41
    }
42
43
    /**
44
     * Applies context to subject and returns subject.
45
     *
46
     * @return T
47
     */
48
    public function value(): mixed
49
    {
50
        ($this->context)($this->subject);
51
        return $this->subject;
52
    }
53
}
54