Skip to content

Ignore errors while loading ObjectManager #662

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

Draft
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Doctrine/DoctrineDiagnoseExtension.php
Original file line number Diff line number Diff line change
@@ -30,12 +30,22 @@ public function __construct(

public function print(Output $output): void
{
$objectManager = $this->objectMetadataResolver->getObjectManager();

$output->writeLineFormatted(sprintf(
'<info>Doctrine\'s objectManagerLoader:</info> %s',
$this->objectMetadataResolver->hasObjectManagerLoader() ? 'In use' : 'No',
));

$objectManager = $this->objectMetadataResolver->getObjectManager();
if ($this->objectMetadataResolver->getLastError() !== null) {
$output->writeLineFormatted(sprintf(
'<error>Doctrine\'s objectManagerLoader error:</error> %s',
$this->objectMetadataResolver->getLastError()->getMessage(),
));

$output->writeLineFormatted('');
}

if ($objectManager instanceof EntityManagerInterface) {
$connection = $objectManager->getConnection();
$driver = $this->driverDetector->detect($connection);
16 changes: 15 additions & 1 deletion src/Type/Doctrine/ObjectMetadataResolver.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
use PHPStan\Doctrine\Mapping\ClassMetadataFactory;
use PHPStan\ShouldNotHappenException;
use ReflectionException;
use Throwable;
use function class_exists;
use function is_file;
use function is_readable;
@@ -26,6 +27,8 @@ final class ObjectMetadataResolver

private string $tmpDir;

private ?Throwable $lastError = null;

public function __construct(
?string $objectManagerLoader,
string $tmpDir
@@ -89,6 +92,11 @@ public function isTransient(string $className): bool
}
}

public function getLastError(): ?Throwable
{
return $this->lastError;
}

private function getMetadataFactory(): ?ClassMetadataFactory
{
if ($this->metadataFactory !== null) {
@@ -160,7 +168,13 @@ private function loadObjectManager(string $objectManagerLoader): ?ObjectManager
));
}

return require $objectManagerLoader;
try {
return require $objectManagerLoader;
} catch (Throwable $error) {
$this->lastError = $error;

return null;
}
}

}

Unchanged files with check annotations Beta

