Completed
Push — master ( 73f026...dc38fa )
by Sebastian
04:16
created

DbRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 49
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAll() 0 4 1
A find() 0 4 1
A findOnline() 0 4 1
A getAllOnline() 0 6 1
A findByUrl() 0 13 2
1
<?php
2
3
namespace App\Foundation\Repositories;
4
5
use Illuminate\Support\Collection;
6
7
abstract class DbRepository extends BaseRepository implements Repository
8
{
9
    public function getAll() : Collection
10
    {
11
        return $this->query()->get();
12
    }
13
14
    /**
15
     * @return \Illuminate\Database\Eloquent\Model|null
16
     */
17
    public function find(int $id)
18
    {
19
        return $this->query()->find($id);
20
    }
21
22
    /**
23
     * @return \Illuminate\Database\Eloquent\Model|null
24
     */
25
    public function findOnline(int $id)
26
    {
27
        return $this->query()->online()->find($id);
28
    }
29
30
    public function getAllOnline() : Collection
31
    {
32
        return $this->query()
33
            ->online()
34
            ->get();
35
    }
36
37
    /**
38
     * @return \Illuminate\Database\Eloquent\Model|null
39
     */
40
    public function findByUrl(string $url)
41
    {
42
        $model = static::MODEL;
43
44
        if (! isset((new $model)->translatedAttributes)) {
45
            return $this->query()->online()->where('url', $url)->first();
46
        }
47
48
        return $this->query()
49
            ->online()
50
            ->whereTranslation('url', $url, content_locale())
51
            ->first();
52
    }
53
54
55
}
56