Completed
Push — master ( 561a6b...54ff97 )
by Edson
9s
created

Tpl   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 3 1
A config() 0 3 1
A engine() 0 7 3
A assign() 0 7 2
1
<?php
2
3
namespace Sketch;
4
5
use Sketch\Tpl\Engine;
6
7
/**
8
 * Class Tpl
9
 * @package Sketch
10
 */
11
class Tpl
12
{
13
    /**
14
     * @var array
15
     */
16
    private static $assign = [];
17
    /**
18
     * @var null
19
     */
20
    private static $engine = null;
21
22
    /**
23
     * @return Engine
24
     */
25 2
    private static function engine(): Engine
26
    {
27 2
        if (!isset(self::$engine) || is_null(self::$engine)) {
28 2
            self::$engine = new Engine;
0 ignored issues
show
Documentation Bug introduced by
It seems like new Sketch\Tpl\Engine() of type Sketch\Tpl\Engine is incompatible with the declared type null of property $engine.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
29
        }
30
31 2
        return self::$engine;
32
    }
33
34
    /**
35
     * @param array $config
36
     * @throws \Exception
37
     */
38 2
    public static function config(array $config): void
39
    {
40 2
        self::engine()->config($config);
41 2
    }
42
43
    /**
44
     * @param string $key
45
     * @param $value
46
     */
47 2
    public static function assign(string $key, $value): void
48
    {
49 2
        if (is_array($value)) {
50 2
            $value = json_decode(json_encode($value), false);
51
        }
52
53 2
        self::$assign[$key] = $value;
54 2
    }
55
56
    /**
57
     * @param string $template
58
     * @return string
59
     */
60 2
    public static function render(string $template): string
61
    {
62 2
        return self::engine()->render($template, self::$assign);
63
    }
64
}
65