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 ( cf9260...b52382 )
by
unknown
03:19
created

Page::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
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\Http\Presenter;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Framework\Libraries\Ui\Components\Breadcrumb;
19
use O2System\Framework\Libraries\Ui\Contents\Link;
20
use O2System\Kernel\Http\Message\Uri;
21
use O2System\Psr\Patterns\Structural\Repository\AbstractRepository;
22
use O2System\Spl\DataStructures\SplArrayObject;
23
use O2System\Spl\Info\SplFileInfo;
24
25
/**
26
 * Class Page
27
 *
28
 * @package App\DataStructures
29
 */
30
class Page extends AbstractRepository
31
{
32
    /**
33
     * Page::$file
34
     *
35
     * @var \O2System\Spl\Info\SplFileInfo
36
     */
37
    public $file;
38
39
    /**
40
     * Page Variables
41
     *
42
     * @var array
43
     */
44
    private $vars = [];
45
46
    /**
47
     * Page Presets
48
     *
49
     * @var SplArrayObject
50
     */
51
    private $presets;
52
53
    // ------------------------------------------------------------------------
54
55
    /**
56
     * Page::__construct
57
     */
58
    public function __construct()
59
    {
60
        // Create Page breadcrumbs
61
        $breadcrumb = new Breadcrumb();
62
        $breadcrumb->createList(new Link(language()->getLine('HOME'), base_url()));
63
        $this->store('breadcrumb', $breadcrumb);
64
65
        // Store Page Uri
66
        $uri = new Uri();
67
        $this->store('uri', $uri);
68
    }
69
70
    // ------------------------------------------------------------------------
71
72
    /**
73
     * Page::setVars
74
     *
75
     * @param array $vars
76
     *
77
     * @return static
78
     */
79
    public function setVars(array $vars)
80
    {
81
        $this->vars = $vars;
82
83
        return $this;
84
    }
85
86
    // ------------------------------------------------------------------------
87
88
    /**
89
     * Page::getVars
90
     *
91
     * Gets page variables.
92
     *
93
     * @return array
94
     */
95
    public function getVars()
96
    {
97
        return $this->vars;
98
    }
99
100
    // ------------------------------------------------------------------------
101
102
    /**
103
     * Page::setPresets
104
     *
105
     * @param \O2System\Spl\DataStructures\SplArrayObject $presets
106
     *
107
     * @return static
108
     */
109
    public function setPresets(SplArrayObject $presets)
110
    {
111
        $this->presets = $presets;
112
113
        return $this;
114
    }
115
116
    // ------------------------------------------------------------------------
117
118
    /**
119
     * Page::getPresets
120
     *
121
     * Gets page presets.
122
     *
123
     * @return bool|\O2System\Spl\DataStructures\SplArrayObject
124
     */
125
    public function getPresets()
126
    {
127
        if ($this->presets instanceof SplArrayObject) {
0 ignored issues
show
introduced by
$this->presets is always a sub-type of O2System\Spl\DataStructures\SplArrayObject.
Loading history...
128
            return $this->presets;
129
        }
130
131
        return false;
132
    }
133
134
    // ------------------------------------------------------------------------
135
136
    /**
137
     * Page::setFile
138
     *
139
     * @param $filePath
140
     *
141
     * @return static
142
     */
143
    public function setFile($filePath)
144
    {
145
        if (is_file($filePath)) {
146
            $this->file = new SplFileInfo($filePath);
147
148
            if (file_exists(
149
                $propertiesFilePath = $this->file->getPath() . DIRECTORY_SEPARATOR . str_replace(
150
                        '.phtml',
151
                        '.json',
152
                        strtolower($this->file->getBasename())
153
                    )
154
            )) {
155
                $properties = file_get_contents($propertiesFilePath);
156
                $properties = json_decode($properties, true);
157
158
                if (isset($properties[ 'vars' ])) {
159
                    $this->vars = $properties[ 'vars' ];
160
                }
161
162
                if (isset($properties[ 'presets' ])) {
163
                    $this->presets = new SplArrayObject($properties[ 'presets' ]);
164
                }
165
            }
166
        }
167
168
        return $this;
169
    }
170
171
    // ------------------------------------------------------------------------
172
173
    /**
174
     * Page::setHeader
175
     *
176
     * @param string $header
177
     *
178
     * @return static
179
     */
180
    public function setHeader($header)
181
    {
182
        $header = trim($header);
183
        $header = language($header);
184
        $this->store('header', $header);
185
        presenter()->meta->title->append($header);
0 ignored issues
show
Bug introduced by
$header of type O2System\Framework\Servi...ernel\Services\Language is incompatible with the type string expected by parameter $header of O2System\Framework\Http\...er\Meta\Title::append(). ( Ignorable by Annotation )

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

185
        presenter()->meta->title->append(/** @scrutinizer ignore-type */ $header);
Loading history...
186
187
        return $this;
188
    }
189
190
    // ------------------------------------------------------------------------
191
192
    /**
193
     * Page::setTitle
194
     *
195
     * @param string $title
196
     *
197
     * @return static
198
     */
199
    public function setTitle($title)
200
    {
201
        $title = trim($title);
202
        $title = language($title);
203
        $this->store('title', $title);
204
        presenter()->meta->title->append($title);
0 ignored issues
show
Bug introduced by
$title of type O2System\Framework\Servi...ernel\Services\Language is incompatible with the type string expected by parameter $header of O2System\Framework\Http\...er\Meta\Title::append(). ( Ignorable by Annotation )

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

204
        presenter()->meta->title->append(/** @scrutinizer ignore-type */ $title);
Loading history...
205
206
        return $this;
207
    }
208
209
    // ------------------------------------------------------------------------
210
211
    /**
212
     * Page::setDescription
213
     *
214
     * @param string $description
215
     *
216
     * @return static
217
     */
218
    public function setDescription($description)
219
    {
220
        $description = trim($description);
221
        $this->store('description', $description);
222
223
        return $this;
224
    }
225
226
    // ------------------------------------------------------------------------
227
228
    /**
229
     * Page::setContent
230
     *
231
     * @param string $content
232
     *
233
     * @return static
234
     */
235
    public function setContent($content)
236
    {
237
        if ( ! empty($content)) {
238
            presenter()->partials->offsetSet('content', $content);
239
        }
240
241
        return $this;
242
    }
243
}