CallableEntry::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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