erichard / SublimePHPCompanion

A Sublime Text plugin that provides cool stuff for PHP 5.3+ coding session.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`use TraitName` breaks find_use command.

g105b opened this issue · comments

When there are traits in use within a class, the find_use command is broken.

This is due to the use keyword having more than one meaning, dependent on context. One meaning is to "import" or "alias" a namespaced class. Another meaning is to "insert" a trait, and another meaning is to import a variable from an outer scope.

It seems that SublimePHPCompanion's find_use command is only taking the first meaning into account. It feels like the command simply looks for the nearest use keyword and adds the imports there. If a use keyword exists inside a class definition, everything breaks causing syntax errors.

Not sure I understand the problem. The plugin add the use statment after the namespace declaration.

You want the plugin to do something else ?

There is a bug in the logic.

<?php
namespace Test;

class Example {

    public function __construct() {
        $thing = new Thing(); // find use here is fine.
    }
}
<?php
namespace Test;

class Example {

    use SomeTrait;
    use AnotherTrait;

    public function __construct() {
        $thing = new Thing(); // find use here breaks things because of the traits.
    }
}

I just tried your use case and the use statement is added at the right place and does not break anything.

Can you show me what you expect when using find_use in the second case ?

This is what I expect:

<?php
namespace Test;

use \some\namespace\Thing; // ** This is where the namespace import should be put. **

class Example {

    use SomeTrait;
    use AnotherTrait;

    public function __construct() {
        $thing = new Thing(); // find use here breaks things because of the traits.
    }
}

This is what I actually get:

<?php
namespace Test;

class Example {

    use \some\namespace\Thing; // ** it is actually added here - as if it were a trait - which breaks things **
    use SomeTrait;
    use AnotherTrait;

    public function __construct() {
        $thing = new Thing(); // find use here breaks things because of the traits.
    }
}
commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.