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

Add support for PhpStorms unused public code detection #92

Open
uehler opened this issue Apr 4, 2019 · 2 comments
Open

Add support for PhpStorms unused public code detection #92

uehler opened this issue Apr 4, 2019 · 2 comments

Comments

@uehler
Copy link
Contributor

uehler commented Apr 4, 2019

Since PhpStorm 2019.1 there is a feature, which detects unused public code. But there are some places in the shopware plugin code which are not recognized properly. I am not 100% sure if this is a task for this plugin but I try it anyway:

Controller:

class Shopware_Controllers_Frontend_MyController extends \Enlight_Controller_Action {
// some code
}

The controller class name is marked as unused, the methods are recognized correct. This is only the case for "old" plugin controllers without namespaces.

Subscriber:
If you have a subscriber like

use Enlight_Controller_ActionEventArgs as ActionEventArgs;

public static function getSubscribedEvents(): array
    {
        return [
            'Enlight_Controller_Action_PostDispatchSecure_Frontend_Detail' => 'onPostDispatchSecureFrontendDetail',
        ];
    }

public function onPostDispatchSecureFrontendDetail(ActionEventArgs $args)
    {
       // some code
    }

the onPostDispatchSecureFrontendDetail-Method is marked as used, which is awesome. But if you register the subscriber like

ActionEventArgs::POST_SECURE_EVENT . '_Frontend_Detail' => 'onPostDispatchSecureFrontendDetail',

the method is marked as unused, and PhpStorm doesn't recognize the connection between the method and the subscriber anymore. The connection between those worked until PhpStorm 2018.3.

@bcremer
Copy link

bcremer commented Apr 4, 2019

The problem is on the phpstorm side. Certain classes are not called directly but via the framework. This includes controllers and DI-Factories as well as Test-Classes.
PHPStorm calls these classes "EntryPoint".

Unfortunately in PHPStorm it is not yet possible to configure EntryPoints.
In IntelliJ IDEA there is a setting for that, see: https://blog.jetbrains.com/idea/2016/09/intellij-idea-2016-3-eap-makes-unused-code-detection-more-flexible/

@cedricziel
Copy link
Contributor

Internally, code is recognized as "unused", when there is no reference to it, that's why the second example is not recognized.

Handling concatenated strings and/or constant literals as references to a class would be a platform-feature. IMHO.

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