Passed
Push — master ( 158252...631a8c )
by Maxim
02:44
created

HtmlCache   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A end() 0 6 1
A __construct() 0 6 1
1
<?php
2
3
namespace WebComplete\core\utils\cache;
4
5
class HtmlCache
6
{
7
8
    /**
9
     * @var CacheService
10
     */
11
    protected $cacheService;
12
    /**
13
     * @var string
14
     */
15
    protected $key;
16
    /**
17
     * @var int
18
     */
19
    protected $ttl;
20
    /**
21
     * @var array
22
     */
23
    protected $tags;
24
25
    /**
26
     * @param CacheService $cacheService
27
     * @param string $key
28
     * @param int $ttl
29
     * @param array $tags
30
     */
31
    public function __construct(CacheService $cacheService, string $key, int $ttl = null, array $tags = [])
32
    {
33
        $this->cacheService = $cacheService;
34
        $this->key = $key;
35
        $this->ttl = $ttl;
36
        $this->tags = $tags;
37
    }
38
39
    public function end()
40
    {
41
        $content = ob_get_contents();
42
        ob_end_clean();
43
        Cache::set($this->key, $content, $this->ttl, $this->tags);
44
        echo $content;
45
    }
46
}
47