diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 600f10af..778334bd 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -22,10 +22,9 @@ jobs: os: - "ubuntu-20.04" php-version: - - "7.4" - - "8.0" - "8.1" - "8.2" + - "8.3" stability: - "stable" symfony-version: @@ -39,19 +38,10 @@ jobs: include: - dependencies: "lowest" os: "ubuntu-20.04" - php-version: "7.4" + php-version: "8.1" driver-version: "1.5.0" stability: "stable" symfony-version: "5.4.*" - exclude: - - php-version: "7.4" - symfony-version: "6.2.*" - - php-version: "7.4" - symfony-version: "6.3.*" - - php-version: "8.0" - symfony-version: "6.2.*" - - php-version: "8.0" - symfony-version: "6.3.*" services: mongodb: diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index fcf3bf5a..eee411e5 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: php-version: - - "8.1" + - "8.2" steps: - name: "Checkout code" diff --git a/APM/PSRCommandLogger.php b/APM/PSRCommandLogger.php index 3ce15f08..149bce4c 100644 --- a/APM/PSRCommandLogger.php +++ b/APM/PSRCommandLogger.php @@ -18,14 +18,8 @@ final class PSRCommandLogger implements CommandLoggerInterface { private bool $registered = false; - private ?LoggerInterface $logger; - - private string $prefix; - - public function __construct(?LoggerInterface $logger, string $prefix = 'MongoDB command: ') + public function __construct(private ?LoggerInterface $logger, private string $prefix = 'MongoDB command: ') { - $this->logger = $logger; - $this->prefix = $prefix; } public function register(): void diff --git a/APM/StopwatchCommandLogger.php b/APM/StopwatchCommandLogger.php index a5121b42..484d4f3e 100644 --- a/APM/StopwatchCommandLogger.php +++ b/APM/StopwatchCommandLogger.php @@ -18,11 +18,8 @@ final class StopwatchCommandLogger implements CommandLoggerInterface { private bool $registered = false; - private ?Stopwatch $stopwatch; - - public function __construct(?Stopwatch $stopwatch) + public function __construct(private ?Stopwatch $stopwatch) { - $this->stopwatch = $stopwatch; } public function register(): void diff --git a/CacheWarmer/HydratorCacheWarmer.php b/CacheWarmer/HydratorCacheWarmer.php index 5d608712..7351f308 100644 --- a/CacheWarmer/HydratorCacheWarmer.php +++ b/CacheWarmer/HydratorCacheWarmer.php @@ -31,11 +31,8 @@ */ class HydratorCacheWarmer implements CacheWarmerInterface { - private ContainerInterface $container; - - public function __construct(ContainerInterface $container) + public function __construct(private ContainerInterface $container) { - $this->container = $container; } /** diff --git a/CacheWarmer/PersistentCollectionCacheWarmer.php b/CacheWarmer/PersistentCollectionCacheWarmer.php index 2fb75efe..135e9017 100644 --- a/CacheWarmer/PersistentCollectionCacheWarmer.php +++ b/CacheWarmer/PersistentCollectionCacheWarmer.php @@ -32,11 +32,8 @@ */ class PersistentCollectionCacheWarmer implements CacheWarmerInterface { - private ContainerInterface $container; - - public function __construct(ContainerInterface $container) + public function __construct(private ContainerInterface $container) { - $this->container = $container; } /** diff --git a/CacheWarmer/ProxyCacheWarmer.php b/CacheWarmer/ProxyCacheWarmer.php index b7532cda..1380e8eb 100644 --- a/CacheWarmer/ProxyCacheWarmer.php +++ b/CacheWarmer/ProxyCacheWarmer.php @@ -33,11 +33,8 @@ */ class ProxyCacheWarmer implements CacheWarmerInterface { - private ContainerInterface $container; - - public function __construct(ContainerInterface $container) + public function __construct(private ContainerInterface $container) { - $this->container = $container; } /** diff --git a/Command/LoadDataFixturesDoctrineODMCommand.php b/Command/LoadDataFixturesDoctrineODMCommand.php index 74bdc4c3..83694e42 100644 --- a/Command/LoadDataFixturesDoctrineODMCommand.php +++ b/Command/LoadDataFixturesDoctrineODMCommand.php @@ -27,13 +27,9 @@ */ class LoadDataFixturesDoctrineODMCommand extends DoctrineODMCommand { - private ?SymfonyFixturesLoaderInterface $fixturesLoader; - - public function __construct(?ManagerRegistry $registry = null, ?KernelInterface $kernel = null, ?SymfonyFixturesLoaderInterface $fixturesLoader = null) + public function __construct(?ManagerRegistry $registry = null, ?KernelInterface $kernel = null, private ?SymfonyFixturesLoaderInterface $fixturesLoader = null) { parent::__construct($registry); - - $this->fixturesLoader = $fixturesLoader; } /** @return bool */ diff --git a/DataCollector/CommandDataCollector.php b/DataCollector/CommandDataCollector.php index a1c75b93..cb555587 100644 --- a/DataCollector/CommandDataCollector.php +++ b/DataCollector/CommandDataCollector.php @@ -21,11 +21,8 @@ class CommandDataCollector extends DataCollector { - private CommandLogger $commandLogger; - - public function __construct(CommandLogger $commandLogger) + public function __construct(private CommandLogger $commandLogger) { - $this->commandLogger = $commandLogger; } public function collect(Request $request, Response $response, ?Throwable $exception = null): void diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index c2ec3532..5d8b6680 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -52,8 +52,7 @@ */ class DoctrineMongoDBExtension extends AbstractDoctrineExtension { - /** @var string */ - private static $odmVersion; + private static ?string $odmVersion = null; /** @internal */ public const CONFIGURATION_TAG = 'doctrine.odm.configuration'; @@ -658,7 +657,7 @@ private static function getODMVersion(): string if (self::$odmVersion === null) { try { self::$odmVersion = PrettyVersions::getVersion('doctrine/mongodb-odm')->getPrettyVersion(); - } catch (Throwable $t) { + } catch (Throwable) { return 'unknown'; } } diff --git a/Form/DoctrineMongoDBTypeGuesser.php b/Form/DoctrineMongoDBTypeGuesser.php index 789f63f9..a57e01bd 100644 --- a/Form/DoctrineMongoDBTypeGuesser.php +++ b/Form/DoctrineMongoDBTypeGuesser.php @@ -182,7 +182,7 @@ protected function getMetadata($class) foreach ($this->registry->getManagers() as $name => $dm) { try { return $this->cache[$class] = [$dm->getClassMetadata($class), $name]; - } catch (MappingException $e) { + } catch (MappingException) { // not an entity or mapped super class } } diff --git a/Loader/SymfonyFixturesLoader.php b/Loader/SymfonyFixturesLoader.php index c83bd01b..4a137886 100644 --- a/Loader/SymfonyFixturesLoader.php +++ b/Loader/SymfonyFixturesLoader.php @@ -50,7 +50,7 @@ public function addFixtures(array $fixtures): void public function addFixture(FixtureInterface $fixture): void { - $class = get_class($fixture); + $class = $fixture::class; $this->loadedFixtures[$class] = $fixture; $reflection = new ReflectionClass($fixture); @@ -106,7 +106,7 @@ public function getFixtures(array $groups = []) $filteredFixtures = []; foreach ($fixtures as $fixture) { foreach ($groups as $group) { - $fixtureClass = get_class($fixture); + $fixtureClass = $fixture::class; if (isset($this->groupsFixtureMapping[$group][$fixtureClass])) { $filteredFixtures[$fixtureClass] = $fixture; @@ -145,7 +145,7 @@ private function validateDependencies(array $fixtures, FixtureInterface $fixture foreach ($dependenciesClasses as $class) { if (! array_key_exists($class, $fixtures)) { - throw new RuntimeException(sprintf('Fixture "%s" was declared as a dependency for fixture "%s", but it was not included in any of the loaded fixture groups.', $class, get_class($fixture))); + throw new RuntimeException(sprintf('Fixture "%s" was declared as a dependency for fixture "%s", but it was not included in any of the loaded fixture groups.', $class, $fixture::class)); } } } diff --git a/ManagerConfigurator.php b/ManagerConfigurator.php index b9be6b39..14a6d699 100644 --- a/ManagerConfigurator.php +++ b/ManagerConfigurator.php @@ -13,17 +13,13 @@ */ class ManagerConfigurator { - /** @var array */ - private array $enabledFilters = []; - /** * Construct. * * @param array $enabledFilters */ - public function __construct(array $enabledFilters) + public function __construct(private array $enabledFilters = []) { - $this->enabledFilters = $enabledFilters; } /** diff --git a/ManagerRegistry.php b/ManagerRegistry.php index a76d2b46..113d9f85 100644 --- a/ManagerRegistry.php +++ b/ManagerRegistry.php @@ -46,7 +46,7 @@ public function getAliasNamespace($alias) try { return $objectManager->getConfiguration()->getDocumentNamespace($alias); - } catch (MongoDBException $e) { + } catch (MongoDBException) { } } diff --git a/README.markdown b/README.markdown index 2738b731..13b94c27 100644 --- a/README.markdown +++ b/README.markdown @@ -13,7 +13,7 @@ Compatibility ============= The current version of this bundle has the following requirements: - * PHP 7.4 or newer is required + * PHP 8.1 or newer is required * `ext-mongodb` 1.5 or newer * Symfony 5.4 or newer is required diff --git a/Repository/ContainerRepositoryFactory.php b/Repository/ContainerRepositoryFactory.php index 4d9a7a92..374d0490 100644 --- a/Repository/ContainerRepositoryFactory.php +++ b/Repository/ContainerRepositoryFactory.php @@ -27,12 +27,9 @@ 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) + public function __construct(private ContainerInterface $container) { - $this->container = $container; } /** diff --git a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php index 198bd8df..386538ce 100644 --- a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php +++ b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php @@ -334,7 +334,6 @@ public function testAnnotationsBundleMappingDetection(): void $this->assertEquals('Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\AnnotationsBundle\Document', $calls[0][1][1]); } - /** @requires PHP 8.0 */ public function testAttributesBundleMappingDetection(): void { if (! class_exists(AttributeDriver::class)) { diff --git a/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php b/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php index fae11e35..fbe69742 100644 --- a/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php @@ -65,7 +65,6 @@ public function testParameterOverride(string $option, string $parameter, string $this->assertEquals($value, $container->getParameter('doctrine_mongodb.odm.' . $parameter)); } - /** @requires PHP 8 */ public function testAsDocumentListenerAttribute(): void { $container = $this->getContainer('DocumentListenerBundle'); diff --git a/Tests/DocumentValueResolverFunctionalTest.php b/Tests/DocumentValueResolverFunctionalTest.php index d26004c4..5fb51468 100644 --- a/Tests/DocumentValueResolverFunctionalTest.php +++ b/Tests/DocumentValueResolverFunctionalTest.php @@ -20,10 +20,7 @@ use function sys_get_temp_dir; use function uniqid; -/** - * @requires PHP 8.0 - * @requires function \Symfony\Bridge\Doctrine\Attribute\MapEntity::__construct - */ +/** @requires function \Symfony\Bridge\Doctrine\Attribute\MapEntity::__construct */ class DocumentValueResolverFunctionalTest extends WebTestCase { public function testWithoutConfiguration(): void diff --git a/Tests/FixtureIntegrationTest.php b/Tests/FixtureIntegrationTest.php index 91e36f2d..0abb3533 100644 --- a/Tests/FixtureIntegrationTest.php +++ b/Tests/FixtureIntegrationTest.php @@ -24,7 +24,6 @@ use function array_map; use function assert; -use function get_class; use function sprintf; use function sys_get_temp_dir; use function uniqid; @@ -51,7 +50,7 @@ public function testFixturesLoader(): void $actualFixtures = $loader->getFixtures(); $this->assertCount(2, $actualFixtures); - $actualFixtureClasses = array_map(static fn ($fixture) => get_class($fixture), $actualFixtures); + $actualFixtureClasses = array_map(static fn ($fixture) => $fixture::class, $actualFixtures); $this->assertSame([ OtherFixtures::class, @@ -82,7 +81,7 @@ public function testFixturesLoaderWhenFixtureHasDependencyThatIsNotYetLoaded(): $actualFixtures = $loader->getFixtures(); $this->assertCount(2, $actualFixtures); - $actualFixtureClasses = array_map(static fn ($fixture) => get_class($fixture), $actualFixtures); + $actualFixtureClasses = array_map(static fn ($fixture) => $fixture::class, $actualFixtures); $this->assertSame([ OtherFixtures::class, @@ -138,7 +137,7 @@ public function testFixturesLoaderWithGroupsOptionViaInterface(): void $actualFixtures = $loader->getFixtures(['staging']); $this->assertCount(1, $actualFixtures); - $actualFixtureClasses = array_map(static fn ($fixture) => get_class($fixture), $actualFixtures); + $actualFixtureClasses = array_map(static fn ($fixture) => $fixture::class, $actualFixtures); $this->assertSame([ OtherFixtures::class, @@ -227,7 +226,7 @@ public function testLoadFixturesViaGroupWithFulfilledDependency(): void $actualFixtures = $loader->getFixtures(['fulfilledDependencyGroup']); $this->assertCount(2, $actualFixtures); - $actualFixtureClasses = array_map(static fn ($fixture) => get_class($fixture), $actualFixtures); + $actualFixtureClasses = array_map(static fn ($fixture) => $fixture::class, $actualFixtures); $this->assertSame([ OtherFixtures::class, @@ -258,7 +257,7 @@ public function testLoadFixturesByShortName(): void $actualFixtures = $loader->getFixtures(['OtherFixtures']); $this->assertCount(1, $actualFixtures); - $actualFixtureClasses = array_map(static fn ($fixture) => get_class($fixture), $actualFixtures); + $actualFixtureClasses = array_map(static fn ($fixture) => $fixture::class, $actualFixtures); $this->assertSame([ OtherFixtures::class, diff --git a/Tests/Fixtures/FooBundle/Controller/DocumentValueResolverController.php b/Tests/Fixtures/FooBundle/Controller/DocumentValueResolverController.php index 8348027b..784e2693 100644 --- a/Tests/Fixtures/FooBundle/Controller/DocumentValueResolverController.php +++ b/Tests/Fixtures/FooBundle/Controller/DocumentValueResolverController.php @@ -15,7 +15,7 @@ final class DocumentValueResolverController { #[Route(path: '/user/{id}', name: 'tv_user_show')] public function showUserByDefault( - User $user + User $user, ): Response { return new Response($user->getId()); } @@ -23,7 +23,7 @@ public function showUserByDefault( #[Route(path: '/user_with_identifier/{identifier}', name: 'tv_user_show_with_identifier')] public function showUserWithMapping( #[MapDocument(mapping: ['identifier' => 'id'])] - User $user + User $user, ): Response { return new Response($user->getId()); } diff --git a/Tests/Fixtures/FooBundle/DataFixtures/RequiredConstructorArgsFixtures.php b/Tests/Fixtures/FooBundle/DataFixtures/RequiredConstructorArgsFixtures.php index e1905678..40f99760 100644 --- a/Tests/Fixtures/FooBundle/DataFixtures/RequiredConstructorArgsFixtures.php +++ b/Tests/Fixtures/FooBundle/DataFixtures/RequiredConstructorArgsFixtures.php @@ -9,8 +9,7 @@ class RequiredConstructorArgsFixtures implements ODMFixtureInterface { - /** @param mixed $fooRequiredArg */ - public function __construct($fooRequiredArg) + public function __construct(mixed $fooRequiredArg) { } diff --git a/Tests/Fixtures/Form/Category.php b/Tests/Fixtures/Form/Category.php index dd1c620a..4d8d9971 100644 --- a/Tests/Fixtures/Form/Category.php +++ b/Tests/Fixtures/Form/Category.php @@ -12,12 +12,8 @@ /** @ODM\Document */ class Category { - /** - * @ODM\Id - * - * @var ObjectId|string|null - */ - protected $id; + /** @ODM\Id */ + protected ObjectId|string|null $id; /** @ODM\Field(type="string") */ public string $name; diff --git a/Tests/Fixtures/Form/Guesser.php b/Tests/Fixtures/Form/Guesser.php index e66d4290..2c9def07 100644 --- a/Tests/Fixtures/Form/Guesser.php +++ b/Tests/Fixtures/Form/Guesser.php @@ -51,6 +51,5 @@ class Guesser */ public array $collectionField; - /** @var mixed */ - public $nonMappedField; + public mixed $nonMappedField; } diff --git a/Tests/Validator/Constraints/UniqueTest.php b/Tests/Validator/Constraints/UniqueTest.php index 8931700c..374de46f 100644 --- a/Tests/Validator/Constraints/UniqueTest.php +++ b/Tests/Validator/Constraints/UniqueTest.php @@ -5,26 +5,19 @@ namespace Doctrine\Bundle\MongoDBBundle\Tests\Validator\Constraints; use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique; -use Doctrine\Common\Annotations\AnnotationReader; use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; use function assert; -use const PHP_VERSION_ID; - final class UniqueTest extends TestCase { public function testWithDefaultProperty(): void { $metadata = new ClassMetadata(UniqueDocumentDummyOne::class); - if (PHP_VERSION_ID >= 80000) { - $loader = new AnnotationLoader(); - } else { - $loader = new AnnotationLoader(new AnnotationReader()); - } + $loader = new AnnotationLoader(); self::assertTrue($loader->loadClassMetadata($metadata)); diff --git a/UPGRADE-4.7.md b/UPGRADE-4.7.md new file mode 100644 index 00000000..4082dd3c --- /dev/null +++ b/UPGRADE-4.7.md @@ -0,0 +1,7 @@ +UPGRADE FROM 4.6 to 4.7 +======================= + +## PHP requirements + +* The bundle now requires PHP 8.1 or newer. If you're not running PHP 8.1 yet, + it's recommended that you upgrade to PHP 8.1 before upgrading the bundle. diff --git a/Validator/Constraints/Unique.php b/Validator/Constraints/Unique.php index 81fa0ad6..d6c437e7 100644 --- a/Validator/Constraints/Unique.php +++ b/Validator/Constraints/Unique.php @@ -32,7 +32,7 @@ public function __construct( $ignoreNull = null, ?array $groups = null, $payload = null, - array $options = [] + array $options = [], ) { parent::__construct( $fields, diff --git a/composer.json b/composer.json index 88a64b34..be732051 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ ], "homepage": "http://www.doctrine-project.org", "require": { - "php": "^7.4 || ^8.0", + "php": "^8.1", "ext-mongodb": "^1.5", "doctrine/annotations": "^1.13 || ^2.0", "doctrine/mongodb-odm": "^2.3", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 0baa167f..0e6a99d2 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -9,7 +9,7 @@ - + . @@ -32,7 +32,8 @@ - + +