Completed
Push — master ( 4c7b9c...e919dc )
by Kamil
21:11
created

FixtureRegistry::getFixture()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
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\Fixture;
13
14
use Webmozart\Assert\Assert;
15
16
/**
17
 * @author Kamil Kokot <[email protected]>
18
 */
19
final class FixtureRegistry implements FixtureRegistryInterface
20
{
21
    /**
22
     * @var array
23
     */
24
    private $fixtures = [];
25
26
    /**
27
     * @param FixtureInterface $fixture
28
     */
29
    public function addFixture(FixtureInterface $fixture)
30
    {
31
        Assert::keyNotExists($this->fixtures, $fixture->getName(), 'Fixture with name "%s" is already registered.');
32
33
        $this->fixtures[$fixture->getName()] = $fixture;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getFixture($name)
40
    {
41
        if (!isset($this->fixtures[$name])) {
42
            throw new FixtureNotFoundException($name);
43
        }
44
45
        return $this->fixtures[$name];
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getFixtures()
52
    {
53
        return $this->fixtures;
54
    }
55
}
56