Completed
Pull Request — master (#22)
by Sergey
15:14
created

RuntimeCacheRepository::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace Isswp101\Persimmon\Repository;
4
5
use Isswp101\Persimmon\Collection\Collection;
6
use Isswp101\Persimmon\Contracts\Storable;
7
use Isswp101\Persimmon\Exceptions\ClassTypeErrorException;
8
use Isswp101\Persimmon\Model\IEloquent;
9
use Isswp101\Persimmon\QueryBuilder\IQueryBuilder;
10
11
class RuntimeCacheRepository implements ICacheRepository
12
{
13
    private $collection;
14
15
    public function __construct()
16
    {
17
        $this->collection = new Collection();
18
    }
19
20
    private function getHash(string $class, string $id): string
21
    {
22
        return $class . '@' . $id;
23
    }
24
25 View Code Duplication
    public function instantiate(string $class): Storable
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $instance = new $class;
28
        if (!$instance instanceof IEloquent) {
29
            throw new ClassTypeErrorException(IEloquent::class);
30
        }
31
        return $instance;
32
    }
33
34
    public function find($id, string $class, array $columns = []): Storable
35
    {
36
        $hash = $this->getHash($class, $id);
37
        $model = $this->collection->get($hash);
38
        if ($model != null && $this->getCachedAttributes()) {
0 ignored issues
show
Bug introduced by
The call to getCachedAttributes() misses some required arguments starting with $id.
Loading history...
39
            return $model;
40
        }
41
        return null;
42
    }
43
44
    public function all(IQueryBuilder $query, string $class, callable $callback = null)
45
    {
46
        // TODO: Implement all() method.
47
    }
48
49
    public function insert(Storable $model)
50
    {
51
        // TODO: Implement insert() method.
52
    }
53
54
    public function update(Storable $model)
55
    {
56
        // TODO: Implement update() method.
57
    }
58
59
    public function delete(Storable $model)
60
    {
61
        // TODO: Implement delete() method.
62
    }
63
64
    public function getCachedAttributes(string $id, string $class): array
65
    {
66
        // TODO: Implement getCachedAttributes() method.
67
    }
68
}