diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
index d22c1b7e2..072662ccb 100644
--- a/.github/workflows/continuous-integration.yml
+++ b/.github/workflows/continuous-integration.yml
@@ -21,10 +21,9 @@ jobs:
fail-fast: false
matrix:
php-version:
- - "7.4"
- - "8.0"
- "8.1"
- "8.2"
+ - "8.3"
dependencies:
- "highest"
stability:
@@ -37,32 +36,27 @@ jobs:
# Tests the lowest set of dependencies
- dependencies: "lowest"
stability: "stable"
- php-version: "7.4"
+ php-version: "8.1"
# Test LTS
- - symfony-require: "5.4.*"
- dependencies: "highest"
- php-version: "8.0"
-
- # Test last supported minor version
- symfony-require: "6.*"
dependencies: "highest"
- php-version: "8.3"
+ php-version: "8.1"
# DBAL only without ORM
- - php-version: "8.3"
+ - php-version: "8.4"
dependencies: "highest"
stability: "stable"
remove-orm: true
# DBAL 4
- - php-version: "8.3"
+ - php-version: "8.4"
dependencies: "highest"
stability: "dev"
remove-orm: true
# Bleeding edge
- - php-version: "8.3"
+ - php-version: "8.4"
dependencies: "highest"
stability: "dev"
@@ -83,7 +77,7 @@ jobs:
- name: "Require symfony/messenger"
run: "composer require --dev symfony/messenger --no-update"
- if: "${{ startsWith(matrix.symfony-require, '5.') }}"
+ if: "${{ startsWith(matrix.symfony-require, '6.') }}"
- name: "Enforce using stable dependencies"
run: "composer config minimum-stability stable"
@@ -93,6 +87,10 @@ jobs:
run: "composer remove doctrine/orm --dev --no-update"
if: "${{ matrix.remove-orm }}"
+ - name: "Remove Psalm"
+ run: "composer remove vimeo/psalm psalm/plugin-phpunit psalm/plugin-symfony --dev --no-update"
+ if: "${{ matrix.php-version == '8.4' }}"
+
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v3"
with:
diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml
index fde93c2f4..3033fc5e0 100644
--- a/.github/workflows/static-analysis.yml
+++ b/.github/workflows/static-analysis.yml
@@ -22,7 +22,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
- php-version: "8.2"
+ php-version: "8.3"
- name: "Enforce using stable dependencies"
run: "composer config minimum-stability stable"
diff --git a/composer.json b/composer.json
index b14faa131..2f1271c3d 100644
--- a/composer.json
+++ b/composer.json
@@ -29,20 +29,19 @@
],
"homepage": "https://www.doctrine-project.org",
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.1",
"doctrine/cache": "^1.11 || ^2.0",
"doctrine/dbal": "^3.7.0 || ^4.0",
"doctrine/persistence": "^2.2 || ^3",
"doctrine/sql-formatter": "^1.0.1",
- "symfony/cache": "^5.4 || ^6.0 || ^7.0",
- "symfony/config": "^5.4 || ^6.0 || ^7.0",
- "symfony/console": "^5.4 || ^6.0 || ^7.0",
- "symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
+ "symfony/cache": "^6.4 || ^7.0",
+ "symfony/config": "^6.4 || ^7.0",
+ "symfony/console": "^6.4 || ^7.0",
+ "symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/deprecation-contracts": "^2.1 || ^3",
- "symfony/doctrine-bridge": "^5.4.46 || ~6.3.12 || ^6.4.3 || ^7.0.3",
- "symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
- "symfony/polyfill-php80": "^1.15",
- "symfony/service-contracts": "^1.1.1 || ^2.0 || ^3"
+ "symfony/doctrine-bridge": "^6.4.3 || ^7.0.3",
+ "symfony/framework-bundle": "^6.4 || ^7.0",
+ "symfony/service-contracts": "^2.5 || ^3"
},
"require-dev": {
"doctrine/annotations": "^1 || ^2",
@@ -50,28 +49,29 @@
"doctrine/deprecations": "^1.0",
"doctrine/orm": "^2.17 || ^3.0",
"friendsofphp/proxy-manager-lts": "^1.0",
- "phpunit/phpunit": "^9.5.26",
- "psalm/plugin-phpunit": "^0.18.4",
+ "phpunit/phpunit": "^9.6.22",
+ "psalm/plugin-phpunit": "^0.19.0",
"psalm/plugin-symfony": "^5",
"psr/log": "^1.1.4 || ^2.0 || ^3.0",
- "symfony/phpunit-bridge": "^6.1 || ^7.0",
- "symfony/property-info": "^5.4 || ^6.0 || ^7.0",
- "symfony/proxy-manager-bridge": "^5.4 || ^6.0 || ^7.0",
- "symfony/security-bundle": "^5.4 || ^6.0 || ^7.0",
- "symfony/stopwatch": "^5.4 || ^6.0 || ^7.0",
- "symfony/string": "^5.4 || ^6.0 || ^7.0",
- "symfony/twig-bridge": "^5.4 || ^6.0 || ^7.0",
- "symfony/validator": "^5.4 || ^6.0 || ^7.0",
- "symfony/var-exporter": "^5.4 || ^6.2 || ^7.0",
- "symfony/web-profiler-bundle": "^5.4 || ^6.0 || ^7.0",
- "symfony/yaml": "^5.4 || ^6.0 || ^7.0",
- "twig/twig": "^1.34 || ^2.12 || ^3.0",
+ "symfony/phpunit-bridge": "^7.2",
+ "symfony/property-info": "^6.4 || ^7.0",
+ "symfony/proxy-manager-bridge": "^6.4 || ^7.0",
+ "symfony/security-bundle": "^6.4 || ^7.0",
+ "symfony/stopwatch": "^6.4 || ^7.0",
+ "symfony/string": "^6.4 || ^7.0",
+ "symfony/twig-bridge": "^6.4 || ^7.0",
+ "symfony/validator": "^6.4 || ^7.0",
+ "symfony/var-exporter": "^6.4 || ^7.0",
+ "symfony/web-profiler-bundle": "^6.4 || ^7.0",
+ "symfony/yaml": "^6.4 || ^7.0",
+ "twig/twig": "^2.13 || ^3.0.4",
"vimeo/psalm": "^5.15"
},
"conflict": {
"doctrine/annotations": ">=3.0",
"doctrine/orm": "<2.17 || >=4.0",
- "twig/twig": "<1.34 || >=2.0 <2.4"
+ "symfony/var-exporter": "< 6.4",
+ "twig/twig": "<2.13 || >=3.0 <3.0.4"
},
"suggest": {
"ext-pdo": "*",
diff --git a/config/messenger.xml b/config/messenger.xml
index 1ca9faa94..a12d403d1 100644
--- a/config/messenger.xml
+++ b/config/messenger.xml
@@ -51,10 +51,6 @@
-
-
-
-
diff --git a/config/orm.xml b/config/orm.xml
index b99cd8587..cf547cd90 100644
--- a/config/orm.xml
+++ b/config/orm.xml
@@ -135,22 +135,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 1d419a4db..eb4550ac9 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -9,7 +9,7 @@
-
+
src
tests
diff --git a/src/Attribute/AsDoctrineListener.php b/src/Attribute/AsDoctrineListener.php
index ed3c7b7d1..43489c523 100644
--- a/src/Attribute/AsDoctrineListener.php
+++ b/src/Attribute/AsDoctrineListener.php
@@ -12,8 +12,8 @@ class AsDoctrineListener
{
public function __construct(
public string $event,
- public ?int $priority = null,
- public ?string $connection = null,
+ public int|null $priority = null,
+ public string|null $connection = null,
) {
}
}
diff --git a/src/Attribute/AsEntityListener.php b/src/Attribute/AsEntityListener.php
index 9b6173c19..b55578736 100644
--- a/src/Attribute/AsEntityListener.php
+++ b/src/Attribute/AsEntityListener.php
@@ -11,12 +11,12 @@
class AsEntityListener
{
public function __construct(
- public ?string $event = null,
- public ?string $method = null,
- public ?bool $lazy = null,
- public ?string $entityManager = null,
- public ?string $entity = null,
- public ?int $priority = null,
+ public string|null $event = null,
+ public string|null $method = null,
+ public bool|null $lazy = null,
+ public string|null $entityManager = null,
+ public string|null $entity = null,
+ public int|null $priority = null,
) {
}
}
diff --git a/src/Attribute/AsMiddleware.php b/src/Attribute/AsMiddleware.php
index a05c10cc2..f1cb8bd53 100644
--- a/src/Attribute/AsMiddleware.php
+++ b/src/Attribute/AsMiddleware.php
@@ -10,7 +10,7 @@ class AsMiddleware
/** @param string[] $connections */
public function __construct(
public array $connections = [],
- public ?int $priority = null,
+ public int|null $priority = null,
) {
}
}
diff --git a/src/CacheWarmer/DoctrineMetadataCacheWarmer.php b/src/CacheWarmer/DoctrineMetadataCacheWarmer.php
index 7cfbd485d..cb0654577 100644
--- a/src/CacheWarmer/DoctrineMetadataCacheWarmer.php
+++ b/src/CacheWarmer/DoctrineMetadataCacheWarmer.php
@@ -13,14 +13,10 @@
/** @final since 2.11 */
class DoctrineMetadataCacheWarmer extends AbstractPhpFileCacheWarmer
{
- private EntityManagerInterface $entityManager;
- private string $phpArrayFile;
-
- public function __construct(EntityManagerInterface $entityManager, string $phpArrayFile)
- {
- $this->entityManager = $entityManager;
- $this->phpArrayFile = $phpArrayFile;
-
+ public function __construct(
+ private readonly EntityManagerInterface $entityManager,
+ private readonly string $phpArrayFile,
+ ) {
parent::__construct($phpArrayFile);
}
@@ -32,7 +28,7 @@ public function isOptional(): bool
return false;
}
- protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter, ?string $buildDir = null): bool
+ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter, string|null $buildDir = null): bool
{
// cache already warmed up, no needs to do it again
if (is_file($this->phpArrayFile)) {
diff --git a/src/Command/DoctrineCommand.php b/src/Command/DoctrineCommand.php
index 866d695cb..144c5a776 100644
--- a/src/Command/DoctrineCommand.php
+++ b/src/Command/DoctrineCommand.php
@@ -16,13 +16,10 @@
*/
abstract class DoctrineCommand extends Command
{
- private ManagerRegistry $doctrine;
-
- public function __construct(ManagerRegistry $doctrine)
- {
+ public function __construct(
+ private readonly ManagerRegistry $doctrine,
+ ) {
parent::__construct();
-
- $this->doctrine = $doctrine;
}
/**
diff --git a/src/Command/ImportMappingDoctrineCommand.php b/src/Command/ImportMappingDoctrineCommand.php
index 951eea691..d30de3bc7 100644
--- a/src/Command/ImportMappingDoctrineCommand.php
+++ b/src/Command/ImportMappingDoctrineCommand.php
@@ -30,15 +30,12 @@
*/
class ImportMappingDoctrineCommand extends DoctrineCommand
{
- /** @var string[] */
- private array $bundles;
-
/** @param string[] $bundles */
- public function __construct(ManagerRegistry $doctrine, array $bundles)
- {
+ public function __construct(
+ ManagerRegistry $doctrine,
+ private readonly array $bundles,
+ ) {
parent::__construct($doctrine);
-
- $this->bundles = $bundles;
}
protected function configure(): void
diff --git a/src/Command/Proxy/OrmProxyCommand.php b/src/Command/Proxy/OrmProxyCommand.php
index 1f3cdb26f..ad7e648f6 100644
--- a/src/Command/Proxy/OrmProxyCommand.php
+++ b/src/Command/Proxy/OrmProxyCommand.php
@@ -14,14 +14,11 @@
*/
trait OrmProxyCommand
{
- private ?EntityManagerProvider $entityManagerProvider;
-
- public function __construct(?EntityManagerProvider $entityManagerProvider = null)
- {
+ public function __construct(
+ private readonly EntityManagerProvider|null $entityManagerProvider = null,
+ ) {
parent::__construct($entityManagerProvider);
- $this->entityManagerProvider = $entityManagerProvider;
-
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.8',
diff --git a/src/ConnectionFactory.php b/src/ConnectionFactory.php
index 2b273bdf9..2d3796986 100644
--- a/src/ConnectionFactory.php
+++ b/src/ConnectionFactory.php
@@ -44,18 +44,16 @@ class ConnectionFactory
'sqlite3' => 'pdo_sqlite',
];
- /** @var mixed[][] */
- private array $typesConfig = [];
-
- private DsnParser $dsnParser;
+ private readonly DsnParser $dsnParser;
private bool $initialized = false;
/** @param mixed[][] $typesConfig */
- public function __construct(array $typesConfig, ?DsnParser $dsnParser = null)
- {
- $this->typesConfig = $typesConfig;
- $this->dsnParser = $dsnParser ?? new DsnParser(self::DEFAULT_SCHEME_MAP);
+ public function __construct(
+ private readonly array $typesConfig = [],
+ DsnParser|null $dsnParser = null,
+ ) {
+ $this->dsnParser = $dsnParser ?? new DsnParser(self::DEFAULT_SCHEME_MAP);
}
/**
@@ -67,7 +65,7 @@ public function __construct(array $typesConfig, ?DsnParser $dsnParser = null)
*
* @return Connection
*/
- public function createConnection(array $params, ?Configuration $config = null, ?EventManager $eventManager = null, array $mappingTypes = [])
+ public function createConnection(array $params, Configuration|null $config = null, EventManager|null $eventManager = null, array $mappingTypes = [])
{
if (! method_exists(Connection::class, 'getEventManager') && $eventManager !== null) {
throw new InvalidArgumentException('Passing an EventManager instance is not supported with DBAL > 3');
diff --git a/src/Controller/ProfilerController.php b/src/Controller/ProfilerController.php
index d85cda0a7..cc00db026 100644
--- a/src/Controller/ProfilerController.php
+++ b/src/Controller/ProfilerController.php
@@ -20,15 +20,11 @@
/** @internal */
class ProfilerController
{
- private Environment $twig;
- private ConnectionRegistry $registry;
- private Profiler $profiler;
-
- public function __construct(Environment $twig, ConnectionRegistry $registry, Profiler $profiler)
- {
- $this->twig = $twig;
- $this->registry = $registry;
- $this->profiler = $profiler;
+ public function __construct(
+ private readonly Environment $twig,
+ private readonly ConnectionRegistry $registry,
+ private readonly Profiler $profiler,
+ ) {
}
/**
@@ -73,7 +69,7 @@ public function explainAction($token, $connectionName, $query)
} else {
$results = $this->explainOtherPlatform($connection, $query);
}
- } catch (Throwable $e) {
+ } catch (Throwable) {
return new Response('This query cannot be explained.');
}
diff --git a/src/DataCollector/DoctrineDataCollector.php b/src/DataCollector/DoctrineDataCollector.php
index 2ecd7a48d..355f0df30 100644
--- a/src/DataCollector/DoctrineDataCollector.php
+++ b/src/DataCollector/DoctrineDataCollector.php
@@ -49,26 +49,23 @@
*/
class DoctrineDataCollector extends BaseCollector
{
- private ManagerRegistry $registry;
- private ?int $invalidEntityCount = null;
+ private int|null $invalidEntityCount = null;
/**
* @var mixed[][]|null
* @psalm-var ?array>
*/
- private ?array $groupedQueries = null;
-
- private bool $shouldValidateSchema;
-
- public function __construct(ManagerRegistry $registry, bool $shouldValidateSchema = true, ?DebugDataHolder $debugDataHolder = null)
- {
- $this->registry = $registry;
- $this->shouldValidateSchema = $shouldValidateSchema;
+ private array|null $groupedQueries = null;
+ public function __construct(
+ private readonly ManagerRegistry $registry,
+ private readonly bool $shouldValidateSchema = true,
+ DebugDataHolder|null $debugDataHolder = null,
+ ) {
parent::__construct($registry, $debugDataHolder);
}
- public function collect(Request $request, Response $response, ?Throwable $exception = null): void
+ public function collect(Request $request, Response $response, Throwable|null $exception = null): void
{
parent::collect($request, $response, $exception);
diff --git a/src/Dbal/BlacklistSchemaAssetFilter.php b/src/Dbal/BlacklistSchemaAssetFilter.php
index e63a2ec86..d17516912 100644
--- a/src/Dbal/BlacklistSchemaAssetFilter.php
+++ b/src/Dbal/BlacklistSchemaAssetFilter.php
@@ -9,13 +9,10 @@
/** @deprecated Implement your own include/exclude mechanism */
class BlacklistSchemaAssetFilter
{
- /** @var string[] */
- private array $blacklist;
-
/** @param string[] $blacklist */
- public function __construct(array $blacklist)
- {
- $this->blacklist = $blacklist;
+ public function __construct(
+ private readonly array $blacklist,
+ ) {
}
/** @param string|AbstractAsset $assetName */
diff --git a/src/Dbal/ManagerRegistryAwareConnectionProvider.php b/src/Dbal/ManagerRegistryAwareConnectionProvider.php
index 7143a66ea..f14e389c6 100644
--- a/src/Dbal/ManagerRegistryAwareConnectionProvider.php
+++ b/src/Dbal/ManagerRegistryAwareConnectionProvider.php
@@ -8,11 +8,9 @@
class ManagerRegistryAwareConnectionProvider implements ConnectionProvider
{
- private AbstractManagerRegistry $managerRegistry;
-
- public function __construct(AbstractManagerRegistry $managerRegistry)
- {
- $this->managerRegistry = $managerRegistry;
+ public function __construct(
+ private readonly AbstractManagerRegistry $managerRegistry,
+ ) {
}
public function getDefaultConnection(): Connection
diff --git a/src/Dbal/RegexSchemaAssetFilter.php b/src/Dbal/RegexSchemaAssetFilter.php
index c60cdea9c..3acee8512 100644
--- a/src/Dbal/RegexSchemaAssetFilter.php
+++ b/src/Dbal/RegexSchemaAssetFilter.php
@@ -8,15 +8,12 @@
class RegexSchemaAssetFilter
{
- private string $filterExpression;
-
- public function __construct(string $filterExpression)
- {
- $this->filterExpression = $filterExpression;
+ public function __construct(
+ private readonly string $filterExpression,
+ ) {
}
- /** @param string|AbstractAsset $assetName */
- public function __invoke($assetName): bool
+ public function __invoke(string|AbstractAsset $assetName): bool
{
if ($assetName instanceof AbstractAsset) {
$assetName = $assetName->getName();
diff --git a/src/Dbal/SchemaAssetsFilterManager.php b/src/Dbal/SchemaAssetsFilterManager.php
index 18cc7400b..5c17973f5 100644
--- a/src/Dbal/SchemaAssetsFilterManager.php
+++ b/src/Dbal/SchemaAssetsFilterManager.php
@@ -9,13 +9,10 @@
*/
class SchemaAssetsFilterManager
{
- /** @var callable[] */
- private array $schemaAssetFilters;
-
/** @param callable[] $schemaAssetFilters */
- public function __construct(array $schemaAssetFilters)
- {
- $this->schemaAssetFilters = $schemaAssetFilters;
+ public function __construct(
+ private readonly array $schemaAssetFilters,
+ ) {
}
/** @param string|AbstractAsset $assetName */
diff --git a/src/DependencyInjection/Compiler/CacheCompatibilityPass.php b/src/DependencyInjection/Compiler/CacheCompatibilityPass.php
index cefe51bb3..657cddb30 100644
--- a/src/DependencyInjection/Compiler/CacheCompatibilityPass.php
+++ b/src/DependencyInjection/Compiler/CacheCompatibilityPass.php
@@ -87,7 +87,7 @@ private function updateSecondLevelCache(ContainerBuilder $container, Definition
}
}
- private function createCompatibilityLayerDefinition(ContainerBuilder $container, string $definitionId): ?Definition
+ private function createCompatibilityLayerDefinition(ContainerBuilder $container, string $definitionId): Definition|null
{
$definition = $container->getDefinition($definitionId);
diff --git a/src/DependencyInjection/Compiler/CacheSchemaSubscriberPass.php b/src/DependencyInjection/Compiler/CacheSchemaSubscriberPass.php
index a9b7f9e35..a317d7a87 100644
--- a/src/DependencyInjection/Compiler/CacheSchemaSubscriberPass.php
+++ b/src/DependencyInjection/Compiler/CacheSchemaSubscriberPass.php
@@ -3,7 +3,6 @@
namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler;
use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;
-use Symfony\Component\Cache\Adapter\PdoAdapter;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -20,22 +19,11 @@ class CacheSchemaSubscriberPass implements CompilerPassInterface
/** @return void */
public function process(ContainerBuilder $container)
{
- // deprecated in Symfony 6.3
- $this->injectAdapters($container, 'doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_subscriber', DoctrineDbalAdapter::class);
-
- $this->injectAdapters($container, 'doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_listener', DoctrineDbalAdapter::class);
-
- // available in Symfony 5.1 and up to Symfony 5.4 (deprecated)
- $this->injectAdapters($container, 'doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', PdoAdapter::class);
- }
-
- private function injectAdapters(ContainerBuilder $container, string $subscriberId, string $class)
- {
- if (! $container->hasDefinition($subscriberId)) {
+ if (! $container->hasDefinition('doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_listener')) {
return;
}
- $subscriber = $container->getDefinition($subscriberId);
+ $subscriber = $container->getDefinition('doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_listener');
$cacheAdaptersReferences = [];
foreach ($container->getDefinitions() as $id => $definition) {
@@ -43,7 +31,7 @@ private function injectAdapters(ContainerBuilder $container, string $subscriberI
continue;
}
- if ($definition->getClass() !== $class) {
+ if ($definition->getClass() !== DoctrineDbalAdapter::class) {
continue;
}
diff --git a/src/DependencyInjection/Compiler/IdGeneratorPass.php b/src/DependencyInjection/Compiler/IdGeneratorPass.php
index e2d52c356..9235e2f7a 100644
--- a/src/DependencyInjection/Compiler/IdGeneratorPass.php
+++ b/src/DependencyInjection/Compiler/IdGeneratorPass.php
@@ -30,9 +30,7 @@ public function process(ContainerBuilder $container): void
return;
}
- $generatorRefs = array_map(static function ($id) {
- return new Reference($id);
- }, $generatorIds);
+ $generatorRefs = array_map(static fn (string $id): Reference => new Reference($id), $generatorIds);
$ref = ServiceLocatorTagPass::register($container, array_combine($generatorIds, $generatorRefs));
$container->setAlias('doctrine.id_generator_locator', new Alias((string) $ref, false));
diff --git a/src/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php b/src/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php
index 5ecbdf58b..d955ad181 100644
--- a/src/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php
+++ b/src/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php
@@ -25,10 +25,7 @@ public function process(ContainerBuilder $container): void
$locatorDef = $container->getDefinition('doctrine.orm.container_repository_factory');
$repoServiceIds = array_keys($container->findTaggedServiceIds(self::REPOSITORY_SERVICE_TAG));
-
- $repoReferences = array_map(static function ($id) {
- return new Reference($id);
- }, $repoServiceIds);
+ $repoReferences = array_map(static fn (string $id): Reference => new Reference($id), $repoServiceIds);
$ref = ServiceLocatorTagPass::register($container, array_combine($repoServiceIds, $repoReferences));
$locatorDef->replaceArgument(0, $ref);
diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php
index ebc833dad..2520e7d3b 100644
--- a/src/DependencyInjection/Configuration.php
+++ b/src/DependencyInjection/Configuration.php
@@ -53,12 +53,9 @@
*/
class Configuration implements ConfigurationInterface
{
- private bool $debug;
-
/** @param bool $debug Whether to use the debug mode */
- public function __construct(bool $debug)
+ public function __construct(private bool $debug)
{
- $this->debug = $debug;
}
public function getConfigTreeBuilder(): TreeBuilder
@@ -122,9 +119,7 @@ private function addDbalSection(ArrayNodeDefinition $node): void
->prototype('array')
->beforeNormalization()
->ifString()
- ->then(static function ($v) {
- return ['class' => $v];
- })
+ ->then(static fn ($v) => ['class' => $v])
->end()
->children()
->scalarNode('class')->isRequired()->end()
@@ -398,9 +393,7 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node): void
->end()
->end()
->beforeNormalization()
- ->ifTrue(static function ($v) {
- return ! isset($v['sessionMode']) && isset($v['session_mode']);
- })
+ ->ifTrue(static fn ($v) => ! isset($v['sessionMode']) && isset($v['session_mode']))
->then(static function ($v) {
$v['sessionMode'] = $v['session_mode'];
unset($v['session_mode']);
@@ -409,9 +402,7 @@ private function configureDbalDriverNode(ArrayNodeDefinition $node): void
})
->end()
->beforeNormalization()
- ->ifTrue(static function ($v) {
- return ! isset($v['MultipleActiveResultSets']) && isset($v['multiple_active_result_sets']);
- })
+ ->ifTrue(static fn ($v) => ! isset($v['MultipleActiveResultSets']) && isset($v['multiple_active_result_sets']))
->then(static function ($v) {
$v['MultipleActiveResultSets'] = $v['multiple_active_result_sets'];
unset($v['multiple_active_result_sets']);
@@ -502,9 +493,7 @@ private function addOrmSection(ArrayNodeDefinition $node): void
->end()
->validate()
->ifString()
- ->then(static function ($v) {
- return constant('Doctrine\ORM\Proxy\ProxyFactory::AUTOGENERATE_' . strtoupper($v));
- })
+ ->then(static fn (string $v) => constant('Doctrine\ORM\Proxy\ProxyFactory::AUTOGENERATE_' . strtoupper($v)))
->end()
->end()
->booleanNode('enable_lazy_ghost_objects')
@@ -600,9 +589,7 @@ private function getOrmEntityListenersNode(): NodeDefinition
$node
->beforeNormalization()
// Yaml normalization
- ->ifTrue(static function ($v) {
- return is_array(reset($v)) && is_string(key(reset($v)));
- })
+ ->ifTrue(static fn ($v) => is_array(reset($v)) && is_string(key(reset($v))))
->then($normalizer)
->end()
->fixXmlConfig('entity', 'entities')
@@ -733,9 +720,7 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition
->prototype('array')
->beforeNormalization()
->ifString()
- ->then(static function ($v) {
- return ['type' => $v];
- })
+ ->then(static fn ($v) => ['type' => $v])
->end()
->treatNullLike([])
->treatFalseLike(['mapping' => false])
@@ -778,15 +763,11 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition
->prototype('array')
->beforeNormalization()
->ifString()
- ->then(static function ($v) {
- return ['class' => $v];
- })
+ ->then(static fn ($v) => ['class' => $v])
->end()
->beforeNormalization()
// The content of the XML node is returned as the "value" key so we need to rename it
- ->ifTrue(static function ($v) {
- return is_array($v) && isset($v['value']);
- })
+ ->ifTrue(static fn ($v) => is_array($v) && isset($v['value']))
->then(static function ($v) {
$v['class'] = $v['value'];
unset($v['value']);
@@ -814,9 +795,7 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition
->prototype('scalar')
->beforeNormalization()
->ifString()
- ->then(static function ($v) {
- return constant(ClassMetadata::class . '::GENERATOR_TYPE_' . strtoupper($v));
- })
+ ->then(static fn (string $v) => constant(ClassMetadata::class . '::GENERATOR_TYPE_' . strtoupper($v)))
->end()
->end()
->end()
@@ -837,9 +816,7 @@ private function getOrmCacheDriverNode(string $name): ArrayNodeDefinition
$node
->beforeNormalization()
->ifString()
- ->then(static function ($v): array {
- return ['type' => $v];
- })
+ ->then(static fn ($v): array => ['type' => $v])
->end()
->children()
->scalarNode('type')->defaultNull()->end()
diff --git a/src/DependencyInjection/DoctrineExtension.php b/src/DependencyInjection/DoctrineExtension.php
index de74334c9..9af5af470 100644
--- a/src/DependencyInjection/DoctrineExtension.php
+++ b/src/DependencyInjection/DoctrineExtension.php
@@ -40,19 +40,12 @@
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use InvalidArgumentException;
use LogicException;
-use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Bridge\Doctrine\Middleware\IdleConnection\Listener;
use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
-use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaListener;
-use Symfony\Bridge\Doctrine\SchemaListener\LockStoreSchemaListener;
-use Symfony\Bridge\Doctrine\SchemaListener\MessengerTransportDoctrineSchemaListener;
-use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber;
-use Symfony\Bridge\Doctrine\SchemaListener\PdoSessionHandlerSchemaListener;
-use Symfony\Bridge\Doctrine\SchemaListener\RememberMeTokenProviderDoctrineSchemaListener;
use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
@@ -85,8 +78,6 @@
use function trait_exists;
use function trigger_deprecation;
-use const PHP_VERSION_ID;
-
/**
* DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
*
@@ -489,26 +480,6 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$container->removeAlias('doctrine.orm.metadata.annotation_reader');
}
- // available in Symfony 6.3
- $container->removeDefinition('doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_' . (class_exists(DoctrineDbalCacheAdapterSchemaListener::class) ? 'subscriber' : 'listener'));
-
- // available in Symfony 6.3
- $container->removeDefinition('doctrine.orm.listeners.doctrine_token_provider_schema_' . (class_exists(RememberMeTokenProviderDoctrineSchemaListener::class) ? 'subscriber' : 'listener'));
-
- // available in Symfony 5.1 and up to Symfony 5.4 (deprecated)
- if (! class_exists(PdoCacheAdapterDoctrineSchemaSubscriber::class)) {
- $container->removeDefinition('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber');
- }
-
- if (! class_exists(PdoSessionHandlerSchemaListener::class)) {
- $container->removeDefinition('doctrine.orm.listeners.pdo_session_handler_schema_listener');
- }
-
- // available in Symfony 6.3 and higher
- if (! class_exists(LockStoreSchemaListener::class)) {
- $container->removeDefinition('doctrine.orm.listeners.lock_store_schema_listener');
- }
-
if (! class_exists(UlidGenerator::class)) {
$container->removeDefinition('doctrine.ulid_generator');
}
@@ -517,51 +488,45 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$container->removeDefinition('doctrine.uuid_generator');
}
- // available in Symfony 6.2 and higher
- if (! class_exists(EntityValueResolver::class)) {
- $container->removeDefinition('doctrine.orm.entity_value_resolver');
+ if (! class_exists(ExpressionLanguage::class)) {
$container->removeDefinition('doctrine.orm.entity_value_resolver.expression_language');
- } else {
- if (! class_exists(ExpressionLanguage::class)) {
- $container->removeDefinition('doctrine.orm.entity_value_resolver.expression_language');
- }
+ }
- $controllerResolverDefaults = [];
+ $controllerResolverDefaults = [];
- if (! $config['controller_resolver']['enabled']) {
- $controllerResolverDefaults['disabled'] = true;
- }
+ if (! $config['controller_resolver']['enabled']) {
+ $controllerResolverDefaults['disabled'] = true;
+ }
- if ($config['controller_resolver']['auto_mapping'] === null) {
- trigger_deprecation('doctrine/doctrine-bundle', '2.12', 'The default value of "doctrine.orm.controller_resolver.auto_mapping" will be changed from `true` to `false`. Explicitly configure `true` to keep existing behaviour.');
- $config['controller_resolver']['auto_mapping'] = true;
- }
+ if ($config['controller_resolver']['auto_mapping'] === null) {
+ trigger_deprecation('doctrine/doctrine-bundle', '2.12', 'The default value of "doctrine.orm.controller_resolver.auto_mapping" will be changed from `true` to `false`. Explicitly configure `true` to keep existing behaviour.');
+ $config['controller_resolver']['auto_mapping'] = true;
+ }
- if ($config['controller_resolver']['auto_mapping'] === true) {
- trigger_deprecation('doctrine/doctrine-bundle', '2.13', 'Enabling the controller resolver automapping feature has been deprecated. Symfony Mapped Route Parameters should be used as replacement.');
- }
+ if ($config['controller_resolver']['auto_mapping'] === true) {
+ trigger_deprecation('doctrine/doctrine-bundle', '2.13', 'Enabling the controller resolver automapping feature has been deprecated. Symfony Mapped Route Parameters should be used as replacement.');
+ }
- if (! $config['controller_resolver']['auto_mapping']) {
- $controllerResolverDefaults['mapping'] = [];
- }
+ if (! $config['controller_resolver']['auto_mapping']) {
+ $controllerResolverDefaults['mapping'] = [];
+ }
- if ($config['controller_resolver']['evict_cache']) {
- $controllerResolverDefaults['evict_cache'] = true;
- }
+ if ($config['controller_resolver']['evict_cache']) {
+ $controllerResolverDefaults['evict_cache'] = true;
+ }
- if ($controllerResolverDefaults) {
- $container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(2, (new Definition(MapEntity::class))->setArguments([
- null,
- null,
- null,
- $controllerResolverDefaults['mapping'] ?? null,
- null,
- null,
- null,
- $controllerResolverDefaults['evict_cache'] ?? null,
- $controllerResolverDefaults['disabled'] ?? false,
- ]));
- }
+ if ($controllerResolverDefaults) {
+ $container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(2, (new Definition(MapEntity::class))->setArguments([
+ null,
+ null,
+ null,
+ $controllerResolverDefaults['mapping'] ?? null,
+ null,
+ null,
+ null,
+ $controllerResolverDefaults['evict_cache'] ?? null,
+ $controllerResolverDefaults['disabled'] ?? false,
+ ]));
}
// not available in Doctrine ORM 3.0 and higher
@@ -593,11 +558,10 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$container->setParameter('doctrine.default_entity_manager', $config['default_entity_manager']);
if ($config['enable_lazy_ghost_objects'] ?? false) {
- // available in Symfony 6.2 and higher
if (! trait_exists(LazyGhostTrait::class)) {
throw new LogicException(
'Lazy ghost objects cannot be enabled because the "symfony/var-exporter" library'
- . ' version 6.2 or higher is not installed. Please run "composer require symfony/var-exporter:^6.2".',
+ . ' is not installed. Please run "composer require symfony/var-exporter".',
);
}
@@ -611,7 +575,7 @@ protected function ormLoad(array $config, ContainerBuilder $container)
throw new LogicException(
'Lazy ghost objects cannot be disabled for ORM 3.',
);
- } elseif (PHP_VERSION_ID >= 80100) {
+ } else {
trigger_deprecation('doctrine/doctrine-bundle', '2.11', 'Not setting "doctrine.orm.enable_lazy_ghost_objects" to true is deprecated.');
}
@@ -1046,7 +1010,7 @@ protected function getMappingObjectDefaultName(): string
return 'Entity';
}
- protected function getMappingResourceConfigDirectory(?string $bundleDir = null): string
+ protected function getMappingResourceConfigDirectory(string|null $bundleDir = null): string
{
if ($bundleDir !== null && is_dir($bundleDir . '/config/doctrine')) {
return 'config/doctrine';
@@ -1217,9 +1181,6 @@ private function loadMessengerServices(ContainerBuilder $container): void
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
$loader->load('messenger.xml');
- // available in Symfony 6.3
- $container->removeDefinition('doctrine.orm.messenger.doctrine_schema_' . (class_exists(MessengerTransportDoctrineSchemaListener::class) ? 'subscriber' : 'listener'));
-
/**
* The Doctrine transport component (symfony/doctrine-messenger) is optional.
* Remove service definition, if it is not available
@@ -1229,7 +1190,6 @@ private function loadMessengerServices(ContainerBuilder $container): void
}
$container->removeDefinition('messenger.transport.doctrine.factory');
- $container->removeDefinition('doctrine.orm.messenger.doctrine_schema_subscriber');
$container->removeDefinition('doctrine.orm.messenger.doctrine_schema_listener');
}
@@ -1255,7 +1215,7 @@ private function registerDbalMiddlewares(
array $connWithLogging,
array $connWithProfiling,
array $connWithBacktrace,
- array $connWithTtl
+ array $connWithTtl,
): void {
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
$loader->load('middlewares.xml');
diff --git a/src/DoctrineBundle.php b/src/DoctrineBundle.php
index 9751cdb77..1ea4bf623 100644
--- a/src/DoctrineBundle.php
+++ b/src/DoctrineBundle.php
@@ -28,7 +28,6 @@
use Symfony\Component\HttpKernel\Bundle\Bundle;
use function assert;
-use function class_exists;
use function clearstatcache;
use function dirname;
use function spl_autoload_unregister;
@@ -36,7 +35,7 @@
/** @final since 2.9 */
class DoctrineBundle extends Bundle
{
- private ?Closure $autoloader = null;
+ private Closure|null $autoloader = null;
/** @return void */
public function build(ContainerBuilder $container)
@@ -75,11 +74,6 @@ public function process(ContainerBuilder $container): void
$container->addCompilerPass(new RemoveProfilerControllerPass());
$container->addCompilerPass(new RemoveLoggingMiddlewarePass());
$container->addCompilerPass(new MiddlewaresPass());
-
- if (! class_exists(RegisterUidTypePass::class)) {
- return;
- }
-
$container->addCompilerPass(new RegisterUidTypePass());
}
diff --git a/src/ManagerConfigurator.php b/src/ManagerConfigurator.php
index acf57edcd..89c95bbd0 100644
--- a/src/ManagerConfigurator.php
+++ b/src/ManagerConfigurator.php
@@ -10,24 +10,20 @@
*/
class ManagerConfigurator
{
- /** @var string[] */
- private array $enabledFilters = [];
-
- /** @var array> */
- private array $filtersParameters = [];
-
/**
* @param string[] $enabledFilters
* @param array> $filtersParameters
*/
- public function __construct(array $enabledFilters, array $filtersParameters)
- {
- $this->enabledFilters = $enabledFilters;
- $this->filtersParameters = $filtersParameters;
+ public function __construct(
+ private readonly array $enabledFilters = [],
+ private readonly array $filtersParameters = [],
+ ) {
}
/**
* Create a connection by name.
+ *
+ * @return void
*/
public function configure(EntityManagerInterface $entityManager)
{
diff --git a/src/Mapping/ClassMetadataCollection.php b/src/Mapping/ClassMetadataCollection.php
index 7b3a9f5c1..bc708dbb1 100644
--- a/src/Mapping/ClassMetadataCollection.php
+++ b/src/Mapping/ClassMetadataCollection.php
@@ -6,16 +6,13 @@
class ClassMetadataCollection
{
- private ?string $path = null;
- private ?string $namespace = null;
-
- /** @var ClassMetadata[] */
- private array $metadata;
+ private string|null $path = null;
+ private string|null $namespace = null;
/** @param ClassMetadata[] $metadata */
- public function __construct(array $metadata)
- {
- $this->metadata = $metadata;
+ public function __construct(
+ private readonly array $metadata,
+ ) {
}
/** @return ClassMetadata[] */
diff --git a/src/Mapping/ContainerEntityListenerResolver.php b/src/Mapping/ContainerEntityListenerResolver.php
index 5bc96d745..13c19d0d8 100644
--- a/src/Mapping/ContainerEntityListenerResolver.php
+++ b/src/Mapping/ContainerEntityListenerResolver.php
@@ -6,7 +6,6 @@
use Psr\Container\ContainerInterface;
use RuntimeException;
-use function get_class;
use function gettype;
use function is_object;
use function sprintf;
@@ -15,8 +14,6 @@
/** @final */
class ContainerEntityListenerResolver implements EntityListenerServiceResolver
{
- private ContainerInterface $container;
-
/** @var object[] Map to store entity listener instances. */
private array $instances = [];
@@ -24,9 +21,9 @@ class ContainerEntityListenerResolver implements EntityListenerServiceResolver
private array $serviceIds = [];
/** @param ContainerInterface $container a service locator for listeners */
- public function __construct(ContainerInterface $container)
- {
- $this->container = $container;
+ public function __construct(
+ private readonly ContainerInterface $container,
+ ) {
}
/**
@@ -54,7 +51,7 @@ public function register($object): void
throw new InvalidArgumentException(sprintf('An object was expected, but got "%s".', gettype($object)));
}
- $className = $this->normalizeClassName(get_class($object));
+ $className = $this->normalizeClassName($object::class);
$this->instances[$className] = $object;
}
diff --git a/src/Mapping/DisconnectedMetadataFactory.php b/src/Mapping/DisconnectedMetadataFactory.php
index 86cbdfbfb..d8b21b408 100644
--- a/src/Mapping/DisconnectedMetadataFactory.php
+++ b/src/Mapping/DisconnectedMetadataFactory.php
@@ -21,11 +21,9 @@
*/
class DisconnectedMetadataFactory
{
- private ManagerRegistry $registry;
-
- public function __construct(ManagerRegistry $registry)
- {
- $this->registry = $registry;
+ public function __construct(
+ private readonly ManagerRegistry $registry,
+ ) {
}
/**
diff --git a/src/Mapping/MappingDriver.php b/src/Mapping/MappingDriver.php
index 88cfec04c..d4759d0ce 100644
--- a/src/Mapping/MappingDriver.php
+++ b/src/Mapping/MappingDriver.php
@@ -9,13 +9,10 @@
class MappingDriver implements MappingDriverInterface
{
- private MappingDriverInterface $driver;
- private ContainerInterface $idGeneratorLocator;
-
- public function __construct(MappingDriverInterface $driver, ContainerInterface $idGeneratorLocator)
- {
- $this->driver = $driver;
- $this->idGeneratorLocator = $idGeneratorLocator;
+ public function __construct(
+ private readonly MappingDriverInterface $driver,
+ private readonly ContainerInterface $idGeneratorLocator,
+ ) {
}
/**
diff --git a/src/Middleware/BacktraceDebugDataHolder.php b/src/Middleware/BacktraceDebugDataHolder.php
index 8eae91188..46269fe27 100644
--- a/src/Middleware/BacktraceDebugDataHolder.php
+++ b/src/Middleware/BacktraceDebugDataHolder.php
@@ -14,16 +14,13 @@
/** @psalm-suppress MissingDependency */
class BacktraceDebugDataHolder extends DebugDataHolder
{
- /** @var string[] */
- private array $connWithBacktraces;
-
/** @var array[]> */
private array $backtraces = [];
/** @param string[] $connWithBacktraces */
- public function __construct(array $connWithBacktraces)
- {
- $this->connWithBacktraces = $connWithBacktraces;
+ public function __construct(
+ private readonly array $connWithBacktraces,
+ ) {
}
public function reset(): void
diff --git a/src/Middleware/DebugMiddleware.php b/src/Middleware/DebugMiddleware.php
index 55aaabb54..c3d7831de 100644
--- a/src/Middleware/DebugMiddleware.php
+++ b/src/Middleware/DebugMiddleware.php
@@ -10,14 +10,12 @@
class DebugMiddleware implements Middleware, ConnectionNameAwareInterface
{
- private DebugDataHolder $debugDataHolder;
- private ?Stopwatch $stopwatch;
private string $connectionName = 'default';
- public function __construct(DebugDataHolder $debugDataHolder, ?Stopwatch $stopwatch)
- {
- $this->debugDataHolder = $debugDataHolder;
- $this->stopwatch = $stopwatch;
+ public function __construct(
+ private readonly DebugDataHolder $debugDataHolder,
+ private readonly Stopwatch|null $stopwatch,
+ ) {
}
public function setConnectionName(string $name): void
diff --git a/src/Middleware/IdleConnectionMiddleware.php b/src/Middleware/IdleConnectionMiddleware.php
index d64d22faf..0cf0b5d13 100644
--- a/src/Middleware/IdleConnectionMiddleware.php
+++ b/src/Middleware/IdleConnectionMiddleware.php
@@ -9,19 +9,16 @@
class IdleConnectionMiddleware implements Middleware, ConnectionNameAwareInterface
{
- private ArrayObject $connectionExpiries;
- /** @var array */
- private array $ttlByConnection;
private string $connectionName;
/**
* @param ArrayObject $connectionExpiries
* @param array $ttlByConnection
*/
- public function __construct(ArrayObject $connectionExpiries, array $ttlByConnection)
- {
- $this->connectionExpiries = $connectionExpiries;
- $this->ttlByConnection = $ttlByConnection;
+ public function __construct(
+ private readonly ArrayObject $connectionExpiries,
+ private readonly array $ttlByConnection,
+ ) {
}
public function setConnectionName(string $name): void
@@ -29,8 +26,14 @@ public function setConnectionName(string $name): void
$this->connectionName = $name;
}
+ /** @psalm-suppress InvalidArgument - see https://github.com/symfony/symfony/pull/59487 */
public function wrap(Driver $driver): IdleConnectionDriver
{
- return new IdleConnectionDriver($driver, $this->connectionExpiries, $this->ttlByConnection[$this->connectionName], $this->connectionName);
+ return new IdleConnectionDriver(
+ $driver,
+ $this->connectionExpiries,
+ $this->ttlByConnection[$this->connectionName],
+ $this->connectionName,
+ );
}
}
diff --git a/src/Orm/ManagerRegistryAwareEntityManagerProvider.php b/src/Orm/ManagerRegistryAwareEntityManagerProvider.php
index 4ef72eb83..d639d1eb1 100644
--- a/src/Orm/ManagerRegistryAwareEntityManagerProvider.php
+++ b/src/Orm/ManagerRegistryAwareEntityManagerProvider.php
@@ -7,16 +7,14 @@
use Doctrine\Persistence\ManagerRegistry;
use RuntimeException;
-use function get_class;
+use function get_debug_type;
use function sprintf;
final class ManagerRegistryAwareEntityManagerProvider implements EntityManagerProvider
{
- private ManagerRegistry $managerRegistry;
-
- public function __construct(ManagerRegistry $managerRegistry)
- {
- $this->managerRegistry = $managerRegistry;
+ public function __construct(
+ private readonly ManagerRegistry $managerRegistry,
+ ) {
}
public function getDefaultManager(): EntityManagerInterface
@@ -36,7 +34,7 @@ public function getManager(string $name): EntityManagerInterface
sprintf(
'Only managers of type "%s" are supported. Instance of "%s given.',
EntityManagerInterface::class,
- get_class($em),
+ get_debug_type($em),
),
);
}
diff --git a/src/Registry.php b/src/Registry.php
index aa84319db..04bd7de4d 100644
--- a/src/Registry.php
+++ b/src/Registry.php
@@ -53,7 +53,7 @@ public function getAliasNamespace($alias)
try {
/** @psalm-suppress UndefinedMethod ORM < 3 specific */
return $objectManager->getConfiguration()->getEntityNamespace($alias);
- } catch (ORMException $e) {
+ } catch (ORMException) {
}
}
diff --git a/src/Repository/ContainerRepositoryFactory.php b/src/Repository/ContainerRepositoryFactory.php
index 9d007c8ef..26f48b339 100644
--- a/src/Repository/ContainerRepositoryFactory.php
+++ b/src/Repository/ContainerRepositoryFactory.php
@@ -28,12 +28,10 @@ final class ContainerRepositoryFactory implements RepositoryFactory
/** @var array */
private array $managedRepositories = [];
- private ContainerInterface $container;
-
/** @param ContainerInterface $container A service locator containing the repositories */
- public function __construct(ContainerInterface $container)
- {
- $this->container = $container;
+ public function __construct(
+ private readonly ContainerInterface $container,
+ ) {
}
/**
@@ -95,7 +93,7 @@ private function doGetRepository(EntityManagerInterface $entityManager, string $
*/
private function getOrCreateRepository(
EntityManagerInterface $entityManager,
- ClassMetadata $metadata
+ ClassMetadata $metadata,
): ObjectRepository {
$repositoryHash = $metadata->getName() . spl_object_hash($entityManager);
if (isset($this->managedRepositories[$repositoryHash])) {
diff --git a/src/Repository/LazyServiceEntityRepository.php b/src/Repository/LazyServiceEntityRepository.php
index c6905994a..fecbe77d5 100644
--- a/src/Repository/LazyServiceEntityRepository.php
+++ b/src/Repository/LazyServiceEntityRepository.php
@@ -20,18 +20,14 @@
*/
class LazyServiceEntityRepository extends EntityRepository implements ServiceEntityRepositoryInterface
{
- private ManagerRegistry $registry;
- private string $entityClass;
-
/**
* @param string $entityClass The class name of the entity this repository manages
* @psalm-param class-string $entityClass
*/
- public function __construct(ManagerRegistry $registry, string $entityClass)
- {
- $this->registry = $registry;
- $this->entityClass = $entityClass;
-
+ public function __construct(
+ private readonly ManagerRegistry $registry,
+ private readonly string $entityClass,
+ ) {
if ($this instanceof LazyObjectInterface) {
$this->initialize();
@@ -50,9 +46,7 @@ public function __get(string $name)
$scope = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['class'] ?? null;
- return (function () use ($name) {
- return $this->$name;
- })->bindTo($this, $scope)();
+ return (fn (): mixed => $this->$name)->bindTo($this, $scope)();
}
public function __isset(string $name): bool
@@ -61,9 +55,7 @@ public function __isset(string $name): bool
$scope = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['class'] ?? null;
- return (function () use ($name) {
- return isset($this->$name);
- })->bindTo($this, $scope)();
+ return (fn (): bool => isset($this->$name))->bindTo($this, $scope)();
}
private function initialize(): void
diff --git a/src/Repository/ServiceEntityRepositoryProxy.php b/src/Repository/ServiceEntityRepositoryProxy.php
index 07dd6c0a1..fc3606f56 100644
--- a/src/Repository/ServiceEntityRepositoryProxy.php
+++ b/src/Repository/ServiceEntityRepositoryProxy.php
@@ -27,7 +27,7 @@
*/
class ServiceEntityRepositoryProxy extends EntityRepository implements ServiceEntityRepositoryInterface
{
- private ?EntityRepository $repository = null;
+ private EntityRepository|null $repository = null;
/** @param class-string $entityClass The class name of the entity this repository manages */
public function __construct(
@@ -41,7 +41,7 @@ public function __construct(
$this->repository = $this->resolveRepository();
}
- public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
+ public function createQueryBuilder(string $alias, string|null $indexBy = null): QueryBuilder
{
return ($this->repository ??= $this->resolveRepository())
->createQueryBuilder($alias, $indexBy);
@@ -66,14 +66,14 @@ public function find(mixed $id, LockMode|int|null $lockMode = null, int|null $lo
* @psalm-suppress InvalidReturnStatement This proxy is used only in combination with newer parent class
* @psalm-suppress InvalidReturnType This proxy is used only in combination with newer parent class
*/
- public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
+ public function findBy(array $criteria, array|null $orderBy = null, int|null $limit = null, int|null $offset = null): array
{
return ($this->repository ??= $this->resolveRepository())
->findBy($criteria, $orderBy, $limit, $offset);
}
/** {@inheritDoc} */
- public function findOneBy(array $criteria, ?array $orderBy = null): object|null
+ public function findOneBy(array $criteria, array|null $orderBy = null): object|null
{
/** @psalm-suppress InvalidReturnStatement This proxy is used only in combination with newer parent class */
return ($this->repository ??= $this->resolveRepository())
diff --git a/tests/CacheSchemaSubscriberTest.php b/tests/CacheSchemaSubscriberTest.php
index 22c7d6a88..2e5275a33 100644
--- a/tests/CacheSchemaSubscriberTest.php
+++ b/tests/CacheSchemaSubscriberTest.php
@@ -5,9 +5,6 @@
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\CacheSchemaSubscriberPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
use Doctrine\ORM\EntityManagerInterface;
-use Generator;
-use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaListener;
-use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
@@ -15,22 +12,13 @@
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
-use function class_exists;
use function interface_exists;
use function sys_get_temp_dir;
class CacheSchemaSubscriberTest extends TestCase
{
- /**
- * @group legacy
- * @dataProvider getSchemaSubscribers
- */
- public function testSchemaSubscriberWiring(string $adapterId, string $subscriberId, string $class): void
+ public function testSchemaSubscriberWiring(): void
{
- if (! class_exists($class)) {
- self::markTestSkipped('symfony/doctrine-bridge version not supported');
- }
-
if (! interface_exists(EntityManagerInterface::class)) {
self::markTestSkipped('This test requires ORM');
}
@@ -63,16 +51,12 @@ public function testSchemaSubscriberWiring(string $adapterId, string $subscriber
'http_method_override' => false,
'cache' => [
'pools' => [
- 'my_cache_adapter' => ['adapter' => $adapterId],
+ 'my_cache_adapter' => ['adapter' => 'cache.adapter.doctrine_dbal'],
],
],
],
], $container);
- if (! $container->has($adapterId)) {
- self::markTestSkipped('symfony/framework-bundle version not supported');
- }
-
$extension = new DoctrineExtension();
$container->registerExtension($extension);
$extension->load([
@@ -82,7 +66,7 @@ public function testSchemaSubscriberWiring(string $adapterId, string $subscriber
],
], $container);
- $container->setAlias('test_subscriber_alias', new Alias($subscriberId, true));
+ $container->setAlias('test_subscriber_alias', new Alias('doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_listener', true));
// prevent my_cache_adapter from inlining
$container->register('uses_my_cache_adapter', 'stdClass')
->addArgument(new Reference('my_cache_adapter'))
@@ -94,19 +78,4 @@ public function testSchemaSubscriberWiring(string $adapterId, string $subscriber
$definition = $container->findDefinition('test_subscriber_alias');
$this->assertEquals([new Reference('my_cache_adapter')], $definition->getArgument(0));
}
-
- public function getSchemaSubscribers(): Generator
- {
- /**
- * available in Symfony 6.3
- */
- yield ['cache.adapter.doctrine_dbal', 'doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_listener', DoctrineDbalCacheAdapterSchemaListener::class];
-
- /**
- * available in Symfony 5.1 and up to Symfony 5.4 (deprecated)
- *
- * @psalm-suppress UndefinedClass
- */
- yield ['cache.adapter.pdo', 'doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', PdoCacheAdapterDoctrineSchemaSubscriber::class];
- }
}
diff --git a/tests/Command/CreateDatabaseDoctrineTest.php b/tests/Command/CreateDatabaseDoctrineTest.php
index da3c46bea..af26b6bec 100644
--- a/tests/Command/CreateDatabaseDoctrineTest.php
+++ b/tests/Command/CreateDatabaseDoctrineTest.php
@@ -59,7 +59,7 @@ public function testExecute(): void
*
* @return MockObject&Container
*/
- private function getMockContainer(string $connectionName, ?array $params = null): MockObject
+ private function getMockContainer(string $connectionName, array|null $params = null): MockObject
{
// Mock the container and everything you'll need here
$mockDoctrine = $this->getMockBuilder(ManagerRegistry::class)
diff --git a/tests/Command/ImportMappingDoctrineCommandTest.php b/tests/Command/ImportMappingDoctrineCommandTest.php
index 9520c12b0..141e14b45 100644
--- a/tests/Command/ImportMappingDoctrineCommandTest.php
+++ b/tests/Command/ImportMappingDoctrineCommandTest.php
@@ -3,7 +3,6 @@
namespace Doctrine\Bundle\DoctrineBundle\Tests\Command;
use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\TestKernel;
-use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
use InvalidArgumentException;
@@ -18,8 +17,6 @@
use function interface_exists;
use function sys_get_temp_dir;
-use const PHP_VERSION_ID;
-
/** @group legacy */
class ImportMappingDoctrineCommandTest extends TestCase
{
@@ -28,10 +25,6 @@ class ImportMappingDoctrineCommandTest extends TestCase
public static function setUpBeforeClass(): void
{
- if (PHP_VERSION_ID < 80000 && ! class_exists(AnnotationReader::class)) {
- self::markTestSkipped('This test requires Annotations when run on PHP 7');
- }
-
if (interface_exists(EntityManagerInterface::class) && class_exists(ClassMetadataExporter::class)) {
return;
}
diff --git a/tests/Command/Proxy/InfoDoctrineCommandTest.php b/tests/Command/Proxy/InfoDoctrineCommandTest.php
index 26fb390a6..3b97005fd 100644
--- a/tests/Command/Proxy/InfoDoctrineCommandTest.php
+++ b/tests/Command/Proxy/InfoDoctrineCommandTest.php
@@ -4,24 +4,16 @@
use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\TestKernel;
use Doctrine\Bundle\DoctrineBundle\Tests\TestCase;
-use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
-use function class_exists;
use function interface_exists;
-use const PHP_VERSION_ID;
-
class InfoDoctrineCommandTest extends TestCase
{
public static function setUpBeforeClass(): void
{
- if (PHP_VERSION_ID < 80000 && ! class_exists(AnnotationReader::class)) {
- self::markTestSkipped('This test requires Annotations when run on PHP 7');
- }
-
if (interface_exists(EntityManagerInterface::class)) {
return;
}
diff --git a/tests/ConnectionFactoryTest.php b/tests/ConnectionFactoryTest.php
index 1abd9a1e5..60a6b7658 100644
--- a/tests/ConnectionFactoryTest.php
+++ b/tests/ConnectionFactoryTest.php
@@ -169,7 +169,7 @@ class FakeConnection extends Connection
/**
* {@inheritDoc}
*/
- public function __construct(array $params, Driver $driver, ?Configuration $config = null)
+ public function __construct(array $params, Driver $driver, Configuration|null $config = null)
{
++self::$creationCount;
diff --git a/tests/DataCollector/DoctrineDataCollectorTest.php b/tests/DataCollector/DoctrineDataCollectorTest.php
index b532fabb2..f92cd8f15 100644
--- a/tests/DataCollector/DoctrineDataCollectorTest.php
+++ b/tests/DataCollector/DoctrineDataCollectorTest.php
@@ -141,7 +141,7 @@ private function createEntityMetadata(string $entityFQCN): ClassMetadata
private function createCollector(
array $managers,
bool $shouldValidateSchema = true,
- ?DebugDataHolder $debugDataHolder = null
+ DebugDataHolder|null $debugDataHolder = null,
): DoctrineDataCollector {
$registry = $this->createMock(ManagerRegistry::class);
$registry
diff --git a/tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/tests/DependencyInjection/AbstractDoctrineExtensionTest.php
index 26d72a2e3..9e49b94c3 100644
--- a/tests/DependencyInjection/AbstractDoctrineExtensionTest.php
+++ b/tests/DependencyInjection/AbstractDoctrineExtensionTest.php
@@ -733,7 +733,7 @@ public function testSetTypedFieldMapper(): void
* @dataProvider cacheConfigProvider
* @group legacy
*/
- public function testCacheConfig(?string $expectedClass, string $entityManagerName, ?string $cacheGetter): void
+ public function testCacheConfig(string|null $expectedClass, string $entityManagerName, string|null $cacheGetter): void
{
if (! interface_exists(EntityManagerInterface::class)) {
self::markTestSkipped('This test requires ORM');
@@ -1461,7 +1461,7 @@ public function testDisableSchemaValidation(): void
private function loadContainer(
string $fixture,
array $bundles = ['YamlBundle'],
- ?CompilerPassInterface $compilerPass = null
+ CompilerPassInterface|null $compilerPass = null,
): ContainerBuilder {
$container = $this->getContainer($bundles);
$container->registerExtension(new DoctrineExtension());
@@ -1538,7 +1538,7 @@ private function assertDICDefinitionMethodCallAt(
int $pos,
Definition $definition,
string $methodName,
- ?array $params = null
+ array|null $params = null,
): void {
$calls = $definition->getMethodCalls();
if (! isset($calls[$pos][0])) {
@@ -1562,7 +1562,7 @@ private function assertDICDefinitionMethodCallAt(
private function assertDICDefinitionMethodCallOnce(
Definition $definition,
string $methodName,
- ?array $params = null
+ array|null $params = null,
): void {
$calls = $definition->getMethodCalls();
$called = false;
@@ -1593,7 +1593,7 @@ private function assertDICDefinitionMethodCallCount(
Definition $definition,
string $methodName,
array $params = [],
- int $nbCalls = 1
+ int $nbCalls = 1,
): void {
$calls = $definition->getMethodCalls();
$called = 0;
@@ -1628,11 +1628,9 @@ private function compileContainer(ContainerBuilder $container): void
class DummySchemaAssetsFilter
{
- private string $tableToIgnore;
-
- public function __construct(string $tableToIgnore)
- {
- $this->tableToIgnore = $tableToIgnore;
+ public function __construct(
+ private readonly string $tableToIgnore,
+ ) {
}
public function __invoke(string $assetName): bool
diff --git a/tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php b/tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php
index 1f731bafa..7e66bfba6 100644
--- a/tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php
+++ b/tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php
@@ -4,7 +4,6 @@
use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\TestKernel;
use Doctrine\Bundle\DoctrineBundle\Tests\TestCase;
-use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Doctrine\ORM\Cache\Region;
use Doctrine\ORM\EntityManagerInterface;
@@ -14,22 +13,15 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
-use function class_exists;
use function get_class;
use function interface_exists;
-use const PHP_VERSION_ID;
-
class CacheCompatibilityPassTest extends TestCase
{
use ExpectDeprecationTrait;
public static function setUpBeforeClass(): void
{
- if (PHP_VERSION_ID < 80000 && ! class_exists(AnnotationReader::class)) {
- self::markTestSkipped('This test requires Annotations when run on PHP 7');
- }
-
if (interface_exists(EntityManagerInterface::class)) {
return;
}
@@ -42,12 +34,9 @@ public function testCacheConfigUsingServiceDefinedByApplication(): void
$customRegionClass = get_class($this->createMock(Region::class));
(new class ($customRegionClass) extends TestKernel {
- private string $regionClass;
-
- public function __construct(string $regionClass)
+ public function __construct(private readonly string $regionClass)
{
parent::__construct(false);
- $this->regionClass = $regionClass;
}
public function registerContainerConfiguration(LoaderInterface $loader): void
diff --git a/tests/DependencyInjection/Compiler/EntityListenerPassTest.php b/tests/DependencyInjection/Compiler/EntityListenerPassTest.php
index e744efe84..0f9d18903 100644
--- a/tests/DependencyInjection/Compiler/EntityListenerPassTest.php
+++ b/tests/DependencyInjection/Compiler/EntityListenerPassTest.php
@@ -26,7 +26,7 @@ public static function setUpBeforeClass(): void
}
/** @dataProvider provideEvents */
- public function testEntityListenersAreRegistered(?string $event, ?string $method, ?string $expectedMethod): void
+ public function testEntityListenersAreRegistered(string|null $event, string|null $method, string|null $expectedMethod): void
{
$container = new ContainerBuilder();
$container->addCompilerPass(new EntityListenerPass());
diff --git a/tests/DependencyInjection/Compiler/IdGeneratorPassTest.php b/tests/DependencyInjection/Compiler/IdGeneratorPassTest.php
index f5fd9c996..a95901a28 100644
--- a/tests/DependencyInjection/Compiler/IdGeneratorPassTest.php
+++ b/tests/DependencyInjection/Compiler/IdGeneratorPassTest.php
@@ -6,34 +6,23 @@
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\IdGeneratorPass;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\CustomIdGenerator;
-use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ORM\EntityManagerInterface;
-use Fixtures\Bundles\AnnotationsBundle\AnnotationsBundle;
-use Fixtures\Bundles\AnnotationsBundle\Entity\TestCustomIdGeneratorEntity as AnnotationCustomIdGeneratorEntity;
use Fixtures\Bundles\AttributesBundle\AttributesBundle;
use Fixtures\Bundles\AttributesBundle\Entity\TestCustomIdGeneratorEntity as AttributeCustomIdGeneratorEntity;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
-use Symfony\Component\HttpKernel\Kernel;
use function assert;
-use function class_exists;
use function interface_exists;
use function sys_get_temp_dir;
use function uniqid;
-use const PHP_VERSION_ID;
-
class IdGeneratorPassTest extends TestCase
{
public static function setUpBeforeClass(): void
{
- if (PHP_VERSION_ID < 80000 && ! class_exists(AnnotationReader::class)) {
- self::markTestSkipped('This test requires Annotations when run on PHP 7');
- }
-
if (interface_exists(EntityManagerInterface::class)) {
return;
}
@@ -43,27 +32,15 @@ public static function setUpBeforeClass(): void
public function testRepositoryServiceWiring(): void
{
- if (PHP_VERSION_ID >= 80000) {
- $bundles = ['AttributesBundle' => AttributesBundle::class];
- $entity = AttributeCustomIdGeneratorEntity::class;
- $mappings = [
- 'AttributesBundle' => [
- 'type' => 'attribute',
- 'dir' => __DIR__ . '/../Fixtures/Bundles/AttributesBundle/Entity',
- 'prefix' => 'Fixtures\Bundles\AttributesBundle\Entity',
- ],
- ];
- } else {
- $bundles = ['AnnotationsBundle' => AnnotationsBundle::class];
- $entity = AnnotationCustomIdGeneratorEntity::class;
- $mappings = [
- 'AnnotationsBundle' => [
- 'type' => 'annotation',
- 'dir' => __DIR__ . '/../Fixtures/Bundles/AnnotationsBundle/Entity',
- 'prefix' => 'Fixtures\Bundles\AnnotationsBundle\Entity',
- ],
- ];
- }
+ $bundles = ['AttributesBundle' => AttributesBundle::class];
+ $entity = AttributeCustomIdGeneratorEntity::class;
+ $mappings = [
+ 'AttributesBundle' => [
+ 'type' => 'attribute',
+ 'dir' => __DIR__ . '/../Fixtures/Bundles/AttributesBundle/Entity',
+ 'prefix' => 'Fixtures\Bundles\AttributesBundle\Entity',
+ ],
+ ];
$container = new ContainerBuilder(new ParameterBag([
'kernel.debug' => false,
@@ -87,20 +64,15 @@ public function testRepositoryServiceWiring(): void
'debug.file_link_format' => null,
]));
- if (class_exists(AnnotationReader::class)) {
- $container->set('annotation_reader', new AnnotationReader());
- }
-
$extension = new FrameworkExtension();
$container->registerExtension($extension);
$extension->load([
'framework' => [
'http_method_override' => false,
- 'annotations' => [
- 'enabled' => class_exists(AnnotationReader::class) && Kernel::VERSION_ID < 60400,
- ],
+ 'annotations' => ['enabled' => false],
'php_errors' => ['log' => true],
- ] + (Kernel::VERSION_ID >= 60200 ? ['handle_all_throwables' => true] : []),
+ 'handle_all_throwables' => true,
+ ],
], $container);
$extension = new DoctrineExtension();
@@ -115,7 +87,7 @@ public function testRepositoryServiceWiring(): void
'orm' => [
'mappings' => $mappings,
'report_fields_where_declared' => true,
- 'enable_lazy_ghost_objects' => PHP_VERSION_ID >= 80100,
+ 'enable_lazy_ghost_objects' => true,
],
],
], $container);
diff --git a/tests/DependencyInjection/Compiler/MiddlewarePassTest.php b/tests/DependencyInjection/Compiler/MiddlewarePassTest.php
index 61b8bd9c7..e19f62e9c 100644
--- a/tests/DependencyInjection/Compiler/MiddlewarePassTest.php
+++ b/tests/DependencyInjection/Compiler/MiddlewarePassTest.php
@@ -22,8 +22,6 @@
use function implode;
use function sprintf;
-use const PHP_VERSION_ID;
-
class MiddlewarePassTest extends TestCase
{
/** @return array */
@@ -418,7 +416,7 @@ private function assertMiddlewareInjected(
ContainerBuilder $container,
string $connName,
string $middlewareClass,
- bool $connectionNameAware = false
+ bool $connectionNameAware = false,
): void {
$middlewareFound = $this->getMiddlewaresForConn($container, $connName, $middlewareClass);
@@ -448,7 +446,7 @@ private function assertMiddlewareInjected(
private function assertMiddlewareNotInjected(
ContainerBuilder $container,
string $connName,
- string $middlewareClass
+ string $middlewareClass,
): void {
$middlewareFound = $this->getMiddlewaresForConn($container, $connName, $middlewareClass);
@@ -463,7 +461,7 @@ private function assertMiddlewareNotInjected(
private function assertMiddlewareOrdering(
ContainerBuilder $container,
string $connName,
- array $expectedOrder
+ array $expectedOrder,
): void {
$middlewareFound = $this->getMiddlewaresForConn($container, $connName);
$classes = array_map(
@@ -479,7 +477,7 @@ private function assertMiddlewareOrdering(
}
/** @return Definition[] */
- private function getMiddlewaresForConn(ContainerBuilder $container, string $connName, ?string $middlewareClass = null): array
+ private function getMiddlewaresForConn(ContainerBuilder $container, string $connName, string|null $middlewareClass = null): array
{
$calls = $container->getDefinition('conf_' . $connName)->getMethodCalls();
$middlewaresFound = [];
@@ -524,19 +522,17 @@ public function wrap(Driver $driver): Driver
}
}
-if (PHP_VERSION_ID >= 80000) {
- #[AsMiddleware]
- class AutoconfiguredMiddleware
- {
- }
+#[AsMiddleware]
+class AutoconfiguredMiddleware
+{
+}
- #[AsMiddleware(connections: ['conn2'])]
- class AutoconfiguredMiddlewareWithConnection
- {
- }
+#[AsMiddleware(connections: ['conn2'])]
+class AutoconfiguredMiddlewareWithConnection
+{
+}
- #[AsMiddleware(priority: 2)]
- class AutoconfiguredMiddlewareWithPriority
- {
- }
+#[AsMiddleware(priority: 2)]
+class AutoconfiguredMiddlewareWithPriority
+{
}
diff --git a/tests/DependencyInjection/DoctrineExtensionTest.php b/tests/DependencyInjection/DoctrineExtensionTest.php
index 7ebce4621..f6fef8509 100644
--- a/tests/DependencyInjection/DoctrineExtensionTest.php
+++ b/tests/DependencyInjection/DoctrineExtensionTest.php
@@ -38,7 +38,6 @@
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
-use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
@@ -60,8 +59,6 @@
use function sprintf;
use function sys_get_temp_dir;
-use const PHP_VERSION_ID;
-
class DoctrineExtensionTest extends TestCase
{
/**
@@ -622,7 +619,7 @@ public function testSingleEntityManagerWithDefaultConfiguration(): void
* @testWith [[]]
* [null]
*/
- public function testSingleEntityManagerWithEmptyConfiguration(?array $ormConfiguration): void
+ public function testSingleEntityManagerWithEmptyConfiguration(array|null $ormConfiguration): void
{
if (! interface_exists(EntityManagerInterface::class)) {
self::markTestSkipped('This test requires ORM');
@@ -944,7 +941,7 @@ public function testAnnotationsBundleMappingDetectionWithVendorNamespace(): void
$calls = $container->getDefinition('doctrine.orm.default_metadata_driver')->getMethodCalls();
$this->assertEquals(
- sprintf('doctrine.orm.default_%s_metadata_driver', PHP_VERSION_ID >= 80000 ? 'attribute' : 'annotation'),
+ sprintf('doctrine.orm.default_%s_metadata_driver', 'attribute'),
(string) $calls[0][1][0],
);
$this->assertEquals('Fixtures\Bundles\Vendor\AnnotationsBundle\Entity', $calls[0][1][1]);
@@ -967,12 +964,7 @@ public function testMessengerIntegration(): void
$this->assertCount(1, $container->getDefinition('messenger.middleware.doctrine_transaction')->getArguments());
$this->assertCount(1, $container->getDefinition('messenger.middleware.doctrine_ping_connection')->getArguments());
$this->assertCount(1, $container->getDefinition('messenger.middleware.doctrine_close_connection')->getArguments());
-
- if (class_exists(DoctrineClearEntityManagerWorkerSubscriber::class)) {
- $this->assertCount(1, $container->getDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager')->getArguments());
- } else {
- $this->assertFalse($container->hasDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager'));
- }
+ $this->assertCount(1, $container->getDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager')->getArguments());
}
public function testMessengerIntegrationWithDoctrineTransport(): void
@@ -1531,7 +1523,7 @@ private function assertDICConstructorArguments(Definition $definition, array $ar
}
/** @param list $params */
- private function assertDICDefinitionMethodCallAt(int $pos, Definition $definition, string $methodName, ?array $params = null): void
+ private function assertDICDefinitionMethodCallAt(int $pos, Definition $definition, string $methodName, array|null $params = null): void
{
$calls = $definition->getMethodCalls();
if (! isset($calls[$pos][0])) {
@@ -1552,7 +1544,7 @@ private function assertDICDefinitionMethodCallAt(int $pos, Definition $definitio
*
* @param list $params
*/
- private function assertDICDefinitionMethodCallOnce(Definition $definition, string $methodName, ?array $params = null): void
+ private function assertDICDefinitionMethodCallOnce(Definition $definition, string $methodName, array|null $params = null): void
{
$calls = $definition->getMethodCalls();
$called = false;
diff --git a/tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php b/tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php
deleted file mode 100644
index 899d3e178..000000000
--- a/tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php
+++ /dev/null
@@ -1,9 +0,0 @@
-resolver = $resolver;
+ public function __construct(
+ private readonly EntityListenerServiceResolver $resolver,
+ ) {
}
/**
diff --git a/tests/DependencyInjection/Fixtures/DbalTestKernel.php b/tests/DependencyInjection/Fixtures/DbalTestKernel.php
index 3709f0522..984e33572 100644
--- a/tests/DependencyInjection/Fixtures/DbalTestKernel.php
+++ b/tests/DependencyInjection/Fixtures/DbalTestKernel.php
@@ -18,16 +18,12 @@
class DbalTestKernel extends Kernel
{
- /** @var array */
- private array $dbalConfig;
-
- private ?string $projectDir = null;
+ private string|null $projectDir = null;
/** @param array $dbalConfig */
- public function __construct(array $dbalConfig = ['driver' => 'pdo_sqlite'])
- {
- $this->dbalConfig = $dbalConfig;
-
+ public function __construct(
+ private readonly array $dbalConfig = ['driver' => 'pdo_sqlite'],
+ ) {
parent::__construct('test', true);
}
diff --git a/tests/DependencyInjection/Fixtures/TestKernel.php b/tests/DependencyInjection/Fixtures/TestKernel.php
index 4ad688190..7d7437c58 100644
--- a/tests/DependencyInjection/Fixtures/TestKernel.php
+++ b/tests/DependencyInjection/Fixtures/TestKernel.php
@@ -3,7 +3,6 @@
namespace Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
-use Doctrine\Common\Annotations\Annotation;
use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
@@ -11,16 +10,13 @@
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Kernel;
-use function class_exists;
use function md5;
use function mt_rand;
use function sys_get_temp_dir;
-use const PHP_VERSION_ID;
-
class TestKernel extends Kernel
{
- private ?string $projectDir = null;
+ private string|null $projectDir = null;
public function __construct(bool $debug = true)
{
@@ -42,9 +38,10 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
$container->loadFromExtension('framework', [
'secret' => 'F00',
'http_method_override' => false,
- 'annotations' => class_exists(Annotation::class) && Kernel::VERSION_ID < 60400,
+ 'annotations' => false,
'php_errors' => ['log' => true],
- ] + (Kernel::VERSION_ID >= 60200 ? ['handle_all_throwables' => true] : []));
+ 'handle_all_throwables' => true,
+ ]);
$container->loadFromExtension('doctrine', [
'dbal' => [
'driver' => 'pdo_sqlite',
@@ -53,10 +50,10 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
'orm' => [
'report_fields_where_declared' => true,
'auto_generate_proxy_classes' => true,
- 'enable_lazy_ghost_objects' => PHP_VERSION_ID >= 80100,
+ 'enable_lazy_ghost_objects' => true,
'mappings' => [
'RepositoryServiceBundle' => [
- 'type' => PHP_VERSION_ID >= 80000 ? 'attribute' : 'annotation',
+ 'type' => 'attribute',
'dir' => __DIR__ . '/Bundles/RepositoryServiceBundle/Entity',
'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Entity',
],
diff --git a/tests/LockStoreSchemaListenerTest.php b/tests/LockStoreSchemaListenerTest.php
index 142645a56..8361c3a57 100644
--- a/tests/LockStoreSchemaListenerTest.php
+++ b/tests/LockStoreSchemaListenerTest.php
@@ -4,14 +4,11 @@
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension;
use Doctrine\ORM\EntityManagerInterface;
-use Symfony\Bridge\Doctrine\SchemaListener\LockStoreSchemaListener;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
-use Symfony\Component\HttpKernel\Kernel;
-use function class_exists;
use function interface_exists;
use function sys_get_temp_dir;
@@ -25,10 +22,6 @@ class LockStoreSchemaListenerTest extends TestCase
*/
public function testLockStoreSchemaSubscriberWiring(array $config, int $expectedCount): void
{
- if (! class_exists(LockStoreSchemaListener::class)) {
- self::markTestSkipped('symfony/doctrine-bridge version not supported');
- }
-
if (! interface_exists(EntityManagerInterface::class)) {
self::markTestSkipped('This test requires ORM');
}
@@ -58,8 +51,11 @@ public function testLockStoreSchemaSubscriberWiring(array $config, int $expected
$container->registerExtension($extension);
$extension->load(
[
- 'framework' => ['http_method_override' => false, 'php_errors' => ['log' => true]]
- + (Kernel::VERSION_ID >= 60200 ? ['handle_all_throwables' => true] : []) + $config,
+ 'framework' => [
+ 'http_method_override' => false,
+ 'php_errors' => ['log' => true],
+ 'handle_all_throwables' => true,
+ ] + $config,
],
$container,
);
diff --git a/tests/Middleware/BacktraceDebugDataHolderTest.php b/tests/Middleware/BacktraceDebugDataHolderTest.php
index 1843e4b56..d155350d1 100644
--- a/tests/Middleware/BacktraceDebugDataHolderTest.php
+++ b/tests/Middleware/BacktraceDebugDataHolderTest.php
@@ -4,33 +4,18 @@
use Doctrine\Bundle\DoctrineBundle\Middleware\BacktraceDebugDataHolder;
use Doctrine\Bundle\DoctrineBundle\Tests\TestCase;
-use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
use Symfony\Bridge\Doctrine\Middleware\Debug\Query;
-use function class_exists;
use function count;
-use function sprintf;
use function strpos;
/**
- * @psalm-suppress UndefinedClass
* @psalm-suppress MissingDependency
* @psalm-suppress InternalMethod
* @psalm-suppress InternalClass
*/
class BacktraceDebugDataHolderTest extends TestCase
{
- protected function setUp(): void
- {
- parent::setUp();
-
- if (class_exists(DebugDataHolder::class)) {
- return;
- }
-
- $this->markTestSkipped(sprintf('This test needs %s to exist', DebugDataHolder::class));
- }
-
public function testAddAndRetrieveData(): void
{
$sut = new BacktraceDebugDataHolder([]);
diff --git a/tests/Middleware/DebugMiddlewareTest.php b/tests/Middleware/DebugMiddlewareTest.php
index 0609834e8..fb488ddee 100644
--- a/tests/Middleware/DebugMiddlewareTest.php
+++ b/tests/Middleware/DebugMiddlewareTest.php
@@ -9,26 +9,12 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use PHPUnit\Framework\TestCase;
-use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
-use function class_exists;
-use function sprintf;
use function strpos;
/** @psalm-suppress MissingDependency */
class DebugMiddlewareTest extends TestCase
{
- protected function setUp(): void
- {
- parent::setUp();
-
- if (class_exists(DebugDataHolder::class)) {
- return;
- }
-
- $this->markTestSkipped(sprintf('This test needs %s to exist', DebugDataHolder::class));
- }
-
public function testData(): void
{
$configuration = new Configuration();
diff --git a/tests/RegistryTest.php b/tests/RegistryTest.php
index b0ef211b9..59dbf81f6 100644
--- a/tests/RegistryTest.php
+++ b/tests/RegistryTest.php
@@ -5,7 +5,6 @@
use Closure;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures\TestKernel;
-use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
@@ -17,11 +16,8 @@
use Symfony\Component\VarExporter\LazyObjectInterface;
use function assert;
-use function class_exists;
use function interface_exists;
-use const PHP_VERSION_ID;
-
class RegistryTest extends TestCase
{
public function testGetDefaultConnectionName(): void
@@ -171,10 +167,6 @@ public function testResetLazyObject(): void
public function testIdentityMapsStayConsistentAfterReset(): void
{
- if (PHP_VERSION_ID < 80000 && ! class_exists(AnnotationReader::class)) {
- self::markTestSkipped('This test requires Annotations when run on PHP 7');
- }
-
if (! interface_exists(EntityManagerInterface::class)) {
self::markTestSkipped('This test requires ORM');
}
diff --git a/tests/Repository/ContainerRepositoryFactoryTest.php b/tests/Repository/ContainerRepositoryFactoryTest.php
index 873c71180..2b6efa0dc 100644
--- a/tests/Repository/ContainerRepositoryFactoryTest.php
+++ b/tests/Repository/ContainerRepositoryFactoryTest.php
@@ -154,9 +154,7 @@ private function createEntityManager(array $entityRepositoryClasses): EntityMana
$em = $this->getMockBuilder(EntityManagerInterface::class)->getMock();
$em->expects($this->any())
->method('getClassMetadata')
- ->willReturnCallback(static function ($class) use ($classMetadatas) {
- return $classMetadatas[$class];
- });
+ ->willReturnCallback(static fn (string $class) => $classMetadatas[$class]);
$em->expects($this->any())
->method('getConfiguration')
diff --git a/tests/ServiceRepositoryTest.php b/tests/ServiceRepositoryTest.php
index 94121b6e6..f3a8143ff 100644
--- a/tests/ServiceRepositoryTest.php
+++ b/tests/ServiceRepositoryTest.php
@@ -19,23 +19,16 @@
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
-use Symfony\Component\HttpKernel\Kernel;
use function class_exists;
use function interface_exists;
use function sys_get_temp_dir;
use function uniqid;
-use const PHP_VERSION_ID;
-
class ServiceRepositoryTest extends TestCase
{
public static function setUpBeforeClass(): void
{
- if (PHP_VERSION_ID < 80000 && ! class_exists(AnnotationReader::class)) {
- self::markTestSkipped('This test requires Annotations when run on PHP 7');
- }
-
if (interface_exists(EntityManagerInterface::class)) {
return;
}
@@ -77,10 +70,9 @@ public function testRepositoryServiceWiring(): void
'framework' => [
'http_method_override' => false,
'php_errors' => ['log' => true],
- 'annotations' => [
- 'enabled' => class_exists(AnnotationReader::class) && Kernel::VERSION_ID < 60400,
- ],
- ] + (Kernel::VERSION_ID >= 60200 ? ['handle_all_throwables' => true] : []),
+ 'annotations' => ['enabled' => false],
+ 'handle_all_throwables' => true,
+ ],
], $container);
$extension = new DoctrineExtension();
@@ -94,10 +86,10 @@ public function testRepositoryServiceWiring(): void
],
'orm' => [
'report_fields_where_declared' => true,
- 'enable_lazy_ghost_objects' => PHP_VERSION_ID >= 80100,
+ 'enable_lazy_ghost_objects' => true,
'mappings' => [
'RepositoryServiceBundle' => [
- 'type' => PHP_VERSION_ID >= 80000 ? 'attribute' : 'annotation',
+ 'type' => 'attribute',
'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Entity',
'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Entity',
],
diff --git a/tests/Twig/DoctrineExtensionTest.php b/tests/Twig/DoctrineExtensionTest.php
index 25c01babf..03626df6d 100644
--- a/tests/Twig/DoctrineExtensionTest.php
+++ b/tests/Twig/DoctrineExtensionTest.php
@@ -157,11 +157,9 @@ public function testItUsesCssOnThePreTag(): void
class DummyClass
{
- protected string $str;
-
- public function __construct(string $str)
- {
- $this->str = $str;
+ public function __construct(
+ private readonly string $str,
+ ) {
}
public function __toString(): string