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

Automatically fix blade variable typos and optional variables #38

Merged
merged 36 commits into from
Sep 18, 2019

Conversation

MrRio
Copy link
Contributor

@MrRio MrRio commented Sep 1, 2019

This PR adds a solution for fixing undefined variables in view files.

Screen Shot 2019-09-01 at 14 34 03

The Solution Provider

  • It starts by looking at how similar the variable name is to viewData that's already passed in. If it's above a threshold it shows these solutions first, in order of most similar.
  • After that, it offers to make the variable optional in the blade template by adding ?? ''

Screen Shot 2019-09-01 at 14 34 23

The Solutions

  • Both solutions start by loading the blade template, and making an in-memory change
  • The original and resulting blade templates are then compiled to PHP using the Blade Compiler
  • The PHP is then tokenized
  • We modify the tokenized original to our expected output
  • The actual tokenized output is compared to the proposed resulting file, if they don't match, the solution action is never offered to the user, but the suggestion text is.

This is to ensure we never break a blade template, it also allows us to build upon the basic find and replace logic in the future.

Automated Tests

There are some automated tests around this, we can expand to include more difficult cases.

@freekmurze
Copy link
Collaborator

This looks awesome. I’ll review it soon. Thanks!

@MrRio
Copy link
Contributor Author

MrRio commented Sep 1, 2019

Thanks! :)

@MrRio
Copy link
Contributor Author

MrRio commented Sep 2, 2019

I'm happy with this if you are, will use draft PRs in future while I'm still working on it

@MrRio
Copy link
Contributor Author

MrRio commented Sep 3, 2019

Thanks for the feedback. All sorted!

@MrRio
Copy link
Contributor Author

MrRio commented Sep 4, 2019

Good to merge?

Copy link
Collaborator

@freekmurze freekmurze left a comment

Choose a reason for hiding this comment

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

Some more nitpicks. After that I think it'll be ready for merge.

Awesome PR 👍

@MrRio
Copy link
Contributor Author

MrRio commented Sep 18, 2019

This is good to merge. 👍

@MrRio MrRio requested a review from freekmurze September 18, 2019 00:08
@mpociot mpociot merged commit 02a6e4e into facade:master Sep 18, 2019
@mpociot
Copy link
Contributor

mpociot commented Sep 18, 2019

Great job on this PR! Thank you!

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.

3 participants