Haehnchen / idea-php-symfony2-plugin

IntelliJ IDEA / PhpStorm Symfony Plugin
https://plugins.jetbrains.com/plugin/7219
MIT License
913 stars 137 forks source link

Wrong hints in services.yml, for services with a parent #1134

Open amici opened 6 years ago

amici commented 6 years ago

What steps will reproduce the problem?

  1. Define a parent class
  2. Define a child class (extend the parent one)
  3. Define both classes as services, while the child is declared with "parent" keyword, so that is uses the service definition of the parent.
  4. In the child service, define some additional arguments (that don't exist in parent service)

What is the expected result? As I add new arguments for the child service, I'd expect to see the matching argument hints in editor. So, properly matched hint for 1st, 2nd or any argument.

What happens instead? The argument hints shown for child service show the hints for the parent service instead.

Example shown below:

ParentService class:

namespace AppBundle\Services;

use Symfony\Component\Routing\Router;

class ParentService
{

    /** @var Router */
    protected $router;

    /**
     * ParentService constructor.
     * @param Router $router
     */
    public function __construct(Router $router)
    {
        $this->router = $router;
    }

}

ChildService class:

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Router;

class ChildService extends ParentService
{
    /** @var Request */
    protected $newarg;

    /**
     * ChildService constructor.
     * @param Router $router
     * @param Request $newarg
     */
    public function __construct(Router $router, Request $newarg)
    {
        $this->newarg = $newarg;
    }
}

The attached image shows the hints shown in PhpStorm, after those two classes are made.

screenshot 16

Thanks!

chrisaligent commented 5 years ago

Just came across this issue myself and it caused a lot of confusion until I tracked down the cause. Our choice now is to either ignore the prominent warnings and hints, or use an alternative method of adding new arguments (possibly via a long list of setter methods): image

smilesrg commented 4 years ago

+1 for this issue

atakajlo commented 4 years ago

Faced same issue. Any updates?

nberces commented 3 years ago

+1 for this issue

chrisaligent commented 3 years ago

I've stopped overriding the constructors for services with a parent, so if I need to add a new dependency I just use a setter method. eg:

services:
    aligent.product.processor.custom:
        parent: oro.product.processor.core
        calls:
         - ['setProductRepository', ['@oro_product.repository.product']]
<?php
class AligentCustomProductProcessor extends OroProductProcessor {
    protected $productRepository;

    // NOTE: No constructor override needed

    // Custom setter
    public function setProductRepository(ProductRepository $productRepository)
    {
        $this->productRepository = $productRepository;
    }
}

Can get messy if you're injecting a lot of new services, but does reduce a lot of the confusion caused by this specific issue, and less likely to experience breaking changes when Oro decides to add a new dependency to the constructor of the service that you extended (it's happened before, even during minor upgrades).

asherry commented 1 year ago

+1 for this issue