Completed
Push — master ( e44765...ab86c3 )
by Andrii
04:18
created

Builder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assembleFile() 0 5 1
A writeFile() 0 9 2
1
<?php
2
3
/*
4
 * Composer plugin for config assembling
5
 *
6
 * @link      https://github.com/hiqdev/composer-config-plugin
7
 * @package   composer-config-plugin
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\composer\config;
13
14
/**
15
 * Builder assembles config files.
16
 *
17
 * @author Andrii Vasyliev <[email protected]>
18
 */
19
class Builder
20
{
21
    /**
22
     * @var array list of configs to build: name => array of pathes
23
     */
24
    public $configs = [];
25
26
27
    const BASE_DIR_SAMPLE = '<base-dir>';
28
29
    protected function assembleFile($name, array $configs)
30
    {
31
        $this->data[$name] = call_user_func_array(['\\hiqdev\\composer\\config\\Helper', 'mergeConfig'], $configs);
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
        $this->writeFile($name, (array) $this->data[$name]);
33
    }
34
35
    /**
36
     * Writes config file.
37
     * @param string $path
38
     * @param array $data
39
     */
40
    protected function writeFile($path, array $data)
41
    {
42
        $path = $this->buildOutputPath($path);
0 ignored issues
show
Bug introduced by
The method buildOutputPath() does not seem to exist on object<hiqdev\composer\config\Builder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
        if (!file_exists(dirname($path))) {
44
            mkdir(dirname($path), 0777, true);
45
        }
46
        $array = str_replace("'" . self::BASE_DIR_SAMPLE, '$baseDir . \'', Helper::exportVar($data));
47
        file_put_contents($path, "<?php\n\n\$baseDir = dirname(dirname(dirname(__DIR__)));\n\nreturn $array;\n");
48
    }
49
50
}
51