Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from StyleCI #12

Merged
merged 1 commit into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ApiModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Relationships/SingleRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function setRelateClassQualifiedName(string $class)
return $this;
}

public function getRelatedClassQualifiedName():string
public function getRelatedClassQualifiedName(): string
{
return $this->relatedClassQualifiedName;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Fakes/City.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
44 changes: 20 additions & 24 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -157,7 +154,7 @@ public function it_should_cast_single_relationship_to_model()
$harbor = new Harbor([
'city' => [
'data' => [
'id' => 1,
'id' => 1,
'name' => 'Montevideo',
],
],
Expand All @@ -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',
],
],
Expand All @@ -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',
],
]);
Expand All @@ -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',
],
]);
Expand All @@ -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',
],
],
Expand All @@ -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',
],
],
Expand All @@ -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',
],
],
Expand All @@ -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',
],
],
Expand All @@ -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',
],
],
Expand All @@ -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',
],
],
Expand Down Expand Up @@ -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',
],
],
Expand All @@ -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');
Expand Down