Completed
Push — develop ( f7c91f...15ec3c )
by Baptiste
02:24
created

Lazy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Compose;
5
6
use Innmind\Compose\{
7
    Definition\Name,
8
    Exception\ReferenceNotFound
9
};
10
11
final class Lazy
12
{
13
    private $load;
14
15 116
    public function __construct(callable $load)
16
    {
17 116
        $this->load = $load;
18 116
    }
19
20 116
    public static function service(
21
        Name $name,
22
        Services $services
23
    ): self {
24 116
        if (!$services->has($name)) {
25 1
            throw new ReferenceNotFound((string) $name);
26
        }
27
28 115
        return new self(static function() use ($services, $name): object {
29 96
            return $services->build($name);
30 115
        });
31
    }
32
33 97
    public function load(): object
34
    {
35 97
        return ($this->load)();
36
    }
37
}
38