Git Product home page Git Product logo

Comments (3)

Bilge avatar Bilge commented on September 27, 2024

Obviously it would be fairly short-sighted to just special-case this one particular occurrence, but I think it points to a larger problem with the inadequacy of the ContainerGetToConstructorInjectionRector rector. In particular, I notice the following undesirable behaviours: Rector prefers to inject a less derived type than the one being fetched, e.g. interfaces and abstract classes, even when the less derived type does not even exist as a service.

I think it would be prudent to:

  • Inject the same service as the one being fetched in the case that the service name matches an existing class name.
  • Use the most derived types (leaf type) if such service definition exists.
  • Only use interface and abstract types if none of the above applies, and such service definition exists for that type. This can be used to help disambiguate which type to hint when there are multiple interfaces involved (but only one has a service definition).

As another clear example of the problem, Rector prefers to replace all my concrete repository services with ObjectRepository interface, which I then have to manually put back to the actual repository/repositories we need (since it will also collapse multiple such services down to a single ObjectRepository, which is even more annoying).

from rector-symfony.

TomasVotruba avatar TomasVotruba commented on September 27, 2024

Hi, the current context is as simple as your describe.
To improve the type resolving, well have to give Rector more context.

There could be simple constant map to pick the better type.

from rector-symfony.

TomasVotruba avatar TomasVotruba commented on September 27, 2024

Closing for lack of feedback. We're narrowing issues to keep focus on active and engaging contributor to keep project growing. Thank you for understanding.

Feel free to re-open with failing test case.

from rector-symfony.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.