Passed
Pull Request — master (#2)
by Riikka
02:22
created

FactoryEntry   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A isFactory() 0 3 1
A createFromCacheParameters() 0 10 1
A __construct() 0 3 1
A getCacheParameters() 0 5 1
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
        /** @var FactoryEntry $factory */
35 1
        $factory = (new \ReflectionClass(static::class))->newInstanceWithoutConstructor();
36 1
        $factory->entry = $class::createFromCacheParameters($cacheParameters);
37
38 1
        return $factory;
39
    }
40
41
    /** {@inheritdoc} */
42 1
    public function getCacheParameters(): array
43
    {
44
        return [
45 1
            \get_class($this->entry),
46 1
            $this->entry->getCacheParameters(),
47
        ];
48
    }
49
50
    /** {@inheritdoc} */
51 1
    public function isFactory(): bool
52
    {
53 1
        return true;
54
    }
55
56
    /** {@inheritdoc} */
57 1
    public function getValue(ContainerInterface $container)
58
    {
59 1
        return $this->entry->getValue($container);
60
    }
61
}
62