-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internal Error : The class ... was not found in the chain configured namespaces #445
Comments
This bug report is missing a link to reproduction at phpstan.org/try. It will most likely be closed after manual review. |
I tried to use phpstan.org/try. but it cannot handle several files... |
|
It is referenced in phpstan.neon:
I tried with this following file => same result:
|
Hello, I have exactly the same issue. I guess this is caused by the fact that there are multiple Doctrine entity manager (I'm working on a DDD app where I separate each aggregate in his own entity manager), and the |
Yep, I've got the same issue, two databases and two entity managers setup, one MySQL and one Postgres |
Today, Symfony 6.4/7.0 ; phpstan 1.10.50 ; php 8.2 => the issue is still here 😢. |
I used the code from this comment: #53 (comment) I updated it a little, just so phpstan, psalm and rector don't complain 😅 (mostly 8.1+ stuff and some missing types) but all the credits goes to @adrienbrault : <?php
use App\Kernel;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
use Symfony\Component\Dotenv\Dotenv;
require __DIR__.'/../vendor/autoload.php';
(new Dotenv())->bootEnv(__DIR__.'/../.env');
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$kernel->boot();
$doctrine = $kernel->getContainer()->get('doctrine');
$metadataFactory = new class($doctrine) implements ClassMetadataFactory {
private readonly Registry $doctrine;
public function __construct(Registry $doctrine)
{
$this->doctrine = $doctrine;
}
public function getAllMetadata(): array
{
$all = [];
foreach ($this->doctrine->getManagers() as $manager) {
$all = [...$all, ...$manager->getMetadataFactory()->getAllMetadata()];
}
return $all;
}
public function getMetadataFor(string $className): ClassMetadata
{
$manager = $this->doctrine->getManagerForClass($className);
if (!$manager instanceof ObjectManager) {
throw new \Exception(__FILE__);
}
return $manager->getClassMetadata($className);
}
public function isTransient(string $className): bool
{
$isTransient = true;
foreach ($this->doctrine->getManagers() as $manager) {
$isTransient = $isTransient && $manager->getMetadataFactory()->isTransient($className);
}
return $isTransient;
}
public function hasMetadataFor(string $className): bool
{
$hasMetadata = false;
foreach ($this->doctrine->getManagers() as $manager) {
$hasMetadata = $hasMetadata || $manager->getMetadataFactory()->hasMetadataFor($className);
}
return $hasMetadata;
}
public function setMetadataFor(string $className, ClassMetadata $class): void
{
throw new \Exception(__FILE__);
}
};
return new class($doctrine, $metadataFactory) implements ObjectManager {
public function __construct(
private readonly Registry $doctrine,
private readonly ClassMetadataFactory $metadataFactory
) {
}
public function getRepository(string $className): ObjectRepository
{
return $this->doctrine->getRepository($className);
}
public function getClassMetadata(string $className): ClassMetadata
{
$manager = $this->doctrine->getManagerForClass($className);
if (!$manager instanceof ObjectManager) {
throw new \Exception(__FILE__);
}
return $manager->getClassMetadata($className);
}
public function getMetadataFactory(): ClassMetadataFactory
{
return $this->metadataFactory;
}
public function find(string $className, mixed $id): ?object
{
throw new \Exception(__FILE__);
}
public function persist(object $object): void
{
throw new \Exception(__FILE__);
}
public function remove(object $object): void
{
throw new \Exception(__FILE__);
}
public function clear(): void
{
throw new \Exception(__FILE__);
}
public function detach(object $object): void
{
throw new \Exception(__FILE__);
}
public function refresh(object $object): void
{
throw new \Exception(__FILE__);
}
public function flush(): void
{
throw new \Exception(__FILE__);
}
public function initializeObject(object $obj): void
{
throw new \Exception(__FILE__);
}
public function contains(object $object): bool
{
throw new \Exception(__FILE__);
}
}; If someone as a large project to test it, fix it (or give feedback), we can probably add this to the README for others? |
Bug report
With lastest Phpstan version, on an up-to-date Symfony 6.2/PHP 8.1 project, I run:
php -d memory_limit=-1 vendor/bin/phpstan analyse src --level=5 -v
It says me :
Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md:
So this is the stacktrace:
My doctrine conf:
Code snippet that reproduces the problem
The clas
AuteurLien
is very simple and never reference to namespaceApp\Entity\Tud
:The text was updated successfully, but these errors were encountered: