Test Failed
Push — main ( ac1aa2...91ffd3 )
by Rafael
51:29
created

ViewTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A __destruct() 0 23 6
1
<?php
2
3
/* Copyright (C) 2024      Rafael San José      <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace Alxarafe\Base;
20
21
use Jenssegers\Blade\Blade;
22
23
trait ViewTrait
24
{
25
    /**
26
     * Theme name. TODO: Has to be updated according to the configuration.
27
     *
28
     * @var string
29
     */
30
    public $theme;
31
32
    /**
33
     * Code lang for <html lang> tag
34
     *
35
     * @var string
36
     */
37
    public $lang = 'en';
38
39
    public $body_class;
40
41
42
    public function __destruct()
43
    {
44
        $this->theme = $_GET['theme'];
45
        if (empty($this->theme)) {
46
            $this->theme = 'adminlte';
47
        }
48
49
        if (!isset($this->template)) {
50
            $this->template = 'index';
51
        }
52
53
        $vars = ['me' => $this];
54
        $viewPaths = [
55
            BASE_PATH . '/Templates',
56
            BASE_PATH . '/Templates/theme/' . $this->theme,
57
            BASE_PATH . '/Templates/common',
58
        ];
59
        $cachePaths = realpath(BASE_PATH . '/../tmp') . '/blade';
60
        if (!is_dir($cachePaths) && !mkdir($cachePaths) && !is_dir($cachePaths)) {
61
            die('Could not create cache directory for templates.');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
62
        }
63
        $blade = new Blade($viewPaths, $cachePaths);
64
        echo $blade->render($this->template, $vars);
65
    }
66
}
67
68