Completed
Push — master ( 5bb9e4...33b9a4 )
by Serhii
09:16 queued 09:08
created

FixturesLoader::getFixtures()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace AppBundle\DataFixtures\ORM;
4
5
class FixturesLoader extends LoadData
6
{
7
    const FIXTURES_EXT = 'yml';
8
9
    /** @var array */
10
    private $fixturesPaths = [];
11
12
    /** @var  string */
13
    private $fixtureSourceDir;
14
15
    public function __construct($dir = null)
16
    {
17
        $dirName = empty($dir) ? '' : $dir.DIRECTORY_SEPARATOR;
18
        $this->fixtureSourceDir = __DIR__.DIRECTORY_SEPARATOR.$dirName;
19
    }
20
21
    /**
22
     * @param string $fixtureName
23
     *
24
     * @throws \Exception
25
     */
26
    public function addFixture(string $fixtureName)
27
    {
28
        $fixturePath = sprintf('%s%s.%s', $this->fixtureSourceDir, $fixtureName, self::FIXTURES_EXT);
29
30
        if (!file_exists($fixturePath)) {
31
            throw new \Exception("Fixture path not found: {$fixturePath}");
32
        }
33
34
        $this->fixturesPaths[] = $fixturePath;
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    protected function getFixtures()
41
    {
42
        return $this->fixturesPaths;
43
    }
44
}
45