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

fix: resolve namespace section and traits correctly #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matzeeable
Copy link

Hi!

I have added a test case and implementation to support PHP traits as requested here #111 and #149.

Instead of backwards-referencing in a Regexp to check if the use is inside a class, I go the following way:

  • Use T-Regex package to obtain the offset of a found use statement
  • When found, get the content before the match
  • Get all previous class { and namespace { definitions (yeah, multiple namespace { definitions are allowed in PHP)
  • Get the last found match and check if it is a class defintion
  • If yes, skip the trait transformation

Backwards-referencing in a Regexp would be much more "nice", but unfortunately PHP does not support it (I used it in JavaScript before).

RegExp is not the recommend way to do such transformations!! This is a simple workaround which works but you should really consider building your tool on top of an AST parser like php-parser.

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.

None yet

1 participant