CallableEntry   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getCacheParameters() 0 3 1
A createFromCacheParameters() 0 3 1
A getValue() 0 3 1
A isFactory() 0 3 1
1
<?php
2
3
namespace Simply\Container\Entry;
4
5
use Psr\Container\ContainerInterface;
6
7
/**
8
 * Container entry that uses a callable to determine the value for the entry.
9
 *
10
 * @author Riikka Kalliomäki <[email protected]>
11
 * @copyright Copyright (c) 2018 Riikka Kalliomäki
12
 * @license http://opensource.org/licenses/mit-license.php MIT License
13
 */
14
class CallableEntry implements EntryInterface
15
{
16
    /** @var callable The callable used to determine the value for the entry */
17
    private $callable;
18
19
    /**
20
     * CallableEntry constructor.
21
     * @param callable $callable The callable used to determine the value for the entry
22
     */
23 3
    public function __construct(callable $callable)
24
    {
25 3
        $this->callable = $callable;
26 3
    }
27
28
    /** {@inheritdoc} */
29 2
    public static function createFromCacheParameters(array $parameters): EntryInterface
30
    {
31 2
        return new static($parameters[0]);
32
    }
33
34
    /** {@inheritdoc} */
35 2
    public function getCacheParameters(): array
36
    {
37 2
        return [$this->callable];
38
    }
39
40
    /** {@inheritdoc} */
41 3
    public function isFactory(): bool
42
    {
43 3
        return false;
44
    }
45
46
    /** {@inheritdoc} */
47 3
    public function getValue(ContainerInterface $container)
48
    {
49 3
        return ($this->callable)($container);
50
    }
51
}
52