Template   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 78
rs 10
c 0
b 0
f 0
ccs 18
cts 18
cp 1
wmc 5
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A minify() 0 6 1
A min() 0 8 1
A setAttributes() 0 6 1
A render() 0 11 2
1
<?php
2
3
namespace Recca0120\LaravelTracy;
4
5
class Template
6
{
7
    /**
8
     * $attributes.
9
     *
10
     * @var array
11
     */
12
    protected $attributes = [];
13
14
    /**
15
     * $minify.
16
     *
17
     * @var bool
18
     */
19
    protected $minify = true;
20
21
    /**
22
     * setAttributes.
23
     *
24
     * @param array $attributes
25
     * @return $this
26
     */
27 2
    public function setAttributes($attributes)
28
    {
29 2
        $this->attributes = $attributes;
30
31 2
        return $this;
32
    }
33
34
    /**
35
     * minify.
36
     *
37
     * @param bool $minify
38
     * @return $this
39
     */
40 2
    public function minify($minify)
41
    {
42 2
        $this->minify = $minify;
43
44 2
        return $this;
45
    }
46
47
    /**
48
     * render.
49
     *
50
     * @param string $view
51
     * @return string
52
     */
53 2
    public function render($view)
54
    {
55 2
        extract($this->attributes);
56
57 2
        ob_start();
58 2
        require $view;
59
60 2
        return $this->minify === true
61 1
            ? $this->min(ob_get_clean())
62 2
            : ob_get_clean();
63
    }
64
65
    /**
66
     * min.
67
     *
68
     * if need min style and script, refrence
69
     * https://gist.github.com/recca0120/5930842de4e0a43a48b8bf027ab058f9
70
     *
71
     * @param string $buffer
72
     * @return string
73
     */
74 1
    protected function min($buffer)
75
    {
76 1
        return preg_replace(
77 1
            ['/<!--(.*)-->/Uis', '/[[:blank:]]+/'],
78 1
            ['', ' '],
79 1
            str_replace(["\n", "\r", "\t"], '', $buffer)
80
        );
81
    }
82
}
83