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

FixturesLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A addFixture() 0 10 2
A getFixtures() 0 4 1
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