Test Failed
Push — master ( 38c078...235f8a )
by Mike
05:57
created

BuildModel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 53
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildModel() 0 17 6
A __construct() 0 8 1
1
<?php
2
3
4
namespace Xervice\Database\Business\Model;
5
6
7
use Symfony\Component\Finder\Finder;
8
use Xervice\Database\Provider\PropelCommandProviderInterface;
9
10
class BuildModel implements BuildModelInterface
11
{
12
    /**
13
     * @var \Xervice\Database\Provider\PropelCommandProviderInterface
14
     */
15
    private $propelCommandProvider;
16
17
    /**
18
     * @var array
19
     */
20
    private $schemaPaths;
21
22
    /**
23
     * @var string
24
     */
25
    private $schemaTarget;
26
27
    /**
28
     * BuildModel constructor.
29
     *
30
     * @param \Xervice\Database\Provider\PropelCommandProviderInterface $propelCommandProvider
31
     * @param array $schemaPaths
32
     */
33 1
    public function __construct(
34
        PropelCommandProviderInterface $propelCommandProvider,
35
        array $schemaPaths,
36
        string $schemaTarget
37
    ) {
38 1
        $this->propelCommandProvider = $propelCommandProvider;
39 1
        $this->schemaPaths = $schemaPaths;
40 1
        $this->schemaTarget = $schemaTarget;
41 1
    }
42
43
    /**
44
     *
45
     */
46 1
    public function buildModel()
47
    {
48 1
        if (!is_dir($this->schemaTarget)) {
49 1
            if (!mkdir($this->schemaTarget, 0777) && !is_dir($this->schemaTarget)) {
50
                throw new \RuntimeException(sprintf('Directory "%s" was not created', $this->schemaTarget));
51
            }
52
        }
53
54 1
        foreach ($this->schemaPaths as $schemaPath) {
55 1
            $finder = new Finder();
56 1
            $finder->files()->name('*.schema.xml')->in($schemaPath);
57 1
            foreach ($finder as $schemaFile) {
58 1
                copy($schemaFile->getRealPath(), $this->schemaTarget . '/' . basename($schemaFile->getRealPath()));
59
            }
60
        }
61
62 1
        $this->propelCommandProvider->execute('model:build');
63
    }
64
}