Completed
Push — master ( 7fc24c...29985a )
by recca
08:20
created

Template::minify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 9.4285
c 2
b 0
f 0
1
<?php
2
3
namespace Recca0120\LaravelTracy;
4
5
class Template
6
{
7
    protected $attributes = [];
8
9
    /**
10
     * setAttributes.
11
     *
12
     * @param array $attributes
13
     */
14 2
    public function setAttributes($attributes)
15
    {
16 2
        $this->attributes = $attributes;
17 2
    }
18
19
    /**
20
     * render.
21
     *
22
     * @param string $view
23
     * @return string
24
     */
25 2
    public function render($view)
26
    {
27 2
        extract($this->attributes);
28
29 2
        ob_start();
30 2
        require $view;
31
32 2
        return $this->minify(ob_get_clean());
33
    }
34
35
    /**
36
     * minify.
37
     *
38
     * if need minify style and script, refrence
39
     * https://gist.github.com/recca0120/5930842de4e0a43a48b8bf027ab058f9
40
     *
41
     * @param string $buff
42
     * @return string
43
     */
44 2
    protected function minify($buff)
45
    {
46 2
        return preg_replace(
47 2
            ['/<!--(.*)-->/Uis', '/[[:blank:]]+/'],
48 2
            ['', ' '],
49 2
            str_replace(["\n", "\r", "\t"], '', $buff)
50 2
        );
51
    }
52
}
53