Completed
Push — master ( c4f7f5...ee49f4 )
by Alejandro
04:40
created

TightConfig::__construct()   C

Complexity

Conditions 7
Paths 48

Size

Total Lines 24
Code Lines 16

Duplication

Lines 8
Ratio 33.33 %

Importance

Changes 4
Bugs 1 Features 3
Metric Value
c 4
b 1
f 3
dl 8
loc 24
rs 6.7272
cc 7
eloc 16
nc 48
nop 1
1
<?php
2
3
namespace Tight;
4
5
/*
6
 * The MIT License
7
 *
8
 * Copyright 2016 Alejandro Peña Florentín ([email protected]).
9
 *
10
 * Permission is hereby granted, free of charge, to any person obtaining a copy
11
 * of this software and associated documentation files (the "Software"), to deal
12
 * in the Software without restriction, including without limitation the rights
13
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
 * copies of the Software, and to permit persons to whom the Software is
15
 * furnished to do so, subject to the following conditions:
16
 *
17
 * The above copyright notice and this permission notice shall be included in
18
 * all copies or substantial portions of the Software.
19
 *
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
 * THE SOFTWARE.
27
 */
28
29
/**
30
 * TightConfig class
31
 *
32
 * @author Alejandro Peña Florentín ([email protected])
33
 */
34
class TightConfig
35
{
36
37
    /**
38
     * @var string Application base path
39
     */
40
    public $basePath = null;
41
42
    /**
43
     * @var array Smarty settings
44
     */
45
    public $smarty = [
46
        "template_dir" => "./templates",
47
        "compile_dir" => "./templates_c",
48
        "config_dir" => "./configs",
49
        "cache_dir" => "./cache"
50
    ];
51
52
    /**
53
     * @var array Router settings
54
     */
55
    public $router = [
56
        "mvc" => [
57
            "enable" => false,
58
            "index" => "Root",
59
        ]
60
    ];
61
62
    /**
63
     * @var array MVC settings
64
     */
65
    public $mvc = [
66
        "enaleRouter" => false,
67
        "indexName"=> "Root",
68
        "controller_dir" => "./controllers/",
69
        "model_dir" => "./models/",
70
        "view_dir" => "./views/",
71
    ];
72
73
    /**
74
     * Constructor
75
     * 
76
     * Settings can be passed as an array
77
     * @param array $config Settings
78
     */
79
    public function __construct(array $config = []) {
80
        if (isset($config['basePath'])) {
81
            $this->basePath = $config['basePath'];
82
            unset($config['basePath']);
83
        }
84
        if (isset($config["smarty"])) {
85
            $this->smarty = array_replace_recursive($this->smarty, $config["smarty"]);
86
            unset($config["smarty"]);
87
        }
88 View Code Duplication
        if (isset($config["router"])) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
            $this->router = array_replace_recursive($this->router, $config["router"]);
90
            unset($config['router']);
91
        }
92 View Code Duplication
        if (isset($config["mvc"])) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
            $this->mvc = array_replace_recursive($this->mvc, $config["mvc"]);
94
            unset($config["mvc"]);
95
        }
96
        // Creates custom config
97
        if (count($config) > 0) {
98
            foreach ($config as $key => $value) {
99
                $this->$key = $value;
100
            }
101
        }
102
    }
103
104
}
105