Completed
Push — master ( ab8175...d69783 )
by Kamil
15s
created

LazySuiteRegistry   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 63
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addSuite() 0 4 1
A getSuite() 0 12 3
A getSuites() 0 9 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\FixturesBundle\Suite;
13
14
/**
15
 * @author Kamil Kokot <[email protected]>
16
 */
17
final class LazySuiteRegistry implements SuiteRegistryInterface
18
{
19
    /**
20
     * @var SuiteFactoryInterface
21
     */
22
    private $suiteFactory;
23
24
    /**
25
     * @var array
26
     */
27
    private $suiteDefinitions = [];
28
29
    /**
30
     * @var array
31
     */
32
    private $suites = [];
33
34
    /**
35
     * @param SuiteFactoryInterface $suiteFactory
36
     */
37
    public function __construct(SuiteFactoryInterface $suiteFactory)
38
    {
39
        $this->suiteFactory = $suiteFactory;
40
    }
41
42
    /**
43
     * @param string $name
44
     * @param array $configuration
45
     */
46
    public function addSuite($name, array $configuration)
47
    {
48
        $this->suiteDefinitions[$name] = $configuration;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getSuite($name)
55
    {
56
        if (isset($this->suites[$name])) {
57
            return $this->suites[$name];
58
        }
59
60
        if (!isset($this->suiteDefinitions[$name])) {
61
            throw new SuiteNotFoundException($name);
62
        }
63
64
        return $this->suites[$name] = $this->suiteFactory->createSuite($name, $this->suiteDefinitions[$name]);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function getSuites()
71
    {
72
        $suites = [];
73
        foreach (array_keys($this->suiteDefinitions) as $name) {
74
            $suites[$name] = $this->getSuite($name);
75
        }
76
77
        return $suites;
78
    }
79
}
80