From 7d7dcb3e33cba05455e0981e6130a158c955b4e0 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sun, 29 Aug 2021 15:40:40 +1000 Subject: [PATCH] Rename AdapterInterface parameter --- src/Adapter/AdapterInterface.php | 4 ++-- src/Adapter/EloquentAdapter.php | 13 ++++++------- src/Adapter/NullAdapter.php | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index c82a2c3..61074ff 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -93,14 +93,14 @@ interface AdapterInterface * * @return mixed|null|Deferred */ - public function getHasOne($model, HasOne $relationship, bool $linkage, Context $context); + public function getHasOne($model, HasOne $relationship, bool $linkageOnly, Context $context); /** * Get a list of models for a has-many relationship for the model. * * @return array|Deferred */ - public function getHasMany($model, HasMany $relationship, bool $linkage, Context $context); + public function getHasMany($model, HasMany $relationship, bool $linkageOnly, Context $context); /** * Determine whether this resource type represents the given model. diff --git a/src/Adapter/EloquentAdapter.php b/src/Adapter/EloquentAdapter.php index 60c1f22..09709d5 100644 --- a/src/Adapter/EloquentAdapter.php +++ b/src/Adapter/EloquentAdapter.php @@ -12,12 +12,11 @@ namespace Tobyz\JsonApiServer\Adapter; use Closure; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; -use Illuminate\Database\Eloquent\Relations\HasOneThrough; -use Illuminate\Database\Eloquent\Relations\MorphOneOrMany; use InvalidArgumentException; use Tobyz\JsonApiServer\Context; use Tobyz\JsonApiServer\Deferred; @@ -42,7 +41,7 @@ class EloquentAdapter implements AdapterInterface } } - public function query() + public function query(): Builder { return $this->model->query(); } @@ -97,13 +96,13 @@ class EloquentAdapter implements AdapterInterface return $model->getAttribute($this->getAttributeProperty($attribute)); } - public function getHasOne($model, HasOne $relationship, bool $linkage, Context $context) + public function getHasOne($model, HasOne $relationship, bool $linkageOnly, Context $context) { // If this is a belongs-to relationship, and we only need to get the ID // for linkage, then we don't have to actually load the relation because // the ID is stored in a column directly on the model. We will mock up a // related model with the value of the ID filled. - if ($linkage) { + if ($linkageOnly) { $relation = $this->getEloquentRelation($model, $relationship); if ($relation instanceof BelongsTo) { @@ -122,7 +121,7 @@ class EloquentAdapter implements AdapterInterface return $this->getRelationship($model, $relationship, $context); } - public function getHasMany($model, HasMany $relationship, bool $linkage, Context $context) + public function getHasMany($model, HasMany $relationship, bool $linkageOnly, Context $context) { return $this->getRelationship($model, $relationship, $context); } @@ -147,7 +146,7 @@ class EloquentAdapter implements AdapterInterface return $model instanceof $this->model; } - public function model() + public function model(): Model { return $this->model->newInstance(); } diff --git a/src/Adapter/NullAdapter.php b/src/Adapter/NullAdapter.php index cc88daf..bdd008c 100644 --- a/src/Adapter/NullAdapter.php +++ b/src/Adapter/NullAdapter.php @@ -58,11 +58,11 @@ class NullAdapter implements AdapterInterface { } - public function getHasOne($model, HasOne $relationship, bool $linkage, Context $context) + public function getHasOne($model, HasOne $relationship, bool $linkageOnly, Context $context) { } - public function getHasMany($model, HasMany $relationship, bool $linkage, Context $context) + public function getHasMany($model, HasMany $relationship, bool $linkageOnly, Context $context) { }