Skip to content

Traits not being handled properly #111

Description

@jakubmikita

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.

Activity

  1. tangrufus commented on Feb 6, 2020

    @tangrufus
    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

  2. jakubmikita commented on Feb 7, 2020

    @jakubmikita
    Author

    What about a simple check if { precedes the use?

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

  3. tangrufus commented on Feb 7, 2020

    @tangrufus
    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
  4. jakubmikita commented on Feb 7, 2020

    @jakubmikita
    Author

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

  5. jakubmikita commented on Feb 7, 2020

    @jakubmikita
    Author

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

  6. added a commit that references this issue on Apr 8, 2020
    f5deb1d
  7. matzeeable commented on Apr 8, 2020

    @matzeeable

    @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.

  8. added a commit that references this issue on Apr 8, 2020
    a814daa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions