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

feat(console): add make:view command #864

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

gturpin-dev
Copy link
Contributor

This PR adds the make:view command
This PR check a TODO on #759

I'm not familiar with the view system in Tempest so I need detailed review on stubs and supported generated classes.
That being said, I currently support the creation of a basic view file like this :
make:view home => this will ask for home.view.php path and then creates an empty php file
make:view HomeView class => this second enum parameter will specify that we want to create the view class documented here https://tempestphp.com/docs/framework/views/#view-objects

I don't know if more view class are needed for this command, but I think this is something that can be added when needed 😄

src/Tempest/View/src/Commands/MakeViewCommand.php Outdated Show resolved Hide resolved
src/Tempest/View/src/Commands/MakeViewCommand.php Outdated Show resolved Hide resolved

private function getStubFileFromViewType(ViewType $viewType): StubFile
{
try {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's necessary to throw an exception type, and re-throw another type after. Can you just return the match result?

I'm also curious about that "guardrail", wouldn't phpstan always catch it if we added a new ViewType? We don't need to throw here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because StubFile can also throw an InvalidArgumentException so we catch this to throw a more specific exception.

For the "guardrail", you're right, phpstan will catch it until we change the config ( I don't think this should happen )
But, it's more a personal preference to have a more specific error message instead of a generic phpstan error.
I can remove it on make commands where I've implemented that if you prefer ?

gturpin-dev and others added 2 commits December 23, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants