Test Failed
Push — master ( e387ef...0464de )
by Lexey
03:14
created

Config   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 72
ccs 6
cts 21
cp 0.2857
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createFormArray() 0 14 4
A getDist() 0 4 1
A getTarget() 0 4 1
A isKeepOutdatedEnv() 0 4 1
1
<?php
2
3
namespace LF\EnvDiff;
4
5
class Config
6
{
7
    const DEFAULT_TARGET = '.env';
8
    CONST DEFAULT_DIST   = '.env.dist';
9
10
    /** @var string */
11
    private $dist;
12
13
    /** @var string */
14
    private $target;
15
16
    /** @var bool */
17
    private $keepOutdatedEnv;
18
19
    /**
20
     * Config constructor.
21
     *
22
     * @param string $dist
23
     * @param string $target
24
     * @param bool   $keepOutdatedEnv
25
     */
26
    public function __construct($dist = self::DEFAULT_DIST, $target = self::DEFAULT_TARGET, $keepOutdatedEnv = true)
27
    {
28
        $this->dist            = $dist;
29
        $this->target          = $target;
30
        $this->keepOutdatedEnv = $keepOutdatedEnv;
31
    }
32
33
    /**
34
     * @param array $config
35
     *
36
     * @return static
37
     */
38
    public static function createFormArray(array $config = [])
39
    {
40
        if (empty($config['target'])) {
41
            $config['target'] = '.env';
42
        }
43
        if (empty($config['dist'])) {
44 13
            $config['dist'] = $config['target'] . '.dist';
45
        }
46 13
        if (!isset($config['keep-outdated'])) {
47
            $config['keep-outdated'] = true;
48
        }
49
50
        return new static($config['dist'], $config['target'], (bool) $config['keep-outdated']);
51
    }
52 13
53
    /**
54 13
     * @return string
55
     */
56
    public function getDist()
57
    {
58
        return $this->dist;
59
    }
60 12
61
    /**
62 12
     * @return string
63
     */
64
    public function getTarget()
65
    {
66
        return $this->target;
67
    }
68
69
    /**
70
     * @return boolean
71
     */
72
    public function isKeepOutdatedEnv()
73
    {
74
        return $this->keepOutdatedEnv;
75
    }
76
}
77