Passed
Push — master ( a9574a...4c3e72 )
by Arthur
07:41
created

CacheObserver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A updated() 0 3 1
A created() 0 3 1
A deleted() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 11.10.18
6
 * Time: 13:31.
7
 */
8
9
namespace Foundation\Observers;
10
11
use Foundation\Abstracts\Observers\Observer;
12
use Foundation\Cache\ModelCache;
13
use Foundation\Traits\Cacheable;
14
15
//TODO change this to work with the new object modelcache.
16
class CacheObserver extends Observer
17
{
18
    /**
19
     * @param Cacheable | \Eloquent $model
20
     */
21 25
    public function created($model)
22
    {
23 25
        $model::cache()->store($model);
0 ignored issues
show
Bug introduced by
It seems like $model can also be of type Foundation\Traits\Cacheable; however, parameter $model of Foundation\Cache\ModelCacheOOP::store() does only seem to accept Eloquent, maybe add an additional type check? ( Ignorable by Annotation )

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

23
        $model::cache()->store(/** @scrutinizer ignore-type */ $model);
Loading history...
24 25
    }
25
26
    /**
27
     * @param Cacheable | \Eloquent $model
28
     */
29 1
    public function updated($model)
30
    {
31 1
        $model::cache()->store($model);
0 ignored issues
show
Bug introduced by
It seems like $model can also be of type Foundation\Traits\Cacheable; however, parameter $model of Foundation\Cache\ModelCacheOOP::store() does only seem to accept Eloquent, maybe add an additional type check? ( Ignorable by Annotation )

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

31
        $model::cache()->store(/** @scrutinizer ignore-type */ $model);
Loading history...
32 1
    }
33
34
    /**
35
     * @param Cacheable | \Eloquent $model
36
     */
37 1
    public function deleted($model)
38
    {
39 1
        $model::cache()->remove($model->getKey());
0 ignored issues
show
Bug introduced by
It seems like getKey() 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

39
        $model::cache()->remove($model->/** @scrutinizer ignore-call */ getKey());
Loading history...
40 1
    }
41
}
42