Passed
Pull Request — master (#4)
by Ryuichi
84:53 queued 39:54
created

LoggerCache::__destruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace WebStream\Log;
4
5
use WebStream\Cache\Driver\ICache;
0 ignored issues
show
Bug introduced by
The type WebStream\Cache\Driver\ICache was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
/**
8
 * LoggerCache
9
 * @author Ryuichi Tanaka
10
 * @since 2016/05/23
11
 * @version 0.7
12
 */
13
class LoggerCache
14
{
15
    /**
16
     * @var ICache キャッシュドライバ
17
     */
18
    private $driver;
19
20
    /**
21
     * @var string キャッシュキー
22
     */
23
    private $key;
24
25
    /**
26
     * @var int キャッシュインデックス
27
     */
28
    private $index;
29
30
    /**
31
     * constructor
32 142
     */
33
    public function __construct(ICache $driver)
34 142
    {
35 142
        $this->driver = $driver;
36 142
        $this->key = md5(get_class($this));
37 142
        $this->index = 0;
38
    }
39
40
    /**
41
     * destructor
42 1
     */
43
    public function __destruct()
44 1
    {
45 1
        $this->clear();
46
    }
47
48
    /**
49
     * キャッシュに追加
50
     * @param string $content キャッシュデータ
51 96
     */
52
    public function add(string $content)
53 96
    {
54 96
        $this->driver->add($this->key . $this->index++, $content);
55
    }
56
57
    /**
58
     * キャッシュを返却する
59
     * @return array<string> キャッシュデータ
60 1
     */
61
    public function get()
62 1
    {
63 1
        $list = [];
64 1
        for ($i = 0; $i < $this->index; $i++) {
65
            $list[] = $this->driver->get($this->key . $i);
66
        }
67 1
68
        return $list;
69
    }
70
71
    /**
72
     * キャッシュデータ数を返却する
73
     * @return int キャッシュデータ数
74 96
     */
75
    public function length()
76 96
    {
77
        return $this->index;
78
    }
79
80
    /**
81
     * キャッシュクリア
82
     */
83
    public function clear()
84
    {
85
        $this->driver->clear();
86
    }
87
}
88