@@ -25,12 +25,12 @@ discard block |
||
25 | 25 | * @param Model $model |
26 | 26 | * @throws \ReflectionException |
27 | 27 | */ |
28 | - public function __construct( Model $model ) |
|
28 | + public function __construct(Model $model) |
|
29 | 29 | { |
30 | 30 | $this->model = $model; |
31 | 31 | |
32 | 32 | // A clean copy of the model is needed when the scope needs to be reset. |
33 | - $reflex = new \ReflectionClass( $model ); |
|
33 | + $reflex = new \ReflectionClass($model); |
|
34 | 34 | $this->modelClassName = $reflex->getName(); |
35 | 35 | |
36 | 36 | $this->skipCriteria = FALSE; |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | $this->eagerLoadRelations(); |
49 | 49 | $this->applyCriteria(); |
50 | 50 | |
51 | - if ( !is_null( $value ) ) $this->model = $this->model->where( $field, $value ); |
|
51 | + if (!is_null($value)) $this->model = $this->model->where($field, $value); |
|
52 | 52 | |
53 | - $result = $this->model->first( $columns ); |
|
53 | + $result = $this->model->first($columns); |
|
54 | 54 | |
55 | 55 | $this->resetScope(); |
56 | 56 | |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | $this->eagerLoadRelations(); |
69 | 69 | $this->applyCriteria(); |
70 | 70 | |
71 | - if ( !is_null( $value ) && !is_null( $field ) ) $this->model = $this->model->where( $field, $value ); |
|
71 | + if (!is_null($value) && !is_null($field)) $this->model = $this->model->where($field, $value); |
|
72 | 72 | |
73 | - $result = $this->model->get( $columns ); |
|
73 | + $result = $this->model->get($columns); |
|
74 | 74 | |
75 | 75 | $this->resetScope(); |
76 | 76 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | { |
88 | 88 | $this->eagerLoadRelations(); |
89 | 89 | $this->applyCriteria(); |
90 | - $result = $this->model->whereIn( $field, $value )->get( $columns ); |
|
90 | + $result = $this->model->whereIn($field, $value)->get($columns); |
|
91 | 91 | |
92 | 92 | $this->resetScope(); |
93 | 93 | |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | * @param array $columns |
99 | 99 | * @return \Illuminate\Database\Eloquent\Collection|static[] |
100 | 100 | */ |
101 | - public function findAll( array $columns = ['*'] ) |
|
101 | + public function findAll(array $columns = ['*']) |
|
102 | 102 | { |
103 | 103 | $this->eagerLoadRelations(); |
104 | 104 | $this->applyCriteria(); |
105 | - $result = $this->model->all( $columns ); |
|
105 | + $result = $this->model->all($columns); |
|
106 | 106 | |
107 | 107 | $this->resetScope(); |
108 | 108 | |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * @param array|string $relations |
114 | 114 | * @return $this |
115 | 115 | */ |
116 | - public function with( $relations ) |
|
116 | + public function with($relations) |
|
117 | 117 | { |
118 | - if ( is_string( $relations ) ) $relations = func_get_args(); |
|
118 | + if (is_string($relations)) $relations = func_get_args(); |
|
119 | 119 | |
120 | 120 | $this->with = $relations; |
121 | 121 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @param CriteriaInterface $criteria |
128 | 128 | * @return $this |
129 | 129 | */ |
130 | - public function addCriteria( CriteriaInterface $criteria) |
|
130 | + public function addCriteria(CriteriaInterface $criteria) |
|
131 | 131 | { |
132 | 132 | $this->criteria[] = $criteria; |
133 | 133 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param bool $status |
140 | 140 | * @return $this |
141 | 141 | */ |
142 | - public function skipCriteria( $status = TRUE ) |
|
142 | + public function skipCriteria($status = TRUE) |
|
143 | 143 | { |
144 | 144 | $this->skipCriteria = $status; |
145 | 145 | return $this; |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | { |
156 | 156 | $this->eagerLoadRelations(); |
157 | 157 | $this->applyCriteria(); |
158 | - $result = $this->model->paginate( $perPage, $columns ); |
|
158 | + $result = $this->model->paginate($perPage, $columns); |
|
159 | 159 | |
160 | 160 | $this->resetScope(); |
161 | 161 | |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | * @param int $currentPage |
168 | 168 | * @return $this |
169 | 169 | */ |
170 | - public function setCurrentPage( $currentPage ) |
|
170 | + public function setCurrentPage($currentPage) |
|
171 | 171 | { |
172 | - \Illuminate\Pagination\Paginator::currentPageResolver(function() use ( $currentPage ) |
|
172 | + \Illuminate\Pagination\Paginator::currentPageResolver(function() use ($currentPage) |
|
173 | 173 | { |
174 | 174 | return $currentPage; |
175 | 175 | }); |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function create(array $data) |
186 | 186 | { |
187 | - $cleanFields = $this->cleanUnfillableFields( $data ); |
|
187 | + $cleanFields = $this->cleanUnfillableFields($data); |
|
188 | 188 | |
189 | - $createdObject = $this->model->create( $cleanFields ); |
|
189 | + $createdObject = $this->model->create($cleanFields); |
|
190 | 190 | |
191 | 191 | $this->resetScope(); |
192 | 192 | |
@@ -201,14 +201,14 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function updateBy(array $data, $value = NULL, $field = 'id') |
203 | 203 | { |
204 | - $cleanFields = $this->cleanUnfillableFields( $data ); |
|
204 | + $cleanFields = $this->cleanUnfillableFields($data); |
|
205 | 205 | |
206 | - if ( !is_null( $value ) ) |
|
206 | + if (!is_null($value)) |
|
207 | 207 | { |
208 | 208 | // Single update. |
209 | - $this->model->where( $field, $value)->update( $cleanFields ); |
|
209 | + $this->model->where($field, $value)->update($cleanFields); |
|
210 | 210 | |
211 | - foreach( $cleanFields as $F => $V ) $this->model->{$F} = $V; |
|
211 | + foreach ($cleanFields as $F => $V) $this->model->{$F} = $V; |
|
212 | 212 | |
213 | 213 | $returnedVal = $this->model; |
214 | 214 | } else |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | // Mass update. |
217 | 217 | $this->applyCriteria(); |
218 | 218 | |
219 | - $returnedVal = $this->model->update( $cleanFields ); |
|
219 | + $returnedVal = $this->model->update($cleanFields); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | $this->resetScope(); |
@@ -230,14 +230,14 @@ discard block |
||
230 | 230 | * @return bool |
231 | 231 | * @throws \Exception |
232 | 232 | */ |
233 | - public function delete( $value = null, $field = 'id' ) |
|
233 | + public function delete($value = null, $field = 'id') |
|
234 | 234 | { |
235 | 235 | $this->applyCriteria(); |
236 | 236 | |
237 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->delete(); |
|
237 | + if (!is_null($value)) $result = $this->model->where($field, $value)->delete(); |
|
238 | 238 | else |
239 | 239 | { |
240 | - if ( !empty( $this->criteria ) ) $result = $this->model->delete(); |
|
240 | + if (!empty($this->criteria)) $result = $this->model->delete(); |
|
241 | 241 | else $result = FALSE; |
242 | 242 | } |
243 | 243 | |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | public function resetScope() |
266 | 266 | { |
267 | 267 | $this->criteria = []; |
268 | - $this->skipCriteria( FALSE ); |
|
268 | + $this->skipCriteria(FALSE); |
|
269 | 269 | $this->model = new $this->modelClassName(); |
270 | 270 | return $this; |
271 | 271 | } |
@@ -279,10 +279,10 @@ discard block |
||
279 | 279 | { |
280 | 280 | $this->applyCriteria(); |
281 | 281 | |
282 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->forceDelete(); |
|
282 | + if (!is_null($value)) $result = $this->model->where($field, $value)->forceDelete(); |
|
283 | 283 | else |
284 | 284 | { |
285 | - if ( !empty( $this->criteria ) ) $result = $this->model->forceDelete(); |
|
285 | + if (!empty($this->criteria)) $result = $this->model->forceDelete(); |
|
286 | 286 | else $result = FALSE; |
287 | 287 | } |
288 | 288 | |
@@ -300,10 +300,10 @@ discard block |
||
300 | 300 | */ |
301 | 301 | protected function eagerLoadRelations() |
302 | 302 | { |
303 | - if ( is_array( $this->with ) ) |
|
303 | + if (is_array($this->with)) |
|
304 | 304 | { |
305 | - $with = new With( $this->with ); |
|
306 | - $this->addCriteria( $with ); |
|
305 | + $with = new With($this->with); |
|
306 | + $this->addCriteria($with); |
|
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
@@ -312,9 +312,9 @@ discard block |
||
312 | 312 | * @param array $data |
313 | 313 | * @return array |
314 | 314 | */ |
315 | - protected function cleanUnfillableFields( array $data ) |
|
315 | + protected function cleanUnfillableFields(array $data) |
|
316 | 316 | { |
317 | - return array_filter($data, function ($key) { |
|
317 | + return array_filter($data, function($key) { |
|
318 | 318 | return $this->model->isFillable($key); |
319 | 319 | }, ARRAY_FILTER_USE_KEY); |
320 | 320 | } |
@@ -324,11 +324,11 @@ discard block |
||
324 | 324 | */ |
325 | 325 | protected function applyCriteria() |
326 | 326 | { |
327 | - if( !$this->skipCriteria ) |
|
327 | + if (!$this->skipCriteria) |
|
328 | 328 | { |
329 | - foreach( $this->criteria as $criteria ) |
|
329 | + foreach ($this->criteria as $criteria) |
|
330 | 330 | { |
331 | - if( $criteria instanceof CriteriaInterface ) $this->model = $criteria->apply( $this->model, $this ); |
|
331 | + if ($criteria instanceof CriteriaInterface) $this->model = $criteria->apply($this->model, $this); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 |