SingletonDecorator::resolve()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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