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

Lazy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A service() 0 10 2
A __construct() 0 3 1
A load() 0 3 1
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