diff --git a/src/Repositories/BaseRepository.php b/src/Repositories/BaseRepository.php index 538e418..d0d54f1 100644 --- a/src/Repositories/BaseRepository.php +++ b/src/Repositories/BaseRepository.php @@ -189,35 +189,35 @@ protected function prepareQuery($model) // Add a basic where clause to the query foreach ($this->where as $where) { - list($attribute, $operator, $value, $boolean) = array_pad($where, 4, null); + [$attribute, $operator, $value, $boolean] = array_pad($where, 4, null); $model = $model->where($attribute, $operator, $value, $boolean); } // Add a "where in" clause to the query foreach ($this->whereIn as $whereIn) { - list($attribute, $values, $boolean, $not) = array_pad($whereIn, 4, null); + [$attribute, $values, $boolean, $not] = array_pad($whereIn, 4, null); $model = $model->whereIn($attribute, $values, $boolean, $not); } // Add a "where not in" clause to the query foreach ($this->whereNotIn as $whereNotIn) { - list($attribute, $values, $boolean) = array_pad($whereNotIn, 3, null); + [$attribute, $values, $boolean] = array_pad($whereNotIn, 3, null); $model = $model->whereNotIn($attribute, $values, $boolean); } // Add a "where has" clause to the query foreach ($this->whereHas as $whereHas) { - list($relation, $callback, $operator, $count) = array_pad($whereHas, 4, null); + [$relation, $callback, $operator, $count] = array_pad($whereHas, 4, null); $model = $model->whereHas($relation, $callback, $operator, $count); } // Add a "scope" to the query foreach ($this->scopes as $scope => $parameters) { - $model = $model->$scope(...$parameters); + $model = $model->{$scope}(...$parameters); } // Set the "offset" value of the query @@ -232,7 +232,7 @@ protected function prepareQuery($model) // Add an "order by" clause to the query. foreach ($this->orderBy as $orderBy) { - list($attribute, $direction) = $orderBy; + [$attribute, $direction] = $orderBy; $model = $model->orderBy($attribute, $direction); } @@ -246,7 +246,7 @@ protected function prepareQuery($model) // Add a "having" clause to the query foreach ($this->having as $having) { - list($column, $operator, $value, $boolean) = array_pad($having, 4, null); + [$column, $operator, $value, $boolean] = array_pad($having, 4, null); $model = $model->having($column, $operator, $value, $boolean); } diff --git a/src/Repositories/EloquentRepository.php b/src/Repositories/EloquentRepository.php index 4bc1e49..7a1470e 100644 --- a/src/Repositories/EloquentRepository.php +++ b/src/Repositories/EloquentRepository.php @@ -136,7 +136,7 @@ public function simplePaginate($perPage = null, $attributes = ['*'], $pageName = public function findWhere(array $where, $attributes = ['*']) { return $this->executeCallback(get_called_class(), __FUNCTION__, func_get_args(), function () use ($where, $attributes) { - list($attribute, $operator, $value, $boolean) = array_pad($where, 4, null); + [$attribute, $operator, $value, $boolean] = array_pad($where, 4, null); $this->where($attribute, $operator, $value, $boolean); @@ -150,7 +150,7 @@ public function findWhere(array $where, $attributes = ['*']) public function findWhereIn(array $where, $attributes = ['*']) { return $this->executeCallback(get_called_class(), __FUNCTION__, func_get_args(), function () use ($where, $attributes) { - list($attribute, $values, $boolean, $not) = array_pad($where, 4, null); + [$attribute, $values, $boolean, $not] = array_pad($where, 4, null); $this->whereIn($attribute, $values, $boolean, $not); @@ -164,7 +164,7 @@ public function findWhereIn(array $where, $attributes = ['*']) public function findWhereNotIn(array $where, $attributes = ['*']) { return $this->executeCallback(get_called_class(), __FUNCTION__, func_get_args(), function () use ($where, $attributes) { - list($attribute, $values, $boolean) = array_pad($where, 3, null); + [$attribute, $values, $boolean] = array_pad($where, 3, null); $this->whereNotIn($attribute, $values, $boolean); @@ -178,7 +178,7 @@ public function findWhereNotIn(array $where, $attributes = ['*']) public function findWhereHas(array $where, $attributes = ['*']) { return $this->executeCallback(get_called_class(), __FUNCTION__, func_get_args(), function () use ($where, $attributes) { - list($relation, $callback, $operator, $count) = array_pad($where, 4, null); + [$relation, $callback, $operator, $count] = array_pad($where, 4, null); $this->whereHas($relation, $callback, $operator, $count); @@ -403,7 +403,7 @@ protected function extractRelations($entity, array $attributes): array if (method_exists($entity, $relation)) { $relations[$relation] = [ 'values' => $attributes[$relation], - 'class' => get_class($entity->$relation()), + 'class' => get_class($entity->{$relation}()), ]; } }); @@ -426,7 +426,7 @@ protected function syncRelations($entity, array $relations, $detaching = true): switch ($relation['class']) { case 'Illuminate\Database\Eloquent\Relations\BelongsToMany': default: - $entity->$method()->sync((array) $relation['values'], $detaching); + $entity->{$method}()->sync((array) $relation['values'], $detaching); break; } } diff --git a/src/Traits/Criteriable.php b/src/Traits/Criteriable.php index fea1796..e547343 100644 --- a/src/Traits/Criteriable.php +++ b/src/Traits/Criteriable.php @@ -156,7 +156,7 @@ protected function addCriterion($criterion, $list) $criterion = call_user_func_array([$this, 'instantiateCriterion'], $this->extractCriterionClassAndArgs($criterion)); } - $this->$list[$this->getCriterionName($criterion)] = $criterion; + $this->{$list}[$this->getCriterionName($criterion)] = $criterion; return $this; } diff --git a/tests/AbstractEloquentTest.php b/tests/AbstractEloquentTest.php index 7f7296e..70fa26c 100644 --- a/tests/AbstractEloquentTest.php +++ b/tests/AbstractEloquentTest.php @@ -22,7 +22,7 @@ abstract class AbstractEloquentTests extends TestCase protected $container; /** Setup the database schema. */ - public function setUp() + protected function setUp() { $this->setupContainer(); $this->setupDatabase(new Manager($this->getContainer())); @@ -128,7 +128,7 @@ protected function schema(): Builder * * @return void */ - public function tearDown(): void + protected function tearDown(): void { $this->schema()->drop('users'); $this->schema()->drop('posts'); diff --git a/tests/EloquentRepositoryCriteriaTest.php b/tests/EloquentRepositoryCriteriaTest.php index 2cfe247..d04a402 100644 --- a/tests/EloquentRepositoryCriteriaTest.php +++ b/tests/EloquentRepositoryCriteriaTest.php @@ -495,6 +495,7 @@ public function apply($builder, $repository) class ThirdTestWithArgumentsCriterion implements \Rinvex\Repository\Contracts\CriterionContract { protected $from; + protected $to; public function __construct($from, $to) diff --git a/tests/Stubs/EloquentPost.php b/tests/Stubs/EloquentPost.php index 0f25f8b..ff621fc 100644 --- a/tests/Stubs/EloquentPost.php +++ b/tests/Stubs/EloquentPost.php @@ -7,6 +7,7 @@ class EloquentPost extends \Illuminate\Database\Eloquent\Model { protected $table = 'posts'; + protected $fillable = ['user_id', 'parent_id', 'name']; public function user() diff --git a/tests/Stubs/EloquentPostRepository.php b/tests/Stubs/EloquentPostRepository.php index d469a92..531b288 100644 --- a/tests/Stubs/EloquentPostRepository.php +++ b/tests/Stubs/EloquentPostRepository.php @@ -9,5 +9,6 @@ class EloquentPostRepository extends EloquentRepository { protected $model = EloquentPost::class; + protected $repositoryId = 'rinvex.repository.post'; } diff --git a/tests/Stubs/EloquentUser.php b/tests/Stubs/EloquentUser.php index a1e24f1..442edaa 100644 --- a/tests/Stubs/EloquentUser.php +++ b/tests/Stubs/EloquentUser.php @@ -7,6 +7,7 @@ class EloquentUser extends \Illuminate\Database\Eloquent\Model { protected $table = 'users'; + protected $fillable = ['name', 'email', 'age']; public function posts() diff --git a/tests/Stubs/EloquentUserRepository.php b/tests/Stubs/EloquentUserRepository.php index fe1a962..e3c2b8d 100644 --- a/tests/Stubs/EloquentUserRepository.php +++ b/tests/Stubs/EloquentUserRepository.php @@ -12,5 +12,6 @@ class EloquentUserRepository extends EloquentRepository use Criteriable; protected $model = EloquentUser::class; + protected $repositoryId = 'rinvex.repository.user'; }