Completed
Push — master ( cf2713...aee5ae )
by Sherif
02:07
created

BaseService   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 190
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A list() 0 4 1
A all() 0 4 1
A search() 0 4 1
A paginate() 0 4 1
A paginateBy() 0 4 1
A save() 0 4 1
A delete() 0 4 1
A find() 0 4 1
A findBy() 0 4 1
A first() 0 4 1
A deleted() 0 4 1
A restore() 0 4 1
1
<?php
2
3
namespace App\Modules\Core\BaseClasses;
4
5
use App\Modules\Core\Interfaces\BaseServiceInterface;
6
use App\Modules\Core\Decorators\CachingDecorator;
7
8
abstract class BaseService implements BaseServiceInterface
9
{
10
    /**
11
     * @var object
12
     */
13
    protected $repo;
14
15
    /**
16
     * Init new object.
17
     *
18
     * @param   mixed  $repo
19
     * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
20
     */
21
    public function __construct($repo)
22
    {
23
        $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository'));
24
    }
25
26
    /**
27
     * Fetch records with relations based on the given params.
28
     *
29
     * @param   string  $relations
30
     * @param   array   $conditions
31
     * @param   integer $perPage
32
     * @param   string  $sortBy
33
     * @param   boolean $desc
34
     * @return collection
35
     */
36
    public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true)
37
    {
38
        return $this->repo->list($relations, $conditions, $perPage, $sortBy, $desc);
39
    }
40
41
    /**
42
     * Fetch all records with relations from the storage.
43
     *
44
     * @param  array   $relations
45
     * @param  string  $sortBy
46
     * @param  boolean $desc
47
     * @param  array   $columns
48
     * @return collection
49
     */
50
    public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
51
    {
52
        return $this->repo->all($relations, $sortBy, $desc, $columns);
53
    }
54
55
    /**
56
     * Fetch all records with relations from storage in pages
57
     * that matche the given query.
58
     *
59
     * @param  string  $query
60
     * @param  integer $perPage
61
     * @param  array   $relations
62
     * @param  string  $sortBy
63
     * @param  boolean $desc
64
     * @param  array   $columns
65
     * @return collection
66
     */
67
    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
68
    {
69
        return $this->repo->search($query, $perPage, $relations, $sortBy, $desc, $columns);
70
    }
71
    
72
    /**
73
     * Fetch all records with relations from storage in pages.
74
     *
75
     * @param  integer $perPage
76
     * @param  array   $relations
77
     * @param  string  $sortBy
78
     * @param  boolean $desc
79
     * @param  array   $columns
80
     * @return collection
81
     */
82
    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
83
    {
84
        return $this->repo->paginate($perPage, $relations, $sortBy, $desc, $columns);
85
    }
86
87
    /**
88
     * Fetch all records with relations based on
89
     * the given condition from storage in pages.
90
     *
91
     * @param  array   $conditions array of conditions
92
     * @param  integer $perPage
93
     * @param  array   $relations
94
     * @param  string  $sortBy
95
     * @param  boolean $desc
96
     * @param  array   $columns
97
     * @return collection
98
     */
99
    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
100
    {
101
        return $this->repo->paginateBy($conditions, $perPage, $relations, $sortBy, $desc, $columns);
102
    }
103
    
104
    /**
105
     * Save the given model to the storage.
106
     *
107
     * @param  array $data
108
     * @return mixed
109
     */
110
    public function save(array $data)
111
    {
112
        return $this->repo->save($data);
113
    }
114
115
    /**
116
     * Delete record from the storage based on the given
117
     * condition.
118
     *
119
     * @param  var $value condition value
120
     * @param  string $attribute condition column name
121
     * @return void
122
     */
123
    public function delete($value, $attribute = 'id')
124
    {
125
        return $this->repo->save($value, $attribute);
126
    }
127
    
128
    /**
129
     * Fetch records from the storage based on the given
130
     * id.
131
     *
132
     * @param  integer $id
133
     * @param  string[]   $relations
134
     * @param  array   $columns
135
     * @return object
136
     */
137
    public function find($id, $relations = [], $columns = ['*'])
138
    {
139
        return $this->repo->find($id, $relations, $columns);
140
    }
141
    
142
    /**
143
     * Fetch records from the storage based on the given
144
     * condition.
145
     *
146
     * @param  array   $conditions array of conditions
147
     * @param  array   $relations
148
     * @param  string  $sortBy
149
     * @param  boolean $desc
150
     * @param  array   $columns
151
     * @return collection
152
     */
153
    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*'])
154
    {
155
        return $this->repo->findBy($conditions, $relations, $sortBy, $desc, $columns);
156
    }
157
158
    /**
159
     * Fetch the first record from the storage based on the given
160
     * condition.
161
     *
162
     * @param  array   $conditions array of conditions
163
     * @param  array   $relations
164
     * @param  array   $columns
165
     * @return object
166
     */
167
    public function first($conditions, $relations = [], $columns = ['*'])
168
    {
169
        return $this->repo->first($conditions, $relations, $columns);
170
    }
171
172
    /**
173
     * Return the deleted models in pages based on the given conditions.
174
     *
175
     * @param  array   $conditions array of conditions
176
     * @param  integer $perPage
177
     * @param  string  $sortBy
178
     * @param  boolean $desc
179
     * @param  array   $columns
180
     * @return collection
181
     */
182
    public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*'])
183
    {
184
        return $this->repo->deleted($conditions, $perPage, $sortBy, $desc, $columns);
185
    }
186
187
    /**
188
     * Restore the deleted model.
189
     *
190
     * @param  integer $id
191
     * @return void
192
     */
193
    public function restore($id)
194
    {
195
        return $this->repo->restore($id);
196
    }
197
}
198