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 ( a1835d...10e84a )
by
unknown
02:48
created

Widget   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 135
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 135
rs 10
c 0
b 0
f 0
wmc 13

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getNamespace() 0 12 2
A getParameter() 0 3 1
A getChecksum() 0 3 1
A getProperties() 0 3 1
A isValid() 0 7 2
A __construct() 0 15 4
A getCode() 0 3 1
A getPresets() 0 3 1
1
<?php
2
/**
3
 * This file is part of the O2System 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\Containers\Modules\DataStructures\Module;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Spl\DataStructures\SplArrayObject;
19
use O2System\Spl\Info\SplDirectoryInfo;
20
21
/**
22
 * Class Widget
23
 *
24
 * @package O2System\Framework\Containers\Modules\DataStructures\Module
25
 */
26
class Widget extends SplDirectoryInfo
27
{
28
    /**
29
     * Widget::$properties
30
     *
31
     * @var array
32
     */
33
    private $properties = [];
34
35
    /**
36
     * Widget::$presets
37
     *
38
     * @var array
39
     */
40
    private $presets = [];
41
42
    /**
43
     * Widget::__construct
44
     *
45
     * @param string $dir
46
     */
47
    public function __construct($dir)
48
    {
49
        parent::__construct($dir);
50
51
        // Set Widget Properties
52
        if (is_file($propFilePath = $dir . 'widget.json')) {
53
            $properties = json_decode(file_get_contents($propFilePath), true);
54
55
            if (json_last_error() === JSON_ERROR_NONE) {
56
                if (isset($properties[ 'config' ])) {
57
                    $this->presets = $properties[ 'presets' ];
58
                    unset($properties[ 'presets' ]);
59
                }
60
61
                $this->properties = $properties;
62
            }
63
        }
64
    }
65
66
    // ------------------------------------------------------------------------
67
68
    /**
69
     * Widget::isValid
70
     *
71
     * @return bool
72
     */
73
    public function isValid()
74
    {
75
        if (count($this->properties)) {
76
            return true;
77
        }
78
79
        return false;
80
    }
81
82
    // ------------------------------------------------------------------------
83
84
    /**
85
     * Widget::getParameter
86
     *
87
     * @return string
88
     */
89
    public function getParameter()
90
    {
91
        return $this->getDirName();
92
    }
93
94
    // ------------------------------------------------------------------------
95
96
    /**
97
     * Widget::getCode
98
     *
99
     * @return string
100
     */
101
    public function getCode()
102
    {
103
        return strtoupper(substr(md5($this->getDirName()), 2, 7));
104
    }
105
106
    // ------------------------------------------------------------------------
107
108
    /**
109
     * Widget::getChecksum
110
     *
111
     * @return string
112
     */
113
    public function getChecksum()
114
    {
115
        return md5($this->getMTime());
116
    }
117
118
    // ------------------------------------------------------------------------
119
120
    /**
121
     * Widget::getProperties
122
     *
123
     * @return \O2System\Spl\DataStructures\SplArrayObject
124
     */
125
    public function getProperties()
126
    {
127
        return new SplArrayObject($this->properties);
128
    }
129
130
    // ------------------------------------------------------------------------
131
132
    /**
133
     * Widget::getNamespace
134
     *
135
     * @return mixed|string
136
     */
137
    public function getNamespace()
138
    {
139
        if (isset($this->properties[ 'namespace' ])) {
140
            return $this->properties[ 'namespace' ];
141
        }
142
143
        $dir = $this->getRealPath();
144
        $dirParts = explode('Widgets' . DIRECTORY_SEPARATOR, $dir);
145
        $namespace = loader()->getDirNamespace(reset($dirParts)) . 'Widgets\\' . str_replace(['/', DIRECTORY_SEPARATOR],
146
                '\\', end($dirParts));
147
148
        return $namespace;
149
    }
150
151
    // ------------------------------------------------------------------------
152
153
    /**
154
     * Widget::getConfig
155
     *
156
     * @return \O2System\Spl\DataStructures\SplArrayObject
157
     */
158
    public function getPresets()
159
    {
160
        return new SplArrayObject($this->presets);
161
    }
162
}