GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 9c3470...c852c0 )
by
unknown
02:52
created

Theme::getPresets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System PHP Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Framework\Datastructures\Module;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Framework\Datastructures\Module\Theme\Layout;
19
use O2System\Spl\Datastructures\SplArrayObject;
20
use O2System\Spl\Info\SplDirectoryInfo;
21
use O2System\Spl\Info\SplFileInfo;
22
23
/**
24
 * Class Theme
25
 *
26
 * @package O2System\Framework\Datastructures\Metadata
27
 */
28
class Theme extends SplDirectoryInfo
29
{
30
    /**
31
     * Theme Properties
32
     *
33
     * @var array
34
     */
35
    private $properties = [];
36
37
    /**
38
     * Theme Presets
39
     *
40
     * @var array
41
     */
42
    private $presets = [];
43
44
    /**
45
     * Theme Layout
46
     *
47
     * @var SplFileInfo
48
     */
49
    private $layout;
50
51
    /**
52
     * Theme::__construct
53
     *
54
     * @param string $dir
55
     */
56
    public function __construct($dir)
57
    {
58
        parent::__construct($dir);
59
60
        // Set Theme Properties
61
        if (is_file($propFilePath = $dir . 'theme.json')) {
62
            $properties = json_decode(file_get_contents($propFilePath), true);
63
64
            if (json_last_error() === JSON_ERROR_NONE) {
65
                if(isset($properties['config'])) {
66
                    $this->presets = $properties['presets'];
67
                    unset($properties['presets']);
68
                }
69
70
                $this->properties = $properties;
71
            }
72
        }
73
    }
74
75
    public function isValid()
76
    {
77
        if (count($this->properties)) {
78
            return true;
79
        }
80
81
        return false;
82
    }
83
84
    public function getParameter()
85
    {
86
        return $this->getDirName();
87
    }
88
89
    public function getCode()
90
    {
91
        return strtoupper(substr(md5($this->getDirName()), 2, 7));
92
    }
93
94
    public function getChecksum()
95
    {
96
        return md5($this->getMTime());
97
    }
98
99
    public function getProperties()
100
    {
101
        return new SplArrayObject($this->properties);
102
    }
103
104
    public function getPresets()
105
    {
106
        return new SplArrayObject($this->presets);
107
    }
108
109
    public function getUrl($path = null)
110
    {
111
        return path_to_url($this->getRealPath() . $path);
112
    }
113
114
    public function getLayout($layout = null)
115
    {
116
        if (isset($layout)) {
117
            if (false !== ($layout = $this->loadLayout($layout))) {
118
                return $layout;
119
            }
120
        }
121
122
        if ($this->layout instanceof Layout) {
123
            return $this->layout;
124
        }
125
126
        return false;
127
    }
128
129
    public function setLayout($layout)
130
    {
131
        if (false !== ($layout = $this->loadLayout($layout))) {
132
            $this->layout = $layout;
133
134
            // add theme layout public directory
135
            loader()->addPublicDir($this->layout->getPath() . 'assets');
136
137
            presenter()->assets->autoload(
0 ignored issues
show
Bug Best Practice introduced by
The property assets does not exist on O2System\Framework\Http\Presenter. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method autoload() does not exist on null. ( Ignorable by Annotation )

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

137
            presenter()->assets->/** @scrutinizer ignore-call */ 
138
                                 autoload(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
138
                [
139
                    'css' => ['layout'],
140
                    'js'  => ['layout'],
141
                ]
142
            );
143
144
            $partials = $this->layout->getPartials()->getArrayCopy();
145
146
            foreach ($partials as $offset => $partial) {
147
                presenter()->partials->addPartial($offset, $partial->getPathName());
0 ignored issues
show
Bug Best Practice introduced by
The property partials does not exist on O2System\Framework\Http\Presenter. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method addPartial() does not exist on null. ( Ignorable by Annotation )

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

147
                presenter()->partials->/** @scrutinizer ignore-call */ 
148
                                       addPartial($offset, $partial->getPathName());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
148
            }
149
150
            return true;
151
        }
152
153
        return false;
154
    }
155
156
    protected function loadLayout($layout)
157
    {
158
        $extensions = ['.php', '.phtml', '.html', '.tpl'];
159
160
        if (isset($this->presets[ 'extensions' ])) {
161
            array_unshift($partialsExtensions, $this->presets[ 'extension' ]);
162
        } elseif (isset($this->presets[ 'extension' ])) {
163
            array_unshift($extensions, $this->presets[ 'extension' ]);
164
        }
165
166
        foreach ($extensions as $extension) {
167
168
            $extension = trim($extension, '.');
169
170
            if ($layout === 'theme') {
171
                $layoutFilePath = $this->getRealPath() . 'theme.' . $extension;
172
            } else {
173
                $layoutFilePath = $this->getRealPath() . 'layouts' . DIRECTORY_SEPARATOR . dash($layout) . DIRECTORY_SEPARATOR . 'layout.' . $extension;
174
            }
175
176
            if (is_file($layoutFilePath)) {
177
                return new Layout($layoutFilePath);
178
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
179
            }
180
        }
181
182
        return false;
183
    }
184
}