@@ -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,11 +300,11 @@ 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 ); |
|
| 305 | + $with = new With($this->with); |
|
| 306 | 306 | |
| 307 | - $this->model = $this->addCriteria( $with ); |
|
| 307 | + $this->model = $this->addCriteria($with); |
|
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | |
@@ -313,9 +313,9 @@ discard block |
||
| 313 | 313 | * @param array $data |
| 314 | 314 | * @return array |
| 315 | 315 | */ |
| 316 | - protected function cleanUnfillableFields( array $data ) |
|
| 316 | + protected function cleanUnfillableFields(array $data) |
|
| 317 | 317 | { |
| 318 | - return array_filter($data, function ($key) { |
|
| 318 | + return array_filter($data, function($key) { |
|
| 319 | 319 | return $this->model->isFillable($key); |
| 320 | 320 | }, ARRAY_FILTER_USE_KEY); |
| 321 | 321 | } |
@@ -325,11 +325,11 @@ discard block |
||
| 325 | 325 | */ |
| 326 | 326 | protected function applyCriteria() |
| 327 | 327 | { |
| 328 | - if( !$this->skipCriteria ) |
|
| 328 | + if (!$this->skipCriteria) |
|
| 329 | 329 | { |
| 330 | - foreach( $this->criteria as $criteria ) |
|
| 330 | + foreach ($this->criteria as $criteria) |
|
| 331 | 331 | { |
| 332 | - if( $criteria instanceof CriteriaInterface ) $this->model = $criteria->apply( $this->model, $this ); |
|
| 332 | + if ($criteria instanceof CriteriaInterface) $this->model = $criteria->apply($this->model, $this); |
|
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | |
@@ -48,7 +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 ) ) { |
|
| 52 | + $this->model = $this->model->where( $field, $value ); |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | $result = $this->model->first( $columns ); |
| 54 | 56 | |
@@ -68,7 +70,9 @@ discard block |
||
| 68 | 70 | $this->eagerLoadRelations(); |
| 69 | 71 | $this->applyCriteria(); |
| 70 | 72 | |
| 71 | - if ( !is_null( $value ) && !is_null( $field ) ) $this->model = $this->model->where( $field, $value ); |
|
| 73 | + if ( !is_null( $value ) && !is_null( $field ) ) { |
|
| 74 | + $this->model = $this->model->where( $field, $value ); |
|
| 75 | + } |
|
| 72 | 76 | |
| 73 | 77 | $result = $this->model->get( $columns ); |
| 74 | 78 | |
@@ -115,7 +119,9 @@ discard block |
||
| 115 | 119 | */ |
| 116 | 120 | public function with( $relations ) |
| 117 | 121 | { |
| 118 | - if ( is_string( $relations ) ) $relations = func_get_args(); |
|
| 122 | + if ( is_string( $relations ) ) { |
|
| 123 | + $relations = func_get_args(); |
|
| 124 | + } |
|
| 119 | 125 | |
| 120 | 126 | $this->with = $relations; |
| 121 | 127 | |
@@ -208,7 +214,9 @@ discard block |
||
| 208 | 214 | // Single update. |
| 209 | 215 | $this->model->where( $field, $value)->update( $cleanFields ); |
| 210 | 216 | |
| 211 | - foreach( $cleanFields as $F => $V ) $this->model->{$F} = $V; |
|
| 217 | + foreach( $cleanFields as $F => $V ) { |
|
| 218 | + $this->model->{$F} = $V; |
|
| 219 | + } |
|
| 212 | 220 | |
| 213 | 221 | $returnedVal = $this->model; |
| 214 | 222 | } else |
@@ -234,11 +242,15 @@ discard block |
||
| 234 | 242 | { |
| 235 | 243 | $this->applyCriteria(); |
| 236 | 244 | |
| 237 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->delete(); |
|
| 238 | - else |
|
| 245 | + if ( !is_null( $value ) ) { |
|
| 246 | + $result = $this->model->where( $field, $value )->delete(); |
|
| 247 | + } else |
|
| 239 | 248 | { |
| 240 | - if ( !empty( $this->criteria ) ) $result = $this->model->delete(); |
|
| 241 | - else $result = FALSE; |
|
| 249 | + if ( !empty( $this->criteria ) ) { |
|
| 250 | + $result = $this->model->delete(); |
|
| 251 | + } else { |
|
| 252 | + $result = FALSE; |
|
| 253 | + } |
|
| 242 | 254 | } |
| 243 | 255 | |
| 244 | 256 | $this->resetScope(); |
@@ -279,11 +291,15 @@ discard block |
||
| 279 | 291 | { |
| 280 | 292 | $this->applyCriteria(); |
| 281 | 293 | |
| 282 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->forceDelete(); |
|
| 283 | - else |
|
| 294 | + if ( !is_null( $value ) ) { |
|
| 295 | + $result = $this->model->where( $field, $value )->forceDelete(); |
|
| 296 | + } else |
|
| 284 | 297 | { |
| 285 | - if ( !empty( $this->criteria ) ) $result = $this->model->forceDelete(); |
|
| 286 | - else $result = FALSE; |
|
| 298 | + if ( !empty( $this->criteria ) ) { |
|
| 299 | + $result = $this->model->forceDelete(); |
|
| 300 | + } else { |
|
| 301 | + $result = FALSE; |
|
| 302 | + } |
|
| 287 | 303 | } |
| 288 | 304 | |
| 289 | 305 | $this->resetScope(); |
@@ -329,7 +345,9 @@ discard block |
||
| 329 | 345 | { |
| 330 | 346 | foreach( $this->criteria as $criteria ) |
| 331 | 347 | { |
| 332 | - if( $criteria instanceof CriteriaInterface ) $this->model = $criteria->apply( $this->model, $this ); |
|
| 348 | + if( $criteria instanceof CriteriaInterface ) { |
|
| 349 | + $this->model = $criteria->apply( $this->model, $this ); |
|
| 350 | + } |
|
| 333 | 351 | } |
| 334 | 352 | } |
| 335 | 353 | |
@@ -23,9 +23,9 @@ |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | - * @param mixed $queryBuilder |
|
| 27 | - * @return mixed |
|
| 28 | - */ |
|
| 26 | + * @param mixed $queryBuilder |
|
| 27 | + * @return mixed |
|
| 28 | + */ |
|
| 29 | 29 | public function apply( $queryBuilder ) |
| 30 | 30 | { |
| 31 | 31 | // Do something with the query builder and return it. |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * With constructor. |
| 18 | 18 | * @param array $with |
| 19 | 19 | */ |
| 20 | - public function __construct( array $with = [] ) |
|
| 20 | + public function __construct(array $with = []) |
|
| 21 | 21 | { |
| 22 | 22 | $this->with = $with; |
| 23 | 23 | } |
@@ -26,10 +26,10 @@ discard block |
||
| 26 | 26 | * @param mixed $queryBuilder |
| 27 | 27 | * @return mixed |
| 28 | 28 | */ |
| 29 | - public function apply( $queryBuilder ) |
|
| 29 | + public function apply($queryBuilder) |
|
| 30 | 30 | { |
| 31 | 31 | // Do something with the query builder and return it. |
| 32 | - if ( $this->with ) $queryBuilder->with( $this->with ); |
|
| 32 | + if ($this->with) $queryBuilder->with($this->with); |
|
| 33 | 33 | |
| 34 | 34 | return $queryBuilder; |
| 35 | 35 | } |
@@ -29,7 +29,9 @@ |
||
| 29 | 29 | public function apply( $queryBuilder ) |
| 30 | 30 | { |
| 31 | 31 | // Do something with the query builder and return it. |
| 32 | - if ( $this->with ) $queryBuilder->with( $this->with ); |
|
| 32 | + if ( $this->with ) { |
|
| 33 | + $queryBuilder->with( $this->with ); |
|
| 34 | + } |
|
| 33 | 35 | |
| 34 | 36 | return $queryBuilder; |
| 35 | 37 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | * @param mixed $queryBuilder |
| 15 | 15 | * @return mixed |
| 16 | 16 | */ |
| 17 | - public function apply( $queryBuilder ) |
|
| 17 | + public function apply($queryBuilder) |
|
| 18 | 18 | { |
| 19 | 19 | return $queryBuilder->inRandomOrder(); |
| 20 | 20 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param $field |
| 19 | 19 | * @param array $list |
| 20 | 20 | */ |
| 21 | - public function __construct( $field, array $list ) |
|
| 21 | + public function __construct($field, array $list) |
|
| 22 | 22 | { |
| 23 | 23 | $this->field = $field; |
| 24 | 24 | $this->list = $list; |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | * @param mixed $queryBuilder |
| 29 | 29 | * @return mixed |
| 30 | 30 | */ |
| 31 | - public function apply( $queryBuilder ) |
|
| 31 | + public function apply($queryBuilder) |
|
| 32 | 32 | { |
| 33 | 33 | // Do something with the query builder and return it. |
| 34 | - return $queryBuilder->whereNotIn( $this->field, $this->list ); |
|
| 34 | + return $queryBuilder->whereNotIn($this->field, $this->list); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @param array $list |
| 21 | 21 | * @param string $field |
| 22 | 22 | */ |
| 23 | - public function __construct( $relationName, array $list, $field = 'id' ) |
|
| 23 | + public function __construct($relationName, array $list, $field = 'id') |
|
| 24 | 24 | { |
| 25 | 25 | $this->relationName = $relationName; |
| 26 | 26 | $this->list = $list; |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | * @param mixed $queryBuilder |
| 32 | 32 | * @return mixed |
| 33 | 33 | */ |
| 34 | - public function apply( $queryBuilder ) |
|
| 34 | + public function apply($queryBuilder) |
|
| 35 | 35 | { |
| 36 | 36 | // Do something with the query builder and return it. |
| 37 | - return $queryBuilder->whereHas( $this->relationName, function ($query) { |
|
| 38 | - $query->whereIn( $this->field, $this->list); |
|
| 37 | + return $queryBuilder->whereHas($this->relationName, function($query) { |
|
| 38 | + $query->whereIn($this->field, $this->list); |
|
| 39 | 39 | }); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param $field |
| 19 | 19 | * @param array $list |
| 20 | 20 | */ |
| 21 | - public function __construct( $field, array $list ) |
|
| 21 | + public function __construct($field, array $list) |
|
| 22 | 22 | { |
| 23 | 23 | $this->field = $field; |
| 24 | 24 | $this->list = $list; |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | * @param mixed $queryBuilder |
| 29 | 29 | * @return mixed |
| 30 | 30 | */ |
| 31 | - public function apply( $queryBuilder ) |
|
| 31 | + public function apply($queryBuilder) |
|
| 32 | 32 | { |
| 33 | 33 | // Do something with the query builder and return it. |
| 34 | - return $queryBuilder->whereIn( $this->field, $this->list ); |
|
| 34 | + return $queryBuilder->whereIn($this->field, $this->list); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | } |