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

Config   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 72
ccs 22
cts 22
cp 1
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 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