Defines   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 31
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadFile() 0 8 2
A writeFile() 0 3 1
A buildRequires() 0 8 2
1
<?php
2
/**
3
 * Composer plugin for config assembling
4
 *
5
 * @link      https://github.com/hiqdev/composer-config-plugin
6
 * @package   composer-config-plugin
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\composer\config\configs;
12
13
/**
14
 * Defines class represents output configuration file with constant definitions.
15
 *
16
 * @author Andrii Vasyliev <[email protected]>
17
 *
18
 * @since php5.5
19
 */
20
class Defines extends Config
21
{
22
    protected function loadFile($path)
23
    {
24
        parent::loadFile($path);
25
        if (pathinfo($path, PATHINFO_EXTENSION) !== 'php') {
26
            return [];
27
        }
28
29
        return [$path];
30
    }
31
32
    public function buildRequires()
33
    {
34
        $res = [];
35
        foreach ($this->values as $path) {
36
            $res[] = "require_once '$path';";
37
        }
38
39
        return implode("\n", $res);
40
    }
41
42
    /**
43
     * @param string $path
44
     * @param array  $data
45
     * @throws \ReflectionException
46
     * @throws \hiqdev\composer\config\exceptions\FailedWriteException
47
     */
48
    protected function writeFile($path, array $data)
49
    {
50
        $this->writePhpFile($path, $this->buildRequires(), true, false);
51
    }
52
}
53