From 3e1bf12ad00b60c513d502002c4e447bdde2d22e Mon Sep 17 00:00:00 2001 From: Xenofon Spafaridis Date: Sun, 14 Feb 2016 22:47:02 +0200 Subject: [PATCH] Improve codestyle --- src/Filter.php | 9 ++------- src/Relationship.php | 17 ++++------------- tests/src/RelationshipTest.php | 4 ++-- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/Filter.php b/src/Filter.php index 608b0b7..c163a85 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -425,13 +425,8 @@ public static function parseFromParameters($parameters, $modelClass) */ public function __get($name) { - switch ($name) { - case 'primary': - return $this->primary; - case 'relationships': - return $this->relationships; - case 'attributes': - return $this->attributes; + if (in_array($name, ['primary', 'relationships', 'attributes'])) { + return $this->{$name}; } throw new \Exception(sprintf( diff --git a/src/Relationship.php b/src/Relationship.php index 76c9f65..1920aca 100644 --- a/src/Relationship.php +++ b/src/Relationship.php @@ -27,7 +27,7 @@ * @property-read int $type * @property-read string|null $recordDataAttribute * @property-read object $callbacks - * @property-read int $flags + * @property int $flags */ class Relationship { @@ -191,17 +191,8 @@ public function __construct( */ public function __get($name) { - switch ($name) { - case 'modelClass': - return $this->modelClass; - case 'type': - return $this->type; - case 'recordDataAttribute': - return $this->recordDataAttribute; - case 'callbacks': - return $this->callbacks; - case 'flags': - return $this->flags; + if (in_array($name, ['modelClass', 'type', 'recordDataAttribute', 'callbacks', 'flags'])) { + return $this->{$name}; } throw new \Exception(sprintf( @@ -217,7 +208,7 @@ public function __get($name) * @throws \Exception */ public function __set($name, $value) { - if (in_array($name, ['flag'])) { + if (in_array($name, ['flags'])) { $this->{$name} = $value; return $this; } diff --git a/tests/src/RelationshipTest.php b/tests/src/RelationshipTest.php index 495bd98..d296d05 100644 --- a/tests/src/RelationshipTest.php +++ b/tests/src/RelationshipTest.php @@ -174,9 +174,9 @@ public function testGetFailure() */ public function testSet() { - $this->relationship->{'flag'} = Relationship::FLAG_INCLUDE_BY_DEFAULT; + $this->relationship->{'flags'} = Relationship::FLAG_INCLUDE_BY_DEFAULT; - $this->assertSame(Relationship::FLAG_INCLUDE_BY_DEFAULT, $this->relationship->{'flag'}); + $this->assertSame(Relationship::FLAG_INCLUDE_BY_DEFAULT, $this->relationship->{'flags'}); } /**