Add support for PhpStorms unused public code detection
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.
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/
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.