Passed
Push — master ( b33b8e...5acb2c )
by Gabriel
04:09
created

IsCachedTrait::generateCacheData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Nip\Records\Registry\Traits;
4
5
use Nip\Cache\Cacheable\CanCache;
6
7
/**
8
 * Trait IsCachedTrait
9
 * @package Nip\Records\Registry\Traits
10
 */
11
trait IsCachedTrait
12
{
13
    use CanCache;
14
15
    /**
16
     * @inheritDoc
17
     */
18 26
    public function offsetSet($key, $value)
19
    {
20 26
        $this->needsCaching(true);
21 26
        parent::offsetSet($key, $value);
22 26
    }
23
24
    public function __destruct()
25
    {
26
        $this->checkSaveCache();
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    protected function generateCacheData()
33
    {
34
        return $this->all();
0 ignored issues
show
Bug introduced by
It seems like all() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        return $this->/** @scrutinizer ignore-call */ all();
Loading history...
35
    }
36
37 1
    protected function doLoad(): void
38
    {
39 1
        $data = $this->getDataFromCache();
40 1
        if (is_array($data)) {
41
            $this->setItems($data);
0 ignored issues
show
Bug introduced by
It seems like setItems() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
            $this->/** @scrutinizer ignore-call */ 
42
                   setItems($data);
Loading history...
42
        }
43 1
    }
44
}
45