diff --git a/src/ApiModel.php b/src/ApiModel.php index cff1668..64d566c 100644 --- a/src/ApiModel.php +++ b/src/ApiModel.php @@ -183,7 +183,7 @@ public function __set($key, $value) } } - protected function hasRelationship($key): ? string + protected function hasRelationship($key): ?string { if (method_exists($this, $key) && ($this->{$key}() instanceof Relationship || $this->{$key}() instanceof SingleRelationship)) { @@ -226,7 +226,7 @@ public function __get($key) * * @return bool */ - public function exists() : bool + public function exists(): bool { foreach ($this->requiredParameters as $parameter) { if (!$this->has($parameter)) { diff --git a/src/Relationships/SingleRelationship.php b/src/Relationships/SingleRelationship.php index 9078943..9016452 100644 --- a/src/Relationships/SingleRelationship.php +++ b/src/Relationships/SingleRelationship.php @@ -15,7 +15,7 @@ public function setRelateClassQualifiedName(string $class) return $this; } - public function getRelatedClassQualifiedName():string + public function getRelatedClassQualifiedName(): string { return $this->relatedClassQualifiedName; } diff --git a/tests/Fakes/City.php b/tests/Fakes/City.php index 8ff113b..0549219 100644 --- a/tests/Fakes/City.php +++ b/tests/Fakes/City.php @@ -8,6 +8,6 @@ class City extends ApiModel { public function partnerCity() { - return $this->hasOne(City::class, 'partner_city'); + return $this->hasOne(self::class, 'partner_city'); } } diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 354c1cd..8f092b0 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -49,8 +49,7 @@ public function it_should_assign_a_value_to_a_parameter() /** @test */ public function it_should_throw_an_error_on_immutble_parameters() { - $model = new class() extends ApiModel - { + $model = new class() extends ApiModel { public function getFooAttribute() { return 'bar'; @@ -66,8 +65,7 @@ public function getFooAttribute() /** @test */ public function it_should_throw_an_error_on_immutble_methods() { - $model = new class() extends ApiModel - { + $model = new class() extends ApiModel { public function fakeMethod(): string { return 'I return a string'; @@ -83,8 +81,7 @@ public function fakeMethod(): string /** @test */ public function it_should_return_null_getting_value_on_defined_methods() { - $model = new class() extends ApiModel - { + $model = new class() extends ApiModel { public function fakeMethod(): string { return 'I return a string'; @@ -157,7 +154,7 @@ public function it_should_cast_single_relationship_to_model() $harbor = new Harbor([ 'city' => [ 'data' => [ - 'id' => 1, + 'id' => 1, 'name' => 'Montevideo', ], ], @@ -172,7 +169,7 @@ public function it_should_cast_single_relationship_to_model_and_preserve_attribu $harbor = new Harbor([ 'city' => [ 'data' => [ - 'id' => 1, + 'id' => 1, 'name' => 'Montevideo', ], ], @@ -186,7 +183,7 @@ public function it_should_cast_single_relationship_to_model_event_without_data() { $harbor = new Harbor([ 'city' => [ - 'id' => 1, + 'id' => 1, 'name' => 'Montevideo', ], ]); @@ -199,7 +196,7 @@ public function it_should_refresh_a_relationship_when_setting_new_value() { $harbor = new Harbor([ 'city' => [ - 'id' => 1, + 'id' => 1, 'name' => 'Montevideo', ], ]); @@ -217,7 +214,7 @@ public function it_should_property_from_relationship_should_be_accessed() $harbor = new Harbor([ 'city' => [ 'data' => [ - 'id' => 1, + 'id' => 1, 'name' => 'Montevideo', ], ], @@ -233,7 +230,7 @@ public function it_should_property_from_relationship_should_be_accessed_as_objec $harbor = new Harbor([ 'city' => [ 'data' => [ - 'id' => 1, + 'id' => 1, 'name' => 'Montevideo', ], ], @@ -249,7 +246,7 @@ public function it_should_property_from_relationship_should_be_accessed_double() $harbor = new Harbor([ 'city' => [ 'data' => [ - 'id' => 1, + 'id' => 1, 'name' => 'Montevideo', ], ], @@ -265,10 +262,10 @@ public function it_should_preserve_attributes_for_child_properties() $harbor = new Harbor([ 'city' => [ 'data' => [ - 'id' => 1, - 'name' => 'Montevideo', + 'id' => 1, + 'name' => 'Montevideo', 'partner_city' => [ - 'id' => 2, + 'id' => 2, 'name' => 'Berlin', ], ], @@ -286,11 +283,11 @@ public function it_should_return_a_collection_of_boats() 'boats' => [ 'data' => [ [ - 'id' => 1, + 'id' => 1, 'name' => 'Queen Mary', ], [ - 'id' => 2, + 'id' => 2, 'name' => 'Reconcho', ], ], @@ -307,11 +304,11 @@ public function it_should_refresh_a_collection_of_relationships() 'boats' => [ 'data' => [ [ - 'id' => 1, + 'id' => 1, 'name' => 'Queen Mary', ], [ - 'id' => 2, + 'id' => 2, 'name' => 'Reconcho', ], ], @@ -340,9 +337,9 @@ public function it_should_eager_load_default_relationships() 'visited_cities' => [ 'data' => [ [ - 'name' => 'Montevideo', + 'name' => 'Montevideo', 'partner_city' => [ - 'id' => 2, + 'id' => 2, 'name' => 'Berlin', ], ], @@ -360,8 +357,7 @@ public function it_should_eager_load_default_relationships() /** @test */ public function it_should_not_eager_load_any_relationship_if_not_in_include_default_array() { - $model = new class(['visited_cities' => ['data' => [['name' => 'Montevideo'], ['name' => 'London']]]]) extends ApiModel - { + $model = new class(['visited_cities' => ['data' => [['name' => 'Montevideo'], ['name' => 'London']]]]) extends ApiModel { public function visitedCities() { return $this->hasMany(City::class, 'visited_cities');