Checks   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 154
rs 10
c 1
b 0
f 0
wmc 12
lcom 1
cbo 3

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A _validate() 0 13 2
A setTemplate() 0 10 1
A existance() 0 22 3
A dirname() 0 7 1
A result() 0 16 4
1
<?php
2
3
/**
4
 * Contains some tools to check themes with
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Core
9
 * @package   Themes
10
 * @author    Hans-Joachim Piepereit <[email protected]>
11
 * @copyright 2013 cSphere Team
12
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
13
 * @link      http://www.csphere.eu
14
 **/
15
16
namespace csphere\core\themes;
17
18
/**
19
 * Contains some tools to check themes with
20
 *
21
 * @category  Core
22
 * @package   Themes
23
 * @author    Hans-Joachim Piepereit <[email protected]>
24
 * @copyright 2013 cSphere Team
25
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
26
 * @link      http://www.csphere.eu
27
 **/
28
29
class Checks
30
{
31
    /**
32
     * Theme that will be used
33
     **/
34
    private $_theme = '';
35
36
    /**
37
     * Local path
38
     **/
39
    private $_path = '';
40
41
    /**
42
     * File that will be used
43
     **/
44
    private $_file = '';
45
46
    /**
47
     * Remember positive existance checks
48
     **/
49
    private $_existance = false;
50
51
    /**
52
     * Get theme to see if it exists
53
     *
54
     * @param string $theme Name of theme
55
     *
56
     * @return \csphere\core\themes\Checks
57
     **/
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
58
59
    public function __construct($theme)
60
    {
61
        $this->_path = \csphere\core\init\path();
62
63
        $this->_theme = $theme;
64
65
        // Check theme details
66
        $this->_validate();
67
68
        $this->_file = 'csphere/themes/' . $this->_theme . '/index.htm';
69
    }
70
71
    /**
72
     * Check if plugin is valid
73
     *
74
     * @throws \Exception
75
     *
76
     * @return void
77
    **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
78
79
    private function _validate()
80
    {
81
        $meta = new \csphere\core\themes\Metadata();
82
83
        $exists = $meta->exists($this->_theme);
84
85
        if ($exists == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
86
87
            $msg = 'Theme not found: "' . $this->_theme . '"';
88
89
            throw new \Exception($msg);
90
        }
91
    }
92
93
    /**
94
     * Set target for template files
95
     *
96
     * @param string $target Name of target
97
     * @param string $plugin Name of plugin
98
     *
99
     * @return void
100
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
101
102
    public function setTemplate($target, $plugin)
103
    {
104
105
        $metadata=new \csphere\core\plugins\metadata();
106
        $type=$metadata->templateType($plugin, $target);
107
108
        $this->_file = 'csphere/themes/' . $this->_theme
109
                     . '/templates/' . $plugin . '/' . $type. '/' . $target . '.tpl';
110
111
    }
112
113
    /**
114
     * Checks if the target file exists
115
     *
116
     * @return boolean
117
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
118
119
    public function existance()
120
    {
121
        $result = false;
122
123
        // Check for file existance if not done already
124
        if ($this->_existance == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
125
126
            $result = true;
127
        } else {
128
129
            $target = $this->_path . $this->_file;
130
131
            // File must set before
132
            if (file_exists($target)) {
133
134
                $this->_existance = true;
135
                $result           = true;
136
            }
137
        }
138
139
        return $result;
140
    }
141
142
    /**
143
     * Dirname for external theme path
144
     *
145
     * @return string
146
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
147
148
    public function dirname()
149
    {
150
        $target = \csphere\core\http\Request::get('dirname')
151
                . 'csphere/themes/' . $this->_theme . '/';
152
153
        return $target;
154
    }
155
156
    /**
157
     * Replies with the target file
158
     *
159
     * @param boolean $path Append local path which defaults to true
160
     *
161
     * @throws \Exception
162
     *
163
     * @return string
164
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
165
166
    public function result($path = true)
167
    {
168
        $exists = $this->existance();
169
170
        // File must be there to return its origin
171
        if ($exists == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
172
173
            throw new \Exception('Theme target not found: "' . $this->_file . '"');
174
175
        } else {
176
177
            $place = ($path == true) ? $this->_path . $this->_file :  $this->_file;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
178
        }
179
180
        return isset($place) ? $place : '';
181
    }
182
}
183