1 | <?php |
||
12 | class Repository implements RepositoryContract, CriteriaPerformer |
||
13 | { |
||
14 | /** |
||
15 | * @var EloquentModel |
||
16 | */ |
||
17 | protected $model; |
||
18 | |||
19 | /** |
||
20 | * @var Collection |
||
21 | */ |
||
22 | protected $criteria; |
||
23 | |||
24 | /** |
||
25 | * @var bool |
||
26 | */ |
||
27 | protected $skipCriteria = false; |
||
28 | |||
29 | /** |
||
30 | */ |
||
31 | 12 | public function __construct(EloquentModel $model) |
|
36 | |||
37 | /** |
||
38 | * @return EloquentModel |
||
39 | */ |
||
40 | 1 | public function getModel() |
|
44 | |||
45 | /** |
||
46 | * @param array $with |
||
47 | * @return Collection |
||
48 | */ |
||
49 | 1 | public function all(array $with = array()) |
|
60 | |||
61 | /** |
||
62 | * @param int $perPage |
||
63 | * @return mixed |
||
64 | */ |
||
65 | 1 | public function paginate($perPage = 15, array $with = array()) |
|
76 | |||
77 | /** |
||
78 | * @param array $data |
||
79 | * @return EloquentModel |
||
80 | */ |
||
81 | 3 | public function create(array $data) |
|
89 | |||
90 | /** |
||
91 | * @param array $data |
||
92 | * @param $id |
||
93 | * @param string $field |
||
94 | * @return EloquentModel |
||
95 | */ |
||
96 | 2 | public function update(array $data, $id, $field = "id") |
|
110 | |||
111 | /** |
||
112 | * @param $id |
||
113 | * @return integer |
||
114 | */ |
||
115 | 1 | public function delete($id) |
|
116 | { |
||
117 | 1 | $result = $this->model->destroy($id); |
|
118 | |||
119 | 1 | $this->refresh(); |
|
120 | |||
121 | 1 | return $result; |
|
122 | } |
||
123 | |||
124 | /** |
||
125 | * @param $id |
||
126 | * @return mixed |
||
127 | */ |
||
128 | 2 | public function find($id, array $with = array()) |
|
139 | |||
140 | /** |
||
141 | * @param $id |
||
142 | * @return mixed|Exception |
||
143 | */ |
||
144 | public function findOrFail($id, array $with = array()) |
||
155 | |||
156 | /** |
||
157 | * @param $field |
||
158 | * @param $value |
||
159 | * @return mixed |
||
160 | */ |
||
161 | public function findBy($field, $value, array $with = array()) |
||
172 | |||
173 | /** |
||
174 | * @param $field |
||
175 | * @param $value |
||
176 | * @return mixed |
||
177 | */ |
||
178 | public function findByOrFail($field, $value, array $with = array()) |
||
189 | |||
190 | /** |
||
191 | * @param $field |
||
192 | * @param $value |
||
193 | * @return mixed |
||
194 | */ |
||
195 | public function findAllBy($field, $value, array $with = array()) |
||
206 | |||
207 | /** |
||
208 | * @param array $with |
||
209 | * @return void |
||
210 | */ |
||
211 | 4 | protected function addWithCriteria(array $with = array()) |
|
217 | |||
218 | /** |
||
219 | * |
||
220 | */ |
||
221 | 6 | protected function refresh() |
|
230 | |||
231 | /** |
||
232 | * @param bool $status |
||
233 | * @return $this |
||
234 | */ |
||
235 | public function skipCriteria($status = true) |
||
241 | |||
242 | /** |
||
243 | * @return Collection |
||
244 | */ |
||
245 | 4 | public function getCriteria() |
|
249 | |||
250 | /** |
||
251 | * @param Criteria $criteria |
||
252 | * @return $this |
||
253 | */ |
||
254 | public function getByCriteria(Criteria $criteria) |
||
260 | |||
261 | /** |
||
262 | * @param Criteria $criteria |
||
263 | * @return $this |
||
264 | */ |
||
265 | public function pushCriteria(Criteria $criteria) |
||
271 | |||
272 | /** |
||
273 | * @return $this |
||
274 | */ |
||
275 | 4 | public function applyCriteria() |
|
287 | } |
||
288 |
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.