FactoryEntry::createFromCacheParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
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
 * Provides a wrapper for other entries to disallow caching of returned values.
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 FactoryEntry implements EntryInterface
15
{
16
    /** @var EntryInterface The actual container entry used to determine the value */
17
    private $entry;
18
19
    /**
20
     * FactoryType constructor.
21
     * @param EntryInterface $type The actual container entry used to determine the value
22
     */
23 1
    public function __construct(EntryInterface $type)
24
    {
25 1
        $this->entry = $type;
26 1
    }
27
28
    /** {@inheritdoc} */
29 1
    public static function createFromCacheParameters(array $parameters): EntryInterface
30
    {
31
        /** @var EntryInterface $class */
32 1
        [$class, $cacheParameters] = $parameters;
33
34 1
        return new static($class::createFromCacheParameters($cacheParameters));
35
    }
36
37
    /** {@inheritdoc} */
38 1
    public function getCacheParameters(): array
39
    {
40
        return [
41 1
            \get_class($this->entry),
42 1
            $this->entry->getCacheParameters(),
43
        ];
44
    }
45
46
    /** {@inheritdoc} */
47 1
    public function isFactory(): bool
48
    {
49 1
        return true;
50
    }
51
52
    /** {@inheritdoc} */
53 1
    public function getValue(ContainerInterface $container)
54
    {
55 1
        return $this->entry->getValue($container);
56
    }
57
}
58