SingletonDecorator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 13
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lit\Air\Recipe\Decorator;
6
7
use Lit\Air\Psr\Container;
8
9
/**
10
 * Turns a recipe into a singleton. When it's resolved once, the value will be cached and reused.
11
 */
12
class SingletonDecorator extends AbstractRecipeDecorator
13
{
14
    protected $value;
15
    protected $isResolved = false;
16
17 2
    public function resolve(Container $container)
18
    {
19 2
        if (!$this->isResolved) {
20 2
            $this->value = $this->recipe->resolve($container);
21 2
            $this->isResolved = true;
22
        }
23
24 2
        return $this->value;
25
    }
26
}
27