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

ArrayToYamlGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A generate() 0 15 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