Passed
Push — master ( 3849b2...6d2bbe )
by Edson
01:17
created

Tpl::setDev()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bonfim\Tpl;
4
5
class Tpl
6
{
7
    private static $assign = [];
8
    private static $engine = null;
9
10
    private static $dev = false;
11
    private static $dir = 'view/';
12
    private static $url = 'http://localhost/';
13
    private static $assets = 'assets/';
14
15
    private static function engine(): Engine
16
    {
17
        if (!isset(self::$engine) || is_null(self::$engine)) {
18
            self::$engine = new Engine;
19
        }
20
        return self::$engine;
21
    }
22
23
    public static function setDev(bool $dev): void
24
    {
25
        self::$dev = $dev;
26
    }
27
28
    public static function setDir(String $dir): void
29
    {
30
        self::$dir = $dir;
31
    }
32
33
    public static function getDir(): String
34
    {
35
        return self::$dir;
36
    }
37
38
    public static function setUrl(String $url): void
39
    {
40
        self::$url = $url;
41
    }
42
43
    public static function getUrl(): String
44
    {
45
        return self::$url;
46
    }
47
48
    public static function setAssets(String $assets)
49
    {
50
        self::$assets = $assets;
51
    }
52
53
    public static function getAssets(): String
54
    {
55
        return self::$assets;
56
    }
57
58
    public static function config(array $config): void
59
    {
60
        self::engine()->config($config);
0 ignored issues
show
Bug introduced by
The method config() does not exist on Bonfim\Tpl\Engine. ( Ignorable by Annotation )

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

60
        self::engine()->/** @scrutinizer ignore-call */ config($config);

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...
61
    }
62
63
    public static function assign(string $key, $value): void
64
    {
65
        if (is_array($value)) {
66
            $value = json_decode(json_encode($value), false);
67
        }
68
        self::$assign[$key] = $value;
69
    }
70
71
    public static function render(string $template, array $values = []): void
72
    {
73
        foreach ($values as $key => $value) {
74
            self::assign($key, $value);
75
        }
76
77
        echo self::engine()->render($template, self::$assign);
78
    }
79
}
80