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

Lazy::service()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
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