Rename AdapterInterface parameter

This commit is contained in:
Toby Zerner 2021-08-29 15:40:40 +10:00
parent bc09e000d8
commit 7d7dcb3e33
3 changed files with 10 additions and 11 deletions

View File

@ -93,14 +93,14 @@ interface AdapterInterface
* *
* @return mixed|null|Deferred * @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. * Get a list of models for a has-many relationship for the model.
* *
* @return array|Deferred * @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. * Determine whether this resource type represents the given model.

View File

@ -12,12 +12,11 @@
namespace Tobyz\JsonApiServer\Adapter; namespace Tobyz\JsonApiServer\Adapter;
use Closure; use Closure;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\Relations\MorphOneOrMany;
use InvalidArgumentException; use InvalidArgumentException;
use Tobyz\JsonApiServer\Context; use Tobyz\JsonApiServer\Context;
use Tobyz\JsonApiServer\Deferred; use Tobyz\JsonApiServer\Deferred;
@ -42,7 +41,7 @@ class EloquentAdapter implements AdapterInterface
} }
} }
public function query() public function query(): Builder
{ {
return $this->model->query(); return $this->model->query();
} }
@ -97,13 +96,13 @@ class EloquentAdapter implements AdapterInterface
return $model->getAttribute($this->getAttributeProperty($attribute)); 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 // 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 // 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 // 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. // related model with the value of the ID filled.
if ($linkage) { if ($linkageOnly) {
$relation = $this->getEloquentRelation($model, $relationship); $relation = $this->getEloquentRelation($model, $relationship);
if ($relation instanceof BelongsTo) { if ($relation instanceof BelongsTo) {
@ -122,7 +121,7 @@ class EloquentAdapter implements AdapterInterface
return $this->getRelationship($model, $relationship, $context); 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); return $this->getRelationship($model, $relationship, $context);
} }
@ -147,7 +146,7 @@ class EloquentAdapter implements AdapterInterface
return $model instanceof $this->model; return $model instanceof $this->model;
} }
public function model() public function model(): Model
{ {
return $this->model->newInstance(); return $this->model->newInstance();
} }

View File

@ -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)
{ {
} }