ConfigInit   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 13

5 Methods

Rating   Name   Duplication   Size   Complexity  
A directConfig() 0 8 5
A runConfig() 0 7 2
A laravelConfig() 0 6 1
A generalConfig() 0 8 1
A setConfig() 0 11 4
1
<?php
2
/* 
3
	Author: Irfa Ardiansyah <[email protected]>
4
*/
5
namespace Irfa\SerialNumber\Core;
6
7
class ConfigInit
8
{
9
    protected $length;
10
    protected $segment;
11
    protected $seperator;
12
    protected $charset;
13
14
    protected function runConfig($config_array=null)
15
    {
16
        if(empty($config_array))
17
        {
18
            $this->setConfig();
19
        } else {
20
            $this->directConfig($config_array);
21
        }
22
    }
23
24
    private function setConfig()
25
    {
26
         if (function_exists('config') and function_exists('app')) {//Load Config For Laravel
27
            if(!empty(config('irfa.serial_number'))) 
28
            {
29
                $this->laravelConfig();
30
            } else{
31
                $this->generalConfig();
32
            }
33
       } else{//Load Config for Non-Laravel
34
            $this->generalConfig();
35
       }
36
    }
37
    private function laravelConfig()
38
    {
39
        $this->length       = config('irfa.serial_number.length');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        $this->length       = /** @scrutinizer ignore-call */ config('irfa.serial_number.length');
Loading history...
40
        $this->segment      = config('irfa.serial_number.segment');
41
        $this->seperator    = config('irfa.serial_number.seperator'); 
42
        $this->charset      = config('irfa.serial_number.charset'); 
43
    }
44
45
    private function generalConfig()
46
    {
47
        require dirname(__DIR__, 2)."/config/config.php";
48
49
        $this->length       = $config['length'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $config seems to be never defined.
Loading history...
50
        $this->segment      = $config['segment'];
51
        $this->seperator    = $config['seperator']; 
52
        $this->charset      = $config['charset']; 
53
    }
54
55
    private function directConfig($arr)
56
    {
57
        require dirname(__DIR__, 2)."/config/config.php";
58
59
        $this->length       = isset($arr['length']) ? $arr['length']:$config['length'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $config seems to be never defined.
Loading history...
60
        $this->segment      = isset($arr['segment']) ? $arr['segment']:$config['segment'];
61
        $this->seperator    = isset($arr['seperator']) ? $arr['seperator']:$config['seperator']; 
62
        $this->charset      = isset($arr['charset']) ? $arr['charset']:$config['charset']; 
63
    }
64
65
}
66
67