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.
Completed
Push — master ( 4f628a...3fa33b )
by やかみ
02:35
created

View::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
crap 2.0185
rs 9.4285
c 1
b 0
f 0
1
<?php
2
/**
3
 * Kotori.php
4
 *
5
 * A Tiny Model-View-Controller PHP Framework
6
 *
7
 * This content is released under the Apache 2 License
8
 *
9
 * Copyright (c) 2015-2017 Kotori Technology. All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 *     http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23
24
/**
25
 * View Class
26
 *
27
 * @package     Kotori
28
 * @subpackage  Core
29
 * @author      Kokororin
30
 * @link        https://kotori.love
31
 */
32
namespace Kotori\Core;
33
34
use Kotori\Debug\Hook;
35
use Kotori\Exception\NotFoundException;
36
use Kotori\Exception\ResponseException;
37
use Kotori\Traits\ControllerMethodsTrait;
38
39
class View
40
{
41
    use ControllerMethodsTrait;
42
    /**
43
     * Template Direcory
44
     *
45
     * @var string
46
     */
47
    protected $tplDir;
48
49
    /**
50
     *
51
     * Template Path
52
     *
53
     * @var string
54
     */
55
    protected $viewPath;
56
57
    /**
58
     * Variable List
59
     *
60
     * @var array
61
     */
62
    protected $data = [];
63
64
    /**
65
     * Variable List for TplInclude
66
     *
67
     * @var array
68
     */
69
    protected $needData;
70
71
    /**
72
     * Class constructor
73
     *
74
     * @param  string $tplDir
75
     * @return void
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...
76
     */
77 3
    public function __construct($tplDir = null)
78
    {
79 3
        if (null == $tplDir) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $tplDir of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
80 3
            $this->tplDir = Container::get('config')->get('app_full_path') . '/views/';
81
        } else {
82
            $this->tplDir = $tplDir;
83
        }
84
85 3
        Hook::listen(__CLASS__);
86 3
    }
87
88
    /**
89
     * Set variables for Template
90
     *
91
     * @param  string $key
92
     * @param  mixed  $value
93
     * @return \Kotori\Core\View
94
     */
95
    public function assign($key, $value)
96
    {
97
        $this->data[$key] = $value;
98
        return $this;
99
    }
100
101
    /**
102
     * Display Output
103
     *
104
     * Processes and sends finalized output data to the browser along
105
     *
106
     * @param  string $tpl
107
     * @return void
108
     *
109
     * @throws \Kotori\Exception\NotFoundException
110
     * @throws \Kotori\Exception\ResponseException
111
     */
112
    public function display($tpl = '')
113
    {
114
        if (Container::get('request')->isCli()) {
115
            throw new ResponseException('cannot render template in CLI mode');
116
        }
117
118
        if ('' === $tpl) {
119
            $tpl = Container::get('route')->getController() . '/'
120
            . Container::get('route')->getAction();
121
        }
122
123
        $this->viewPath = $this->tplDir . $tpl . '.html';
124
        if (!Helper::isFile($this->viewPath)) {
125
            throw new NotFoundException('Template is not existed.');
126
        }
127
128
        unset($tpl);
129
        ob_start();
130
        extract($this->data, EXTR_OVERWRITE);
131
        include $this->viewPath;
132
        $buffer = ob_get_contents();
133
        ob_get_clean();
134
        $output = Helper::comment() . preg_replace('|</body>.*?</html>|is', '', $buffer, -1, $count) . Container::get('trace')->showTrace();
135
        if ($count > 0) {
136
            $output .= '</body></html>';
137
        }
138
139
        echo $output;
140
    }
141
142
    /**
143
     * Include Template
144
     *
145
     * @param  string $path
146
     * @param  array  $data
147
     * @return void
148
     */
149
    public function need($path, $data = [])
150
    {
151
        $this->needData = [
152
            'path' => Container::get('config')->get('app_full_path') . '/views/' . $path . '.html',
153
            'data' => $data,
154
        ];
155
        unset($path, $data);
156
        extract($this->needData['data']);
157
        include $this->needData['path'];
158
    }
159
160
}
161