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

Traits not being handled properly #111

Open
jakubmikita opened this issue Feb 5, 2020 · 7 comments
Open

Traits not being handled properly #111

jakubmikita opened this issue Feb 5, 2020 · 7 comments

Comments

@jakubmikita
Copy link

Trait:

namespace Package\Section;

use Package\Traits

class Example {

	use Traits\Common;

}

Gets replaced with:

namespace Imposter\Prefix\Package\Section;

use Imposter\Prefix\Package\Traits

class Example {

	use Imposter\Prefix\Traits\Common;

}

We could always backslashit: use \Package\Traits\Common; but then it becomes use Imposter\Prefix\\Package\Traits\Common

Is there any workaround? It might be related to #58 but this doesn't seem to apply to traits.

@tangrufus
Copy link
Member

I can confirm the current version doesn't work with traits.
However, I couldn't think of a way to make our regex distingush:

  • use outside class {}
  • use inside class {} (traits)

Maybe #101 or alternatives are worth investigating

@jakubmikita
Copy link
Author

What about a simple check if { precedes the use?

I don't think the use tag in the header can be in any {}

@tangrufus
Copy link
Member

I must admit confess I am bad at regex. Can you help with the regex please?

  1. Add a use xxxxxx trait in Dummy.php
  2. Add the expected result in Expected.php
  3. Either change the regex in Transformer.php OR add a new transform function like the ones in Transformer::doTransform
  4. $ composer test

@jakubmikita
Copy link
Author

I'm a regex lame too 🙈 but let me see what I can do with this one

@jakubmikita
Copy link
Author

@jakubmikita
Copy link
Author

Well, look like #101 is a way to go indeed

@matzeeable
Copy link

@Kubitomakita I have started a PR #150 to workaround the traits issue because I need this for my own open-source project as mentioned in #149. But I need to quote myself for this here again:

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

No branches or pull requests

3 participants