Config   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 51
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0
wmc 12

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 4
A getDefaults() 0 7 4
A checkKey() 0 5 4
1
<?php
2
namespace Sender\Config;
3
4
use Noodlehaus\Config as Nood;
5
use Noodlehaus\AbstractConfig;
6
7
/**
8
 * Default Config file
9
 *
10
 * @package    Sender\Config\Config
11
 * @author     VenkatS <[email protected]>
12
 * @link       https://github.com/tesark/msg91-php
13
 * @license    MIT
14
 */
15
16
class Config extends AbstractConfig// pending
17
{
18
    private $common;
19
    private $hasTransAuth;
20
    private $hasPromoAuth;
21
    private $hasOtpAuth;
22
    public function __construct()
23
    {
24
        $file = $_SERVER["DOCUMENT_ROOT"].'/../config';
25
        if (file_exists($file)) {
26
            $config = new Nood($file);
27
            if (isset($config['msg91'])) {
28
                if ($this->checkKey('common', $config['msg91'])) {
29
                    $this->common = $config['msg91']['common'];
30
                    //Check Config file variable present
31
                    $this->hasTransAuth = $this->checkKey('transAuthKey', $this->common);
32
                    $this->hasPromoAuth = $this->checkKey('promoAuthKey', $this->common);
33
                    $this->hasOtpAuth = $this->checkKey('otpAuthKey', $this->common);
34
                }
35
            }
36
        } else {
37
            return false;
38
        }
39
    }
40
    /*
41
     * This function return Default and Env file Values
42
     *
43
     */
44
    public function getDefaults()
45
    {
46
        return array(
47
            'common' => [
48
                'transAuthKey' => getenv('TRANSAUTHKEY') ? (string) getenv('TRANSAUTHKEY') : $this->hasTransAuth,
49
                'promoAuthKey' => getenv('PROMOAUTHKEY') ? (string) getenv('PROMOAUTHKEY') : $this->hasPromoAuth,
50
                'otpAuthKey'   => getenv('OTPAUTHKEY') ? (string) getenv('OTPAUTHKEY') : $this->hasOtpAuth,
51
            ],
52
        );
53
    }
54
    /**
55
     * This function check key present in array
56
     *
57
     * @param string $key Array key value
58
     * @param array  $array Check array
59
     *
60
     * @return string Return array value
61
     */
62
    protected function checkKey($key, $array)
63
    {
64
        if (isset($key) && is_array($array)) {
65
            if (array_key_exists($key, $array)) {
66
                return $array[$key];
67
            }
68
        }
69
    }
70
}
71