MixedEntry::getCacheParameters()   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 0
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
 * A standard container entry that may be any value or a closure used to determine that value.
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 MixedEntry implements EntryInterface
15
{
16
    /** @var mixed The value for the entry */
17
    private $value;
18
19
    /**
20
     * MixedType constructor.
21
     * @param mixed $value The value for the entry
22
     */
23 12
    public function __construct($value)
24
    {
25 12
        $this->value = $value;
26 12
    }
27
28
    /** {@inheritdoc} */
29 3
    public static function createFromCacheParameters(array $parameters): EntryInterface
30
    {
31 3
        return new static($parameters[0]);
32
    }
33
34
    /** {@inheritdoc} */
35 5
    public function getCacheParameters(): array
36
    {
37 5
        return [$this->value];
38
    }
39
40
    /** {@inheritdoc} */
41 9
    public function isFactory(): bool
42
    {
43 9
        return false;
44
    }
45
46
    /** {@inheritdoc} */
47 9
    public function getValue(ContainerInterface $container)
48
    {
49 9
        if ($this->value instanceof \Closure) {
50 2
            return ($this->value)($container);
51
        }
52
53 8
        return $this->value;
54
    }
55
}
56