Completed
Push — wip-platform ( c33bec...2d2054 )
by
unknown
03:47
created

ArrayToYamlGenerator::generate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
/*
4
 *
5
 * Copyright (C) 2015-2017 Libre Informatique
6
 *
7
 * This file is licenced under the GNU LGPL v3.
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Blast\Bundle\CoreBundle\Generator;
13
14
use Sensio\Bundle\GeneratorBundle\Generator\Generator;
15
16
/**
17
 * Class ArrayToYamlGenerator.
18
 */
19
class ArrayToYamlGenerator extends Generator
20
{
21
    private $file;
22
23
    /**
24
     * @param string $file
25
     */
26
    public function __construct($file, $skeletonDirectories)
27
    {
28
        $this->file = $file;
29
        $this->setSkeletonDirs($skeletonDirectories);
30
    }
31
32
    /**
33
     * @param string $array
34
     *
35
     * @throws \RuntimeException
36
     */
37
    public function generate($array, $skeleton)
38
    {
39
        $parts = explode('.', $this->file->getPathName());
0 ignored issues
show
Bug introduced by
The method getPathName cannot be called on $this->file (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
40
        array_pop($parts);
41
42
        $file = implode('.', $parts) . '.yml';
43
44
        if (file_exists($file)) {
45
            return;
46
        }
47
48
        $this->renderFile($skeleton, $file, array(
49
            'array' => $array,
50
        ));
51
    }
52
}
53