Doctrine TypeProvider does not work for class fields
See original GitHub issueHi all! In the following example the type provider fails to recognize types when calling getManager()
on doctrine. A call to the manager is often necessary as there might be multiple of them.
Something to note is that on the following example all of the cases will work if one would use directly the $registry
argument rather than the class field. Also the RegistryInterface
is not in fact the default but rather a custom one inheriting Symfony\Bridge\Doctrine\RegistryInterface
and overriding the default @doctrine
service.
class SomeService
{
/** @var RegistryInterface */
private $registry;
public function __construct(RegistryInterface $registry) {
$this->registry = $registry;
$works = $this->registry
->getRepository(Customer::class)
->find(1);
$doesntWork = $this->registry
->getManager()
->getRepository(Customer::class)
->findBy(1);
$neitherDoesThis = $this->registry
->getManager('main')
->getRepository(Customer::class)
->find(1);
}
}
Additional info:
Item | Version |
---|---|
PHP | 7.3.13 |
Plugin | 0.20.198 |
PhpStorm | Build #PS-201.7846.90, built on June 3, 2020 |
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:12
Top Results From Across the Web
Could not resolve type of column Symfony - Stack Overflow
I want to achieve a join between my product entity and my provider entity, only, all seems ok but it does not work...
Read more >Timestamp is not a valid Doctrine column type #35498 - GitHub
Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with...
Read more >Working with Objects - Doctrine
DQL enables you to query for persistent objects in the language of objects. DQL understands classes, fields, inheritance and associations. DQL is syntactically ......
Read more >Forms (Symfony Docs)
The recommended workflow when working with Symfony forms is the following: Build the form in a Symfony controller or using a dedicated form...
Read more >Doctrine 2 ORM Documentation - Read the Docs
This guide covers getting started with the Doctrine ORM. After working through the guide you should know: • How to install and configure ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like I have this bug in PhpStorm 2020.2 with symfony plugin 0.21.203 I have entity Hospital, and SomeCommand.php
Sample code
Hospital class is resolved, findBy method signature seems to be resolved (check gif), but $hospitals have type object[] 👍
findAll() / find($x) - doesnt work as well.
Any ideas how can I fix it without adding
?
It does seem to be fixed. However the strangest bug appears where nested objects are no longer able to be autocompleted even though their type is known. Probably a phpstorm issue though.
Does that happen for you @Jasonoro ?
In the above example the IDE is no longer able to autocomplete the DateTime methods from
getCreatedAt
. When type-hinting theres
variable with a docblock everything works properly again.