Completed
Push — wip-platform ( 1b7118...2b724b )
by
unknown
03:32
created

BlastGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addResource() 0 17 2
1
<?php
2
3
/*
4
 * This file is part of the Blast Project package.
5
 *
6
 * Copyright (C) 2015-2017 Libre Informatique
7
 *
8
 * This file is licenced under the GNU LGPL v3.
9
 * For the full copyright and license information, please view the LICENSE.md
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Blast\Bundle\CoreBundle\Generator;
14
15
use Sensio\Bundle\GeneratorBundle\Generator\Generator;
16
use Sonata\AdminBundle\Model\ModelManagerInterface;
17
18
/**
19
 * Class BlastGenerator.
20
 */
21
class BlastGenerator extends Generator
22
{
23
    private $file;
24
25
    private $modelManager;
26
27
    /**
28
     * @param string $file
29
     */
30
    public function __construct($file, ModelManagerInterface $manager, $skeletonDirectories)
31
    {
32
        $this->file = (string) $file;
33
        $this->modelManager = $manager;
34
        $this->setSkeletonDirs($skeletonDirectories);
35
    }
36
37
    /**
38
     * @param string $modelClass
39
     *
40
     * @throws \RuntimeException
41
     */
42
    public function addResource($modelClass)
43
    {
44
        $code = '';
45
46
        if (is_file($this->file)) {
47
            $code = rtrim(file_get_contents($this->file));
48
        }
49
50
        $parts = explode('\\', $modelClass);
51
52
        $this->renderFile('Blast.yml.twig', $this->file, array(
53
            'fqcn'    => $modelClass,
54
            'fields'  => $this->modelManager->getExportFields($modelClass),
55
            'entity'  => array_pop($parts),
56
            'oldCode' => $code,
57
        ));
58
    }
59
}
60