Lazy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
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 __construct() 0 3 1
A load() 0 3 1
A service() 0 10 2
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 123
    public function __construct(callable $load)
16
    {
17 123
        $this->load = $load;
18 123
    }
19
20 121
    public static function service(
21
        Name $name,
22
        Services $services
23
    ): self {
24 121
        if (!$services->has($name)) {
25 1
            throw new ReferenceNotFound((string) $name);
26
        }
27
28 120
        return new self(static function() use ($services, $name): object {
29 105
            return $services->build($name);
30 120
        });
31
    }
32
33 108
    public function load(): object
34
    {
35 108
        return ($this->load)();
36
    }
37
}
38