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

RuntimeCacheRepository::all()   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 3
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 IRepository
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
        if (!$this->collection->has($hash)) {
38
            $this->collection->put($hash, new EloquentCache());
39
        }
40
        return $this->collection->get($hash);
41
    }
42
43
    public function all(IQueryBuilder $query, string $class, callable $callback = null)
44
    {
45
        // TODO: Implement all() method.
46
    }
47
48
    public function insert(Storable $model)
49
    {
50
        // TODO: Implement insert() method.
51
    }
52
53
    public function update(Storable $model)
54
    {
55
        // TODO: Implement update() method.
56
    }
57
58
    public function delete(Storable $model)
59
    {
60
        // TODO: Implement delete() method.
61
    }
62
}