protected function initialize(): void
{
$drivers = [];
if (class_exists(AnnotationDriver::class) && class_exists(AnnotationReader::class)) {

Check failure on line 31 in src/Doctrine/Mapping/ClassMetadataFactory.php

GitHub Actions / PHPStan (8.3, composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctri...

Access to constant on deprecated class Doctrine\ORM\Mapping\Driver\AnnotationDriver: This class will be removed in 3.0 without replacement. Copyright (c) Doctrine Project From https://github.com/doctrine/orm/blob/40fbbf4429b0d66517244051237a2bd0616a7a13/src/Mapping/Driver/AnnotationDriver.php
$docParser = new DocParser();
$docParser->setIgnoreNotImportedAnnotations(true);
$drivers[] = new AnnotationDriver(new AnnotationReader($docParser));

Check failure on line 34 in src/Doctrine/Mapping/ClassMetadataFactory.php

GitHub Actions / PHPStan (8.3, composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctri...

Call to method __construct() of deprecated class Doctrine\ORM\Mapping\Driver\AnnotationDriver: This class will be removed in 3.0 without replacement. Copyright (c) Doctrine Project From https://github.com/doctrine/orm/blob/40fbbf4429b0d66517244051237a2bd0616a7a13/src/Mapping/Driver/AnnotationDriver.php

Check failure on line 34 in src/Doctrine/Mapping/ClassMetadataFactory.php

GitHub Actions / PHPStan (8.3, composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctri...

Instantiation of deprecated class Doctrine\ORM\Mapping\Driver\AnnotationDriver: This class will be removed in 3.0 without replacement. Copyright (c) Doctrine Project From https://github.com/doctrine/orm/blob/40fbbf4429b0d66517244051237a2bd0616a7a13/src/Mapping/Driver/AnnotationDriver.php
}
if (class_exists(AttributeDriver::class) && PHP_VERSION_ID >= 80000) {
$drivers[] = new AttributeDriver([]);
$config->setMetadataCache(new ArrayCachePool());
$metadataDriver = new MappingDriverChain();
$metadataDriver->addDriver(new AnnotationDriver(

Check failure on line 20 in tests/Classes/entity-manager.php

GitHub Actions / PHPStan (8.3, composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctri...

Call to method __construct() of deprecated class Doctrine\ORM\Mapping\Driver\AnnotationDriver: This class will be removed in 3.0 without replacement. Copyright (c) Doctrine Project From https://github.com/doctrine/orm/blob/40fbbf4429b0d66517244051237a2bd0616a7a13/src/Mapping/Driver/AnnotationDriver.php

Check failure on line 20 in tests/Classes/entity-manager.php

GitHub Actions / PHPStan (8.3, composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctri...

Instantiation of deprecated class Doctrine\ORM\Mapping\Driver\AnnotationDriver: This class will be removed in 3.0 without replacement. Copyright (c) Doctrine Project From https://github.com/doctrine/orm/blob/40fbbf4429b0d66517244051237a2bd0616a7a13/src/Mapping/Driver/AnnotationDriver.php
new AnnotationReader(),
[__DIR__ . '/data'],
), 'PHPStan\\Rules\\Doctrine\\ORM\\');
$config->setMetadataCache(new ArrayCachePool());
$config->setMetadataDriverImpl(
new AnnotationDriver(

Check failure on line 16 in tests/DoctrineIntegration/ORM/entity-manager.php

GitHub Actions / PHPStan (8.3, composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctri...

Call to method __construct() of deprecated class Doctrine\ORM\Mapping\Driver\AnnotationDriver: This class will be removed in 3.0 without replacement. Copyright (c) Doctrine Project From https://github.com/doctrine/orm/blob/40fbbf4429b0d66517244051237a2bd0616a7a13/src/Mapping/Driver/AnnotationDriver.php

Check failure on line 16 in tests/DoctrineIntegration/ORM/entity-manager.php

GitHub Actions / PHPStan (8.3, composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctri...

Instantiation of deprecated class Doctrine\ORM\Mapping\Driver\AnnotationDriver: This class will be removed in 3.0 without replacement. Copyright (c) Doctrine Project From https://github.com/doctrine/orm/blob/40fbbf4429b0d66517244051237a2bd0616a7a13/src/Mapping/Driver/AnnotationDriver.php
new AnnotationReader(),
[__DIR__ . '/data'],
),
if (InstalledVersions::satisfies(new VersionParser(), 'doctrine/orm', '3.*')) {
$config->setMetadataDriverImpl(new AttributeDriver([__DIR__ . '/Entity']));
} else {
$config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), [__DIR__ . '/Entity']));

Check failure on line 5142 in tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php

GitHub Actions / PHPStan (8.3, composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctri...

Call to method __construct() of deprecated class Doctrine\ORM\Mapping\Driver\AnnotationDriver: This class will be removed in 3.0 without replacement. Copyright (c) Doctrine Project From https://github.com/doctrine/orm/blob/40fbbf4429b0d66517244051237a2bd0616a7a13/src/Mapping/Driver/AnnotationDriver.php

Check failure on line 5142 in tests/Platform/QueryResultTypeWalkerFetchTypeMatrixTest.php

GitHub Actions / PHPStan (8.3, composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctri...

Instantiation of deprecated class Doctrine\ORM\Mapping\Driver\AnnotationDriver: This class will be removed in 3.0 without replacement. Copyright (c) Doctrine Project From https://github.com/doctrine/orm/blob/40fbbf4429b0d66517244051237a2bd0616a7a13/src/Mapping/Driver/AnnotationDriver.php
}
$config->addCustomStringFunction('INT_PI', TypedExpressionIntegerPiFunction::class);
$config->setMetadataCache(new ArrayCachePool());
$metadataDriver = new MappingDriverChain();
$metadataDriver->addDriver(new AnnotationDriver(

Check failure on line 18 in tests/Rules/DeadCode/entity-manager.php

GitHub Actions / PHPStan (8.3, composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctri...

Call to method __construct() of deprecated class Doctrine\ORM\Mapping\Driver\AnnotationDriver: This class will be removed in 3.0 without replacement. Copyright (c) Doctrine Project From https://github.com/doctrine/orm/blob/40fbbf4429b0d66517244051237a2bd0616a7a13/src/Mapping/Driver/AnnotationDriver.php
new AnnotationReader(),
[__DIR__ . '/data'],
), 'PHPStan\\Rules\\Doctrine\\ORM\\');