Completed
Push — master ( dbfa6d...65a5eb )
by Bernhard
16s queued 12s
created

DotEnvConfiguration::env()   C

Complexity

Conditions 12
Paths 11

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 0
cts 25
cp 0
rs 6.9666
c 0
b 0
f 0
cc 12
nc 11
nop 2
crap 156

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * \Wicked\Timely\DotEnvConfiguration
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * This source file is subject to the Open Software License (OSL 3.0)
8
 * that is available through the world-wide-web at this URL:
9
 * http://opensource.org/licenses/osl-3.0.php
10
 *
11
 * PHP version 5
12
 *
13
 * @author    wick-ed
14
 * @copyright 2020 Bernhard Wick
15
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
 * @link      https://github.com/wick-ed/timely
17
 */
18
19
namespace Wicked\Timely;
20
21
use JiraRestApi\Configuration\DotEnvConfiguration as JiraDotEnvConfiguration;
22
23
/**
24
 * DotEnvConfiguration class file
25
 *
26
 * @author    wick-ed
27
 * @copyright 2020 Bernhard Wick
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/wick-ed/timely
30
 */
31
class DotEnvConfiguration extends JiraDotEnvConfiguration
32
{
33
34
    protected $pushService;
35
36
    /**
37
     * DotEnvConfiguration constructor.
38
     *
39
     * @param string $path Path to the configuration file
40
     *
41
     * @throws \JiraRestApi\JiraException
42
     */
43
    public function __construct($path = '.')
44
    {
45
        parent::__construct(realpath(__DIR__ . '/../'));
46
        $this->pushService = $this->env('PUSH_SERVICE');
47
    }
48
49
    /**
50
     * Gets the value of an environment variable. Supports boolean, empty and null.
51
     *
52
     * @param string $key
53
     * @param mixed  $default
54
     *
55
     * @return mixed
56
     */
57
    protected function env($key, $default = null)
58
    {
59
        $value = getenv($key);
60
61
        if ($value === false) {
62
            return $default;
63
        }
64
65
        switch (strtolower($value)) {
66
            case 'true':
67
            case '(true)':
68
                return true;
69
70
            case 'false':
71
            case '(false)':
72
                return false;
73
74
            case 'empty':
75
            case '(empty)':
76
                return '';
77
78
            case 'null':
79
            case '(null)':
80
                return;
81
        }
82
83
        if ($this->startsWith($value, '"') && $this->endsWith($value, '"')) {
84
            return substr($value, 1, -1);
85
        }
86
87
        return $value;
88
    }
89
90
    /**
91
     * @return mixed
92
     */
93
    public function getPushService()
94
    {
95
        return $this->pushService;
96
    }
97
98
    /**
99
     * Setter for the jira password configuration
100
     *
101
     * @param string $value Password value to set
102
     *
103
     * @return void
104
     */
105
    public function setJiraPassword($value)
106
    {
107
        $this->jiraPassword = $value;
108
    }
109
}
110