Theme   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 59
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 14 3
A name() 0 4 2
A find() 0 14 3
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Core
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Core".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core;
17
18
use Cake\Core\App;
19
use JBZoo\Utils\FS;
20
use Cake\Core\Configure;
21
22
/**
23
 * Class Theme
24
 *
25
 * @package Core
26
 */
27
class Theme extends \Core\Core\Plugin
28
{
29
30
    /**
31
     * Setup current theme.
32
     *
33
     * @param   null|string $prefix
34
     *
35
     * @return  null|string
36
     */
37
    public static function setup($prefix = null)
38
    {
39
        $theme = self::name($prefix);
40
        $path  = self::find($theme);
41
42
        if ($path !== null) {
43
            $config = self::getData($theme, 'meta');
44
            if ($config->get('type') == 'theme') {
45
                return $theme;
46
            }
47
        }
48
49
        return null;
50
    }
51
52
    /**
53
     * Get name by prefix.
54
     *
55
     * @param   string|null $prefix
56
     *
57
     * @return  mixed
58
     */
59
    public static function name($prefix = null)
60
    {
61
        return ($prefix == 'admin') ? Configure::read('Theme.admin') : Configure::read('Theme.site');
62
    }
63
64
    /**
65
     * Find theme plugin in path.
66
     *
67
     * @param   string $theme
68
     *
69
     * @return  null|string
70
     */
71
    public static function find($theme)
72
    {
73
        $paths = App::path('Plugin');
74
        foreach ($paths as $path) {
75
            $path = FS::clean($path . '/', DS);
76
            $themeFolder = $path . $theme;
77
78
            if (FS::isDir($themeFolder)) {
79
                return $themeFolder;
80
            }
81
        }
82
83
        return Configure::read('plugins.' . $theme);
84
    }
85
}
86