From b56811c9ee99489c3913fb025d6ac7d638318248 Mon Sep 17 00:00:00 2001 From: Colin Hall Date: Wed, 10 Jun 2020 21:32:58 +0100 Subject: [PATCH] Remove object in relationship namespace Was only introduced in PHP7.2 --- .gitignore | 4 +++- src/Support/Relations/HasMany.php | 2 +- src/Support/Relations/HasOne.php | 18 +++++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 863147d..3c64062 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ docs vendor coverage /dev -/tests \ No newline at end of file +/tests +/.idea +.idea diff --git a/src/Support/Relations/HasMany.php b/src/Support/Relations/HasMany.php index 63e5e08..de1cb64 100644 --- a/src/Support/Relations/HasMany.php +++ b/src/Support/Relations/HasMany.php @@ -109,7 +109,7 @@ public function detach($object) } - public function save(object $object) + public function save($object) { if($object instanceof $this->relatedClass){ $this->attach($this->updateFields($object)->save()); diff --git a/src/Support/Relations/HasOne.php b/src/Support/Relations/HasOne.php index d306008..b51824f 100644 --- a/src/Support/Relations/HasOne.php +++ b/src/Support/Relations/HasOne.php @@ -25,7 +25,7 @@ public function __construct($related, $owner, $name, $field, $updateFields = []) $this->boot(); } - public function boot() + public function boot() { if(array_key_exists($this->name, $this->owner->getAttributes())){ $this->hydrate($this->owner->getAttributes()[$this->name]); @@ -42,7 +42,7 @@ public function boot() } } - protected function hydrate($data) + protected function hydrate($data) { if($data != []){ if($this->owner->hasKey()){ @@ -54,13 +54,13 @@ protected function hydrate($data) } } - public function empty() + public function empty() { $this->relation = null; return $this; } - public function save(object $object) + public function save($object) { if($this->relation == null){ if($object instanceof InteractsWithAPI){ @@ -73,21 +73,21 @@ public function save(object $object) throw new IncorrectRelationshipModel($this->related, $object); } } else { - throw new NotAPersistableModel($this->owner, $this->related); + throw new NotAPersistableModel($this->owner, $this->related); } } throw new RelationAlreadyExistsException($this->owner, $this->related); } - public function getResults() + public function getResults() { if(empty($this->relation)){ $this->getRelationFromApi(); - } + } return $this->relation; } - public function getRelationFromApi() + public function getRelationFromApi() { $this->relation = $this->related->newInstance([$this->field => $this->owner->getKey()])->getOne(); if($this->field != null && $this->owner->hasKey() && $this->relation != null){ @@ -108,4 +108,4 @@ public function make($data) // Be good to add these:- findOrNew, updateOrCreate -} \ No newline at end of file +}