Comments (3)
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.
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.
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)
- Symfony 7 rector rule collection HOT 8
- .
- Can't make yaml routing to annotation/attribute rule work HOT 4
- [Downgrade] New rule to handle attribute Symfony Command to Symfony HOT 6
- [PHP 8.0] Add swagger attribute set HOT 1
- Update readme with RectorConfigBuilder HOT 8
- The rector rule for TranslatorInterface does not take into account possible null parameter HOT 1
- Symfony Console: Migrate `configure` to `AsCommand` HOT 6
- Updated for rector 1+ HOT 2
- Bug: ContainerGetToConstructorInjectionRector replaces constant with object HOT 1
- [Symfony 7.0] Add AsDoctrineListener rule HOT 2
- [Symfony 7.0] Add AsMessageHandler HOT 2
- Symfony 6 Rules about ContainerInterface HOT 6
- Symfony 6.1 - `AsCommand` addition not correct when using constants in name HOT 21
- [Symfony 6.3] Consider adding nested autowire attribute
- StringToArrayArgumentProcessRector with $process->setInput() HOT 1
- Replace ParameterBagInterface with #[Autowire()] attribute HOT 2
- #[AsMessageHandler] on abstract classes produces untagged services
- Error when running `StringExtensionToConfigBuilderRector` on simple configuration file HOT 4
- Please clarify if both xml & php versions of the container need to be configured HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rector-symfony.