Completed
Push — master ( 3b1951...58d3fb )
by Lexey
02:23
created

Config::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 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 11
    public function __construct($dist = self::DEFAULT_DIST, $target = self::DEFAULT_TARGET, $keepOutdatedEnv = true)
27
    {
28 11
        $this->dist            = $dist;
29 11
        $this->target          = $target;
30 11
        $this->keepOutdatedEnv = $keepOutdatedEnv;
31 11
    }
32
33
    /**
34
     * @param array $config
35
     *
36
     * @return static
37
     */
38 11
    public static function createFormArray(array $config = [])
39
    {
40 11
        if (empty($config['target'])) {
41 2
            $config['target'] = '.env';
42 2
        }
43 11
        if (empty($config['dist'])) {
44 3
            $config['dist'] = $config['target'] . '.dist';
45 3
        }
46 11
        if (!isset($config['keep-outdated'])) {
47 10
            $config['keep-outdated'] = true;
48 10
        }
49
50 11
        return new static($config['dist'], $config['target'], (bool) $config['keep-outdated']);
51
    }
52
53
    /**
54
     * @return string
55
     */
56 30
    public function getDist()
57
    {
58 30
        return $this->dist;
59
    }
60
61
    /**
62
     * @return string
63
     */
64 30
    public function getTarget()
65
    {
66 30
        return $this->target;
67
    }
68
69
    /**
70
     * @return boolean
71
     */
72 17
    public function isKeepOutdatedEnv()
73
    {
74 17
        return $this->keepOutdatedEnv;
75
    }
76
}
77