AbstractModule   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 7
Bugs 2 Features 3
Metric Value
wmc 6
c 7
b 2
f 3
lcom 1
cbo 1
dl 0
loc 75
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getModuleVersion() 0 3 1
A getModuleName() 0 3 1
A setConfig() 0 5 1
A getConfig() 0 3 1
A getAppConfig() 0 3 1
onConfigChange() 0 1 ?
onLoad() 0 1 ?
onRemove() 0 1 ?
1
<?php
2
3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2016 Alejandro Peña Florentín ([email protected]).
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
namespace Tight\Modules;
28
29
/**
30
 * AbstractModule class for creating Tight Framework modules
31
 *
32
 * @author Alejandro Peña Florentín ([email protected])
33
 */
34
abstract class AbstractModule
35
{
36
37
    /**
38
     * @var string Module name
39
     */
40
    private $moduleName;
41
42
    /**
43
     * @var string Module version
44
     */
45
    private $version;
46
47
    /**
48
     * @var \Tight\TightConfig Application settings
49
     */
50
    private $appConfig;
51
52
    /**
53
     * @var \Tight\BaseConfig Module configuration
54
     */
55
    private $moduleConfig;
56
57
    public function __construct($name, $version = "v1.0") {
58
        $this->moduleName = $name;
59
        $this->version = $version;
60
        $app = \Tight\Tight::getInstance();
61
        $this->appConfig = $app->getConfig();
62
    }
63
64
    public function getModuleVersion() {
65
        return $this->version;
66
    }
67
68
    /**
69
     * Gets the module name
70
     * @return string Module name
71
     */
72
    public function getModuleName() {
73
        return $this->moduleName;
74
    }
75
76
    /**
77
     * Sets the module configuration
78
     * @param \Tight\BaseConfig $conf Configuration
79
     * @return \Tight\Modules\AbstractModule Fluent setter
80
     */
81
    public function setConfig(\Tight\BaseConfig $conf) {
82
        $this->moduleConfig = $conf;
83
        $this->onConfigChange();
84
        return $this;
85
    }
86
87
    /**
88
     * Gets the module configuration
89
     * @return \Tight\BaseConfig Config
90
     */
91
    public function getConfig() {
92
        return $this->moduleConfig;
93
    }
94
95
    /**
96
     * Gets the application configuration
97
     * @return \Tight\TightConfig Tight app config
98
     */
99
    public function getAppConfig() {
100
        return $this->appConfig;
101
    }
102
103
    abstract public function onConfigChange();
104
105
    abstract public function onLoad();
106
107
    abstract public function onRemove();
108
}
109