Model situation:
In my project, I extend ArticleFacade, add there new public myNewFunction(), and configure my new service as an alias for the original one in services.yml, something like this:
Shopsys\FrameworkBundle\Model\Article\ArticleFacade: '@Shopsys\ShopBundle\Model\Article\ArticleFacade'
Then, I want to use ArticleFacade::myNewFunction() in Controller\Front\ArticleController that has a dependency on ArticleFacade from the core (ie. FrameworkBundle).
At the moment, I am able to use the new function thanks to the DI container configuration, however, the IDE is not aware of it as the dependency is still typehinted and annotated as the original ArticleFacade from the core, and therefore I am not able to click on the function myNewFunction and navigate to the proper class. This might be very confusing from a long-term maintainability point of view.
Possible solutions
/**
- * @var \Shopsys\FrameworkBundle\Model\Article\ArticleFacade
+ * @var \Shopsys\ShopBundle\Model\Article\ArticleFacade
*/
private $articleFacade;
ArticleFacade (ie. the descendant implemented by me in ShopBundle) indeed:- public function __construct(\Shopsys\FrameworkBundle\Model\Article\ArticleFacade $articleFacade)
+ public function __construct(\Shopsys\ShopBundle\Model\Article\ArticleFacade $articleFacade)
{
$this->articleFacade = $articleFacade;
}
Personally, I prefer the solution 2. I am thinking about implementation of some fixer, that would automatically change all the dependencies in project-base in such a case, maybe it could add the entry to services.yml as well. Basically, if you extended a class, the fixer would ensure that it is used everywhere in your project instead of the parent class.
More on that, we should cover the situation when I extend some class that is dependent on a class that I have already extended:
ShopBundle\ArticleFacade extends FrameworkBundle\ArticleFacadeFrameworkBundle\Admin\ArticleController is dependent on FrameworkBundle\ArticleFacade - everything ok so farShopBundle\Admin\ArticleController extends FrameworkBundle\Admin\ArticleController - now I should probably ovewrite the dependency on FrameworkBundle\ArticleFacade and start using my ShopBundle\ArticleFacadeI would like to validate the fixer idea so I am asking here for your opinions or other suggestions.
There is a consensus on the proper usage of extended classes in project.
Is it possible to provide more related articles, docs, etc. covering your mind map about planned "Service extension-ability"? I have found articles and docs only about entity related extensions, I am not sure if it is same
Provided examples are too simple from my point of view and therefore little bit misleading
for example I want to use some third party "module" (or package), which also extends ArticleFacade with method extendedModuleFunction() and I want to add my new function/extension called myDreamArticleFunction() on top of this extension and now I want to use in my controller both functions
if it is only about IDE support and autocomplete; I would suggest to have a look at
.phpstorm.meta.php to help IDE to understand how extension works in SSFW
This issue has been automatically marked as stale because there was no activity within the last 4 months (and it is quite a long time). It will be closed if no further activity occurs. Thank you for your contributions.
up
Hi, @simara-svatopluk is already analyzing possible solutions for this :wink:
Most helpful comment
Is it possible to provide more related articles, docs, etc. covering your mind map about planned "Service extension-ability"? I have found articles and docs only about entity related extensions, I am not sure if it is same
Provided examples are too simple from my point of view and therefore little bit misleading
for example I want to use some third party "module" (or package), which also extends
ArticleFacadewith methodextendedModuleFunction()and I want to add my new function/extension calledmyDreamArticleFunction()on top of this extension and now I want to use in my controller both functionsif it is only about IDE support and autocomplete; I would suggest to have a look at
.phpstorm.meta.php to help IDE to understand how extension works in SSFW