Completed
Pull Request — master (#160)
by
unknown
04:47
created

Loader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 37
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCache() 0 4 1
A clearCache() 0 4 1
A instantiateFixtures() 0 14 2
1
<?php
2
3
namespace Knp\FriendlyContexts\Alice\Fixtures;
4
5
use Knp\FriendlyContexts\Alice\ProviderResolver;
6
use Nelmio\Alice\Fixtures\Loader as BaseLoader;
7
8
class Loader extends BaseLoader
9
{
10
    private $cache = [];
11
12
    public function __construct($locale, ProviderResolver $providers)
13
    {
14
        parent::__construct($locale, $providers->all());
15
    }
16
17
    public function getCache()
18
    {
19
        return $this->cache;
20
    }
21
22
    public function clearCache()
23
    {
24
        $this->cache = [];
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function instantiateFixtures(array $fixtures)
31
    {
32
        parent::instantiateFixtures($fixtures);
33
34
        /** @var \Nelmio\Alice\Fixtures\Fixture $fixture */
35
        foreach ($fixtures as $fixture) {
36
            /** @var \Nelmio\Alice\Fixtures\PropertyDefinition $property */
37
            $spec = array_map(function ($property) {
38
                return $property->getValue();
39
            }, $fixture->getProperties());
40
41
            $this->cache[] = [ $spec, $this->objects->get($fixture->getName()) ];
42
        }
43
    }
44
}
45