Repository   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 108
rs 10
c 0
b 0
f 0
wmc 13

9 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 2
A getModel() 0 3 1
A restore() 0 7 2
A findTrashed() 0 3 1
A find() 0 3 1
A delete() 0 7 2
A tableExists() 0 3 1
A count() 0 3 1
A trashed() 0 4 2
1
<?php
2
3
namespace Translation\Repositories;
4
5
class Repository
6
{
7
    /**
8
     *  Return the model related to this finder.
9
     *
10
     * @return \Illuminate\Database\Eloquent\Model
11
     */
12
    public function getModel()
13
    {
14
        return $this->model;
15
    }
16
17
    /**
18
     *  Check if the model's table exists
19
     *
20
     * @return boolean
21
     */
22
    public function tableExists()
23
    {
24
        return $this->model->getConnection()->getSchemaBuilder()->hasTable($this->model->getTable());
25
    }
26
27
    /**
28
     *  Retrieve all records.
29
     *
30
     * @param  array   $related Related object to include.
31
     * @param  integer $perPage Number of records to retrieve per page. If zero the whole result set is returned.
32
     * @return \Illuminate\Database\Eloquent\Model
33
     */
34
    public function all($related = [], $perPage = 0)
35
    {
36
        $results = $this->model->with($related)->orderBy('created_at', 'DESC');
37
        return $perPage ? $results->paginate($perPage) : $results->get();
38
    }
39
40
    /**
41
     *  Retrieve all trashed.
42
     *
43
     * @param  array   $related Related object to include.
44
     * @param  integer $perPage Number of records to retrieve per page. If zero the whole result set is returned.
45
     * @return \Illuminate\Database\Eloquent\Model
46
     */
47
    public function trashed($related = [], $perPage = 0)
48
    {
49
        $trashed = $this->model->onlyTrashed()->with($related);
50
        return $perPage ? $trashed->paginate($perPage) : $trashed->get();
51
    }
52
53
    /**
54
     *  Retrieve a single record by id.
55
     *
56
     * @param  integer $id
57
     * @return \Illuminate\Database\Eloquent\Model
58
     */
59
    public function find($id, $related = [])
60
    {
61
        return $this->model->with($related)->find($id);
62
    }
63
64
    /**
65
     *  Retrieve a single record by id.
66
     *
67
     * @param  integer $id
68
     * @return \Illuminate\Database\Eloquent\Model
69
     */
70
    public function findTrashed($id, $related = [])
71
    {
72
        return $this->model->onlyTrashed()->with($related)->find($id);
73
    }
74
75
    /**
76
     *  Remove a record.
77
     *
78
     * @param  \Illuminate\Database\Eloquent\Model $model
79
     * @return boolean
80
     */
81
    public function delete($id)
82
    {
83
        $model = $this->model->where('id', $id)->first();
84
        if (!$model) {
85
            return false;
86
        }
87
        return $model->delete();
88
    }
89
90
    /**
91
     *  Restore a record.
92
     *
93
     * @param  int $id
94
     * @return boolean
95
     */
96
    public function restore($id)
97
    {
98
        $model = $this->findTrashed($id);
99
        if ($model) {
0 ignored issues
show
introduced by
$model is of type Illuminate\Database\Eloquent\Model, thus it always evaluated to true.
Loading history...
100
            $model->restore();
101
        }
102
        return $model;
103
    }
104
105
    /**
106
     *  Returns total number of entries in DB.
107
     *
108
     * @return integer
109
     */
110
    public function count()
111
    {
112
        return $this->model->count();
113
    }
114
}
115