MixedEntry   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromCacheParameters() 0 3 1
A getCacheParameters() 0 3 1
A __construct() 0 3 1
A isFactory() 0 3 1
A getValue() 0 7 2
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