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

NEW: Refactor OperationScaffolder subclasses to use resolved type name #182

Merged
merged 1 commit into from
Jan 30, 2019
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/Scaffolding/Scaffolders/CRUD/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getName()
return $name;
}

return 'create' . ucfirst($this->getTypeName());
return 'create' . ucfirst($this->getResolvedTypeName());
}

/**
Expand Down Expand Up @@ -107,7 +107,7 @@ protected function generateInputType(Manager $manager)
*/
protected function inputTypeName()
{
return $this->getTypeName() . 'CreateInputType';
return $this->getResolvedTypeName() . 'CreateInputType';
}

public function resolve($object, array $args, $context, ResolveInfo $info)
Expand Down
2 changes: 1 addition & 1 deletion src/Scaffolding/Scaffolders/CRUD/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getName()
return $name;
}

return 'delete' . ucfirst($this->getTypeName());
return 'delete' . ucfirst($this->getResolvedTypeName());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Scaffolding/Scaffolders/CRUD/Read.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getName()
return $name;
}

$typePlural = $this->pluralise($this->getTypeName());
$typePlural = $this->pluralise($this->getResolvedTypeName());
return 'read' . ucfirst($typePlural);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Scaffolding/Scaffolders/CRUD/ReadOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getName()
return $name;
}

return 'readOne' . ucfirst($this->getTypeName());
return 'readOne' . ucfirst($this->getResolvedTypeName());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Scaffolding/Scaffolders/CRUD/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getName()
return $name;
}

return 'update' . ucfirst($this->getTypeName());
return 'update' . ucfirst($this->getResolvedTypeName());
}

/**
Expand Down Expand Up @@ -114,7 +114,7 @@ protected function generateInputType(Manager $manager)
*/
protected function inputTypeName()
{
return $this->getTypeName() . 'UpdateInputType';
return $this->getResolvedTypeName() . 'UpdateInputType';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Scaffolding/Scaffolders/DataObjectScaffolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct($dataObjectClass)
*/
public function getTypeName()
{
return $this->typeName();
return $this->getDataObjectTypeName();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Scaffolding/Scaffolders/ListQueryScaffolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function applyConfig(array $config)
} else {
throw new InvalidArgumentException(sprintf(
'sortableFields must be an array (see %s)',
$this->getTypeName()
$this->getResolvedTypeName()
));
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/Scaffolding/Scaffolders/MutationScaffolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ public function scaffold(Manager $manager)
];
}

public function getTypeName()
/**
* If a type name has not been assigned, fallback to the typename that gets generated
* off the dataobject
*
* @return string
*/
protected function getResolvedTypeName()
{
return parent::getTypeName() ?: $this->typeName();
return $this->getTypeName() ?: $this->getDataObjectTypeName();
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/Scaffolding/Scaffolders/QueryScaffolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ public function setNested($bool)
return $this;
}

public function getTypeName()
/**
* If a type name has not been assigned, fallback to the typename that gets generated
* off the dataobject
*
* @return string
*/
protected function getResolvedTypeName()
{
return parent::getTypeName() ?: $this->typeName();
return $this->getTypeName() ?: $this->getDataObjectTypeName();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Scaffolding/Traits/DataObjectTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ public function getDataObjectClass()

/**
* Type name inferred from the dataobject.
* This should not be called directly, but only by getTypeName()
*
* @return string
*/
protected function typeName()
public function getDataObjectTypeName()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be public? From the usage above, it looks like this is mostly dealing with internal logic consideration.

If it turns out we need it to be public later, it's easy to make it public.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a @throws statement.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but would make this an API breakage, and since it's essentially a bug fix, I really would love to get it into 3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this an API breakage? There's no getDataObjectTypeName right now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And introducing APIs to fix bugs is fine in Semver.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the protected method is risky but also fine in terms of semver. They're not part of our "public API"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is targeted at version 3. Which hasn't been release yet. Or do we consider RC to be part of our semver commitment?

{
$dataObjectClass = $this->getDataObjectClass();
if (!$dataObjectClass) {
Expand Down