diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c03a8db0c4..12824a12fc 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -24,8 +24,6 @@ jobs: fail-fast: false matrix: php-version: - - "7.4" - - "8.0" - "8.1" - "8.2" - "8.3" @@ -38,12 +36,12 @@ jobs: - "" include: - deps: "lowest" - php-version: "7.4" + php-version: "8.1" - deps: "highest" php-version: "8.4" # Run builds on low and high PHP versions with `doctrine/annotations` removed - deps: "highest" - php-version: "7.4" + php-version: "8.1" no-annotations: true - deps: "highest" php-version: "8.4" @@ -51,7 +49,7 @@ jobs: # Run builds on high PHP version with `doctrine/orm` version pinned - deps: "highest" php-version: "8.4" - orm: "^2.14" + orm: "^2.20" - deps: "highest" php-version: "8.4" orm: "^3.0" @@ -109,7 +107,7 @@ jobs: - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "8.2" + php-version: "8.4" extensions: mongodb - name: "Install dependencies with Composer" diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index cc2ea3136b..1b49a4a78f 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -31,8 +31,8 @@ ->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect()) ->setRules([ '@DoctrineAnnotation' => true, - '@PHP74Migration' => true, - '@PHP74Migration:risky' => true, + '@PHP81Migration' => true, + '@PHP80Migration:risky' => true, '@PHPUnit91Migration:risky' => true, '@PSR2' => true, '@Symfony' => true, @@ -78,6 +78,7 @@ 'random_api_migration' => true, 'return_assignment' => true, 'self_accessor' => true, + 'single_line_empty_body' => true, 'static_lambda' => true, 'strict_param' => true, 'ternary_to_null_coalescing' => true, diff --git a/CHANGELOG.md b/CHANGELOG.md index d303164147..ddcb994e02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ a release. ## [Unreleased] ### Changed +- Dropped support for PHP < 8.1 - Sluggable: Replaced abandoned `behat/transliterator` with `symfony/string` for default transliteration and urlization steps (#2985) ## [3.20.1] - 2025-09-14 diff --git a/composer.json b/composer.json index bbf9357ad5..3a65dc7e2a 100644 --- a/composer.json +++ b/composer.json @@ -40,21 +40,21 @@ "docs": "https://github.com/doctrine-extensions/DoctrineExtensions/tree/main/doc" }, "require": { - "php": "^7.4 || ^8.0", - "doctrine/collections": "^1.2 || ^2.0", + "php": "^8.1", + "doctrine/collections": "^1.6.5 || ^2.0", "doctrine/deprecations": "^1.0", "doctrine/event-manager": "^1.2 || ^2.0", - "doctrine/persistence": "^2.2 || ^3.0 || ^4.0", + "doctrine/persistence": "^2.5.2 || ^3.0 || ^4.0", "psr/cache": "^1 || ^2 || ^3", "psr/clock": "^1", "symfony/cache": "^5.4 || ^6.0 || ^7.0", "symfony/string": "^5.4 || ^6.0 || ^7.0" }, "require-dev": { - "behat/transliterator": "^1.2", - "doctrine/annotations": "^1.13 || ^2.0", - "doctrine/cache": "^1.11 || ^2.0", - "doctrine/common": "^2.13 || ^3.0", + "behat/transliterator": "^1.3", + "doctrine/annotations": "^1.14 || ^2.0", + "doctrine/cache": "^1.12.1 || ^2.0", + "doctrine/common": "^3.1", "doctrine/dbal": "^3.7 || ^4.0", "doctrine/doctrine-bundle": "^2.3", "doctrine/mongodb-odm": "^2.3", @@ -73,9 +73,9 @@ "symfony/yaml": "^5.4 || ^6.0 || ^7.0" }, "conflict": { - "behat/transliterator": "<1.2 || >=2.0", - "doctrine/annotations": "<1.13 || >=3.0", - "doctrine/common": "<2.13 || >=4.0", + "behat/transliterator": "<1.3 || >=2.0", + "doctrine/annotations": "<1.14 || >=3.0", + "doctrine/common": "<3.1 || >=4.0", "doctrine/dbal": "<3.7 || >=5.0", "doctrine/mongodb-odm": "<2.3 || >=3.0", "doctrine/orm": "<2.20 || >=3.0 <3.3 || >=4.0" diff --git a/example/app/Command/PrintCategoryTranslationTreeCommand.php b/example/app/Command/PrintCategoryTranslationTreeCommand.php index 43d1180fb9..211d204242 100644 --- a/example/app/Command/PrintCategoryTranslationTreeCommand.php +++ b/example/app/Command/PrintCategoryTranslationTreeCommand.php @@ -18,15 +18,14 @@ use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; use Gedmo\Translatable\Query\TreeWalker\TranslationWalker; use Gedmo\Translatable\TranslatableListener; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand(name: 'app:print-category-translation-tree', description: 'Seeds an example category tree with translations and prints the tree.')] final class PrintCategoryTranslationTreeCommand extends Command { - protected static $defaultName = 'app:print-category-translation-tree'; - protected static $defaultDescription = 'Seeds an example category tree with translations and prints the tree.'; - protected function execute(InputInterface $input, OutputInterface $output): int { /** @var EntityManagerHelper $helper */ diff --git a/example/app/Entity/Category.php b/example/app/Entity/Category.php index bd51a48b90..c0a66160c1 100644 --- a/example/app/Entity/Category.php +++ b/example/app/Entity/Category.php @@ -13,6 +13,7 @@ use App\Entity\Repository\CategoryRepository; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; @@ -29,7 +30,7 @@ #[ORM\Table(name: 'ext_categories')] #[ORM\Entity(repositoryClass: CategoryRepository::class)] #[Gedmo\TranslationEntity(class: CategoryTranslation::class)] -class Category +class Category implements \Stringable { /** * @ORM\Column(type="integer") @@ -39,33 +40,27 @@ class Category #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue] - private $id; + private ?int $id = null; /** - * @var string|null - * * @Gedmo\Translatable * * @ORM\Column(length=64) */ #[Gedmo\Translatable] #[ORM\Column(length: 64)] - private $title; + private ?string $title = null; /** - * @var string|null - * * @Gedmo\Translatable * * @ORM\Column(type="text", nullable=true) */ #[Gedmo\Translatable] #[ORM\Column(type: Types::TEXT, nullable: true)] - private $description; + private ?string $description = null; /** - * @var string|null - * * @Gedmo\Translatable * @Gedmo\Slug(fields={"created", "title"}) * @@ -74,7 +69,7 @@ class Category #[Gedmo\Translatable] #[Gedmo\Slug(fields: ['created', 'title'])] #[ORM\Column(length: 64, unique: true)] - private $slug; + private ?string $slug = null; /** * @Gedmo\TreeLeft @@ -83,7 +78,7 @@ class Category */ #[Gedmo\TreeLeft] #[ORM\Column(type: Types::INTEGER)] - private $lft; + private ?int $lft = null; /** * @Gedmo\TreeRight @@ -92,7 +87,7 @@ class Category */ #[Gedmo\TreeRight] #[ORM\Column(type: Types::INTEGER)] - private $rgt; + private ?int $rgt = null; /** * @Gedmo\TreeParent @@ -103,7 +98,7 @@ class Category #[Gedmo\TreeParent] #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')] - private $parent; + private ?self $parent = null; /** * @Gedmo\TreeRoot @@ -112,7 +107,7 @@ class Category */ #[Gedmo\TreeRoot] #[ORM\Column(type: Types::INTEGER, nullable: true)] - private $root; + private ?int $root = null; /** * @Gedmo\TreeLevel @@ -121,9 +116,11 @@ class Category */ #[Gedmo\TreeLevel] #[ORM\Column(name: 'lvl', type: Types::INTEGER)] - private $level; + private ?int $level = null; /** + * @var Collection + * * @ORM\OneToMany(targetEntity="Category", mappedBy="parent") */ #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] @@ -136,7 +133,7 @@ class Category */ #[Gedmo\Timestampable(on: 'create')] #[ORM\Column(type: Types::DATETIME_MUTABLE)] - private $created; + private ?\DateTime $created = null; /** * @Gedmo\Timestampable(on="update") @@ -145,7 +142,7 @@ class Category */ #[Gedmo\Timestampable(on: 'update')] #[ORM\Column(type: Types::DATETIME_MUTABLE)] - private $updated; + private ?\DateTime $updated = null; /** * @Gedmo\Blameable(on="create") @@ -154,7 +151,7 @@ class Category */ #[Gedmo\Blameable(on: 'create')] #[ORM\Column(type: Types::STRING)] - private $createdBy; + private ?string $createdBy = null; /** * @Gedmo\Blameable(on="update") @@ -163,9 +160,11 @@ class Category */ #[Gedmo\Blameable(on: 'update')] #[ORM\Column(type: Types::STRING)] - private $updatedBy; + private ?string $updatedBy = null; /** + * @var Collection + * * @ORM\OneToMany( * targetEntity="CategoryTranslation", * mappedBy="object", @@ -173,7 +172,7 @@ class Category * ) */ #[ORM\OneToMany(targetEntity: CategoryTranslation::class, mappedBy: 'object', cascade: ['persist', 'remove'])] - private $translations; + private Collection $translations; public function __construct() { @@ -181,17 +180,20 @@ public function __construct() $this->translations = new ArrayCollection(); } - public function __toString() + public function __toString(): string { - return $this->getTitle(); + return (string) $this->getTitle(); } - public function getTranslations() + /** + * @return Collection + */ + public function getTranslations(): Collection { return $this->translations; } - public function addTranslation(CategoryTranslation $t) + public function addTranslation(CategoryTranslation $t): void { if (!$this->translations->contains($t)) { $this->translations[] = $t; @@ -199,87 +201,90 @@ public function addTranslation(CategoryTranslation $t) } } - public function getSlug() + public function getSlug(): ?string { return $this->slug; } - public function getId() + public function getId(): ?int { return $this->id; } - public function setTitle($title) + public function setTitle(?string $title): void { $this->title = $title; } - public function getTitle() + public function getTitle(): ?string { return $this->title; } - public function setDescription($description) + public function setDescription(?string $description): void { $this->description = $description; } - public function getDescription() + public function getDescription(): ?string { return $this->description; } - public function setParent($parent) + public function setParent(?self $parent): void { $this->parent = $parent; } - public function getParent() + public function getParent(): ?self { return $this->parent; } - public function getRoot() + public function getRoot(): ?int { return $this->root; } - public function getLevel() + public function getLevel(): ?int { return $this->level; } - public function getChildren() + /** + * @return Collection + */ + public function getChildren(): Collection { return $this->children; } - public function getLeft() + public function getLeft(): ?int { return $this->lft; } - public function getRight() + public function getRight(): ?int { return $this->rgt; } - public function getCreated() + public function getCreated(): ?\DateTime { return $this->created; } - public function getUpdated() + public function getUpdated(): ?\DateTime { return $this->updated; } - public function getCreatedBy() + public function getCreatedBy(): ?string { return $this->createdBy; } - public function getUpdatedBy() + public function getUpdatedBy(): ?string { return $this->updatedBy; } diff --git a/example/app/Entity/CategoryTranslation.php b/example/app/Entity/CategoryTranslation.php index 2f28b50045..793f409073 100644 --- a/example/app/Entity/CategoryTranslation.php +++ b/example/app/Entity/CategoryTranslation.php @@ -35,14 +35,7 @@ class CategoryTranslation extends AbstractPersonalTranslation #[ORM\JoinColumn(name: 'object_id', referencedColumnName: 'id', onDelete: 'CASCADE')] protected $object; - /** - * Convenient constructor - * - * @param string $locale - * @param string $field - * @param string $value - */ - public function __construct($locale, $field, $value) + public function __construct(string $locale, string $field, string $value) { $this->setLocale($locale); $this->setField($field); diff --git a/example/app/Entity/Repository/CategoryRepository.php b/example/app/Entity/Repository/CategoryRepository.php index 543ea30ee5..75d3304c3c 100644 --- a/example/app/Entity/Repository/CategoryRepository.php +++ b/example/app/Entity/Repository/CategoryRepository.php @@ -17,6 +17,4 @@ /** * @template-extends NestedTreeRepository */ -final class CategoryRepository extends NestedTreeRepository -{ -} +final class CategoryRepository extends NestedTreeRepository {} diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3a0d96376b..0c147842c8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -36,12 +36,6 @@ parameters: count: 1 path: src/Blameable/Mapping/Driver/Yaml.php - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 2 - path: src/DoctrineExtensions.php - - message: '#^Access to offset ''inherited'' on an unknown class Doctrine\\ODM\\MongoDB\\Mapping\\AssociationFieldMapping\.$#' identifier: class.notFound @@ -444,18 +438,6 @@ parameters: count: 1 path: src/SoftDeleteable/Mapping/Validator.php - - - message: '#^Access to an undefined property Gedmo\\SoftDeleteable\\Query\\TreeWalker\\Exec\\MultiTableDeleteExecutor\:\:\$_sqlStatements\.$#' - identifier: property.notFound - count: 1 - path: src/SoftDeleteable/Query/TreeWalker/Exec/MultiTableDeleteExecutor.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Gedmo\\SoftDeleteable\\Query\\TreeWalker\\Exec\\MultiTableDeleteExecutor\) and ''sqlStatements'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: src/SoftDeleteable/Query/TreeWalker/Exec/MultiTableDeleteExecutor.php - - message: '#^Method Gedmo\\SoftDeleteable\\Query\\TreeWalker\\SoftDeleteableWalker\:\:__construct\(\) has parameter \$parserResult with no type specified\.$#' identifier: missingType.parameter @@ -894,42 +876,6 @@ parameters: count: 1 path: src/Tree/TreeListener.php - - - message: '#^Method Gedmo\\Uploadable\\Event\\UploadableBaseEventArgs\:\:__construct\(\) has parameter \$config with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/Uploadable/Event/UploadableBaseEventArgs.php - - - - message: '#^Method Gedmo\\Uploadable\\Event\\UploadableBaseEventArgs\:\:getExtensionConfiguration\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/Uploadable/Event/UploadableBaseEventArgs.php - - - - message: '#^Property Gedmo\\Uploadable\\Event\\UploadableBaseEventArgs\:\:\$config is never read, only written\.$#' - identifier: property.onlyWritten - count: 1 - path: src/Uploadable/Event/UploadableBaseEventArgs.php - - - - message: '#^Property Gedmo\\Uploadable\\Event\\UploadableBaseEventArgs\:\:\$config type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/Uploadable/Event/UploadableBaseEventArgs.php - - - - message: '#^Property Gedmo\\Uploadable\\Event\\UploadableBaseEventArgs\:\:\$extensionConfiguration is never written, only read\.$#' - identifier: property.onlyRead - count: 1 - path: src/Uploadable/Event/UploadableBaseEventArgs.php - - - - message: '#^Property Gedmo\\Uploadable\\Event\\UploadableBaseEventArgs\:\:\$extensionConfiguration type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/Uploadable/Event/UploadableBaseEventArgs.php - - message: '#^Method Gedmo\\Uploadable\\FileInfo\\FileInfoArray\:\:getName\(\) never returns null so it can be removed from the return type\.$#' identifier: return.unusedType @@ -984,60 +930,6 @@ parameters: count: 3 path: src/Uploadable/UploadableListener.php - - - message: '#^Class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 2 - path: tests/Gedmo/DoctrineExtensionsTest.php - - - - message: '#^Property Gedmo\\Tests\\Mapping\\Fixture\\Attribute\\TranslatableModel\:\:\$title \(string\|null\) is never assigned string so it can be removed from the property type\.$#' - identifier: property.unusedType - count: 1 - path: tests/Gedmo/Mapping/Fixture/Attribute/TranslatableModel.php - - - - message: '#^Property Gedmo\\Tests\\Mapping\\Fixture\\Attribute\\TranslatableModel\:\:\$titleFallbackFalse \(string\|null\) is never assigned string so it can be removed from the property type\.$#' - identifier: property.unusedType - count: 1 - path: tests/Gedmo/Mapping/Fixture/Attribute/TranslatableModel.php - - - - message: '#^Property Gedmo\\Tests\\Mapping\\Fixture\\Attribute\\TranslatableModel\:\:\$titleFallbackTrue \(string\|null\) is never assigned string so it can be removed from the property type\.$#' - identifier: property.unusedType - count: 1 - path: tests/Gedmo/Mapping/Fixture/Attribute/TranslatableModel.php - - - - message: '#^Class Gedmo\\Tests\\Translatable\\Fixture\\CategoryTranslation not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Gedmo/Mapping/Fixture/Category.php - - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 2 - path: tests/Gedmo/Mapping/MappingEventSubscriberTest.php - - - - message: '#^Parameter \#1 \$driverImpl of method Doctrine\\ORM\\Configuration\:\:setMetadataDriverImpl\(\) expects Doctrine\\Persistence\\Mapping\\Driver\\MappingDriver, Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver given\.$#' - identifier: argument.type - count: 2 - path: tests/Gedmo/Mapping/MappingEventSubscriberTest.php - - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Gedmo/Mapping/MappingTest.php - - - - message: '#^Parameter \#1 \$driverImpl of method Doctrine\\ORM\\Configuration\:\:setMetadataDriverImpl\(\) expects Doctrine\\Persistence\\Mapping\\Driver\\MappingDriver, Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver given\.$#' - identifier: argument.type - count: 1 - path: tests/Gedmo/Mapping/MappingTest.php - - message: '#^Call to an undefined method Doctrine\\Persistence\\Mapping\\ClassMetadata\\:\:mapField\(\)\.$#' identifier: method.notFound @@ -1056,18 +948,6 @@ parameters: count: 1 path: tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php - - - - message: '#^Parameter \#1 \$driverImpl of method Doctrine\\ORM\\Configuration\:\:setMetadataDriverImpl\(\) expects Doctrine\\Persistence\\Mapping\\Driver\\MappingDriver, Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver given\.$#' - identifier: argument.type - count: 1 - path: tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php - - message: '#^Call to an undefined method Doctrine\\Persistence\\Mapping\\ClassMetadata\\:\:getReflectionProperty\(\)\.$#' identifier: method.notFound @@ -1086,18 +966,6 @@ parameters: count: 1 path: tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Attribute.php - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 2 - path: tests/Gedmo/Mapping/MultiManagerMappingTest.php - - - - message: '#^Parameter \#1 \$nestedDriver of method Doctrine\\Persistence\\Mapping\\Driver\\MappingDriverChain\:\:addDriver\(\) expects Doctrine\\Persistence\\Mapping\\Driver\\MappingDriver, Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver given\.$#' - identifier: argument.type - count: 1 - path: tests/Gedmo/Mapping/ORMMappingTestCase.php - - message: '#^Parameter \#1 \$nestedDriver of method Doctrine\\Persistence\\Mapping\\Driver\\MappingDriverChain\:\:addDriver\(\) expects Doctrine\\Persistence\\Mapping\\Driver\\MappingDriver, Doctrine\\ORM\\Mapping\\Driver\\YamlDriver given\.$#' identifier: argument.type @@ -1122,12 +990,6 @@ parameters: count: 1 path: tests/Gedmo/Mapping/ReferenceIntegrityMappingTest.php - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Gedmo/Mapping/TreeMappingTest.php - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\YamlDriver not found\.$#' identifier: class.notFound @@ -1140,48 +1002,12 @@ parameters: count: 1 path: tests/Gedmo/Mapping/TreeMappingTest.php - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Gedmo/Mapping/Xml/ClosureTreeMappingTest.php - - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Gedmo/Mapping/Xml/MaterializedPathTreeMappingTest.php - - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php - - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php - - message: '#^Method Gedmo\\Tests\\Sluggable\\Fixture\\Doctrine\\FakeFilter\:\:addFilterConstraint\(\) has parameter \$targetTableAlias with no type specified\.$#' identifier: missingType.parameter count: 1 path: tests/Gedmo/Sluggable/Fixture/Doctrine/FakeFilter.php - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\YamlDriver not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Gedmo/Sluggable/Issue/Issue116Test.php - - - - message: '#^Parameter \#1 \$nestedDriver of method Doctrine\\Persistence\\Mapping\\Driver\\MappingDriverChain\:\:addDriver\(\) expects Doctrine\\Persistence\\Mapping\\Driver\\MappingDriver, Doctrine\\ORM\\Mapping\\Driver\\YamlDriver given\.$#' - identifier: argument.type - count: 1 - path: tests/Gedmo/Sluggable/Issue/Issue116Test.php - - message: '#^Parameter \$args of method Gedmo\\Tests\\SoftDeleteable\\Fixture\\Listener\\WithLifecycleEventArgsFromORMTypeListener\:\:postSoftDelete\(\) has invalid type Doctrine\\ORM\\Event\\LifecycleEventArgs\.$#' identifier: class.notFound @@ -1194,42 +1020,12 @@ parameters: count: 1 path: tests/Gedmo/SoftDeleteable/Fixture/Listener/WithLifecycleEventArgsFromORMTypeListener.php - - - message: '#^Method Gedmo\\Tests\\Timestampable\\Fixture\\ArticleCarbon\:\:getCreated\(\) should return Carbon\\Carbon\|null but returns DateTime\|null\.$#' - identifier: return.type - count: 1 - path: tests/Gedmo/Timestampable/Fixture/ArticleCarbon.php - - message: '#^Call to function method_exists\(\) with Doctrine\\ORM\\EntityManager\|null and ''merge'' will always evaluate to false\.$#' identifier: function.impossibleType count: 2 path: tests/Gedmo/Timestampable/TimestampableTest.php - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Gedmo/Tool/BaseTestCaseOM.php - - - - message: '#^Method Gedmo\\Tests\\Tool\\BaseTestCaseOM\:\:getORMDriver\(\) should return Doctrine\\Persistence\\Mapping\\Driver\\MappingDriver but returns Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver\.$#' - identifier: return.type - count: 1 - path: tests/Gedmo/Tool/BaseTestCaseOM.php - - - - message: '#^Instantiated class Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Gedmo/Tool/BaseTestCaseORM.php - - - - message: '#^Method Gedmo\\Tests\\Tool\\BaseTestCaseORM\:\:getMetadataDriverImplementation\(\) should return Doctrine\\Persistence\\Mapping\\Driver\\MappingDriver but returns Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver\.$#' - identifier: return.type - count: 1 - path: tests/Gedmo/Tool/BaseTestCaseORM.php - - message: '#^Property Gedmo\\Tests\\Tree\\MaterializedPathODMMongoDBRepositoryTest\:\:\$repo \(Gedmo\\Tree\\Document\\MongoDB\\Repository\\MaterializedPathRepository\\) does not accept Doctrine\\ORM\\EntityRepository\\.$#' identifier: assign.propertyType diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ae95c956a6..5c11c7bc8e 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -17,6 +17,7 @@ parameters: - '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never written, only read\.$#' - '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never read, only written\.$#' - '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is unused\.$#' + - '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ (.*) is never assigned (.*) so it can be removed from the property type\.$#' - '#^Method Gedmo\\(?:[^\\]+\\)*Mapping\\Driver[^:]+::readExtendedMetadata\(\) with return type void returns [\w\|<>\s,]+ but should not return anything\.$#' - '#^Result of method Gedmo\\Mapping\\Driver::readExtendedMetadata\(\) \(void\) is used\.$#' excludePaths: diff --git a/rector.php b/rector.php index ebb3971a6a..99d7a5c8b3 100644 --- a/rector.php +++ b/rector.php @@ -10,6 +10,8 @@ */ use Rector\Config\RectorConfig; +use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; +use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; use Rector\ValueObject\PhpVersion; @@ -19,12 +21,17 @@ __DIR__.'/tests', __DIR__.'/example', ]) - ->withPhpVersion(PhpVersion::PHP_74) + ->withPhpVersion(PhpVersion::PHP_81) ->withPhpSets() ->withConfiguredRule(TypedPropertyFromAssignsRector::class, []) ->withSkip([ + ReadOnlyPropertyRector::class => [ + __DIR__.'/tests', // A lot of test fixtures have properties that aren't mutated, don't let Rector try to make them readonly though + ], + ClassPropertyAssignToConstructorPromotionRector::class => [ + __DIR__.'/tests/Gedmo/Wrapper/Fixture/Entity/CompositeRelation.php', // @todo: Remove this when https://github.com/doctrine/orm/issues/8255 is solved + ], TypedPropertyFromAssignsRector::class => [ - __DIR__.'/src/Mapping/MappedEventSubscriber.php', // Rector is trying to set a type on the $annotationReader property which requires a union type, not supported on PHP 7.4 __DIR__.'/tests/Gedmo/Blameable/Fixture/Entity/Company.php', // @todo: Remove this when fixing the configuration for the `Company::$created` property __DIR__.'/tests/Gedmo/Wrapper/Fixture/Entity/CompositeRelation.php', // @todo: Remove this when https://github.com/doctrine/orm/issues/8255 is solved ], diff --git a/src/AbstractTrackingListener.php b/src/AbstractTrackingListener.php index a818601ffc..a0fb730c78 100644 --- a/src/AbstractTrackingListener.php +++ b/src/AbstractTrackingListener.php @@ -82,7 +82,7 @@ public function onFlush(EventArgs $args) // check all scheduled updates $all = array_merge($ea->getScheduledObjectInsertions($uow), $ea->getScheduledObjectUpdates($uow)); foreach ($all as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if (!$config = $this->getConfiguration($om, $meta->getName())) { continue; } @@ -129,7 +129,7 @@ public function onFlush(EventArgs $args) foreach ($trackedFields as $trackedField) { $trackedChild = null; $tracked = null; - $parts = explode('.', $trackedField); + $parts = explode('.', (string) $trackedField); if (isset($parts[1])) { $tracked = $parts[0]; $trackedChild = $parts[1]; @@ -147,7 +147,7 @@ public function onFlush(EventArgs $args) if (!is_object($changingObject)) { throw new UnexpectedValueException("Field - [{$tracked}] is expected to be object in class - {$meta->getName()}"); } - $objectMeta = $om->getClassMetadata(get_class($changingObject)); + $objectMeta = $om->getClassMetadata($changingObject::class); $om->initializeObject($changingObject); $value = $objectMeta->getReflectionProperty($trackedChild)->getValue($changingObject); } else { @@ -185,7 +185,7 @@ public function prePersist(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($config = $this->getConfiguration($om, $meta->getName())) { if (isset($config['update'])) { foreach ($config['update'] as $field) { diff --git a/src/Blameable/Mapping/Driver/Annotation.php b/src/Blameable/Mapping/Driver/Annotation.php index 7dae3a81ca..3b33f1665b 100644 --- a/src/Blameable/Mapping/Driver/Annotation.php +++ b/src/Blameable/Mapping/Driver/Annotation.php @@ -18,6 +18,4 @@ * * @internal */ -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/src/Blameable/Mapping/Event/Adapter/ODM.php b/src/Blameable/Mapping/Event/Adapter/ODM.php index a89e967517..d334c6d9b9 100644 --- a/src/Blameable/Mapping/Event/Adapter/ODM.php +++ b/src/Blameable/Mapping/Event/Adapter/ODM.php @@ -18,6 +18,4 @@ * * @author David Buchmann */ -final class ODM extends BaseAdapterODM implements BlameableAdapter -{ -} +final class ODM extends BaseAdapterODM implements BlameableAdapter {} diff --git a/src/Blameable/Mapping/Event/Adapter/ORM.php b/src/Blameable/Mapping/Event/Adapter/ORM.php index ea836b8bd6..a3d6a8a557 100644 --- a/src/Blameable/Mapping/Event/Adapter/ORM.php +++ b/src/Blameable/Mapping/Event/Adapter/ORM.php @@ -18,6 +18,4 @@ * * @author David Buchmann */ -final class ORM extends BaseAdapterORM implements BlameableAdapter -{ -} +final class ORM extends BaseAdapterORM implements BlameableAdapter {} diff --git a/src/Blameable/Mapping/Event/BlameableAdapter.php b/src/Blameable/Mapping/Event/BlameableAdapter.php index 3c048f6dae..3a1e37e809 100644 --- a/src/Blameable/Mapping/Event/BlameableAdapter.php +++ b/src/Blameable/Mapping/Event/BlameableAdapter.php @@ -16,6 +16,4 @@ * * @author David Buchmann */ -interface BlameableAdapter extends AdapterInterface -{ -} +interface BlameableAdapter extends AdapterInterface {} diff --git a/src/DoctrineExtensions.php b/src/DoctrineExtensions.php index bde3b6b9f2..96bb1e1967 100644 --- a/src/DoctrineExtensions.php +++ b/src/DoctrineExtensions.php @@ -9,15 +9,11 @@ namespace Gedmo; -use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\Annotations\PsrCachedReader; use Doctrine\Common\Annotations\Reader; use Doctrine\Deprecations\Deprecation; use Doctrine\ODM\MongoDB\Mapping\Driver as DriverMongodbODM; use Doctrine\ORM\Mapping\Driver as DriverORM; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; -use Gedmo\Exception\RuntimeException; -use Symfony\Component\Cache\Adapter\ArrayAdapter; /** * Version class allows checking the required dependencies @@ -44,11 +40,7 @@ public static function registerMappingIntoDriverChainORM(MappingDriverChain $dri __DIR__.'/Tree/Entity', ]; - if (\PHP_VERSION_ID >= 80000) { - $driver = new DriverORM\AttributeDriver($paths); - } else { - $driver = new DriverORM\AnnotationDriver($reader ?? self::createAnnotationReader(), $paths); - } + $driver = new DriverORM\AttributeDriver($paths); $driverChain->addDriver($driver, 'Gedmo'); } @@ -65,11 +57,7 @@ public static function registerAbstractMappingIntoDriverChainORM(MappingDriverCh __DIR__.'/Tree/Entity/MappedSuperclass', ]; - if (\PHP_VERSION_ID >= 80000) { - $driver = new DriverORM\AttributeDriver($paths); - } else { - $driver = new DriverORM\AnnotationDriver($reader ?? self::createAnnotationReader(), $paths); - } + $driver = new DriverORM\AttributeDriver($paths); $driverChain->addDriver($driver, 'Gedmo'); } @@ -85,11 +73,7 @@ public static function registerMappingIntoDriverChainMongodbODM(MappingDriverCha __DIR__.'/Loggable/Document', ]; - if (\PHP_VERSION_ID >= 80000) { - $driver = new DriverMongodbODM\AttributeDriver($paths); - } else { - $driver = new DriverMongodbODM\AnnotationDriver($reader ?? self::createAnnotationReader(), $paths); - } + $driver = new DriverMongodbODM\AttributeDriver($paths); $driverChain->addDriver($driver, 'Gedmo'); } @@ -105,11 +89,7 @@ public static function registerAbstractMappingIntoDriverChainMongodbODM(MappingD __DIR__.'/Loggable/Document/MappedSuperclass', ]; - if (\PHP_VERSION_ID >= 80000) { - $driver = new DriverMongodbODM\AttributeDriver($paths); - } else { - $driver = new DriverMongodbODM\AnnotationDriver($reader ?? self::createAnnotationReader(), $paths); - } + $driver = new DriverMongodbODM\AttributeDriver($paths); $driverChain->addDriver($driver, 'Gedmo'); } @@ -130,16 +110,4 @@ public static function registerAnnotations(): void // Purposefully no-op'd, all supported versions of `doctrine/annotations` support autoloading } - - /** - * @throws RuntimeException if running PHP 7 and the `doctrine/annotations` package is not installed - */ - private static function createAnnotationReader(): PsrCachedReader - { - if (!class_exists(AnnotationReader::class)) { - throw new RuntimeException(sprintf('The "%1$s" class requires the "doctrine/annotations" package to use annotations but it is not available. Try running "composer require doctrine/annotations" or upgrade to PHP 8 to use attributes.', self::class)); - } - - return new PsrCachedReader(new AnnotationReader(), new ArrayAdapter()); - } } diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php index 6ce3e3478b..c52c042497 100644 --- a/src/Exception/BadMethodCallException.php +++ b/src/Exception/BadMethodCallException.php @@ -18,6 +18,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class BadMethodCallException extends \BadMethodCallException implements Exception -{ -} +class BadMethodCallException extends \BadMethodCallException implements Exception {} diff --git a/src/Exception/FeatureNotImplementedException.php b/src/Exception/FeatureNotImplementedException.php index 8d5296bdc7..0a0612bcdf 100644 --- a/src/Exception/FeatureNotImplementedException.php +++ b/src/Exception/FeatureNotImplementedException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class FeatureNotImplementedException extends \RuntimeException implements Exception -{ -} +class FeatureNotImplementedException extends \RuntimeException implements Exception {} diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 5a74245e69..5451be2b0c 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -16,6 +16,4 @@ * * @author Gediminas Morkevicius */ -class InvalidArgumentException extends \InvalidArgumentException implements Exception -{ -} +class InvalidArgumentException extends \InvalidArgumentException implements Exception {} diff --git a/src/Exception/InvalidMappingException.php b/src/Exception/InvalidMappingException.php index 0df59a1765..c2525fdb1b 100644 --- a/src/Exception/InvalidMappingException.php +++ b/src/Exception/InvalidMappingException.php @@ -21,6 +21,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class InvalidMappingException extends InvalidArgumentException implements Exception -{ -} +class InvalidMappingException extends InvalidArgumentException implements Exception {} diff --git a/src/Exception/ReferenceIntegrityStrictException.php b/src/Exception/ReferenceIntegrityStrictException.php index 53c0d09522..bbe44aada6 100644 --- a/src/Exception/ReferenceIntegrityStrictException.php +++ b/src/Exception/ReferenceIntegrityStrictException.php @@ -16,6 +16,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class ReferenceIntegrityStrictException extends RuntimeException -{ -} +class ReferenceIntegrityStrictException extends RuntimeException {} diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index dcb860ed65..095f49700f 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -16,6 +16,4 @@ * * @author Gediminas Morkevicius */ -class RuntimeException extends \RuntimeException implements Exception -{ -} +class RuntimeException extends \RuntimeException implements Exception {} diff --git a/src/Exception/TreeLockingException.php b/src/Exception/TreeLockingException.php index 2a7aa417c7..42300f79bd 100644 --- a/src/Exception/TreeLockingException.php +++ b/src/Exception/TreeLockingException.php @@ -17,6 +17,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class TreeLockingException extends RuntimeException -{ -} +class TreeLockingException extends RuntimeException {} diff --git a/src/Exception/UnexpectedValueException.php b/src/Exception/UnexpectedValueException.php index 9d1fc344cf..a5f056720b 100644 --- a/src/Exception/UnexpectedValueException.php +++ b/src/Exception/UnexpectedValueException.php @@ -18,6 +18,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UnexpectedValueException extends \UnexpectedValueException implements Exception -{ -} +class UnexpectedValueException extends \UnexpectedValueException implements Exception {} diff --git a/src/Exception/UnsupportedObjectManagerException.php b/src/Exception/UnsupportedObjectManagerException.php index e35e8b2221..98edfc58a4 100644 --- a/src/Exception/UnsupportedObjectManagerException.php +++ b/src/Exception/UnsupportedObjectManagerException.php @@ -18,6 +18,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UnsupportedObjectManagerException extends InvalidArgumentException implements Exception -{ -} +class UnsupportedObjectManagerException extends InvalidArgumentException implements Exception {} diff --git a/src/Exception/UploadableCantWriteException.php b/src/Exception/UploadableCantWriteException.php index 032a912379..cd3635dd17 100644 --- a/src/Exception/UploadableCantWriteException.php +++ b/src/Exception/UploadableCantWriteException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableCantWriteException extends UploadableException implements Exception -{ -} +class UploadableCantWriteException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableCouldntGuessMimeTypeException.php b/src/Exception/UploadableCouldntGuessMimeTypeException.php index 59b7988791..282cef15be 100644 --- a/src/Exception/UploadableCouldntGuessMimeTypeException.php +++ b/src/Exception/UploadableCouldntGuessMimeTypeException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableCouldntGuessMimeTypeException extends UploadableException implements Exception -{ -} +class UploadableCouldntGuessMimeTypeException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableDirectoryNotFoundException.php b/src/Exception/UploadableDirectoryNotFoundException.php index c4208b8e37..5c784a23f0 100644 --- a/src/Exception/UploadableDirectoryNotFoundException.php +++ b/src/Exception/UploadableDirectoryNotFoundException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableDirectoryNotFoundException extends UploadableException implements Exception -{ -} +class UploadableDirectoryNotFoundException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableException.php b/src/Exception/UploadableException.php index 11a450ede2..a76a660e12 100644 --- a/src/Exception/UploadableException.php +++ b/src/Exception/UploadableException.php @@ -17,6 +17,4 @@ * @author Gustavo Falco * @author Gediminas Morkevicius */ -class UploadableException extends RuntimeException implements Exception -{ -} +class UploadableException extends RuntimeException implements Exception {} diff --git a/src/Exception/UploadableExtensionException.php b/src/Exception/UploadableExtensionException.php index 1e365fb1e9..792e769a85 100644 --- a/src/Exception/UploadableExtensionException.php +++ b/src/Exception/UploadableExtensionException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableExtensionException extends UploadableException implements Exception -{ -} +class UploadableExtensionException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableFileAlreadyExistsException.php b/src/Exception/UploadableFileAlreadyExistsException.php index 36f6eb8f8d..d2a26a4341 100644 --- a/src/Exception/UploadableFileAlreadyExistsException.php +++ b/src/Exception/UploadableFileAlreadyExistsException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableFileAlreadyExistsException extends UploadableException implements Exception -{ -} +class UploadableFileAlreadyExistsException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableFileNotReadableException.php b/src/Exception/UploadableFileNotReadableException.php index 9bede35e0b..d9bed4ae1d 100644 --- a/src/Exception/UploadableFileNotReadableException.php +++ b/src/Exception/UploadableFileNotReadableException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableFileNotReadableException extends UploadableException implements Exception -{ -} +class UploadableFileNotReadableException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableFormSizeException.php b/src/Exception/UploadableFormSizeException.php index 71ddc48099..d24e2f1046 100644 --- a/src/Exception/UploadableFormSizeException.php +++ b/src/Exception/UploadableFormSizeException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableFormSizeException extends UploadableException implements Exception -{ -} +class UploadableFormSizeException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableIniSizeException.php b/src/Exception/UploadableIniSizeException.php index 14300d0a68..7a98b6df89 100644 --- a/src/Exception/UploadableIniSizeException.php +++ b/src/Exception/UploadableIniSizeException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableIniSizeException extends UploadableException implements Exception -{ -} +class UploadableIniSizeException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableInvalidFileException.php b/src/Exception/UploadableInvalidFileException.php index c36edf128a..8f03a52e58 100644 --- a/src/Exception/UploadableInvalidFileException.php +++ b/src/Exception/UploadableInvalidFileException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableInvalidFileException extends UploadableException implements Exception -{ -} +class UploadableInvalidFileException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableInvalidMimeTypeException.php b/src/Exception/UploadableInvalidMimeTypeException.php index d90aca708d..43755f57ac 100644 --- a/src/Exception/UploadableInvalidMimeTypeException.php +++ b/src/Exception/UploadableInvalidMimeTypeException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableInvalidMimeTypeException extends UploadableException implements Exception -{ -} +class UploadableInvalidMimeTypeException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableInvalidPathException.php b/src/Exception/UploadableInvalidPathException.php index c767d2a595..3e7e49e185 100644 --- a/src/Exception/UploadableInvalidPathException.php +++ b/src/Exception/UploadableInvalidPathException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableInvalidPathException extends UploadableException implements Exception -{ -} +class UploadableInvalidPathException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableMaxSizeException.php b/src/Exception/UploadableMaxSizeException.php index 3b3e68be92..48a5d1f40c 100644 --- a/src/Exception/UploadableMaxSizeException.php +++ b/src/Exception/UploadableMaxSizeException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableMaxSizeException extends UploadableException implements Exception -{ -} +class UploadableMaxSizeException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableNoFileException.php b/src/Exception/UploadableNoFileException.php index 2ca3fae1d0..0aa9b3fdbe 100644 --- a/src/Exception/UploadableNoFileException.php +++ b/src/Exception/UploadableNoFileException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableNoFileException extends UploadableException implements Exception -{ -} +class UploadableNoFileException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableNoPathDefinedException.php b/src/Exception/UploadableNoPathDefinedException.php index 51db45ea92..6f197a06b0 100644 --- a/src/Exception/UploadableNoPathDefinedException.php +++ b/src/Exception/UploadableNoPathDefinedException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableNoPathDefinedException extends UploadableException implements Exception -{ -} +class UploadableNoPathDefinedException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableNoTmpDirException.php b/src/Exception/UploadableNoTmpDirException.php index b21303a630..8c3a560b9f 100644 --- a/src/Exception/UploadableNoTmpDirException.php +++ b/src/Exception/UploadableNoTmpDirException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableNoTmpDirException extends UploadableException implements Exception -{ -} +class UploadableNoTmpDirException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadablePartialException.php b/src/Exception/UploadablePartialException.php index 5b2974e5ac..6d4e4d745b 100644 --- a/src/Exception/UploadablePartialException.php +++ b/src/Exception/UploadablePartialException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadablePartialException extends UploadableException implements Exception -{ -} +class UploadablePartialException extends UploadableException implements Exception {} diff --git a/src/Exception/UploadableUploadException.php b/src/Exception/UploadableUploadException.php index 9ccf4f967c..b42f5ba5a4 100644 --- a/src/Exception/UploadableUploadException.php +++ b/src/Exception/UploadableUploadException.php @@ -19,6 +19,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadableUploadException extends UploadableException implements Exception -{ -} +class UploadableUploadException extends UploadableException implements Exception {} diff --git a/src/IpTraceable/Mapping/Driver/Annotation.php b/src/IpTraceable/Mapping/Driver/Annotation.php index 03d7537db1..55741fdfe4 100644 --- a/src/IpTraceable/Mapping/Driver/Annotation.php +++ b/src/IpTraceable/Mapping/Driver/Annotation.php @@ -18,6 +18,4 @@ * * @internal */ -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/src/IpTraceable/Mapping/Event/Adapter/ODM.php b/src/IpTraceable/Mapping/Event/Adapter/ODM.php index 5520865903..f36ebd102a 100644 --- a/src/IpTraceable/Mapping/Event/Adapter/ODM.php +++ b/src/IpTraceable/Mapping/Event/Adapter/ODM.php @@ -18,6 +18,4 @@ * * @author Pierre-Charles Bertineau */ -final class ODM extends BaseAdapterODM implements IpTraceableAdapter -{ -} +final class ODM extends BaseAdapterODM implements IpTraceableAdapter {} diff --git a/src/IpTraceable/Mapping/Event/Adapter/ORM.php b/src/IpTraceable/Mapping/Event/Adapter/ORM.php index 0e22a45376..fce7f55e4e 100644 --- a/src/IpTraceable/Mapping/Event/Adapter/ORM.php +++ b/src/IpTraceable/Mapping/Event/Adapter/ORM.php @@ -18,6 +18,4 @@ * * @author Pierre-Charles Bertineau */ -final class ORM extends BaseAdapterORM implements IpTraceableAdapter -{ -} +final class ORM extends BaseAdapterORM implements IpTraceableAdapter {} diff --git a/src/IpTraceable/Mapping/Event/IpTraceableAdapter.php b/src/IpTraceable/Mapping/Event/IpTraceableAdapter.php index 7a93a501d4..1f8c53fc91 100644 --- a/src/IpTraceable/Mapping/Event/IpTraceableAdapter.php +++ b/src/IpTraceable/Mapping/Event/IpTraceableAdapter.php @@ -16,6 +16,4 @@ * * @author Pierre-Charles Bertineau */ -interface IpTraceableAdapter extends AdapterInterface -{ -} +interface IpTraceableAdapter extends AdapterInterface {} diff --git a/src/Loggable/LoggableListener.php b/src/Loggable/LoggableListener.php index 7fd66df1eb..23916491d7 100644 --- a/src/Loggable/LoggableListener.php +++ b/src/Loggable/LoggableListener.php @@ -170,7 +170,7 @@ public function postPersist(EventArgs $args) $wrapped = AbstractWrapper::wrap($object, $om); $logEntry = $this->pendingLogEntryInserts[$oid]; - $logEntryMeta = $om->getClassMetadata(get_class($logEntry)); + $logEntryMeta = $om->getClassMetadata($logEntry::class); $id = $wrapped->getIdentifier(false, true); $logEntryMeta->getReflectionProperty('objectId')->setValue($logEntry, $id); @@ -185,7 +185,7 @@ public function postPersist(EventArgs $args) $identifiers = $wrapped->getIdentifier(false); foreach ($this->pendingRelatedObjects[$oid] as $props) { $logEntry = $props['log']; - $logEntryMeta = $om->getClassMetadata(get_class($logEntry)); + $logEntryMeta = $om->getClassMetadata($logEntry::class); $oldData = $data = $logEntry->getData(); $data[$props['field']] = $identifiers; @@ -272,7 +272,7 @@ protected function getUsername(): ?string return $actor->__toString(); } - throw new UnexpectedValueException(\sprintf('The loggable extension requires the actor provider to return a string or an object implementing the "getUserIdentifier()", "getUsername()", or "__toString()" methods. "%s" cannot be used as an actor.', get_class($actor))); + throw new UnexpectedValueException(\sprintf('The loggable extension requires the actor provider to return a string or an object implementing the "getUserIdentifier()", "getUsername()", or "__toString()" methods. "%s" cannot be used as an actor.', $actor::class)); } return $this->username; @@ -290,9 +290,7 @@ protected function getUsername(): ?string * * @return void */ - protected function prePersistLogEntry($logEntry, $object) - { - } + protected function prePersistLogEntry($logEntry, $object) {} protected function getNamespace() { diff --git a/src/Loggable/Mapping/Driver/Annotation.php b/src/Loggable/Mapping/Driver/Annotation.php index 45f895952a..4259ac719b 100644 --- a/src/Loggable/Mapping/Driver/Annotation.php +++ b/src/Loggable/Mapping/Driver/Annotation.php @@ -18,6 +18,4 @@ * * @internal */ -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/src/Loggable/Mapping/Event/Adapter/ODM.php b/src/Loggable/Mapping/Event/Adapter/ODM.php index d193949591..39e2e5b2e3 100644 --- a/src/Loggable/Mapping/Event/Adapter/ODM.php +++ b/src/Loggable/Mapping/Event/Adapter/ODM.php @@ -41,7 +41,7 @@ public function isPostInsertGenerator($meta) public function getNewVersion($meta, $object) { $dm = $this->getObjectManager(); - $objectMeta = $dm->getClassMetadata(get_class($object)); + $objectMeta = $dm->getClassMetadata($object::class); $identifierField = $this->getSingleIdentifierFieldName($objectMeta); $objectId = $objectMeta->getReflectionProperty($identifierField)->getValue($object); diff --git a/src/Loggable/Mapping/Event/Adapter/ORM.php b/src/Loggable/Mapping/Event/Adapter/ORM.php index 83fcac8ad4..38ab7a2184 100644 --- a/src/Loggable/Mapping/Event/Adapter/ORM.php +++ b/src/Loggable/Mapping/Event/Adapter/ORM.php @@ -42,7 +42,7 @@ public function isPostInsertGenerator($meta) public function getNewVersion($meta, $object) { $em = $this->getObjectManager(); - $objectMeta = $em->getClassMetadata(get_class($object)); + $objectMeta = $em->getClassMetadata($object::class); $wrapper = new EntityWrapper($object, $em); $objectId = $wrapper->getIdentifier(false, true); diff --git a/src/Mapping/Annotation/Annotation.php b/src/Mapping/Annotation/Annotation.php index 85a5f412e8..49585a6490 100644 --- a/src/Mapping/Annotation/Annotation.php +++ b/src/Mapping/Annotation/Annotation.php @@ -14,6 +14,4 @@ /** * @internal */ -interface Annotation -{ -} +interface Annotation {} diff --git a/src/Mapping/Annotation/ForwardCompatibilityTrait.php b/src/Mapping/Annotation/ForwardCompatibilityTrait.php index 7fff690273..ad565f597d 100644 --- a/src/Mapping/Annotation/ForwardCompatibilityTrait.php +++ b/src/Mapping/Annotation/ForwardCompatibilityTrait.php @@ -21,11 +21,8 @@ trait ForwardCompatibilityTrait /** * @param array $data * @param array $args - * @param mixed $value - * - * @return mixed */ - private function getAttributeValue(array $data, string $attributeName, array $args, int $argumentNum, $value) + private function getAttributeValue(array $data, string $attributeName, array $args, int $argumentNum, mixed $value): mixed { if (array_key_exists($argumentNum, $args)) { return $args[$argumentNum]; diff --git a/src/Mapping/Annotation/Language.php b/src/Mapping/Annotation/Language.php index 019f3d7543..7e1ff62d13 100644 --- a/src/Mapping/Annotation/Language.php +++ b/src/Mapping/Annotation/Language.php @@ -22,6 +22,4 @@ * @author Gediminas Morkevicius */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class Language implements GedmoAnnotation -{ -} +final class Language implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/Locale.php b/src/Mapping/Annotation/Locale.php index 7a18317eca..07a042356c 100644 --- a/src/Mapping/Annotation/Locale.php +++ b/src/Mapping/Annotation/Locale.php @@ -22,6 +22,4 @@ * @author Gediminas Morkevicius */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class Locale implements GedmoAnnotation -{ -} +final class Locale implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/ReferenceMany.php b/src/Mapping/Annotation/ReferenceMany.php index 55dd82eecf..d8cd7448a3 100644 --- a/src/Mapping/Annotation/ReferenceMany.php +++ b/src/Mapping/Annotation/ReferenceMany.php @@ -22,6 +22,4 @@ * @final since gedmo/doctrine-extensions 3.11 */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -class ReferenceMany extends Reference -{ -} +class ReferenceMany extends Reference {} diff --git a/src/Mapping/Annotation/ReferenceManyEmbed.php b/src/Mapping/Annotation/ReferenceManyEmbed.php index 211a7611be..a7617fff66 100644 --- a/src/Mapping/Annotation/ReferenceManyEmbed.php +++ b/src/Mapping/Annotation/ReferenceManyEmbed.php @@ -17,6 +17,4 @@ * @final since gedmo/doctrine-extensions 3.11 */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -class ReferenceManyEmbed extends Reference -{ -} +class ReferenceManyEmbed extends Reference {} diff --git a/src/Mapping/Annotation/ReferenceOne.php b/src/Mapping/Annotation/ReferenceOne.php index 1eb98bea1b..c8a9f2a0fb 100644 --- a/src/Mapping/Annotation/ReferenceOne.php +++ b/src/Mapping/Annotation/ReferenceOne.php @@ -22,6 +22,4 @@ * @final since gedmo/doctrine-extensions 3.11 */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -class ReferenceOne extends Reference -{ -} +class ReferenceOne extends Reference {} diff --git a/src/Mapping/Annotation/SortableGroup.php b/src/Mapping/Annotation/SortableGroup.php index bb96846f0b..6e0741927c 100644 --- a/src/Mapping/Annotation/SortableGroup.php +++ b/src/Mapping/Annotation/SortableGroup.php @@ -22,6 +22,4 @@ * @Target("PROPERTY") */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class SortableGroup implements GedmoAnnotation -{ -} +final class SortableGroup implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/SortablePosition.php b/src/Mapping/Annotation/SortablePosition.php index 44ca9ec41a..1523767ccb 100644 --- a/src/Mapping/Annotation/SortablePosition.php +++ b/src/Mapping/Annotation/SortablePosition.php @@ -22,6 +22,4 @@ * @Target("PROPERTY") */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class SortablePosition implements GedmoAnnotation -{ -} +final class SortablePosition implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/TreeLeft.php b/src/Mapping/Annotation/TreeLeft.php index ac3d0ede57..630cc7f9bc 100644 --- a/src/Mapping/Annotation/TreeLeft.php +++ b/src/Mapping/Annotation/TreeLeft.php @@ -22,6 +22,4 @@ * @author Gediminas Morkevicius */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class TreeLeft implements GedmoAnnotation -{ -} +final class TreeLeft implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/TreeLockTime.php b/src/Mapping/Annotation/TreeLockTime.php index 13e56d93ba..845ff1cdb1 100644 --- a/src/Mapping/Annotation/TreeLockTime.php +++ b/src/Mapping/Annotation/TreeLockTime.php @@ -23,6 +23,4 @@ * @author Gediminas Morkevicius */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class TreeLockTime implements GedmoAnnotation -{ -} +final class TreeLockTime implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/TreeParent.php b/src/Mapping/Annotation/TreeParent.php index 9a84bc8e57..001568824d 100644 --- a/src/Mapping/Annotation/TreeParent.php +++ b/src/Mapping/Annotation/TreeParent.php @@ -22,6 +22,4 @@ * @author Gediminas Morkevicius */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class TreeParent implements GedmoAnnotation -{ -} +final class TreeParent implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/TreePathHash.php b/src/Mapping/Annotation/TreePathHash.php index 9a1545d843..c7f1d485b5 100644 --- a/src/Mapping/Annotation/TreePathHash.php +++ b/src/Mapping/Annotation/TreePathHash.php @@ -22,6 +22,4 @@ * @author */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class TreePathHash implements GedmoAnnotation -{ -} +final class TreePathHash implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/TreePathSource.php b/src/Mapping/Annotation/TreePathSource.php index 5fa6ce5656..535892c067 100644 --- a/src/Mapping/Annotation/TreePathSource.php +++ b/src/Mapping/Annotation/TreePathSource.php @@ -23,6 +23,4 @@ * @author Gediminas Morkevicius */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class TreePathSource implements GedmoAnnotation -{ -} +final class TreePathSource implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/TreeRight.php b/src/Mapping/Annotation/TreeRight.php index 727cf508f1..462a89e971 100644 --- a/src/Mapping/Annotation/TreeRight.php +++ b/src/Mapping/Annotation/TreeRight.php @@ -22,6 +22,4 @@ * @author Gediminas Morkevicius */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class TreeRight implements GedmoAnnotation -{ -} +final class TreeRight implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/UploadableFileMimeType.php b/src/Mapping/Annotation/UploadableFileMimeType.php index aac630ff66..5592f0da7d 100644 --- a/src/Mapping/Annotation/UploadableFileMimeType.php +++ b/src/Mapping/Annotation/UploadableFileMimeType.php @@ -23,6 +23,4 @@ * @author Gediminas Morkevicius */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class UploadableFileMimeType implements GedmoAnnotation -{ -} +final class UploadableFileMimeType implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/UploadableFileName.php b/src/Mapping/Annotation/UploadableFileName.php index 0c5e10d94c..0c900d2a14 100644 --- a/src/Mapping/Annotation/UploadableFileName.php +++ b/src/Mapping/Annotation/UploadableFileName.php @@ -22,6 +22,4 @@ * @author tiger-seo */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class UploadableFileName implements GedmoAnnotation -{ -} +final class UploadableFileName implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/UploadableFilePath.php b/src/Mapping/Annotation/UploadableFilePath.php index 8ec5f2e0af..0e6ed98e9f 100644 --- a/src/Mapping/Annotation/UploadableFilePath.php +++ b/src/Mapping/Annotation/UploadableFilePath.php @@ -23,6 +23,4 @@ * @author Gediminas Morkevicius */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class UploadableFilePath implements GedmoAnnotation -{ -} +final class UploadableFilePath implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/UploadableFileSize.php b/src/Mapping/Annotation/UploadableFileSize.php index a0715bd78e..b4a3f59157 100644 --- a/src/Mapping/Annotation/UploadableFileSize.php +++ b/src/Mapping/Annotation/UploadableFileSize.php @@ -23,6 +23,4 @@ * @author Gediminas Morkevicius */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class UploadableFileSize implements GedmoAnnotation -{ -} +final class UploadableFileSize implements GedmoAnnotation {} diff --git a/src/Mapping/Annotation/Versioned.php b/src/Mapping/Annotation/Versioned.php index db99b7bc07..3df34abbee 100644 --- a/src/Mapping/Annotation/Versioned.php +++ b/src/Mapping/Annotation/Versioned.php @@ -24,6 +24,4 @@ * @author Gediminas Morkevicius */ #[\Attribute(\Attribute::TARGET_PROPERTY)] -final class Versioned implements GedmoAnnotation -{ -} +final class Versioned implements GedmoAnnotation {} diff --git a/src/Mapping/Driver/AbstractAnnotationDriver.php b/src/Mapping/Driver/AbstractAnnotationDriver.php index 2a6badb4b1..8a1ee8fd24 100644 --- a/src/Mapping/Driver/AbstractAnnotationDriver.php +++ b/src/Mapping/Driver/AbstractAnnotationDriver.php @@ -114,9 +114,7 @@ public function getMetaReflectionClass($meta) * * @return void */ - public function validateFullMetadata(ClassMetadata $meta, array $config) - { - } + public function validateFullMetadata(ClassMetadata $meta, array $config) {} /** * Checks if $field type is valid diff --git a/src/Mapping/Driver/AnnotationDriverInterface.php b/src/Mapping/Driver/AnnotationDriverInterface.php index f9ead4c668..ad2412cd35 100644 --- a/src/Mapping/Driver/AnnotationDriverInterface.php +++ b/src/Mapping/Driver/AnnotationDriverInterface.php @@ -17,6 +17,4 @@ * * @deprecated since gedmo/doctrine-extensions 3.16, will be removed in version 4.0. */ -interface AnnotationDriverInterface extends AttributeDriverInterface -{ -} +interface AnnotationDriverInterface extends AttributeDriverInterface {} diff --git a/src/Mapping/Driver/AttributeAnnotationReader.php b/src/Mapping/Driver/AttributeAnnotationReader.php index ec0a70590d..ae0c302087 100644 --- a/src/Mapping/Driver/AttributeAnnotationReader.php +++ b/src/Mapping/Driver/AttributeAnnotationReader.php @@ -23,15 +23,10 @@ */ final class AttributeAnnotationReader implements Reader { - private Reader $annotationReader; - - private AttributeReader $attributeReader; - - public function __construct(AttributeReader $attributeReader, Reader $annotationReader) - { - $this->attributeReader = $attributeReader; - $this->annotationReader = $annotationReader; - } + public function __construct( + private readonly AttributeReader $attributeReader, + private readonly Reader $annotationReader, + ) {} /** * @phpstan-param \ReflectionClass $class diff --git a/src/Mapping/Driver/Chain.php b/src/Mapping/Driver/Chain.php index 65d60bec26..ab7953ac20 100644 --- a/src/Mapping/Driver/Chain.php +++ b/src/Mapping/Driver/Chain.php @@ -78,7 +78,7 @@ public function setDefaultDriver(Driver $driver) public function readExtendedMetadata($meta, array &$config) { foreach ($this->_drivers as $namespace => $driver) { - if (0 === strpos($meta->getName(), $namespace)) { + if (str_starts_with($meta->getName(), $namespace)) { $extendedMetadata = $driver->readExtendedMetadata($meta, $config); if (\is_array($extendedMetadata)) { diff --git a/src/Mapping/Event/Adapter/ORM.php b/src/Mapping/Event/Adapter/ORM.php index bca7cbade6..0d30c8e66a 100644 --- a/src/Mapping/Event/Adapter/ORM.php +++ b/src/Mapping/Event/Adapter/ORM.php @@ -105,7 +105,7 @@ public function getObjectManager() 'Calling "%s()" on event args of class "%s" that does not implement "getObjectManager()" is deprecated since gedmo/doctrine-extensions 3.14' .' and will throw a "%s" error in version 4.0.', __METHOD__, - get_class($this->args), + $this->args::class, \Error::class ); @@ -131,7 +131,7 @@ public function getObject(): object 'Calling "%s()" on event args of class "%s" that does not imeplement "getObject()" is deprecated since gedmo/doctrine-extensions 3.14' .' and will throw a "%s" error in version 4.0.', __METHOD__, - get_class($this->args), + $this->args::class, \Error::class ); diff --git a/src/Mapping/ExtensionMetadataFactory.php b/src/Mapping/ExtensionMetadataFactory.php index 16d321cc3f..dcb085f64f 100644 --- a/src/Mapping/ExtensionMetadataFactory.php +++ b/src/Mapping/ExtensionMetadataFactory.php @@ -68,15 +68,17 @@ class ExtensionMetadataFactory */ protected $annotationReader; - private ?CacheItemPoolInterface $cacheItemPool = null; - /** * @param Reader|AttributeReader|object|null $annotationReader * * @note Providing any object as the third argument is deprecated, as of 4.0 an {@see AttributeReader} will be required */ - public function __construct(ObjectManager $objectManager, string $extensionNamespace, ?object $annotationReader = null, ?CacheItemPoolInterface $cacheItemPool = null) - { + public function __construct( + ObjectManager $objectManager, + string $extensionNamespace, + ?object $annotationReader = null, + private readonly ?CacheItemPoolInterface $cacheItemPool = null + ) { if (null !== $annotationReader) { if ($annotationReader instanceof Reader) { Deprecation::trigger( @@ -103,7 +105,6 @@ public function __construct(ObjectManager $objectManager, string $extensionNames $this->extensionNamespace = $extensionNamespace; $omDriver = $objectManager->getConfiguration()->getMetadataDriverImpl(); $this->driver = $this->getDriver($omDriver); - $this->cacheItemPool = $cacheItemPool; } /** @@ -201,7 +202,7 @@ protected function getDriver($omDriver) } $driver = null; - $className = get_class($omDriver); + $className = $omDriver::class; $driverName = substr($className, strrpos($className, '\\') + 1); if ($omDriver instanceof MappingDriverChain || 'DriverChain' === $driverName) { $driver = new Chain(); @@ -214,7 +215,7 @@ protected function getDriver($omDriver) } else { $driverName = substr($driverName, 0, strpos($driverName, 'Driver')); $isSimplified = false; - if ('Simplified' === substr($driverName, 0, 10)) { + if (str_starts_with($driverName, 'Simplified')) { // support for simplified file drivers $driverName = substr($driverName, 10); $isSimplified = true; @@ -227,7 +228,7 @@ protected function getDriver($omDriver) // try to fall back to either an annotation or attribute driver depending on the available dependencies if (interface_exists(Reader::class)) { $driverClassName = $this->extensionNamespace.'\Mapping\Driver\Annotation'; - } elseif (\PHP_VERSION_ID >= 80000) { + } else { $driverClassName = $this->extensionNamespace.'\Mapping\Driver\Attribute'; } diff --git a/src/Mapping/MappedEventSubscriber.php b/src/Mapping/MappedEventSubscriber.php index d5b87c5388..2641ca5672 100644 --- a/src/Mapping/MappedEventSubscriber.php +++ b/src/Mapping/MappedEventSubscriber.php @@ -83,19 +83,13 @@ abstract class MappedEventSubscriber implements EventSubscriber /** * Custom annotation reader * - * @var Reader|AttributeReader|object|false|null + * @var Reader|AttributeReader|object|false */ - private $annotationReader = false; + private object|false $annotationReader = false; - /** - * @var Reader|AttributeReader|false|null - */ - private static $defaultAnnotationReader = false; + private static Reader|AttributeReader|false $defaultAnnotationReader = false; - /** - * @var CacheItemPoolInterface|null - */ - private $cacheItemPool; + private ?CacheItemPoolInterface $cacheItemPool = null; private ?ClockInterface $clock = null; @@ -240,7 +234,7 @@ public function loadMetadataForObjectClass(ObjectManager $objectManager, $metada try { $config = $factory->getExtensionMetadata($metadata); - } catch (\ReflectionException $e) { + } catch (\ReflectionException) { // entity\document generator is running $config = []; // will not store a cached version, to remap later } @@ -261,7 +255,7 @@ public function loadMetadataForObjectClass(ObjectManager $objectManager, $metada */ protected function getEventAdapter(EventArgs $args) { - $class = get_class($args); + $class = $args::class; if (preg_match('@Doctrine\\\([^\\\]+)@', $class, $m) && in_array($m[1], ['ODM', 'ORM'], true)) { if (!isset($this->adapters[$m[1]])) { $adapterClass = $this->getNamespace().'\\Mapping\\Event\\Adapter\\'.$m[1]; @@ -304,7 +298,7 @@ abstract protected function getNamespace(); protected function setFieldValue(AdapterInterface $adapter, $object, $field, $oldValue, $newValue) { $manager = $adapter->getObjectManager(); - $meta = $manager->getClassMetadata(get_class($object)); + $meta = $manager->getClassMetadata($object::class); $uow = $manager->getUnitOfWork(); $meta->getReflectionProperty($field)->setValue($object, $newValue); @@ -317,18 +311,14 @@ protected function setFieldValue(AdapterInterface $adapter, $object, $field, $ol * * If a reader cannot be created due to missing requirements, no default will be set as the reader is only required for annotation or attribute metadata, * and the {@see ExtensionMetadataFactory} can handle raising an error if it tries to create a mapping driver that requires this reader. - * - * @return Reader|AttributeReader|null */ - private function getDefaultAnnotationReader() + private function getDefaultAnnotationReader(): Reader|AttributeReader { if (false === self::$defaultAnnotationReader) { if (class_exists(PsrCachedReader::class)) { self::$defaultAnnotationReader = new PsrCachedReader(new AnnotationReader(), new ArrayAdapter()); - } elseif (\PHP_VERSION_ID >= 80000) { - self::$defaultAnnotationReader = new AttributeReader(); } else { - self::$defaultAnnotationReader = null; + self::$defaultAnnotationReader = new AttributeReader(); } } @@ -347,7 +337,7 @@ private function getCacheItemPool(ObjectManager $objectManager): CacheItemPoolIn if ($objectManager instanceof EntityManagerInterface || $objectManager instanceof DocumentManager) { $metadataFactory = $objectManager->getMetadataFactory(); - $getCache = \Closure::bind(static fn (AbstractClassMetadataFactory $metadataFactory): ?CacheItemPoolInterface => $metadataFactory->getCache(), null, \get_class($metadataFactory)); + $getCache = \Closure::bind(static fn (AbstractClassMetadataFactory $metadataFactory): ?CacheItemPoolInterface => $metadataFactory->getCache(), null, $metadataFactory::class); $metadataCache = $getCache($metadataFactory); diff --git a/src/ReferenceIntegrity/Mapping/Driver/Annotation.php b/src/ReferenceIntegrity/Mapping/Driver/Annotation.php index 7637215bb9..bcb4e00e3a 100644 --- a/src/ReferenceIntegrity/Mapping/Driver/Annotation.php +++ b/src/ReferenceIntegrity/Mapping/Driver/Annotation.php @@ -18,6 +18,4 @@ * * @internal */ -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/src/ReferenceIntegrity/ReferenceIntegrityListener.php b/src/ReferenceIntegrity/ReferenceIntegrityListener.php index c6113ee60d..3c9df0ca74 100644 --- a/src/ReferenceIntegrity/ReferenceIntegrityListener.php +++ b/src/ReferenceIntegrity/ReferenceIntegrityListener.php @@ -71,7 +71,7 @@ public function preRemove(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $class = get_class($object); + $class = $object::class; $meta = $om->getClassMetadata($class); if ($config = $this->getConfiguration($om, $meta->getName())) { diff --git a/src/References/Mapping/Driver/Annotation.php b/src/References/Mapping/Driver/Annotation.php index 3382d254e8..7b7c7fca6a 100644 --- a/src/References/Mapping/Driver/Annotation.php +++ b/src/References/Mapping/Driver/Annotation.php @@ -18,6 +18,4 @@ * * @internal */ -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/src/References/Mapping/Event/Adapter/ODM.php b/src/References/Mapping/Event/Adapter/ODM.php index b302171467..286f7e8cf6 100644 --- a/src/References/Mapping/Event/Adapter/ODM.php +++ b/src/References/Mapping/Event/Adapter/ODM.php @@ -35,7 +35,7 @@ public function getIdentifier($om, $object, $single = true) if ($object instanceof PersistenceProxy) { $id = $om->getUnitOfWork()->getEntityIdentifier($object); } else { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $id = []; foreach ($meta->getIdentifier() as $name) { $id[$name] = $meta->getReflectionProperty($name)->getValue($object); @@ -69,7 +69,7 @@ public function getSingleReference($om, $class, $identifier) public function extractIdentifier($om, $object, $single = true) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($object instanceof GhostObjectInterface) { $id = $om->getUnitOfWork()->getDocumentIdentifier($object); } else { diff --git a/src/References/Mapping/Event/Adapter/ORM.php b/src/References/Mapping/Event/Adapter/ORM.php index 1f116c122a..9869c8c47c 100644 --- a/src/References/Mapping/Event/Adapter/ORM.php +++ b/src/References/Mapping/Event/Adapter/ORM.php @@ -34,7 +34,7 @@ public function getIdentifier($om, $object, $single = true) } if ($om instanceof MongoDocumentManager) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($object instanceof GhostObjectInterface) { $id = $om->getUnitOfWork()->getDocumentIdentifier($object); } else { @@ -49,7 +49,7 @@ public function getIdentifier($om, $object, $single = true) } if ($om instanceof PhpcrDocumentManager) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); assert(1 === count($meta->getIdentifier())); $id = $meta->getReflectionProperty($meta->getIdentifier()[0])->getValue($object); @@ -82,7 +82,7 @@ public function extractIdentifier($om, $object, $single = true) if ($object instanceof PersistenceProxy) { $id = $om->getUnitOfWork()->getEntityIdentifier($object); } else { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $id = []; foreach ($meta->getIdentifier() as $name) { $id[$name] = $meta->getReflectionProperty($name)->getValue($object); @@ -110,7 +110,7 @@ public function extractIdentifier($om, $object, $single = true) private function throwIfNotDocumentManager($dm): void { if (!($dm instanceof MongoDocumentManager) && !($dm instanceof PhpcrDocumentManager)) { - throw new InvalidArgumentException(sprintf('Expected a %s or %s instance but got "%s"', MongoDocumentManager::class, 'Doctrine\ODM\PHPCR\DocumentManager', is_object($dm) ? get_class($dm) : gettype($dm))); + throw new InvalidArgumentException(sprintf('Expected a %s or %s instance but got "%s"', MongoDocumentManager::class, 'Doctrine\ODM\PHPCR\DocumentManager', get_debug_type($dm))); } } } diff --git a/src/References/ReferencesListener.php b/src/References/ReferencesListener.php index de61a48ba8..2011e4ac15 100644 --- a/src/References/ReferencesListener.php +++ b/src/References/ReferencesListener.php @@ -46,19 +46,12 @@ */ class ReferencesListener extends MappedEventSubscriber { - /** - * @var array - */ - private array $managers; - /** * @param array $managers */ - public function __construct(array $managers = []) + public function __construct(private array $managers = []) { parent::__construct(); - - $this->managers = $managers; } /** @@ -87,13 +80,12 @@ public function postLoad(EventArgs $eventArgs) $ea = $this->getEventAdapter($eventArgs); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $config = $this->getConfiguration($om, $meta->getName()); if (isset($config['referenceOne'])) { foreach ($config['referenceOne'] as $mapping) { $property = $meta->reflClass->getProperty($mapping['field']); - $property->setAccessible(true); if (isset($mapping['identifier'])) { $referencedObjectId = $meta->getFieldValue($object, $mapping['identifier']); if (null !== $referencedObjectId) { @@ -113,7 +105,6 @@ public function postLoad(EventArgs $eventArgs) if (isset($config['referenceMany'])) { foreach ($config['referenceMany'] as $mapping) { $property = $meta->reflClass->getProperty($mapping['field']); - $property->setAccessible(true); if (isset($mapping['mappedBy'])) { $id = $ea->extractIdentifier($om, $object); $manager = $this->getManager($mapping['type']); @@ -212,13 +203,12 @@ public function updateManyEmbedReferences(EventArgs $eventArgs) $ea = $this->getEventAdapter($eventArgs); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $config = $this->getConfiguration($om, $meta->getName()); if (isset($config['referenceManyEmbed'])) { foreach ($config['referenceManyEmbed'] as $mapping) { $property = $meta->reflClass->getProperty($mapping['field']); - $property->setAccessible(true); $id = $ea->extractIdentifier($om, $object); $manager = $this->getManager('document'); @@ -259,14 +249,13 @@ private function updateReferences(EventArgs $eventArgs): void $ea = $this->getEventAdapter($eventArgs); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $config = $this->getConfiguration($om, $meta->getName()); if (isset($config['referenceOne'])) { foreach ($config['referenceOne'] as $mapping) { if (isset($mapping['identifier'])) { $property = $meta->reflClass->getProperty($mapping['field']); - $property->setAccessible(true); $referencedObject = $property->getValue($object); if (is_object($referencedObject)) { diff --git a/src/Sluggable/Handler/InversedRelativeSlugHandler.php b/src/Sluggable/Handler/InversedRelativeSlugHandler.php index b8ac0483bb..4b84a53b3b 100644 --- a/src/Sluggable/Handler/InversedRelativeSlugHandler.php +++ b/src/Sluggable/Handler/InversedRelativeSlugHandler.php @@ -43,26 +43,22 @@ public function __construct(SluggableListener $sluggable) $this->sluggable = $sluggable; } - public function onChangeDecision(SluggableAdapter $ea, array &$config, $object, &$slug, &$needToChangeSlug) - { - } + public function onChangeDecision(SluggableAdapter $ea, array &$config, $object, &$slug, &$needToChangeSlug) {} - public function postSlugBuild(SluggableAdapter $ea, array &$config, $object, &$slug) - { - } + public function postSlugBuild(SluggableAdapter $ea, array &$config, $object, &$slug) {} /** * @param ClassMetadata $meta */ public static function validate(array $options, ClassMetadata $meta) { - if (!isset($options['relationClass']) || !strlen($options['relationClass'])) { + if (!isset($options['relationClass']) || !strlen((string) $options['relationClass'])) { throw new InvalidMappingException("'relationClass' option must be specified for object slug mapping - {$meta->getName()}"); } - if (!isset($options['mappedBy']) || !strlen($options['mappedBy'])) { + if (!isset($options['mappedBy']) || !strlen((string) $options['mappedBy'])) { throw new InvalidMappingException("'mappedBy' option must be specified for object slug mapping - {$meta->getName()}"); } - if (!isset($options['inverseSlugField']) || !strlen($options['inverseSlugField'])) { + if (!isset($options['inverseSlugField']) || !strlen((string) $options['inverseSlugField'])) { throw new InvalidMappingException("'inverseSlugField' option must be specified for object slug mapping - {$meta->getName()}"); } } diff --git a/src/Sluggable/Handler/RelativeSlugHandler.php b/src/Sluggable/Handler/RelativeSlugHandler.php index 2fdac40b9a..bbec2a09a3 100644 --- a/src/Sluggable/Handler/RelativeSlugHandler.php +++ b/src/Sluggable/Handler/RelativeSlugHandler.php @@ -78,7 +78,7 @@ public function onChangeDecision(SluggableAdapter $ea, array &$config, $object, public function postSlugBuild(SluggableAdapter $ea, array &$config, $object, &$slug) { $this->originalTransliterator = $this->sluggable->getTransliterator(); - $this->sluggable->setTransliterator([$this, 'transliterate']); + $this->sluggable->setTransliterator($this->transliterate(...)); } /** @@ -91,9 +91,7 @@ public static function validate(array $options, ClassMetadata $meta) } } - public function onSlugCompletion(SluggableAdapter $ea, array &$config, $object, &$slug) - { - } + public function onSlugCompletion(SluggableAdapter $ea, array &$config, $object, &$slug) {} /** * Transliterates the slug and prefixes the slug diff --git a/src/Sluggable/Mapping/Driver/Yaml.php b/src/Sluggable/Mapping/Driver/Yaml.php index 9d96296311..aa2ef40e38 100644 --- a/src/Sluggable/Mapping/Driver/Yaml.php +++ b/src/Sluggable/Mapping/Driver/Yaml.php @@ -107,7 +107,7 @@ private function buildFieldConfiguration(string $field, array $fieldMapping, Cla $handlers = []; if (isset($slug['handlers'])) { foreach ($slug['handlers'] as $handlerClass => $options) { - if (!strlen($handlerClass)) { + if (!strlen((string) $handlerClass)) { throw new InvalidMappingException("SlugHandler class: {$handlerClass} should be a valid class name in entity - {$meta->getName()}"); } $handlers[$handlerClass] = $options; diff --git a/src/Sluggable/Mapping/Event/Adapter/ODM.php b/src/Sluggable/Mapping/Event/Adapter/ODM.php index 9f60cf06bc..75919cb36a 100644 --- a/src/Sluggable/Mapping/Event/Adapter/ODM.php +++ b/src/Sluggable/Mapping/Event/Adapter/ODM.php @@ -37,7 +37,7 @@ public function getSimilarSlugs($object, $meta, array $config, $slug) if (is_object($ubase = $wrapped->getPropertyValue($config['unique_base']))) { $qb->field($config['unique_base'].'.$id')->equals(new \MongoId($ubase->getId())); } elseif ($ubase) { - $qb->where('/^'.preg_quote($ubase, '/').'/.test(this.'.$config['unique_base'].')'); + $qb->where('/^'.preg_quote((string) $ubase, '/').'/.test(this.'.$config['unique_base'].')'); } else { $qb->field($config['unique_base'])->equals(null); } @@ -73,7 +73,7 @@ public function replaceRelative($object, array $config, $target, $replacement) foreach ($result as $targetObject) { ++$count; - $slug = preg_replace("@^{$target}@smi", $replacement.$config['pathSeparator'], $targetObject[$config['slug']]); + $slug = preg_replace("@^{$target}@smi", $replacement.$config['pathSeparator'], (string) $targetObject[$config['slug']]); $dm ->createQueryBuilder() ->updateMany($config['useObjectClass']) @@ -109,7 +109,7 @@ public function replaceInverseRelative($object, array $config, $target, $replace foreach ($result as $targetObject) { ++$count; - $slug = preg_replace("@^{$replacement}@smi", $target, $targetObject[$config['slug']]); + $slug = preg_replace("@^{$replacement}@smi", $target, (string) $targetObject[$config['slug']]); $dm ->createQueryBuilder() ->updateMany($config['useObjectClass']) diff --git a/src/Sluggable/SluggableListener.php b/src/Sluggable/SluggableListener.php index 1f0df30657..286019a175 100644 --- a/src/Sluggable/SluggableListener.php +++ b/src/Sluggable/SluggableListener.php @@ -273,7 +273,7 @@ public function prePersist(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($config = $this->getConfiguration($om, $meta->getName())) { foreach ($config['slugs'] as $slugField => $options) { @@ -307,7 +307,7 @@ public function onFlush(EventArgs $args) // of prePersist in case if record will be changed before flushing this will // ensure correct result. No additional overhead is encountered foreach ($ea->getScheduledObjectInsertions($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($this->getConfiguration($om, $meta->getName())) { // generate first to exclude this object from similar persisted slugs result $this->generateSlug($ea, $object); @@ -317,7 +317,7 @@ public function onFlush(EventArgs $args) // we use onFlush and not preUpdate event to let other // event listeners be nested together foreach ($ea->getScheduledObjectUpdates($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($this->getConfiguration($om, $meta->getName()) && !$uow->isScheduledForInsert($object)) { $this->generateSlug($ea, $object); $this->persisted[$ea->getRootObjectClass($meta)][] = $object; @@ -352,7 +352,7 @@ private function getHandler(string $class): SlugHandlerInterface private function generateSlug(SluggableAdapter $ea, object $object): void { $om = $ea->getObjectManager(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $uow = $om->getUnitOfWork(); $changeSet = $ea->getObjectChangeSet($uow, $object); $isInsert = $uow->isScheduledForInsert($object); @@ -365,7 +365,7 @@ private function generateSlug(SluggableAdapter $ea, object $object): void $slug = $meta->getReflectionProperty($slugField)->getValue($object); // if slug should not be updated, skip it - if (!$options['updatable'] && !$isInsert && (!isset($changeSet[$slugField]) || 0 === strpos($slug, '__sluggable_placeholder__'))) { + if (!$options['updatable'] && !$isInsert && (!isset($changeSet[$slugField]) || str_starts_with((string) $slug, '__sluggable_placeholder__'))) { continue; } // must fetch the old slug from changeset, since $object holds the new version @@ -373,7 +373,7 @@ private function generateSlug(SluggableAdapter $ea, object $object): void $needToChangeSlug = false; // if slug is null, regenerate it, or needs an update - if (null === $slug || 0 === strpos($slug, '__sluggable_placeholder__') || !isset($changeSet[$slugField])) { + if (null === $slug || str_starts_with($slug, '__sluggable_placeholder__') || !isset($changeSet[$slugField])) { $slug = ''; foreach ($options['fields'] as $sluggableField) { @@ -458,11 +458,11 @@ private function generateSlug(SluggableAdapter $ea, object $object): void // cut slug if exceeded in length $length = $mapping->length ?? $mapping['length'] ?? null; - if (null !== $length && strlen($slug) > $length) { - $slug = substr($slug, 0, $length); + if (null !== $length && strlen((string) $slug) > $length) { + $slug = substr((string) $slug, 0, $length); } - if (($mapping->nullable ?? $mapping['nullable'] ?? false) && 0 === strlen($slug)) { + if (($mapping->nullable ?? $mapping['nullable'] ?? false) && 0 === strlen((string) $slug)) { $slug = null; } @@ -502,12 +502,12 @@ private function generateSlug(SluggableAdapter $ea, object $object): void /** * Generates the unique slug * - * @param SlugConfiguration $config + * @phpstan-param SlugConfiguration $config */ private function makeUniqueSlug(SluggableAdapter $ea, object $object, string $preferredSlug, bool $recursing, array $config): string { $om = $ea->getObjectManager(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $similarPersisted = []; // extract unique base $base = false; @@ -524,7 +524,7 @@ private function makeUniqueSlug(SluggableAdapter $ea, object $object, string $pr } $slug = $meta->getReflectionProperty($config['slug'])->getValue($obj); $quotedPreferredSlug = preg_quote($preferredSlug); - if (preg_match("@^{$quotedPreferredSlug}.*@smi", $slug)) { + if (preg_match("@^{$quotedPreferredSlug}.*@smi", (string) $slug)) { $similarPersisted[] = [$config['slug'] => $slug]; } } @@ -540,7 +540,7 @@ private function makeUniqueSlug(SluggableAdapter $ea, object $object, string $pr $quotedSeparator = preg_quote($config['separator']); $quotedPreferredSlug = preg_quote($preferredSlug); foreach ($result as $key => $similar) { - if (!preg_match("@{$quotedPreferredSlug}($|{$quotedSeparator}[\d]+$)@smi", $similar[$config['slug']])) { + if (!preg_match("@{$quotedPreferredSlug}($|{$quotedSeparator}[\d]+$)@smi", (string) $similar[$config['slug']])) { unset($result[$key]); } } @@ -572,7 +572,7 @@ private function makeUniqueSlug(SluggableAdapter $ea, object $object, string $pr $length - (strlen($uniqueSuffix) + strlen($config['separator'])) ); $this->exponent = strlen($uniqueSuffix) - 1; - if (substr($generatedSlug, -strlen($config['separator'])) == $config['separator']) { + if (str_ends_with($generatedSlug, $config['separator'])) { $generatedSlug = substr($generatedSlug, 0, strlen($generatedSlug) - strlen($config['separator'])); } $generatedSlug = $this->makeUniqueSlug($ea, $object, $generatedSlug, true, $config); diff --git a/src/Sluggable/Util/Urlizer.php b/src/Sluggable/Util/Urlizer.php index ba3d0710a6..376117dbfb 100644 --- a/src/Sluggable/Util/Urlizer.php +++ b/src/Sluggable/Util/Urlizer.php @@ -23,6 +23,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class Urlizer extends Transliterator -{ -} +class Urlizer extends Transliterator {} diff --git a/src/SoftDeleteable/Event/PostSoftDeleteEventArgs.php b/src/SoftDeleteable/Event/PostSoftDeleteEventArgs.php index f8a41338b2..d12ef4cc1a 100644 --- a/src/SoftDeleteable/Event/PostSoftDeleteEventArgs.php +++ b/src/SoftDeleteable/Event/PostSoftDeleteEventArgs.php @@ -19,6 +19,4 @@ * * @template-extends LifecycleEventArgs */ -final class PostSoftDeleteEventArgs extends LifecycleEventArgs -{ -} +final class PostSoftDeleteEventArgs extends LifecycleEventArgs {} diff --git a/src/SoftDeleteable/Event/PreSoftDeleteEventArgs.php b/src/SoftDeleteable/Event/PreSoftDeleteEventArgs.php index e01cd73d86..cc94618c3e 100644 --- a/src/SoftDeleteable/Event/PreSoftDeleteEventArgs.php +++ b/src/SoftDeleteable/Event/PreSoftDeleteEventArgs.php @@ -19,6 +19,4 @@ * * @template-extends LifecycleEventArgs */ -final class PreSoftDeleteEventArgs extends LifecycleEventArgs -{ -} +final class PreSoftDeleteEventArgs extends LifecycleEventArgs {} diff --git a/src/SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php b/src/SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php index 12d80c0b4b..3e8fcd9f8d 100644 --- a/src/SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php +++ b/src/SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php @@ -43,23 +43,23 @@ class SoftDeleteableFilter extends BsonFilter * * @phpstan-return array>|null> */ - public function addFilterCriteria(ClassMetadata $targetEntity): array + public function addFilterCriteria(ClassMetadata $class): array { - $class = $targetEntity->getName(); - if (true === ($this->disabled[$class] ?? false)) { + $className = $class->getName(); + if (true === ($this->disabled[$className] ?? false)) { return []; } - if (true === ($this->disabled[$targetEntity->rootDocumentName] ?? false)) { + if (true === ($this->disabled[$class->rootDocumentName] ?? false)) { return []; } - $config = $this->getListener()->getConfiguration($this->getDocumentManager(), $targetEntity->name); + $config = $this->getListener()->getConfiguration($this->getDocumentManager(), $class->name); if (!isset($config['softDeleteable']) || !$config['softDeleteable']) { return []; } - $column = $targetEntity->getFieldMapping($config['fieldName']); + $column = $class->getFieldMapping($config['fieldName']); if (isset($config['timeAware']) && $config['timeAware']) { return [ diff --git a/src/SoftDeleteable/Mapping/Driver/Annotation.php b/src/SoftDeleteable/Mapping/Driver/Annotation.php index a45df5a33c..9fcea638a0 100644 --- a/src/SoftDeleteable/Mapping/Driver/Annotation.php +++ b/src/SoftDeleteable/Mapping/Driver/Annotation.php @@ -18,6 +18,4 @@ * * @internal */ -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php b/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php index c698d205c4..62fafe1839 100644 --- a/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php +++ b/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php @@ -35,7 +35,7 @@ public function setClock(ClockInterface $clock): void */ public function getDateValue($meta, $field) { - $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); + $datetime = $this->clock?->now() ?? new \DateTimeImmutable(); $mapping = $meta->getFieldMapping($field); $type = $mapping['type'] ?? null; diff --git a/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php b/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php index e20b7f1b70..fd31930e45 100644 --- a/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php +++ b/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php @@ -49,12 +49,10 @@ public function getDateValue($meta, $field) * Generates current timestamp for the specified mapping * * @param array|FieldMapping $mapping - * - * @return \DateTimeInterface|int */ - private function getRawDateValue($mapping) + private function getRawDateValue(array|FieldMapping $mapping): \DateTimeInterface|int { - $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); + $datetime = $this->clock?->now() ?? new \DateTimeImmutable(); $type = $mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? ''); if ('integer' === $type) { diff --git a/src/SoftDeleteable/Query/TreeWalker/Exec/MultiTableDeleteExecutor.php b/src/SoftDeleteable/Query/TreeWalker/Exec/MultiTableDeleteExecutor.php index fbe7935fd5..84fe08e448 100644 --- a/src/SoftDeleteable/Query/TreeWalker/Exec/MultiTableDeleteExecutor.php +++ b/src/SoftDeleteable/Query/TreeWalker/Exec/MultiTableDeleteExecutor.php @@ -54,11 +54,6 @@ public function __construct(Node $AST, $sqlWalker, ClassMetadata $meta, Abstract } } - // @todo: Once the minimum supported ORM version is 2.17, this can always write to the `$this->sqlStatements` property - if (property_exists($this, 'sqlStatements')) { - $this->sqlStatements = $sqlStatements; - } else { - $this->_sqlStatements = $sqlStatements; - } + $this->sqlStatements = $sqlStatements; } } diff --git a/src/SoftDeleteable/SoftDeleteableListener.php b/src/SoftDeleteable/SoftDeleteableListener.php index 133aeb1927..6b8e92ce90 100644 --- a/src/SoftDeleteable/SoftDeleteableListener.php +++ b/src/SoftDeleteable/SoftDeleteableListener.php @@ -90,7 +90,7 @@ public function onFlush(EventArgs $args) // getScheduledDocumentDeletions foreach ($ea->getScheduledObjectDeletions($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $config = $this->getConfiguration($om, $meta->getName()); if (isset($config['softDeleteable']) && $config['softDeleteable']) { @@ -200,7 +200,7 @@ private function hasToDispatchNewEvent(ObjectManager $objectManager, EventManage 'https://github.com/doctrine-extensions/DoctrineExtensions/pull/2649', 'Type-hinting to something different than "%s" in "%s::%s()" is deprecated.', $eventClass, - get_class($listener), + $listener::class, $reflMethod->getName() ); diff --git a/src/Sortable/Mapping/Driver/Annotation.php b/src/Sortable/Mapping/Driver/Annotation.php index a1367c4c06..16afd8b89d 100644 --- a/src/Sortable/Mapping/Driver/Annotation.php +++ b/src/Sortable/Mapping/Driver/Annotation.php @@ -18,6 +18,4 @@ * * @internal */ -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/src/Sortable/Mapping/Event/SortableAdapter.php b/src/Sortable/Mapping/Event/SortableAdapter.php index ecdd8ce979..9bf506baf8 100644 --- a/src/Sortable/Mapping/Event/SortableAdapter.php +++ b/src/Sortable/Mapping/Event/SortableAdapter.php @@ -16,6 +16,4 @@ * * @author Lukas Botsch */ -interface SortableAdapter extends AdapterInterface -{ -} +interface SortableAdapter extends AdapterInterface {} diff --git a/src/Sortable/SortableListener.php b/src/Sortable/SortableListener.php index e908a50797..fcdbd2eabd 100644 --- a/src/Sortable/SortableListener.php +++ b/src/Sortable/SortableListener.php @@ -124,7 +124,7 @@ public function onFlush(EventArgs $args) // process all objects being deleted foreach ($ea->getScheduledObjectDeletions($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($config = $this->getConfiguration($om, $meta->getName())) { $this->processDeletion($ea, $config, $meta, $object); } @@ -133,7 +133,7 @@ public function onFlush(EventArgs $args) $updateValues = []; // process all objects being updated foreach ($ea->getScheduledObjectUpdates($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($config = $this->getConfiguration($om, $meta->getName())) { $position = $meta->getReflectionProperty($config['position'])->getValue($object); $updateValues[$position] = [$ea, $config, $meta, $object]; @@ -146,7 +146,7 @@ public function onFlush(EventArgs $args) // process all objects being inserted foreach ($ea->getScheduledObjectInsertions($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($config = $this->getConfiguration($om, $meta->getName())) { $this->processInsert($ea, $config, $meta, $object); } @@ -167,7 +167,7 @@ public function prePersist(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($config = $this->getConfiguration($om, $meta->getName())) { // Get groups @@ -706,7 +706,7 @@ protected function addRelocation($hash, $class, $groups, $start, $stop, $delta, } }, $newDelta); $this->relocations[$hash]['deltas'][] = $newDelta; - } catch (\Exception $e) { + } catch (\Exception) { } } diff --git a/src/Timestampable/Mapping/Driver/Annotation.php b/src/Timestampable/Mapping/Driver/Annotation.php index 52d4d4bc18..34605f2ae9 100644 --- a/src/Timestampable/Mapping/Driver/Annotation.php +++ b/src/Timestampable/Mapping/Driver/Annotation.php @@ -18,6 +18,4 @@ * * @internal */ -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/src/Timestampable/Mapping/Event/Adapter/ODM.php b/src/Timestampable/Mapping/Event/Adapter/ODM.php index 9dc685d61e..8aaae8048a 100644 --- a/src/Timestampable/Mapping/Event/Adapter/ODM.php +++ b/src/Timestampable/Mapping/Event/Adapter/ODM.php @@ -35,7 +35,7 @@ public function setClock(ClockInterface $clock): void */ public function getDateValue($meta, $field) { - $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); + $datetime = $this->clock?->now() ?? new \DateTimeImmutable(); $mapping = $meta->getFieldMapping($field); $type = $mapping['type'] ?? null; diff --git a/src/Timestampable/Mapping/Event/Adapter/ORM.php b/src/Timestampable/Mapping/Event/Adapter/ORM.php index 276bc05c02..1e32416faf 100644 --- a/src/Timestampable/Mapping/Event/Adapter/ORM.php +++ b/src/Timestampable/Mapping/Event/Adapter/ORM.php @@ -49,12 +49,10 @@ public function getDateValue($meta, $field) * Generates current timestamp for the specified mapping * * @param array|FieldMapping $mapping - * - * @return \DateTimeInterface|int */ - private function getRawDateValue($mapping) + private function getRawDateValue(array|FieldMapping $mapping): \DateTimeInterface|int { - $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); + $datetime = $this->clock?->now() ?? new \DateTimeImmutable(); $type = $mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? ''); if ('integer' === $type) { diff --git a/src/Tool/ClassUtils.php b/src/Tool/ClassUtils.php index 5edbe321e0..18ef3ea8bc 100644 --- a/src/Tool/ClassUtils.php +++ b/src/Tool/ClassUtils.php @@ -18,9 +18,7 @@ */ final class ClassUtils { - private function __construct() - { - } + private function __construct() {} /** * Gets the real class name of an object (even if it's a proxy). @@ -39,6 +37,6 @@ public static function getClass(object $object): string return CommonClassUtils::getClass($object); } - return get_class($object); + return $object::class; } } diff --git a/src/Tool/Wrapper/EntityWrapper.php b/src/Tool/Wrapper/EntityWrapper.php index 443c873459..ef99bc6b9d 100644 --- a/src/Tool/Wrapper/EntityWrapper.php +++ b/src/Tool/Wrapper/EntityWrapper.php @@ -32,7 +32,7 @@ class EntityWrapper extends AbstractWrapper * * @var array|null */ - private $identifier; + private ?array $identifier = null; /** * Wrap entity @@ -43,7 +43,7 @@ public function __construct($entity, EntityManagerInterface $em) { $this->om = $em; $this->object = $entity; - $this->meta = $em->getClassMetadata(get_class($this->object)); + $this->meta = $em->getClassMetadata($this->object::class); } public function getPropertyValue($property) diff --git a/src/Tool/Wrapper/MongoDocumentWrapper.php b/src/Tool/Wrapper/MongoDocumentWrapper.php index 94b81e554c..af149e8883 100644 --- a/src/Tool/Wrapper/MongoDocumentWrapper.php +++ b/src/Tool/Wrapper/MongoDocumentWrapper.php @@ -41,7 +41,7 @@ public function __construct($document, DocumentManager $dm) { $this->om = $dm; $this->object = $document; - $this->meta = $dm->getClassMetadata(get_class($this->object)); + $this->meta = $dm->getClassMetadata($this->object::class); } public function getPropertyValue($property) diff --git a/src/Translatable/Document/Repository/TranslationRepository.php b/src/Translatable/Document/Repository/TranslationRepository.php index 5dd18e1016..1bdc309dec 100644 --- a/src/Translatable/Document/Repository/TranslationRepository.php +++ b/src/Translatable/Document/Repository/TranslationRepository.php @@ -64,7 +64,7 @@ public function __construct(DocumentManager $dm, UnitOfWork $uow, ClassMetadata */ public function translate($document, $field, $locale, $value) { - $meta = $this->dm->getClassMetadata(get_class($document)); + $meta = $this->dm->getClassMetadata($document::class); $listener = $this->getTranslatableListener(); $config = $listener->getConfiguration($this->dm, $meta->getName()); if (!isset($config['fields']) || !in_array($field, $config['fields'], true)) { diff --git a/src/Translatable/Entity/Repository/TranslationRepository.php b/src/Translatable/Entity/Repository/TranslationRepository.php index e623669aa4..1b1f4d751a 100644 --- a/src/Translatable/Entity/Repository/TranslationRepository.php +++ b/src/Translatable/Entity/Repository/TranslationRepository.php @@ -60,7 +60,7 @@ public function __construct(EntityManagerInterface $em, ClassMetadata $class) */ public function translate($entity, $field, $locale, $value) { - $meta = $this->getEntityManager()->getClassMetadata(get_class($entity)); + $meta = $this->getEntityManager()->getClassMetadata($entity::class); $listener = $this->getTranslatableListener(); $config = $listener->getConfiguration($this->getEntityManager(), $meta->getName()); if (!isset($config['fields']) || !in_array($field, $config['fields'], true)) { diff --git a/src/Translatable/Mapping/Driver/Annotation.php b/src/Translatable/Mapping/Driver/Annotation.php index 83cb4ecb45..5b05a56600 100644 --- a/src/Translatable/Mapping/Driver/Annotation.php +++ b/src/Translatable/Mapping/Driver/Annotation.php @@ -18,6 +18,4 @@ * * @internal */ -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/src/Translatable/Mapping/Event/Adapter/ODM.php b/src/Translatable/Mapping/Event/Adapter/ODM.php index be64177ce9..ee667600e6 100644 --- a/src/Translatable/Mapping/Event/Adapter/ODM.php +++ b/src/Translatable/Mapping/Event/Adapter/ODM.php @@ -134,7 +134,7 @@ public function removeAssociatedTranslations(AbstractWrapper $wrapped, $transCla public function insertTranslationRecord($translation) { $dm = $this->getObjectManager(); - $meta = $dm->getClassMetadata(get_class($translation)); + $meta = $dm->getClassMetadata($translation::class); $collection = $dm->getDocumentCollection($meta->getName()); $data = []; diff --git a/src/Translatable/Mapping/Event/Adapter/ORM.php b/src/Translatable/Mapping/Event/Adapter/ORM.php index 65afdf4649..2d0b9764f2 100644 --- a/src/Translatable/Mapping/Event/Adapter/ORM.php +++ b/src/Translatable/Mapping/Event/Adapter/ORM.php @@ -191,7 +191,7 @@ public function removeAssociatedTranslations(AbstractWrapper $wrapped, $transCla public function insertTranslationRecord($translation) { $em = $this->getObjectManager(); - $meta = $em->getClassMetadata(get_class($translation)); + $meta = $em->getClassMetadata($translation::class); $data = []; foreach ($meta->getReflectionProperties() as $fieldName => $reflProp) { @@ -245,13 +245,9 @@ private function foreignKey($key, string $className) $meta = $em->getClassMetadata($className); $type = Type::getType($meta->getTypeOfField('foreignKey')); - switch (Type::lookupName($type)) { - case Types::BIGINT: - case Types::INTEGER: - case Types::SMALLINT: - return (int) $key; - default: - return (string) $key; - } + return match (Type::lookupName($type)) { + Types::BIGINT, Types::INTEGER, Types::SMALLINT => (int) $key, + default => (string) $key, + }; } } diff --git a/src/Translatable/Query/TreeWalker/TranslationWalker.php b/src/Translatable/Query/TreeWalker/TranslationWalker.php index 6d006fc25c..105d439cd5 100644 --- a/src/Translatable/Query/TreeWalker/TranslationWalker.php +++ b/src/Translatable/Query/TreeWalker/TranslationWalker.php @@ -9,9 +9,7 @@ namespace Gedmo\Translatable\Query\TreeWalker; -use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; -use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Mapping\ClassMetadata; @@ -90,16 +88,6 @@ class TranslationWalker extends SqlOutputWalker */ private array $translatedComponents = []; - /** - * DBAL database platform - */ - private AbstractPlatform $platform; - - /** - * DBAL database connection - */ - private Connection $conn; - /** * List of aliases to replace with translation * content reference @@ -120,8 +108,6 @@ class TranslationWalker extends SqlOutputWalker public function __construct($query, $parserResult, array $queryComponents) { parent::__construct($query, $parserResult, $queryComponents); - $this->conn = $this->getConnection(); - $this->platform = $this->getConnection()->getDatabasePlatform(); $this->listener = $this->getTranslatableListener(); $this->extractTranslatedComponents($queryComponents); } @@ -282,6 +268,7 @@ private function prepareTranslatedComponents(): void // Skip preparation as there's no need to translate anything return; } + $platform = $this->getConnection()->getDatabasePlatform(); $em = $this->getEntityManager(); $ea = new TranslatableEventAdapter(); $ea->setEntityManager($em); @@ -294,45 +281,45 @@ private function prepareTranslatedComponents(): void $config = $this->listener->getConfiguration($em, $meta->getName()); $transClass = $this->listener->getTranslationClass($ea, $meta->getName()); $transMeta = $em->getClassMetadata($transClass); - $transTable = $quoteStrategy->getTableName($transMeta, $this->platform); + $transTable = $quoteStrategy->getTableName($transMeta, $platform); foreach ($config['fields'] as $field) { $compTblAlias = $this->walkIdentificationVariable($dqlAlias, $field); $tblAlias = $this->getSQLTableAlias('trans'.$compTblAlias.$field); $sql = " {$joinStrategy} JOIN ".$transTable.' '.$tblAlias; - $sql .= ' ON '.$tblAlias.'.'.$quoteStrategy->getColumnName('locale', $transMeta, $this->platform) - .' = '.$this->conn->quote($locale); - $sql .= ' AND '.$tblAlias.'.'.$quoteStrategy->getColumnName('field', $transMeta, $this->platform) - .' = '.$this->conn->quote($field); + $sql .= ' ON '.$tblAlias.'.'.$quoteStrategy->getColumnName('locale', $transMeta, $platform) + .' = '.$this->getConnection()->quote($locale); + $sql .= ' AND '.$tblAlias.'.'.$quoteStrategy->getColumnName('field', $transMeta, $platform) + .' = '.$this->getConnection()->quote($field); $identifier = $meta->getSingleIdentifierFieldName(); - $idColName = $quoteStrategy->getColumnName($identifier, $meta, $this->platform); + $idColName = $quoteStrategy->getColumnName($identifier, $meta, $platform); if ($ea->usesPersonalTranslation($transClass)) { $sql .= ' AND '.$tblAlias.'.'.$transMeta->getSingleAssociationJoinColumnName('object') .' = '.$compTblAlias.'.'.$idColName; } else { - $sql .= ' AND '.$tblAlias.'.'.$quoteStrategy->getColumnName('objectClass', $transMeta, $this->platform) - .' = '.$this->conn->quote($config['useObjectClass']); + $sql .= ' AND '.$tblAlias.'.'.$quoteStrategy->getColumnName('objectClass', $transMeta, $platform) + .' = '.$this->getConnection()->quote($config['useObjectClass']); $mappingFK = $transMeta->getFieldMapping('foreignKey'); $mappingPK = $meta->getFieldMapping($identifier); $fkColName = $this->getCastedForeignKey($compTblAlias.'.'.$idColName, $mappingFK->type ?? $mappingFK['type'], $mappingPK->type ?? $mappingPK['type']); - $sql .= ' AND '.$tblAlias.'.'.$quoteStrategy->getColumnName('foreignKey', $transMeta, $this->platform) + $sql .= ' AND '.$tblAlias.'.'.$quoteStrategy->getColumnName('foreignKey', $transMeta, $platform) .' = '.$fkColName; } isset($this->components[$dqlAlias]) ? $this->components[$dqlAlias] .= $sql : $this->components[$dqlAlias] = $sql; - $originalField = $compTblAlias.'.'.$quoteStrategy->getColumnName($field, $meta, $this->platform); - $substituteField = $tblAlias.'.'.$quoteStrategy->getColumnName('content', $transMeta, $this->platform); + $originalField = $compTblAlias.'.'.$quoteStrategy->getColumnName($field, $meta, $platform); + $substituteField = $tblAlias.'.'.$quoteStrategy->getColumnName('content', $transMeta, $platform); // Treat translation as original field type $fieldMapping = $meta->getFieldMapping($field); - if ((($this->platform instanceof AbstractMySQLPlatform) + if ((($platform instanceof AbstractMySQLPlatform) && in_array($fieldMapping->type ?? $fieldMapping['type'], ['decimal'], true)) - || (!($this->platform instanceof AbstractMySQLPlatform) + || (!($platform instanceof AbstractMySQLPlatform) && !in_array($fieldMapping->type ?? $fieldMapping['type'], ['datetime', 'datetimetz', 'date', 'time'], true))) { $type = Type::getType($fieldMapping->type ?? $fieldMapping['type']); // In ORM 2.x, $fieldMapping is an array. In ORM 3.x, it's a data object. Always cast to an array for compatibility across versions. - $substituteField = 'CAST('.$substituteField.' AS '.$type->getSQLDeclaration((array) $fieldMapping, $this->platform).')'; + $substituteField = 'CAST('.$substituteField.' AS '.$type->getSQLDeclaration((array) $fieldMapping, $platform).')'; } // Fallback to original if was asked for @@ -413,7 +400,7 @@ private function getTranslatableListener(): TranslatableListener private function replace(array $repl, string $str): string { foreach ($repl as $target => $result) { - $str = preg_replace_callback('/(\s|\()('.$target.')(,?)(\s|\)|$)/smi', static fn (array $m): string => $m[1].$result.$m[3].$m[4], $str); + $str = preg_replace_callback('/(\s|\()('.$target.')(,?)(\s|\)|$)/smi', static fn (array $m): string => $m[1].$result.$m[3].$m[4], (string) $str); } return $str; @@ -438,7 +425,7 @@ private function getCastedForeignKey(string $component, string $typeFK, string $ } // try to look at postgres casting - if ($this->platform instanceof PostgreSQLPlatform) { + if ($this->getConnection()->getDatabasePlatform() instanceof PostgreSQLPlatform) { switch ($typeFK) { case 'string': case 'guid': diff --git a/src/Translatable/TranslatableListener.php b/src/Translatable/TranslatableListener.php index 44a04ef979..b4144636e0 100644 --- a/src/Translatable/TranslatableListener.php +++ b/src/Translatable/TranslatableListener.php @@ -347,7 +347,6 @@ public function getTranslatableLocale($object, $meta, $om = null) throw new RuntimeException("There is no locale or language property ({$configurationLocale}) found on object: {$meta->getName()}"); } $reflectionProperty = $class->getProperty($configurationLocale); - $reflectionProperty->setAccessible(true); $value = $reflectionProperty->getValue($object); if (is_object($value) && method_exists($value, '__toString')) { $value = $value->__toString(); @@ -358,7 +357,7 @@ public function getTranslatableLocale($object, $meta, $om = null) } elseif ($om instanceof DocumentManager) { [, $parentObject] = $om->getUnitOfWork()->getParentAssociation($object); if (null !== $parentObject) { - $parentMeta = $om->getClassMetadata(get_class($parentObject)); + $parentMeta = $om->getClassMetadata($parentObject::class); $locale = $this->getTranslatableLocale($parentObject, $parentMeta, $om); } } @@ -389,7 +388,7 @@ public function preFlush(EventArgs $args) assert(false !== $trans); - if ($ea->usesPersonalTranslation(get_class($trans))) { + if ($ea->usesPersonalTranslation($trans::class)) { $entity = $trans->getObject(); } else { $entity = $uow->tryGetById($trans->getForeignKey(), $trans->getObjectClass()); @@ -401,7 +400,7 @@ public function preFlush(EventArgs $args) try { $uow->scheduleForUpdate($entity); - } catch (ORMInvalidArgumentException $e) { + } catch (ORMInvalidArgumentException) { foreach ($fields as $field => $trans) { $this->removeTranslationInDefaultLocale($oid, $field); } @@ -426,7 +425,7 @@ public function onFlush(EventArgs $args) $uow = $om->getUnitOfWork(); // check all scheduled inserts for Translatable objects foreach ($ea->getScheduledObjectInsertions($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $config = $this->getConfiguration($om, $meta->getName()); if (isset($config['fields'])) { $this->handleTranslatableObjectUpdate($ea, $object, true); @@ -434,7 +433,7 @@ public function onFlush(EventArgs $args) } // check all scheduled updates for Translatable entities foreach ($ea->getScheduledObjectUpdates($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $config = $this->getConfiguration($om, $meta->getName()); if (isset($config['fields'])) { $this->handleTranslatableObjectUpdate($ea, $object, false); @@ -442,7 +441,7 @@ public function onFlush(EventArgs $args) } // check scheduled deletions for Translatable entities foreach ($ea->getScheduledObjectDeletions($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $config = $this->getConfiguration($om, $meta->getName()); if (isset($config['fields'])) { $wrapped = AbstractWrapper::wrap($object, $om); @@ -468,7 +467,7 @@ public function postPersist(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); // check if entity is tracked by translatable and without foreign key if ($this->getConfiguration($om, $meta->getName()) && [] !== $this->pendingTranslationInserts) { $oid = spl_object_id($object); @@ -476,7 +475,7 @@ public function postPersist(EventArgs $args) // load the pending translations without key $wrapped = AbstractWrapper::wrap($object, $om); $objectId = $wrapped->getIdentifier(); - $translationClass = $this->getTranslationClass($ea, get_class($object)); + $translationClass = $this->getTranslationClass($ea, $object::class); foreach ($this->pendingTranslationInserts[$oid] as $translation) { if ($ea->usesPersonalTranslation($translationClass)) { $translation->setObject($objectId); @@ -505,7 +504,7 @@ public function postLoad(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $config = $this->getConfiguration($om, $meta->getName()); $locale = $this->defaultLocale; $oid = null; @@ -660,7 +659,7 @@ private function handleTranslatableObjectUpdate(TranslatableAdapter $ea, object $translation = null; foreach ($ea->getScheduledObjectInsertions($uow) as $trans) { if ($locale !== $this->defaultLocale - && get_class($trans) === $translationClass + && $trans::class === $translationClass && $trans->getLocale() === $this->defaultLocale && $trans->getField() === $field && $this->belongsToObject($ea, $trans, $object)) { @@ -672,7 +671,7 @@ private function handleTranslatableObjectUpdate(TranslatableAdapter $ea, object // lookup persisted translations foreach ($ea->getScheduledObjectInsertions($uow) as $trans) { - if (get_class($trans) !== $translationClass + if ($trans::class !== $translationClass || $trans->getLocale() !== $locale || $trans->getField() !== $field) { continue; @@ -818,7 +817,7 @@ private function removeTranslationInDefaultLocale(int $oid, string $field): void * * @return object|Translatable|null Returns translation object if it exists or NULL otherwise */ - private function getTranslationInDefaultLocale(int $oid, string $field) + private function getTranslationInDefaultLocale(int $oid, string $field): ?object { return $this->translationInDefaultLocale[$oid][$field] ?? null; } @@ -828,11 +827,11 @@ private function getTranslationInDefaultLocale(int $oid, string $field) */ private function belongsToObject(TranslatableAdapter $ea, object $trans, object $object): bool { - if ($ea->usesPersonalTranslation(get_class($trans))) { + if ($ea->usesPersonalTranslation($trans::class)) { return $trans->getObject() === $object; } return $trans->getForeignKey() === $object->getId() - && ($trans->getObjectClass() === get_class($object)); + && ($trans->getObjectClass() === $object::class); } } diff --git a/src/Translator/TranslationProxy.php b/src/Translator/TranslationProxy.php index 937f5a1dc6..2fe6b45cfb 100644 --- a/src/Translator/TranslationProxy.php +++ b/src/Translator/TranslationProxy.php @@ -18,24 +18,11 @@ */ class TranslationProxy { - /** - * @var string - */ - protected $locale; - /** - * @var object - */ - protected $translatable; /** * @var string[] */ protected $properties = []; - /** - * @var string - * - * @phpstan-var class-string - */ - protected $class; + /** * @var Collection */ @@ -54,16 +41,18 @@ class TranslationProxy * * @throws \InvalidArgumentException Translation class doesn't implement TranslationInterface */ - public function __construct($translatable, $locale, array $properties, $class, Collection $coll) - { - $this->translatable = $translatable; - $this->locale = $locale; + public function __construct( + protected $translatable, + protected $locale, + array $properties, + protected $class, + Collection $coll + ) { $this->properties = $properties; - $this->class = $class; $this->coll = $coll; - if (!is_subclass_of($class, TranslationInterface::class)) { - throw new \InvalidArgumentException(sprintf('Translation class should implement %s, "%s" given', TranslationInterface::class, $class)); + if (!is_subclass_of($this->class, TranslationInterface::class)) { + throw new \InvalidArgumentException(sprintf('Translation class should implement %s, "%s" given', TranslationInterface::class, $this->class)); } } diff --git a/src/Tree/Document/MongoDB/Repository/MaterializedPathRepository.php b/src/Tree/Document/MongoDB/Repository/MaterializedPathRepository.php index d135c914db..c5201ac7da 100644 --- a/src/Tree/Document/MongoDB/Repository/MaterializedPathRepository.php +++ b/src/Tree/Document/MongoDB/Repository/MaterializedPathRepository.php @@ -116,7 +116,7 @@ public function getChildrenQueryBuilder($node = null, $direct = false, $sortByFi if (is_a($node, $meta->getName())) { $node = new MongoDocumentWrapper($node, $this->dm); - $nodePath = preg_quote($node->getPropertyValue($config['path'])); + $nodePath = preg_quote((string) $node->getPropertyValue($config['path'])); if ($direct) { $regex = sprintf( @@ -149,7 +149,7 @@ public function getChildrenQueryBuilder($node = null, $direct = false, $sortByFi } /** - * G{@inheritdoc} + * {@inheritdoc} */ public function getChildrenQuery($node = null, $direct = false, $sortByField = null, $direction = 'asc', $includeNode = false) { diff --git a/src/Tree/Entity/Repository/ClosureTreeRepository.php b/src/Tree/Entity/Repository/ClosureTreeRepository.php index 41933fdfa0..53af567779 100644 --- a/src/Tree/Entity/Repository/ClosureTreeRepository.php +++ b/src/Tree/Entity/Repository/ClosureTreeRepository.php @@ -407,7 +407,7 @@ public function getNodesHierarchyQueryBuilder($node = null, $direct = false, arr && isset($options['childSort']['field'], $options['childSort']['dir'])) { $q->addOrderBy( 'node.'.$options['childSort']['field'], - 'asc' === strtolower($options['childSort']['dir']) ? 'asc' : 'desc' + 'asc' === strtolower((string) $options['childSort']['dir']) ? 'asc' : 'desc' ); } diff --git a/src/Tree/Entity/Repository/MaterializedPathRepository.php b/src/Tree/Entity/Repository/MaterializedPathRepository.php index 88d416d9e6..d01f181444 100644 --- a/src/Tree/Entity/Repository/MaterializedPathRepository.php +++ b/src/Tree/Entity/Repository/MaterializedPathRepository.php @@ -98,10 +98,10 @@ public function getPathQueryBuilder($node) $node = new EntityWrapper($node, $this->getEntityManager()); $nodePath = $node->getPropertyValue($config['path']); $paths = []; - $nodePathLength = strlen($nodePath); + $nodePathLength = strlen((string) $nodePath); $separatorMatchOffset = 0; while ($separatorMatchOffset < $nodePathLength) { - $separatorPos = strpos($nodePath, $config['path_separator'], $separatorMatchOffset); + $separatorPos = strpos((string) $nodePath, $config['path_separator'], $separatorMatchOffset); if (false === $separatorPos || $separatorPos === $nodePathLength - 1) { // last node, done @@ -112,7 +112,7 @@ public function getPathQueryBuilder($node) $separatorMatchOffset = 1; } else { // add node - $paths[] = substr($nodePath, 0, $config['path_ends_with_separator'] ? $separatorPos + 1 : $separatorPos); + $paths[] = substr((string) $nodePath, 0, $config['path_ends_with_separator'] ? $separatorPos + 1 : $separatorPos); $separatorMatchOffset = $separatorPos + 1; } } @@ -254,7 +254,7 @@ public function getNodesHierarchy($node = null, $direct = false, array $options $nodes = $this->getNodesHierarchyQuery($node, $direct, $options, $includeNode)->getArrayResult(); usort( $nodes, - static fn (array $a, array $b): int => strcmp($a[$path], $b[$path]) + static fn (array $a, array $b): int => strcmp((string) $a[$path], (string) $b[$path]) ); return $nodes; diff --git a/src/Tree/Entity/Repository/NestedTreeRepository.php b/src/Tree/Entity/Repository/NestedTreeRepository.php index f45f499137..5b7b6f4064 100644 --- a/src/Tree/Entity/Repository/NestedTreeRepository.php +++ b/src/Tree/Entity/Repository/NestedTreeRepository.php @@ -215,7 +215,7 @@ public function getPathAsString(object $node, array $options = []): string throw new InvalidArgumentException(sprintf('"stringMethod" option passed in argument 2 to %s must be a valid string.', __METHOD__)); } if (!method_exists($node, $options['stringMethod'])) { - throw new InvalidArgumentException(sprintf('%s must implement method "%s".', get_class($node), $options['stringMethod'])); + throw new InvalidArgumentException(sprintf('%s must implement method "%s".', $node::class, $options['stringMethod'])); } $path = []; @@ -1112,7 +1112,7 @@ public function getNodesHierarchy($node = null, $direct = false, array $options */ protected function doCallWithCompat($method, $args) { - if ('persistAs' === substr($method, 0, 9)) { + if (str_starts_with($method, 'persistAs')) { if (!isset($args[0])) { throw new InvalidArgumentException('Node to persist must be available as first argument.'); } @@ -1121,7 +1121,7 @@ protected function doCallWithCompat($method, $args) $meta = $this->getClassMetadata(); $config = $this->listener->getConfiguration($this->getEntityManager(), $meta->getName()); $position = substr($method, 9); - if ('Of' === substr($method, -2)) { + if (str_ends_with($method, 'Of')) { if (!isset($args[1])) { throw new InvalidArgumentException('If "Of" is specified you must provide parent or sibling as the second argument.'); } @@ -1140,7 +1140,7 @@ protected function doCallWithCompat($method, $args) 'Not implementing the "%s" interface from node "%s" is deprecated since gedmo/doctrine-extensions' .' 3.13 and will throw a "%s" error in version 4.0.', Node::class, - \get_class($node), + $node::class, \TypeError::class ); } diff --git a/src/Tree/Hydrator/ORM/TreeObjectHydrator.php b/src/Tree/Hydrator/ORM/TreeObjectHydrator.php index cb16778419..52d80ce766 100644 --- a/src/Tree/Hydrator/ORM/TreeObjectHydrator.php +++ b/src/Tree/Hydrator/ORM/TreeObjectHydrator.php @@ -24,6 +24,8 @@ * @author Ilija Tovilo * * @final since gedmo/doctrine-extensions 3.11 + * + * @phpstan-import-type TreeConfiguration from TreeListener */ class TreeObjectHydrator extends ObjectHydrator { @@ -32,23 +34,16 @@ class TreeObjectHydrator extends ObjectHydrator /** * @var array + * + * @phpstan-var TreeConfiguration */ - private $config = []; + private array $config = []; - /** - * @var string - */ - private $idField; + private string $idField = ''; - /** - * @var string - */ - private $parentField; + private string $parentField = ''; - /** - * @var string - */ - private $childrenField; + private string $childrenField = ''; /** * @param object $object @@ -59,7 +54,7 @@ class TreeObjectHydrator extends ObjectHydrator */ public function setPropertyValue($object, $property, $value) { - $meta = $this->getEntityManager()->getClassMetadata(get_class($object)); + $meta = $this->getEntityManager()->getClassMetadata($object::class); $meta->getReflectionProperty($property)->setValue($object, $value); } @@ -285,7 +280,7 @@ protected function getEntityClassFromHydratedData($data) $firstMappedEntity = array_values($data); $firstMappedEntity = $firstMappedEntity[0]; - return $this->getEntityManager()->getClassMetadata(get_class($firstMappedEntity))->rootEntityName; + return $this->getEntityManager()->getClassMetadata($firstMappedEntity::class)->rootEntityName; } /** @@ -296,7 +291,7 @@ protected function getEntityClassFromHydratedData($data) */ protected function getPropertyValue($object, $property) { - $meta = $this->getEntityManager()->getClassMetadata(get_class($object)); + $meta = $this->getEntityManager()->getClassMetadata($object::class); return $meta->getReflectionProperty($property)->getValue($object); } diff --git a/src/Tree/Mapping/Driver/Annotation.php b/src/Tree/Mapping/Driver/Annotation.php index d37d20c7d5..639de941a6 100644 --- a/src/Tree/Mapping/Driver/Annotation.php +++ b/src/Tree/Mapping/Driver/Annotation.php @@ -18,6 +18,4 @@ * * @internal */ -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/src/Tree/Mapping/Driver/Attribute.php b/src/Tree/Mapping/Driver/Attribute.php index e8547aac6a..1c1d612e6a 100644 --- a/src/Tree/Mapping/Driver/Attribute.php +++ b/src/Tree/Mapping/Driver/Attribute.php @@ -304,7 +304,7 @@ public function readExtendedMetadata($meta, array &$config) throw new InvalidMappingException("Tree does not support composite identifiers in class - {$meta->getName()}"); } - $method = 'validate'.ucfirst($config['strategy']).'TreeMetadata'; + $method = 'validate'.ucfirst((string) $config['strategy']).'TreeMetadata'; $validator->$method($meta, $config); } else { throw new InvalidMappingException("Cannot find Tree type for class: {$meta->getName()}"); diff --git a/src/Tree/Mapping/Driver/Xml.php b/src/Tree/Mapping/Driver/Xml.php index 383af002ae..6fd267b994 100644 --- a/src/Tree/Mapping/Driver/Xml.php +++ b/src/Tree/Mapping/Driver/Xml.php @@ -247,7 +247,7 @@ public function readExtendedMetadata($meta, array &$config) if (is_array($meta->getIdentifier()) && count($meta->getIdentifier()) > 1) { throw new InvalidMappingException("Tree does not support composite identifiers in class - {$meta->getName()}"); } - $method = 'validate'.ucfirst($config['strategy']).'TreeMetadata'; + $method = 'validate'.ucfirst((string) $config['strategy']).'TreeMetadata'; $validator->$method($meta, $config); } else { throw new InvalidMappingException("Cannot find Tree type for class: {$meta->getName()}"); diff --git a/src/Tree/Mapping/Driver/Yaml.php b/src/Tree/Mapping/Driver/Yaml.php index d7cfe555cd..a1de0e18d4 100644 --- a/src/Tree/Mapping/Driver/Yaml.php +++ b/src/Tree/Mapping/Driver/Yaml.php @@ -128,7 +128,7 @@ public function readExtendedMetadata($meta, array &$config) $separator = '|'; } - if (strlen($separator) > 1) { + if (strlen((string) $separator) > 1) { throw new InvalidMappingException("Tree Path field - [{$field}] Separator {$separator} is invalid. It must be only one character long."); } @@ -205,7 +205,7 @@ public function readExtendedMetadata($meta, array &$config) if (is_array($meta->getIdentifier()) && count($meta->getIdentifier()) > 1) { throw new InvalidMappingException("Tree does not support composite identifiers in class - {$meta->getName()}"); } - $method = 'validate'.ucfirst($config['strategy']).'TreeMetadata'; + $method = 'validate'.ucfirst((string) $config['strategy']).'TreeMetadata'; $validator->$method($meta, $config); } else { throw new InvalidMappingException("Cannot find Tree type for class: {$meta->getName()}"); diff --git a/src/Tree/Mapping/Event/TreeAdapter.php b/src/Tree/Mapping/Event/TreeAdapter.php index 239e2c8035..f4e7309d6b 100644 --- a/src/Tree/Mapping/Event/TreeAdapter.php +++ b/src/Tree/Mapping/Event/TreeAdapter.php @@ -16,6 +16,4 @@ * * @author Gediminas Morkevicius */ -interface TreeAdapter extends AdapterInterface -{ -} +interface TreeAdapter extends AdapterInterface {} diff --git a/src/Tree/RepositoryUtils.php b/src/Tree/RepositoryUtils.php index cad3eafe91..2f477a6dad 100644 --- a/src/Tree/RepositoryUtils.php +++ b/src/Tree/RepositoryUtils.php @@ -27,15 +27,9 @@ class RepositoryUtils implements RepositoryUtilsInterface /** @var ClassMetadata */ protected $meta; - /** @var TreeListener */ - protected $listener; - /** @var ObjectManager&(DocumentManager|EntityManagerInterface) */ protected $om; - /** @var RepositoryInterface */ - protected $repo; - /** * This index is used to hold the children of a node * when using any of the buildTree related methods. @@ -50,12 +44,10 @@ class RepositoryUtils implements RepositoryUtilsInterface * @param TreeListener $listener * @param RepositoryInterface $repo */ - public function __construct(ObjectManager $om, ClassMetadata $meta, $listener, $repo) + public function __construct(ObjectManager $om, ClassMetadata $meta, protected $listener, protected $repo) { $this->om = $om; $this->meta = $meta; - $this->listener = $listener; - $this->repo = $repo; } /** diff --git a/src/Tree/Strategy/AbstractMaterializedPath.php b/src/Tree/Strategy/AbstractMaterializedPath.php index f8aeba2248..9134427796 100644 --- a/src/Tree/Strategy/AbstractMaterializedPath.php +++ b/src/Tree/Strategy/AbstractMaterializedPath.php @@ -95,7 +95,7 @@ public function getName() public function processScheduledInsertion($om, $node, AdapterInterface $ea) { - $meta = $om->getClassMetadata(get_class($node)); + $meta = $om->getClassMetadata($node::class); // ID is always used in a path, // and if it is generated value from engine (like AUTO_INCREMENT), @@ -109,7 +109,7 @@ public function processScheduledInsertion($om, $node, AdapterInterface $ea) public function processScheduledUpdate($om, $node, AdapterInterface $ea) { - $meta = $om->getClassMetadata(get_class($node)); + $meta = $om->getClassMetadata($node::class); $config = $this->listener->getConfiguration($om, $meta->getName()); $uow = $om->getUnitOfWork(); $changeSet = $ea->getObjectChangeSet($uow, $node); @@ -119,7 +119,6 @@ public function processScheduledUpdate($om, $node, AdapterInterface $ea) $originalPath = $changeSet[$config['path']][0]; } else { $pathProp = $meta->getReflectionProperty($config['path']); - $pathProp->setAccessible(true); $originalPath = $pathProp->getValue($node); } @@ -179,13 +178,11 @@ public function processPreUpdate($om, $node) $this->processPreLockingActions($om, $node, self::ACTION_UPDATE); } - public function processMetadataLoad($om, $meta) - { - } + public function processMetadataLoad($om, $meta) {} public function processScheduledDelete($om, $node) { - $meta = $om->getClassMetadata(get_class($node)); + $meta = $om->getClassMetadata($node::class); $config = $this->listener->getConfiguration($om, $meta->getName()); $this->removeNode($om, $meta, $config, $node); @@ -201,20 +198,17 @@ public function processScheduledDelete($om, $node) */ public function updateNode(ObjectManager $om, $node, AdapterInterface $ea) { - $meta = $om->getClassMetadata(get_class($node)); + $meta = $om->getClassMetadata($node::class); $config = $this->listener->getConfiguration($om, $meta->getName()); $uow = $om->getUnitOfWork(); $parentProp = $meta->getReflectionProperty($config['parent']); - $parentProp->setAccessible(true); $parent = $parentProp->getValue($node); $pathProp = $meta->getReflectionProperty($config['path']); - $pathProp->setAccessible(true); $pathSourceProp = $meta->getReflectionProperty($config['path_source']); - $pathSourceProp->setAccessible(true); $path = (string) $pathSourceProp->getValue($node); // We need to avoid the presence of the path separator in the path source - if (false !== strpos($path, $config['path_separator'])) { + if (str_contains($path, $config['path_separator'])) { $msg = 'You can\'t use the Path separator ("%s") as a character for your PathSource field value.'; throw new RuntimeException(sprintf($msg, $config['path_separator'])); @@ -230,7 +224,6 @@ public function updateNode(ObjectManager $om, $node, AdapterInterface $ea) $identifier = $meta->getIdentifierValue($node); } else { $identifierProp = $meta->getReflectionProperty($meta->getSingleIdentifierFieldName()); - $identifierProp->setAccessible(true); $identifier = $identifierProp->getValue($node); } @@ -250,7 +243,7 @@ public function updateNode(ObjectManager $om, $node, AdapterInterface $ea) $parentPath = $pathProp->getValue($parent); // if parent path not ends with separator - if ($parentPath[strlen($parentPath) - 1] !== $config['path_separator']) { + if ($parentPath[strlen((string) $parentPath) - 1] !== $config['path_separator']) { // add separator $path = $pathProp->getValue($parent).$config['path_separator'].$path; } else { @@ -277,7 +270,6 @@ public function updateNode(ObjectManager $om, $node, AdapterInterface $ea) if (isset($config['path_hash'])) { $pathHash = md5($path); $pathHashProp = $meta->getReflectionProperty($config['path_hash']); - $pathHashProp->setAccessible(true); $pathHashProp->setValue($node, $pathHash); $changes[$config['path_hash']] = [null, $pathHash]; } @@ -298,7 +290,6 @@ public function updateNode(ObjectManager $om, $node, AdapterInterface $ea) } $rootProp = $meta->getReflectionProperty($config['root']); - $rootProp->setAccessible(true); $rootProp->setValue($node, $root); $changes[$config['root']] = [null, $root]; } @@ -306,7 +297,6 @@ public function updateNode(ObjectManager $om, $node, AdapterInterface $ea) if (isset($config['level'])) { $level = substr_count($path, $config['path_separator']); $levelProp = $meta->getReflectionProperty($config['level']); - $levelProp->setAccessible(true); $levelProp->setValue($node, $level); $changes[$config['level']] = [null, $level]; } @@ -332,7 +322,7 @@ public function updateNode(ObjectManager $om, $node, AdapterInterface $ea) */ public function updateChildren(ObjectManager $om, $node, AdapterInterface $ea, $originalPath) { - $meta = $om->getClassMetadata(get_class($node)); + $meta = $om->getClassMetadata($node::class); $config = $this->listener->getConfiguration($om, $meta->getName()); $children = $this->getChildren($om, $meta, $config, $originalPath); @@ -352,12 +342,11 @@ public function updateChildren(ObjectManager $om, $node, AdapterInterface $ea, $ */ public function processPreLockingActions($om, $node, $action) { - $meta = $om->getClassMetadata(get_class($node)); + $meta = $om->getClassMetadata($node::class); $config = $this->listener->getConfiguration($om, $meta->getName()); if ($config['activate_locking']) { $parentProp = $meta->getReflectionProperty($config['parent']); - $parentProp->setAccessible(true); $parentNode = $node; while (($parent = $parentProp->getValue($parentNode)) !== null) { @@ -373,7 +362,6 @@ public function processPreLockingActions($om, $node, $action) // If tree is already locked, we throw an exception $lockTimeProp = $meta->getReflectionProperty($config['lock_time']); - $lockTimeProp->setAccessible(true); $lockTime = $lockTimeProp->getValue($parentNode); if (null !== $lockTime) { @@ -420,7 +408,7 @@ public function processPreLockingActions($om, $node, $action) */ public function processPostEventsActions(ObjectManager $om, AdapterInterface $ea, $node, $action) { - $meta = $om->getClassMetadata(get_class($node)); + $meta = $om->getClassMetadata($node::class); $config = $this->listener->getConfiguration($om, $meta->getName()); if ($config['activate_locking']) { diff --git a/src/Tree/Strategy/ODM/MongoDB/MaterializedPath.php b/src/Tree/Strategy/ODM/MongoDB/MaterializedPath.php index 1a5814c2e8..523a47e976 100644 --- a/src/Tree/Strategy/ODM/MongoDB/MaterializedPath.php +++ b/src/Tree/Strategy/ODM/MongoDB/MaterializedPath.php @@ -38,7 +38,7 @@ public function removeNode($om, $meta, $config, $node) // Remove node's children $results = $om->createQueryBuilder() ->find($meta->getName()) - ->field($config['path'])->equals(new Regex('^'.preg_quote($wrapped->getPropertyValue($config['path'])).'.?+')) + ->field($config['path'])->equals(new Regex('^'.preg_quote((string) $wrapped->getPropertyValue($config['path'])).'.?+')) ->getQuery() ->getIterator(); @@ -69,10 +69,9 @@ protected function lockTrees(ObjectManager $om, AdapterInterface $ea) $uow = $om->getUnitOfWork(); foreach ($this->rootsOfTreesWhichNeedsLocking as $root) { - $meta = $om->getClassMetadata(get_class($root)); + $meta = $om->getClassMetadata($root::class); $config = $this->listener->getConfiguration($om, $meta->getName()); $lockTimeProp = $meta->getReflectionProperty($config['lock_time']); - $lockTimeProp->setAccessible(true); $lockTimeValue = new UTCDateTime(); $lockTimeProp->setValue($root, $lockTimeValue); @@ -88,10 +87,9 @@ protected function releaseTreeLocks(ObjectManager $om, AdapterInterface $ea) $uow = $om->getUnitOfWork(); foreach ($this->rootsOfTreesWhichNeedsLocking as $oid => $root) { - $meta = $om->getClassMetadata(get_class($root)); + $meta = $om->getClassMetadata($root::class); $config = $this->listener->getConfiguration($om, $meta->getName()); $lockTimeProp = $meta->getReflectionProperty($config['lock_time']); - $lockTimeProp->setAccessible(true); $lockTimeValue = null; $lockTimeProp->setValue($root, $lockTimeValue); diff --git a/src/Tree/Strategy/ORM/Closure.php b/src/Tree/Strategy/ORM/Closure.php index ec2d98720a..dcf75ffe31 100644 --- a/src/Tree/Strategy/ORM/Closure.php +++ b/src/Tree/Strategy/ORM/Closure.php @@ -242,7 +242,7 @@ public function processMetadataLoad($em, $meta) if (!$hasTheUserExplicitlyDefinedMapping) { $metadataFactory = $em->getMetadataFactory(); - $getCache = \Closure::bind(static fn (AbstractClassMetadataFactory $metadataFactory): ?CacheItemPoolInterface => $metadataFactory->getCache(), null, \get_class($metadataFactory)); + $getCache = \Closure::bind(static fn (AbstractClassMetadataFactory $metadataFactory): ?CacheItemPoolInterface => $metadataFactory->getCache(), null, $metadataFactory::class); $metadataCache = $getCache($metadataFactory); @@ -258,35 +258,25 @@ public function processMetadataLoad($em, $meta) } } - public function onFlushEnd($em, AdapterInterface $ea) - { - } + public function onFlushEnd($em, AdapterInterface $ea) {} public function processPrePersist($em, $node) { $this->pendingChildNodeInserts[spl_object_id($em)][spl_object_id($node)] = $node; } - public function processPreUpdate($em, $node) - { - } + public function processPreUpdate($em, $node) {} - public function processPreRemove($em, $node) - { - } + public function processPreRemove($em, $node) {} - public function processScheduledInsertion($em, $node, AdapterInterface $ea) - { - } + public function processScheduledInsertion($em, $node, AdapterInterface $ea) {} - public function processScheduledDelete($em, $entity) - { - } + public function processScheduledDelete($em, $entity) {} public function processPostUpdate($em, $entity, AdapterInterface $ea) { \assert($em instanceof EntityManagerInterface); - $meta = $em->getClassMetadata(get_class($entity)); + $meta = $em->getClassMetadata($entity::class); $config = $this->listener->getConfiguration($em, $meta->getName()); // Process TreeLevel field value @@ -295,9 +285,7 @@ public function processPostUpdate($em, $entity, AdapterInterface $ea) } } - public function processPostRemove($em, $entity, AdapterInterface $ea) - { - } + public function processPostRemove($em, $entity, AdapterInterface $ea) {} /** * @param EntityManagerInterface $em @@ -308,7 +296,7 @@ public function processPostPersist($em, $entity, AdapterInterface $ea) $emHash = spl_object_id($em); while ($node = array_shift($this->pendingChildNodeInserts[$emHash])) { - $meta = $em->getClassMetadata(get_class($node)); + $meta = $em->getClassMetadata($node::class); $config = $this->listener->getConfiguration($em, $meta->getName()); $identifier = $meta->getSingleIdentifierFieldName(); @@ -395,7 +383,7 @@ public function processPostPersist($em, $entity, AdapterInterface $ea) */ public function processScheduledUpdate($em, $node, AdapterInterface $ea) { - $meta = $em->getClassMetadata(get_class($node)); + $meta = $em->getClassMetadata($node::class); $config = $this->listener->getConfiguration($em, $meta->getName()); $uow = $em->getUnitOfWork(); $changeSet = $uow->getEntityChangeSet($node); @@ -528,7 +516,7 @@ protected function setLevelFieldOnPendingNodes(ObjectManager $em) assert(null !== $first); - $meta = $em->getClassMetadata(get_class($first)); + $meta = $em->getClassMetadata($first::class); unset($first); $identifier = $meta->getIdentifier(); $mapping = $meta->getFieldMapping($identifier[0]); diff --git a/src/Tree/Strategy/ORM/MaterializedPath.php b/src/Tree/Strategy/ORM/MaterializedPath.php index 20ecd85a47..a7d1c3b70f 100644 --- a/src/Tree/Strategy/ORM/MaterializedPath.php +++ b/src/Tree/Strategy/ORM/MaterializedPath.php @@ -32,7 +32,7 @@ public function removeNode($om, $meta, $config, $node) { $wrapped = AbstractWrapper::wrap($node, $om); - $path = addcslashes($wrapped->getPropertyValue($config['path']), '%'); + $path = addcslashes((string) $wrapped->getPropertyValue($config['path']), '%'); $separator = $config['path_ends_with_separator'] ? null : $config['path_separator']; diff --git a/src/Tree/Strategy/ORM/Nested.php b/src/Tree/Strategy/ORM/Nested.php index b43e3261fa..39b5a51b22 100644 --- a/src/Tree/Strategy/ORM/Nested.php +++ b/src/Tree/Strategy/ORM/Nested.php @@ -125,7 +125,7 @@ public function setNodePosition($oid, $position) public function processScheduledInsertion($em, $node, AdapterInterface $ea) { /** @var ClassMetadata $meta */ - $meta = $em->getClassMetadata(get_class($node)); + $meta = $em->getClassMetadata($node::class); $config = $this->listener->getConfiguration($em, $meta->getName()); $meta->getReflectionProperty($config['left'])->setValue($node, 0); @@ -145,7 +145,7 @@ public function processScheduledInsertion($em, $node, AdapterInterface $ea) */ public function processScheduledUpdate($em, $node, AdapterInterface $ea) { - $meta = $em->getClassMetadata(get_class($node)); + $meta = $em->getClassMetadata($node::class); $config = $this->listener->getConfiguration($em, $meta->getName()); $uow = $em->getUnitOfWork(); @@ -186,7 +186,7 @@ public function processScheduledUpdate($em, $node, AdapterInterface $ea) */ public function processPostPersist($em, $node, AdapterInterface $ea) { - $meta = $em->getClassMetadata(get_class($node)); + $meta = $em->getClassMetadata($node::class); $config = $this->listener->getConfiguration($em, $meta->getName()); $parent = $meta->getReflectionProperty($config['parent'])->getValue($node); @@ -198,7 +198,7 @@ public function processPostPersist($em, $node, AdapterInterface $ea) */ public function processScheduledDelete($em, $node) { - $meta = $em->getClassMetadata(get_class($node)); + $meta = $em->getClassMetadata($node::class); $config = $this->listener->getConfiguration($em, $meta->getName()); $uow = $em->getUnitOfWork(); @@ -238,29 +238,17 @@ public function onFlushEnd($em, AdapterInterface $ea) $this->treeEdges = []; } - public function processPreRemove($em, $node) - { - } + public function processPreRemove($em, $node) {} - public function processPrePersist($em, $node) - { - } + public function processPrePersist($em, $node) {} - public function processPreUpdate($em, $node) - { - } + public function processPreUpdate($em, $node) {} - public function processMetadataLoad($em, $meta) - { - } + public function processMetadataLoad($em, $meta) {} - public function processPostUpdate($em, $entity, AdapterInterface $ea) - { - } + public function processPostUpdate($em, $entity, AdapterInterface $ea) {} - public function processPostRemove($em, $entity, AdapterInterface $ea) - { - } + public function processPostRemove($em, $entity, AdapterInterface $ea) {} /** * Update the $node with a different $parent destination @@ -624,7 +612,7 @@ public function shiftRL(EntityManagerInterface $em, $class, $first, $delta, $roo assert(null !== $node); - $nodeMeta = $em->getClassMetadata(get_class($node)); + $nodeMeta = $em->getClassMetadata($node::class); /** @phpstan-ignore-next-line function.alreadyNarrowedType Property introduced in ORM 3.4 */ if (property_exists($nodeMeta, 'propertyAccessors')) { @@ -724,7 +712,7 @@ public function shiftRangeRL(EntityManagerInterface $em, $class, $first, $last, assert(null !== $node); - $nodeMeta = $em->getClassMetadata(get_class($node)); + $nodeMeta = $em->getClassMetadata($node::class); /** @phpstan-ignore-next-line function.alreadyNarrowedType Property introduced in ORM 3.4 */ if (property_exists($nodeMeta, 'propertyAccessors')) { diff --git a/src/Tree/TreeListener.php b/src/Tree/TreeListener.php index 8c73a45898..0fc57ced61 100644 --- a/src/Tree/TreeListener.php +++ b/src/Tree/TreeListener.php @@ -154,7 +154,7 @@ public function onFlush(EventArgs $args) // check all scheduled updates for TreeNodes foreach ($ea->getScheduledObjectInsertions($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($this->getConfiguration($om, $meta->getName())) { $this->usedClassesOnFlush[$meta->getName()] = null; $this->getStrategy($om, $meta->getName())->processScheduledInsertion($om, $object, $ea); @@ -163,7 +163,7 @@ public function onFlush(EventArgs $args) } foreach ($ea->getScheduledObjectUpdates($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($this->getConfiguration($om, $meta->getName())) { $this->usedClassesOnFlush[$meta->getName()] = null; $this->getStrategy($om, $meta->getName())->processScheduledUpdate($om, $object, $ea); @@ -171,7 +171,7 @@ public function onFlush(EventArgs $args) } foreach ($ea->getScheduledObjectDeletions($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($this->getConfiguration($om, $meta->getName())) { $this->usedClassesOnFlush[$meta->getName()] = null; $this->getStrategy($om, $meta->getName())->processScheduledDelete($om, $object); @@ -197,7 +197,7 @@ public function preRemove(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($this->getConfiguration($om, $meta->getName())) { $this->getStrategy($om, $meta->getName())->processPreRemove($om, $object); @@ -218,7 +218,7 @@ public function prePersist(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($this->getConfiguration($om, $meta->getName())) { $this->getStrategy($om, $meta->getName())->processPrePersist($om, $object); @@ -239,7 +239,7 @@ public function preUpdate(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($this->getConfiguration($om, $meta->getName())) { $this->getStrategy($om, $meta->getName())->processPreUpdate($om, $object); @@ -261,7 +261,7 @@ public function postPersist(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($this->getConfiguration($om, $meta->getName())) { $this->getStrategy($om, $meta->getName())->processPostPersist($om, $object, $ea); @@ -283,7 +283,7 @@ public function postUpdate(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($this->getConfiguration($om, $meta->getName())) { $this->getStrategy($om, $meta->getName())->processPostUpdate($om, $object, $ea); @@ -305,7 +305,7 @@ public function postRemove(EventArgs $args) $ea = $this->getEventAdapter($args); $om = $ea->getObjectManager(); $object = $ea->getObject(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($this->getConfiguration($om, $meta->getName())) { $this->getStrategy($om, $meta->getName())->processPostRemove($om, $object, $ea); diff --git a/src/Uploadable/Event/UploadableBaseEventArgs.php b/src/Uploadable/Event/UploadableBaseEventArgs.php index 4f96b7b166..0f2cadfc86 100644 --- a/src/Uploadable/Event/UploadableBaseEventArgs.php +++ b/src/Uploadable/Event/UploadableBaseEventArgs.php @@ -21,60 +21,27 @@ * * @author Gustavo Falco * @author Gediminas Morkevicius + * + * @phpstan-import-type UploadableConfiguration from UploadableListener */ abstract class UploadableBaseEventArgs extends EventArgs { /** - * The instance of the Uploadable listener that fired this event - */ - private UploadableListener $uploadableListener; - - private EntityManagerInterface $em; - - /** - * @todo Check if this property must be removed, as it is not used. - */ - private array $config = []; - - /** - * The Uploadable entity - * - * @var object - */ - private $entity; - - /** - * The configuration of the Uploadable extension for this entity class + * @param UploadableListener $uploadableListener The instance of the Uploadable listener that fired this event + * @param array $extensionConfiguration + * @param object $entity The Uploadable entity + * @param 'INSERT'|'UPDATE'|'DELETE' $action * - * @todo Check if this property must be removed, as it is never set. - * - * @var array - */ - private $extensionConfiguration; - - private FileInfoInterface $fileInfo; - - /** - * Is the file being created, updated or removed? - * This value can be: CREATE, UPDATE or DELETE - * - * @var string + * @phpstan-param UploadableConfiguration $extensionConfiguration */ - private $action; - - /** - * @param object $entity - * @param string $action - */ - public function __construct(UploadableListener $listener, EntityManagerInterface $em, array $config, FileInfoInterface $fileInfo, $entity, $action) - { - $this->uploadableListener = $listener; - $this->em = $em; - $this->config = $config; - $this->fileInfo = $fileInfo; - $this->entity = $entity; - $this->action = $action; - } + public function __construct( + private readonly UploadableListener $uploadableListener, + private readonly EntityManagerInterface $em, + private readonly array $extensionConfiguration, + private readonly FileInfoInterface $fileInfo, + private $entity, + private $action + ) {} /** * Retrieve the associated listener @@ -143,7 +110,9 @@ public function getObject() /** * Retrieve associated Uploadable extension configuration * - * @return array + * @return array + * + * @phpstan-return UploadableConfiguration */ public function getExtensionConfiguration() { @@ -161,9 +130,9 @@ public function getFileInfo() } /** - * Retrieve the action being performed to the entity: CREATE, UPDATE or DELETE + * Retrieve the action being performed to the object * - * @return string + * @return 'INSERT'|'UPDATE'|'DELETE' */ public function getAction() { diff --git a/src/Uploadable/Event/UploadablePostFileProcessEventArgs.php b/src/Uploadable/Event/UploadablePostFileProcessEventArgs.php index 5835f6aa47..3b3c6c0dd6 100644 --- a/src/Uploadable/Event/UploadablePostFileProcessEventArgs.php +++ b/src/Uploadable/Event/UploadablePostFileProcessEventArgs.php @@ -17,6 +17,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadablePostFileProcessEventArgs extends UploadableBaseEventArgs -{ -} +class UploadablePostFileProcessEventArgs extends UploadableBaseEventArgs {} diff --git a/src/Uploadable/Event/UploadablePreFileProcessEventArgs.php b/src/Uploadable/Event/UploadablePreFileProcessEventArgs.php index 465c099dde..7044dff628 100644 --- a/src/Uploadable/Event/UploadablePreFileProcessEventArgs.php +++ b/src/Uploadable/Event/UploadablePreFileProcessEventArgs.php @@ -17,6 +17,4 @@ * * @final since gedmo/doctrine-extensions 3.11 */ -class UploadablePreFileProcessEventArgs extends UploadableBaseEventArgs -{ -} +class UploadablePreFileProcessEventArgs extends UploadableBaseEventArgs {} diff --git a/src/Uploadable/Events.php b/src/Uploadable/Events.php index 7b81d1caae..b983eb95f5 100644 --- a/src/Uploadable/Events.php +++ b/src/Uploadable/Events.php @@ -34,7 +34,5 @@ final class Events */ public const uploadablePostFileProcess = 'uploadablePostFileProcess'; - private function __construct() - { - } + private function __construct() {} } diff --git a/src/Uploadable/Mapping/Driver/Annotation.php b/src/Uploadable/Mapping/Driver/Annotation.php index 2d9172a38b..021f9a5b06 100644 --- a/src/Uploadable/Mapping/Driver/Annotation.php +++ b/src/Uploadable/Mapping/Driver/Annotation.php @@ -21,6 +21,4 @@ * * @internal */ -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/src/Uploadable/Mapping/Validator.php b/src/Uploadable/Mapping/Validator.php index d158fb469b..13c66c7c5b 100644 --- a/src/Uploadable/Mapping/Validator.php +++ b/src/Uploadable/Mapping/Validator.php @@ -176,7 +176,7 @@ public static function validatePath($path) return; } - if (!is_dir($path) && !@mkdir($path, 0777, true)) { + if (!is_dir($path) && !@mkdir($path, 0o777, true)) { throw new UploadableInvalidPathException(sprintf('Unable to create "%s" directory.', $path)); } @@ -221,10 +221,10 @@ public static function validateConfiguration(ClassMetadata $meta, array &$config throw new InvalidMappingException(sprintf($msg, $meta->getName())); } - $config['allowedTypes'] = $config['allowedTypes'] ? (false !== strpos($config['allowedTypes'], ',') ? - explode(',', $config['allowedTypes']) : [$config['allowedTypes']]) : false; - $config['disallowedTypes'] = $config['disallowedTypes'] ? (false !== strpos($config['disallowedTypes'], ',') ? - explode(',', $config['disallowedTypes']) : [$config['disallowedTypes']]) : false; + $config['allowedTypes'] = $config['allowedTypes'] ? (str_contains((string) $config['allowedTypes'], ',') ? + explode(',', (string) $config['allowedTypes']) : [$config['allowedTypes']]) : false; + $config['disallowedTypes'] = $config['disallowedTypes'] ? (str_contains((string) $config['disallowedTypes'], ',') ? + explode(',', (string) $config['disallowedTypes']) : [$config['disallowedTypes']]) : false; if ($config['fileNameField']) { self::validateFileNameField($meta, $config['fileNameField']); diff --git a/src/Uploadable/UploadableListener.php b/src/Uploadable/UploadableListener.php index 7dfa8cacea..3f7e22f747 100644 --- a/src/Uploadable/UploadableListener.php +++ b/src/Uploadable/UploadableListener.php @@ -36,7 +36,9 @@ use Gedmo\Uploadable\Event\UploadablePreFileProcessEventArgs; use Gedmo\Uploadable\FileInfo\FileInfoArray; use Gedmo\Uploadable\FileInfo\FileInfoInterface; +use Gedmo\Uploadable\FilenameGenerator\FilenameGeneratorAlphanumeric; use Gedmo\Uploadable\FilenameGenerator\FilenameGeneratorInterface; +use Gedmo\Uploadable\FilenameGenerator\FilenameGeneratorSha1; use Gedmo\Uploadable\Mapping\Validator; use Gedmo\Uploadable\MimeType\MimeTypeGuesser; use Gedmo\Uploadable\MimeType\MimeTypeGuesserInterface; @@ -73,15 +75,8 @@ class UploadableListener extends MappedEventSubscriber /** * Default path to move files in - * - * @var string - */ - private $defaultPath; - - /** - * Mime type guesser */ - private MimeTypeGuesserInterface $mimeTypeGuesser; + private ?string $defaultPath = null; /** * Default FileInfoInterface class @@ -107,11 +102,9 @@ class UploadableListener extends MappedEventSubscriber */ private array $fileInfoObjects = []; - public function __construct(?MimeTypeGuesserInterface $mimeTypeGuesser = null) + public function __construct(private MimeTypeGuesserInterface $mimeTypeGuesser = new MimeTypeGuesser()) { parent::__construct(); - - $this->mimeTypeGuesser = $mimeTypeGuesser ?? new MimeTypeGuesser(); } /** @@ -152,7 +145,7 @@ public function preFlush(EventArgs $args) foreach ($this->fileInfoObjects as $info) { $entity = $info['entity']; - $meta = $om->getClassMetadata(get_class($entity)); + $meta = $om->getClassMetadata($entity::class); $config = $this->getConfiguration($om, $meta->getName()); // If the entity is in the identity map, it means it will be updated. We need to force the @@ -204,7 +197,7 @@ public function onFlush(EventArgs $args) // Do we need to remove any files? foreach ($ea->getScheduledObjectDeletions($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); if ($config = $this->getConfiguration($om, $meta->getName())) { if (isset($config['uploadable']) && $config['uploadable']) { @@ -252,7 +245,7 @@ public function processFile(AdapterInterface $ea, $object, $action) $om = $ea->getObjectManager(); \assert($om instanceof EntityManagerInterface); $uow = $om->getUnitOfWork(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $config = $this->getConfiguration($om, $meta->getName()); if (!$config || !isset($config['uploadable']) || !$config['uploadable']) { @@ -313,24 +306,12 @@ public function processFile(AdapterInterface $ea, $object, $action) } // We generate the filename based on configuration - $generatorNamespace = 'Gedmo\Uploadable\FilenameGenerator'; - - switch ($config['filenameGenerator']) { - case Validator::FILENAME_GENERATOR_ALPHANUMERIC: - $generatorClass = $generatorNamespace.'\FilenameGeneratorAlphanumeric'; - - break; - case Validator::FILENAME_GENERATOR_SHA1: - $generatorClass = $generatorNamespace.'\FilenameGeneratorSha1'; - - break; - case Validator::FILENAME_GENERATOR_NONE: - $generatorClass = false; - - break; - default: - $generatorClass = $config['filenameGenerator']; - } + $generatorClass = match ($config['filenameGenerator']) { + Validator::FILENAME_GENERATOR_ALPHANUMERIC => FilenameGeneratorAlphanumeric::class, + Validator::FILENAME_GENERATOR_SHA1 => FilenameGeneratorSha1::class, + Validator::FILENAME_GENERATOR_NONE => false, + default => $config['filenameGenerator'], + }; $info = $this->moveFile($fileInfo, $path, $generatorClass, $config['allowOverwrite'], $config['appendNumber'], $object); @@ -339,7 +320,6 @@ public function processFile(AdapterInterface $ea, $object, $action) if ('' !== $config['callback']) { $callbackMethod = $refl->getMethod($config['callback']); - $callbackMethod->setAccessible(true); $callbackMethod->invokeArgs($object, [$info]); } @@ -466,7 +446,7 @@ public function moveFile(FileInfoInterface $fileInfo, $path, $filenameGeneratorC 'fileSize' => $fileInfo->getSize(), ]; - $info['fileName'] = basename($fileInfo->getName()); + $info['fileName'] = basename((string) $fileInfo->getName()); $info['filePath'] = $path.'/'.$info['fileName']; $hasExtension = strrpos($info['fileName'], '.'); @@ -624,7 +604,7 @@ public function addEntityFileInfo($entity, $fileInfo) if (!$fileInfo instanceof FileInfoInterface) { $msg = 'You must pass an instance of FileInfoInterface or a valid array for entity of class "%s".'; - throw new \RuntimeException(sprintf($msg, get_class($entity))); + throw new \RuntimeException(sprintf($msg, $entity::class)); } $this->fileInfoObjects[spl_object_id($entity)] = [ @@ -643,7 +623,7 @@ public function getEntityFileInfo($entity) $oid = spl_object_id($entity); if (!isset($this->fileInfoObjects[$oid])) { - throw new \RuntimeException(sprintf('There\'s no FileInfoInterface object for entity of class "%s".', get_class($entity))); + throw new \RuntimeException(sprintf('There\'s no FileInfoInterface object for entity of class "%s".', $entity::class)); } return $this->fileInfoObjects[$oid]['fileInfo']; @@ -670,6 +650,8 @@ public function getMimeTypeGuesser() * @param array $config * @param object $object Entity * + * @phpstan-param UploadableConfiguration $config + * * @throws UploadableNoPathDefinedException * * @return string @@ -703,6 +685,8 @@ protected function getPath(ClassMetadata $meta, array $config, $object) * @param array $config * @param object $object Entity * + * @phpstan-param UploadableConfiguration $config + * * @return void */ protected function addFileRemoval($meta, $config, $object) @@ -753,6 +737,8 @@ protected function getPropertyValueFromObject(ClassMetadata $meta, $propertyName * @param array $config * @param object $object * + * @phpstan-param UploadableConfiguration $config + * * @return string */ protected function getFilePathFieldValue(ClassMetadata $meta, array $config, $object) @@ -767,6 +753,8 @@ protected function getFilePathFieldValue(ClassMetadata $meta, array $config, $ob * @param array $config * @param object $object * + * @phpstan-param UploadableConfiguration $config + * * @return string */ protected function getFileNameFieldValue(ClassMetadata $meta, array $config, $object) diff --git a/tests/Gedmo/Blameable/Fixture/Document/Article.php b/tests/Gedmo/Blameable/Fixture/Document/Article.php index 796923e552..a0a6f669f3 100644 --- a/tests/Gedmo/Blameable/Fixture/Document/Article.php +++ b/tests/Gedmo/Blameable/Fixture/Document/Article.php @@ -23,11 +23,9 @@ class Article { /** * @ODM\Id - * - * @var string|null */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Blameable/Fixture/Document/Type.php b/tests/Gedmo/Blameable/Fixture/Document/Type.php index e4b5425004..ee32b24b50 100644 --- a/tests/Gedmo/Blameable/Fixture/Document/Type.php +++ b/tests/Gedmo/Blameable/Fixture/Document/Type.php @@ -22,11 +22,9 @@ class Type { /** * @ODM\Id - * - * @var string|null */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Blameable/Fixture/Document/User.php b/tests/Gedmo/Blameable/Fixture/Document/User.php index 6a2255fa39..eb3176302e 100644 --- a/tests/Gedmo/Blameable/Fixture/Document/User.php +++ b/tests/Gedmo/Blameable/Fixture/Document/User.php @@ -22,11 +22,9 @@ class User { /** * @ODM\Id - * - * @var string|null */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Blameable/Fixture/Entity/Article.php b/tests/Gedmo/Blameable/Fixture/Entity/Article.php index 0ecb4263d5..a634752df1 100644 --- a/tests/Gedmo/Blameable/Fixture/Entity/Article.php +++ b/tests/Gedmo/Blameable/Fixture/Entity/Article.php @@ -25,8 +25,6 @@ class Article implements Blameable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Article implements Blameable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=128) diff --git a/tests/Gedmo/Blameable/Fixture/Entity/Comment.php b/tests/Gedmo/Blameable/Fixture/Entity/Comment.php index 6d93430f3b..c91dd036b0 100644 --- a/tests/Gedmo/Blameable/Fixture/Entity/Comment.php +++ b/tests/Gedmo/Blameable/Fixture/Entity/Comment.php @@ -23,8 +23,6 @@ class Comment implements Blameable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Comment implements Blameable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="message", type="text") @@ -53,26 +51,22 @@ class Comment implements Blameable private ?int $status = null; /** - * @var string|null - * * @ORM\Column(name="closed", type="string", nullable=true) * * @Gedmo\Blameable(on="change", field="status", value=1) */ #[ORM\Column(name: 'closed', type: Types::STRING, nullable: true)] #[Gedmo\Blameable(on: 'change', field: 'status', value: 1)] - private $closed; + private ?string $closed = null; /** - * @var string|null - * * @ORM\Column(name="modified", type="string") * * @Gedmo\Blameable(on="update") */ #[ORM\Column(name: 'modified', type: Types::STRING)] #[Gedmo\Blameable(on: 'update')] - private $modified; + private ?string $modified = null; public function setArticle(?Article $article): void { diff --git a/tests/Gedmo/Blameable/Fixture/Entity/Company.php b/tests/Gedmo/Blameable/Fixture/Entity/Company.php index 9c7d411f39..273e97d40e 100644 --- a/tests/Gedmo/Blameable/Fixture/Entity/Company.php +++ b/tests/Gedmo/Blameable/Fixture/Entity/Company.php @@ -25,8 +25,6 @@ class Company implements Blameable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Company implements Blameable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="name", type="string", length=128) @@ -43,15 +41,13 @@ class Company implements Blameable private ?string $name = null; /** - * @var UuidV6|string|null - * * @Gedmo\Blameable(on="create") * * @ORM\Column(name="created", type="uuid") */ #[ORM\Column(name: 'created', type: 'uuid')] #[Gedmo\Blameable(on: 'create')] - private $created; + private UuidV6|string|null $created = null; public function getId(): ?int { diff --git a/tests/Gedmo/Blameable/Fixture/Entity/MappedSupperClass.php b/tests/Gedmo/Blameable/Fixture/Entity/MappedSupperClass.php index 55f1f2c8de..f981ecb066 100644 --- a/tests/Gedmo/Blameable/Fixture/Entity/MappedSupperClass.php +++ b/tests/Gedmo/Blameable/Fixture/Entity/MappedSupperClass.php @@ -22,50 +22,39 @@ class MappedSupperClass { /** - * @var int|null - * - * @ORM\Column(name="id", type="integer") * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") + * @ORM\GeneratedValue + * @ORM\Column(type="integer") */ #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'AUTO')] - #[ORM\Column(name: 'id', type: Types::INTEGER)] - protected $id; + #[ORM\GeneratedValue] + #[ORM\Column(type: Types::INTEGER)] + protected ?int $id = null; /** - * @var string|null - * * @Gedmo\Locale */ #[Gedmo\Locale] - protected $locale; + protected ?string $locale = null; /** - * @var string|null - * * @Gedmo\Translatable * * @ORM\Column(name="name", type="string", length=191) */ #[Gedmo\Translatable] #[ORM\Column(name: 'name', type: Types::STRING, length: 191)] - protected $name; + protected ?string $name = null; /** - * @var string|null - * * @ORM\Column(name="created_by", type="string") * * @Gedmo\Blameable(on="create") */ #[ORM\Column(name: 'created_by', type: Types::STRING)] #[Gedmo\Blameable(on: 'create')] - protected $createdBy; + protected ?string $createdBy = null; - /** - * @codeCoverageIgnore - */ public function getId(): ?int { return $this->id; diff --git a/tests/Gedmo/Blameable/Fixture/Entity/Type.php b/tests/Gedmo/Blameable/Fixture/Entity/Type.php index 70149d5907..06daa50c59 100644 --- a/tests/Gedmo/Blameable/Fixture/Entity/Type.php +++ b/tests/Gedmo/Blameable/Fixture/Entity/Type.php @@ -23,8 +23,6 @@ class Type { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Type #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=128) diff --git a/tests/Gedmo/Blameable/Fixture/Entity/UsingTrait.php b/tests/Gedmo/Blameable/Fixture/Entity/UsingTrait.php index e4de7d04af..494a5676b6 100644 --- a/tests/Gedmo/Blameable/Fixture/Entity/UsingTrait.php +++ b/tests/Gedmo/Blameable/Fixture/Entity/UsingTrait.php @@ -21,15 +21,9 @@ #[ORM\Entity] class UsingTrait { - /* - * Hook Blameable behavior - * updates createdAt, updatedAt fields - */ use BlameableEntity; /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -37,7 +31,7 @@ class UsingTrait #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=128) diff --git a/tests/Gedmo/Blameable/Fixture/Entity/WithoutInterface.php b/tests/Gedmo/Blameable/Fixture/Entity/WithoutInterface.php index 653d9966ac..d26b02e815 100644 --- a/tests/Gedmo/Blameable/Fixture/Entity/WithoutInterface.php +++ b/tests/Gedmo/Blameable/Fixture/Entity/WithoutInterface.php @@ -22,8 +22,6 @@ class WithoutInterface { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class WithoutInterface #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(type="string", length=128) @@ -40,26 +38,22 @@ class WithoutInterface private ?string $title = null; /** - * @var string|null - * * @Gedmo\Blameable(on="create") * * @ORM\Column(type="string") */ #[ORM\Column(type: Types::STRING)] #[Gedmo\Blameable(on: 'create')] - private $created; + private ?string $created = null; /** - * @var string|null - * * @ORM\Column(type="string") * * @Gedmo\Blameable(on="update") */ #[ORM\Column(type: Types::STRING)] #[Gedmo\Blameable(on: 'update')] - private $updated; + private ?string $updated = null; public function getId(): ?int { diff --git a/tests/Gedmo/DoctrineExtensionsTest.php b/tests/Gedmo/DoctrineExtensionsTest.php index dcb91e19ff..aa41f5f1e8 100644 --- a/tests/Gedmo/DoctrineExtensionsTest.php +++ b/tests/Gedmo/DoctrineExtensionsTest.php @@ -11,7 +11,6 @@ namespace Gedmo\Tests; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\ODM\MongoDB\Mapping\Driver as DriverMongodbODM; use Doctrine\ORM\Mapping\Driver as DriverORM; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; @@ -23,9 +22,6 @@ */ final class DoctrineExtensionsTest extends TestCase { - /** - * @requires PHP >= 8.0 - */ public function testRegistersAttributeDriverForConcreteOrmEntitiesToChain(): void { $chain = new MappingDriverChain(); @@ -38,25 +34,6 @@ public function testRegistersAttributeDriverForConcreteOrmEntitiesToChain(): voi static::assertInstanceOf(DriverORM\AttributeDriver::class, $drivers['Gedmo'], 'The attribute driver should be registered to the chain on PHP 8'); } - public function testRegistersAnnotationDriverForConcreteOrmEntitiesToChain(): void - { - if (\PHP_VERSION_ID >= 80000 || !class_exists(AnnotationReader::class)) { - static::markTestSkipped('Test only applies to PHP 7 and requires the doctrine/annotations package'); - } - - $chain = new MappingDriverChain(); - - DoctrineExtensions::registerMappingIntoDriverChainORM($chain); - - $drivers = $chain->getDrivers(); - - static::assertArrayHasKey('Gedmo', $drivers); - static::assertInstanceOf(DriverORM\AnnotationDriver::class, $drivers['Gedmo'], 'The annotations driver should be registered to the chain on PHP 7'); - } - - /** - * @requires PHP >= 8.0 - */ public function testRegistersAttributeDriverForAbstractOrmSuperclassesToChain(): void { $chain = new MappingDriverChain(); @@ -69,25 +46,6 @@ public function testRegistersAttributeDriverForAbstractOrmSuperclassesToChain(): static::assertInstanceOf(DriverORM\AttributeDriver::class, $drivers['Gedmo'], 'The attribute driver should be registered to the chain on PHP 8'); } - public function testRegistersAnnotationDriverForAbstractOrmSuperclassesToChain(): void - { - if (\PHP_VERSION_ID >= 80000 || !class_exists(AnnotationReader::class)) { - static::markTestSkipped('Test only applies to PHP 7 and requires the doctrine/annotations package'); - } - - $chain = new MappingDriverChain(); - - DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($chain); - - $drivers = $chain->getDrivers(); - - static::assertArrayHasKey('Gedmo', $drivers); - static::assertInstanceOf(DriverORM\AnnotationDriver::class, $drivers['Gedmo'], 'The annotations driver should be registered to the chain on PHP 7'); - } - - /** - * @requires PHP >= 8.0 - */ public function testRegistersAttributeDriverForConcreteOdmDocumentsToChain(): void { if (!class_exists(DriverMongodbODM\AttributeDriver::class)) { @@ -104,25 +62,6 @@ public function testRegistersAttributeDriverForConcreteOdmDocumentsToChain(): vo static::assertInstanceOf(DriverMongodbODM\AttributeDriver::class, $drivers['Gedmo'], 'The attribute driver should be registered to the chain on PHP 8'); } - public function testRegistersAnnotationDriverForConcreteOdmDocumentsToChain(): void - { - if (\PHP_VERSION_ID >= 80000 || !class_exists(AnnotationReader::class)) { - static::markTestSkipped('Test only applies to PHP 7 and requires the doctrine/annotations package'); - } - - $chain = new MappingDriverChain(); - - DoctrineExtensions::registerMappingIntoDriverChainMongodbODM($chain); - - $drivers = $chain->getDrivers(); - - static::assertArrayHasKey('Gedmo', $drivers); - static::assertInstanceOf(DriverMongodbODM\AnnotationDriver::class, $drivers['Gedmo'], 'The annotations driver should be registered to the chain on PHP 7'); - } - - /** - * @requires PHP >= 8.0 - */ public function testRegistersAttributeDriverForAbstractOdmSuperclassesToChain(): void { if (!class_exists(DriverMongodbODM\AttributeDriver::class)) { @@ -138,20 +77,4 @@ public function testRegistersAttributeDriverForAbstractOdmSuperclassesToChain(): static::assertArrayHasKey('Gedmo', $drivers); static::assertInstanceOf(DriverMongodbODM\AttributeDriver::class, $drivers['Gedmo'], 'The attribute driver should be registered to the chain on PHP 8'); } - - public function testRegistersAnnotationDriverForAbstractOdmSuperclassesToChain(): void - { - if (\PHP_VERSION_ID >= 80000 || !class_exists(AnnotationReader::class)) { - static::markTestSkipped('Test only applies to PHP 7 and requires the doctrine/annotations package'); - } - - $chain = new MappingDriverChain(); - - DoctrineExtensions::registerAbstractMappingIntoDriverChainMongodbODM($chain); - - $drivers = $chain->getDrivers(); - - static::assertArrayHasKey('Gedmo', $drivers); - static::assertInstanceOf(DriverMongodbODM\AnnotationDriver::class, $drivers['Gedmo'], 'The annotations driver should be registered to the chain on PHP 7'); - } } diff --git a/tests/Gedmo/IpTraceable/ChangeTest.php b/tests/Gedmo/IpTraceable/ChangeTest.php index d0dc6dc95f..8f0b9a1bc2 100644 --- a/tests/Gedmo/IpTraceable/ChangeTest.php +++ b/tests/Gedmo/IpTraceable/ChangeTest.php @@ -25,10 +25,7 @@ final class ChangeTest extends BaseTestCaseORM { private const TEST_IP = '34.234.1.10'; - /** - * @var IpTraceableListener - */ - protected $listener; + private IpTraceableListener $listener; protected function setUp(): void { diff --git a/tests/Gedmo/IpTraceable/Fixture/Article.php b/tests/Gedmo/IpTraceable/Fixture/Article.php index 46797fe9a9..dcf69b613b 100644 --- a/tests/Gedmo/IpTraceable/Fixture/Article.php +++ b/tests/Gedmo/IpTraceable/Fixture/Article.php @@ -25,8 +25,6 @@ class Article implements IpTraceable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Article implements IpTraceable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=128) @@ -48,7 +46,7 @@ class Article implements IpTraceable * @ORM\OneToMany(targetEntity="Gedmo\Tests\IpTraceable\Fixture\Comment", mappedBy="article") */ #[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'article')] - private $comments; + private Collection $comments; /** * @Gedmo\IpTraceable(on="create") diff --git a/tests/Gedmo/IpTraceable/Fixture/Comment.php b/tests/Gedmo/IpTraceable/Fixture/Comment.php index 50c032f3ba..0f4bfac7df 100644 --- a/tests/Gedmo/IpTraceable/Fixture/Comment.php +++ b/tests/Gedmo/IpTraceable/Fixture/Comment.php @@ -23,8 +23,6 @@ class Comment implements IpTraceable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Comment implements IpTraceable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="message", type="text") @@ -53,26 +51,22 @@ class Comment implements IpTraceable private ?int $status = null; /** - * @var string|null - * * @ORM\Column(name="closed", type="string", length=45, nullable=true) * * @Gedmo\IpTraceable(on="change", field="status", value=1) */ #[ORM\Column(name: 'closed', type: Types::STRING, length: 45, nullable: true)] #[Gedmo\IpTraceable(on: 'change', field: 'status', value: 1)] - private $closed; + private ?string $closed = null; /** - * @var string|null - * * @ORM\Column(name="modified", type="string", length=45) * * @Gedmo\IpTraceable(on="update") */ #[ORM\Column(name: 'modified', type: Types::STRING, length: 45)] #[Gedmo\IpTraceable(on: 'update')] - private $modified; + private ?string $modified = null; public function setArticle(?Article $article): void { diff --git a/tests/Gedmo/IpTraceable/Fixture/Document/Article.php b/tests/Gedmo/IpTraceable/Fixture/Document/Article.php index a9f73dc0da..fdcd0ea0dd 100644 --- a/tests/Gedmo/IpTraceable/Fixture/Document/Article.php +++ b/tests/Gedmo/IpTraceable/Fixture/Document/Article.php @@ -22,12 +22,10 @@ class Article { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/IpTraceable/Fixture/Document/Type.php b/tests/Gedmo/IpTraceable/Fixture/Document/Type.php index 4f445fa0b5..dcd064fe73 100644 --- a/tests/Gedmo/IpTraceable/Fixture/Document/Type.php +++ b/tests/Gedmo/IpTraceable/Fixture/Document/Type.php @@ -21,12 +21,10 @@ class Type { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/IpTraceable/Fixture/MappedSupperClass.php b/tests/Gedmo/IpTraceable/Fixture/MappedSupperClass.php index 17353d90a3..7121a8aeff 100644 --- a/tests/Gedmo/IpTraceable/Fixture/MappedSupperClass.php +++ b/tests/Gedmo/IpTraceable/Fixture/MappedSupperClass.php @@ -22,50 +22,39 @@ class MappedSupperClass { /** - * @var int|null - * - * @ORM\Column(name="id", type="integer") * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") + * @ORM\GeneratedValue + * @ORM\Column(type="integer") */ #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'AUTO')] - #[ORM\Column(name: 'id', type: Types::INTEGER)] - protected $id; + #[ORM\GeneratedValue] + #[ORM\Column(type: Types::INTEGER)] + protected ?int $id = null; /** - * @var string|null - * * @Gedmo\Locale */ #[Gedmo\Locale] - protected $locale; + protected ?string $locale = null; /** - * @var string|null - * * @Gedmo\Translatable * * @ORM\Column(name="name", type="string", length=191) */ #[Gedmo\Translatable] #[ORM\Column(name: 'name', type: Types::STRING, length: 191)] - protected $name; + protected ?string $name = null; /** - * @var string|null - * * @ORM\Column(name="created_at", type="string", length=45) * * @Gedmo\IpTraceable(on="create") */ #[ORM\Column(name: 'created_at', type: Types::STRING, length: 45)] #[Gedmo\IpTraceable(on: 'create')] - protected $createdFromIp; + protected ?string $createdFromIp = null; - /** - * @codeCoverageIgnore - */ public function getId(): ?int { return $this->id; diff --git a/tests/Gedmo/IpTraceable/Fixture/Type.php b/tests/Gedmo/IpTraceable/Fixture/Type.php index 51e12e04b9..498c520b1f 100644 --- a/tests/Gedmo/IpTraceable/Fixture/Type.php +++ b/tests/Gedmo/IpTraceable/Fixture/Type.php @@ -23,8 +23,6 @@ class Type { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Type #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=128) diff --git a/tests/Gedmo/IpTraceable/Fixture/UsingTrait.php b/tests/Gedmo/IpTraceable/Fixture/UsingTrait.php index 5d4f891b56..3165d40349 100644 --- a/tests/Gedmo/IpTraceable/Fixture/UsingTrait.php +++ b/tests/Gedmo/IpTraceable/Fixture/UsingTrait.php @@ -21,15 +21,9 @@ #[ORM\Entity] class UsingTrait { - /* - * Hook ipTraceable behavior - * updates createdFromIp, updatedFromIp fields - */ use IpTraceableEntity; /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -37,7 +31,7 @@ class UsingTrait #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=128) diff --git a/tests/Gedmo/IpTraceable/Fixture/WithoutInterface.php b/tests/Gedmo/IpTraceable/Fixture/WithoutInterface.php index f83c2f3e25..428f54dfe0 100644 --- a/tests/Gedmo/IpTraceable/Fixture/WithoutInterface.php +++ b/tests/Gedmo/IpTraceable/Fixture/WithoutInterface.php @@ -22,8 +22,6 @@ class WithoutInterface { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class WithoutInterface #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(type="string", length=128) @@ -40,26 +38,22 @@ class WithoutInterface private ?string $title = null; /** - * @var string|null - * * @Gedmo\IpTraceable(on="create") * * @ORM\Column(type="string", length=45) */ #[ORM\Column(type: Types::STRING, length: 45)] #[Gedmo\IpTraceable(on: 'create')] - private $created; + private ?string $created = null; /** - * @var string|null - * * @ORM\Column(type="string", length=45) * * @Gedmo\IpTraceable(on="update") */ #[ORM\Column(type: Types::STRING, length: 45)] #[Gedmo\IpTraceable(on: 'update')] - private $updated; + private ?string $updated = null; public function getId(): ?int { diff --git a/tests/Gedmo/Loggable/AttributeLoggableEntityTest.php b/tests/Gedmo/Loggable/AttributeLoggableEntityTest.php index 23e6828b6a..5434d81a38 100644 --- a/tests/Gedmo/Loggable/AttributeLoggableEntityTest.php +++ b/tests/Gedmo/Loggable/AttributeLoggableEntityTest.php @@ -18,8 +18,6 @@ /** * These are tests for loggable behavior with an attribute reader * - * @requires PHP >= 8.0 - * * @author Gediminas Morkevicius */ final class AttributeLoggableEntityTest extends LoggableEntityTest diff --git a/tests/Gedmo/Loggable/Fixture/Document/Article.php b/tests/Gedmo/Loggable/Fixture/Document/Article.php index 2ff55057a1..a2ac8e1b83 100644 --- a/tests/Gedmo/Loggable/Fixture/Document/Article.php +++ b/tests/Gedmo/Loggable/Fixture/Document/Article.php @@ -23,15 +23,13 @@ */ #[ODM\Document(collection: 'articles')] #[Gedmo\Loggable] -class Article implements Loggable +class Article implements Loggable, \Stringable { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @Gedmo\Versioned @@ -51,9 +49,9 @@ class Article implements Loggable #[Gedmo\Versioned] private ?Author $author = null; - public function __toString() + public function __toString(): string { - return $this->title; + return (string) $this->title; } public function getId(): ?string diff --git a/tests/Gedmo/Loggable/Fixture/Document/Author.php b/tests/Gedmo/Loggable/Fixture/Document/Author.php index b6010d47d3..2965aa5708 100644 --- a/tests/Gedmo/Loggable/Fixture/Document/Author.php +++ b/tests/Gedmo/Loggable/Fixture/Document/Author.php @@ -23,7 +23,7 @@ */ #[ODM\EmbeddedDocument] #[Gedmo\Loggable] -class Author implements Loggable +class Author implements Loggable, \Stringable { /** * @Gedmo\Versioned @@ -43,7 +43,7 @@ class Author implements Loggable #[Gedmo\Versioned] private ?string $email = null; - public function __toString() + public function __toString(): string { return (string) $this->getName(); } diff --git a/tests/Gedmo/Loggable/Fixture/Document/Comment.php b/tests/Gedmo/Loggable/Fixture/Document/Comment.php index 939d31972a..2f6ac25e11 100644 --- a/tests/Gedmo/Loggable/Fixture/Document/Comment.php +++ b/tests/Gedmo/Loggable/Fixture/Document/Comment.php @@ -27,12 +27,10 @@ class Comment implements Loggable { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @Gedmo\Versioned diff --git a/tests/Gedmo/Loggable/Fixture/Document/Log/Comment.php b/tests/Gedmo/Loggable/Fixture/Document/Log/Comment.php index 61940d4023..17bf9158fc 100644 --- a/tests/Gedmo/Loggable/Fixture/Document/Log/Comment.php +++ b/tests/Gedmo/Loggable/Fixture/Document/Log/Comment.php @@ -25,6 +25,4 @@ * @phpstan-extends AbstractLogEntry */ #[ODM\Document(collection: 'test_comment_log_entries', repositoryClass: LogEntryRepository::class)] -class Comment extends AbstractLogEntry -{ -} +class Comment extends AbstractLogEntry {} diff --git a/tests/Gedmo/Loggable/Fixture/Document/RelatedArticle.php b/tests/Gedmo/Loggable/Fixture/Document/RelatedArticle.php index 08e848dc1b..b3fcdf30f1 100644 --- a/tests/Gedmo/Loggable/Fixture/Document/RelatedArticle.php +++ b/tests/Gedmo/Loggable/Fixture/Document/RelatedArticle.php @@ -28,12 +28,10 @@ class RelatedArticle implements Loggable { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @Gedmo\Versioned @@ -59,7 +57,7 @@ class RelatedArticle implements Loggable * @ODM\ReferenceMany(targetDocument="Gedmo\Tests\Loggable\Fixture\Document\Comment", mappedBy="article") */ #[ODM\ReferenceMany(targetDocument: Comment::class, mappedBy: 'article')] - private $comments; + private Collection $comments; public function __construct() { diff --git a/tests/Gedmo/Loggable/Fixture/Entity/Address.php b/tests/Gedmo/Loggable/Fixture/Entity/Address.php index 1b9f4ee86f..8550d53bc3 100644 --- a/tests/Gedmo/Loggable/Fixture/Entity/Address.php +++ b/tests/Gedmo/Loggable/Fixture/Entity/Address.php @@ -28,49 +28,41 @@ class Address implements Loggable { /** - * @var int|null - * * @ORM\Id - * @ORM\Column(name="id", type="integer") - * @ORM\GeneratedValue(strategy="AUTO") + * @ORM\GeneratedValue + * @ORM\Column(type="integer") */ #[ORM\Id] - #[ORM\Column(name: 'id', type: Types::INTEGER)] - #[ORM\GeneratedValue(strategy: 'AUTO')] - protected $id; + #[ORM\GeneratedValue] + #[ORM\Column(type: Types::INTEGER)] + protected ?int $id = null; /** - * @var string|null - * * @ORM\Column(type="string", length=191) * * @Gedmo\Versioned */ #[ORM\Column(type: Types::STRING, length: 191)] #[Gedmo\Versioned] - protected $street; + protected ?string $street = null; /** - * @var string|null - * * @ORM\Column(type="string", length=191) * * @Gedmo\Versioned */ #[ORM\Column(type: Types::STRING, length: 191)] #[Gedmo\Versioned] - protected $city; + protected ?string $city = null; /** - * @var Geo|null - * * @ORM\Embedded(class="Gedmo\Tests\Loggable\Fixture\Entity\Geo") * * @Gedmo\Versioned */ #[ORM\Embedded(class: Geo::class)] #[Gedmo\Versioned] - protected $geo; + protected ?Geo $geo = null; public function getId(): ?int { diff --git a/tests/Gedmo/Loggable/Fixture/Entity/Article.php b/tests/Gedmo/Loggable/Fixture/Entity/Article.php index dfb9bd209b..c37786302f 100644 --- a/tests/Gedmo/Loggable/Fixture/Entity/Article.php +++ b/tests/Gedmo/Loggable/Fixture/Entity/Article.php @@ -26,16 +26,14 @@ class Article implements Loggable { /** - * @var int|null - * - * @ORM\Column(name="id", type="integer") * @ORM\Id - * @ORM\GeneratedValue(strategy="IDENTITY") + * @ORM\GeneratedValue + * @ORM\Column(type="integer") */ #[ORM\Id] - #[ORM\Column(name: 'id', type: Types::INTEGER)] - #[ORM\GeneratedValue(strategy: 'IDENTITY')] - private $id; + #[ORM\GeneratedValue] + #[ORM\Column(type: Types::INTEGER)] + private ?int $id = null; /** * @Gedmo\Versioned diff --git a/tests/Gedmo/Loggable/Fixture/Entity/Comment.php b/tests/Gedmo/Loggable/Fixture/Entity/Comment.php index b50e2289ef..bfc0f64a01 100644 --- a/tests/Gedmo/Loggable/Fixture/Entity/Comment.php +++ b/tests/Gedmo/Loggable/Fixture/Entity/Comment.php @@ -27,16 +27,14 @@ class Comment implements Loggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ #[ORM\Id] - #[ORM\Column(type: Types::INTEGER)] #[ORM\GeneratedValue] - private $id; + #[ORM\Column(type: Types::INTEGER)] + private ?int $id = null; /** * @Gedmo\Versioned diff --git a/tests/Gedmo/Loggable/Fixture/Entity/Composite.php b/tests/Gedmo/Loggable/Fixture/Entity/Composite.php index c631d2a56c..19fb8940fc 100644 --- a/tests/Gedmo/Loggable/Fixture/Entity/Composite.php +++ b/tests/Gedmo/Loggable/Fixture/Entity/Composite.php @@ -22,22 +22,6 @@ #[Gedmo\Loggable] class Composite { - /** - * @ORM\Id - * @ORM\Column(type="integer") - */ - #[ORM\Id] - #[ORM\Column(name: 'one', type: Types::INTEGER)] - private int $one; - - /** - * @ORM\Id - * @ORM\Column(type="integer") - */ - #[ORM\Id] - #[ORM\Column(name: 'two', type: Types::INTEGER)] - private int $two; - /** * @ORM\Column(length=8) * @@ -47,11 +31,22 @@ class Composite #[Gedmo\Versioned] private ?string $title = null; - public function __construct(int $one, int $two) - { - $this->one = $one; - $this->two = $two; - } + public function __construct( + /** + * @ORM\Id + * @ORM\Column(type="integer") + */ + #[ORM\Id] + #[ORM\Column(name: 'one', type: Types::INTEGER)] + private int $one, + /** + * @ORM\Id + * @ORM\Column(type="integer") + */ + #[ORM\Id] + #[ORM\Column(name: 'two', type: Types::INTEGER)] + private int $two + ) {} public function getOne(): int { diff --git a/tests/Gedmo/Loggable/Fixture/Entity/CompositeRelation.php b/tests/Gedmo/Loggable/Fixture/Entity/CompositeRelation.php index 0cde9c3c4a..ce97c7fe9e 100644 --- a/tests/Gedmo/Loggable/Fixture/Entity/CompositeRelation.php +++ b/tests/Gedmo/Loggable/Fixture/Entity/CompositeRelation.php @@ -22,22 +22,6 @@ #[Gedmo\Loggable] class CompositeRelation { - /** - * @ORM\Id - * @ORM\ManyToOne(targetEntity="Article") - */ - #[ORM\Id] - #[ORM\ManyToOne(targetEntity: Article::class)] - private Article $articleOne; - - /** - * @ORM\Id - * @ORM\ManyToOne(targetEntity="Article") - */ - #[ORM\Id] - #[ORM\ManyToOne(targetEntity: Article::class)] - private Article $articleTwo; - /** * @ORM\Column(length=8) * @@ -47,11 +31,22 @@ class CompositeRelation #[Gedmo\Versioned] private ?string $title = null; - public function __construct(Article $articleOne, Article $articleTwo) - { - $this->articleOne = $articleOne; - $this->articleTwo = $articleTwo; - } + public function __construct( + /** + * @ORM\Id + * @ORM\ManyToOne(targetEntity="Article") + */ + #[ORM\Id] + #[ORM\ManyToOne(targetEntity: Article::class)] + private Article $articleOne, + /** + * @ORM\Id + * @ORM\ManyToOne(targetEntity="Article") + */ + #[ORM\Id] + #[ORM\ManyToOne(targetEntity: Article::class)] + private Article $articleTwo + ) {} public function getArticleOne(): Article { diff --git a/tests/Gedmo/Loggable/Fixture/Entity/Geo.php b/tests/Gedmo/Loggable/Fixture/Entity/Geo.php index 136fbb6bcc..19884f7518 100644 --- a/tests/Gedmo/Loggable/Fixture/Entity/Geo.php +++ b/tests/Gedmo/Loggable/Fixture/Entity/Geo.php @@ -26,9 +26,7 @@ class Geo { /** - * @var string|null - * - * @phpstan-var numeric-string|null + * @var numeric-string|null * * @ORM\Column(type="decimal", precision=9, scale=6) * @@ -36,12 +34,10 @@ class Geo */ #[ORM\Column(type: Types::DECIMAL, precision: 9, scale: 6)] #[Gedmo\Versioned] - protected $latitude; + protected ?string $latitude = null; /** - * @var string|null - * - * @phpstan-var numeric-string|null + * @var numeric-string|null * * @ORM\Column(type="decimal", precision=9, scale=6) * @@ -49,24 +45,22 @@ class Geo */ #[ORM\Column(type: Types::DECIMAL, precision: 9, scale: 6)] #[Gedmo\Versioned] - protected $longitude; + protected ?string $longitude = null; - /** - * @var GeoLocation - * - * @ORM\Embedded(class="Gedmo\Tests\Loggable\Fixture\Entity\GeoLocation") - * - * @Gedmo\Versioned - */ - #[ORM\Embedded(class: GeoLocation::class)] - #[Gedmo\Versioned] - protected $geoLocation; - - public function __construct(float $latitude, float $longitude, GeoLocation $geoLocation) - { + public function __construct( + float $latitude, + float $longitude, + /** + * @ORM\Embedded(class="Gedmo\Tests\Loggable\Fixture\Entity\GeoLocation") + * + * @Gedmo\Versioned + */ + #[ORM\Embedded(class: GeoLocation::class)] + #[Gedmo\Versioned] + protected GeoLocation $geoLocation + ) { $this->latitude = $this->parseFloatToString($latitude); $this->longitude = $this->parseFloatToString($longitude); - $this->geoLocation = $geoLocation; } public function getLatitude(): float @@ -100,7 +94,7 @@ public function setGeoLocation(GeoLocation $geoLocation): void } /** - * @phpstan-return numeric-string + * @return numeric-string */ private function parseFloatToString(float $number): string { diff --git a/tests/Gedmo/Loggable/Fixture/Entity/GeoLocation.php b/tests/Gedmo/Loggable/Fixture/Entity/GeoLocation.php index 0495de48df..cc30361053 100644 --- a/tests/Gedmo/Loggable/Fixture/Entity/GeoLocation.php +++ b/tests/Gedmo/Loggable/Fixture/Entity/GeoLocation.php @@ -25,21 +25,16 @@ #[ORM\Embeddable] class GeoLocation { - /** - * @var string - * - * @ORM\Column(type="string") - * - * @Gedmo\Versioned - */ - #[ORM\Column(type: Types::STRING)] - #[Gedmo\Versioned] - protected $location; - - public function __construct(string $location) - { - $this->location = $location; - } + public function __construct( + /** + * @ORM\Column(type="string") + * + * @Gedmo\Versioned + */ + #[ORM\Column(type: Types::STRING)] + #[Gedmo\Versioned] + protected string $location + ) {} public function getLocation(): string { diff --git a/tests/Gedmo/Loggable/Fixture/Entity/Log/Comment.php b/tests/Gedmo/Loggable/Fixture/Entity/Log/Comment.php index 79625f2a4b..4df92a852f 100644 --- a/tests/Gedmo/Loggable/Fixture/Entity/Log/Comment.php +++ b/tests/Gedmo/Loggable/Fixture/Entity/Log/Comment.php @@ -24,6 +24,4 @@ */ #[ORM\Table(name: 'test_comment_log_entries')] #[ORM\Entity(repositoryClass: LogEntryRepository::class)] -class Comment extends AbstractLogEntry -{ -} +class Comment extends AbstractLogEntry {} diff --git a/tests/Gedmo/Loggable/Fixture/Entity/RelatedArticle.php b/tests/Gedmo/Loggable/Fixture/Entity/RelatedArticle.php index a111553d5a..cac81998ec 100644 --- a/tests/Gedmo/Loggable/Fixture/Entity/RelatedArticle.php +++ b/tests/Gedmo/Loggable/Fixture/Entity/RelatedArticle.php @@ -28,16 +28,14 @@ class RelatedArticle implements Loggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ #[ORM\Id] + #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - #[ORM\GeneratedValue()] - private $id; + private ?int $id = null; /** * @Gedmo\Versioned @@ -63,7 +61,7 @@ class RelatedArticle implements Loggable * @ORM\OneToMany(targetEntity="Comment", mappedBy="article") */ #[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'article')] - private $comments; + private Collection $comments; public function __construct() { diff --git a/tests/Gedmo/Loggable/LoggableDocumentTest.php b/tests/Gedmo/Loggable/LoggableDocumentTest.php index 2d86eb2a46..96e8bba18d 100644 --- a/tests/Gedmo/Loggable/LoggableDocumentTest.php +++ b/tests/Gedmo/Loggable/LoggableDocumentTest.php @@ -63,7 +63,7 @@ public function testLogGeneration(): void static::assertNotNull($log); static::assertSame('create', $log->getAction()); - static::assertSame(get_class($art0), $log->getObjectClass()); + static::assertSame($art0::class, $log->getObjectClass()); static::assertSame('jules', $log->getUsername()); static::assertSame(1, $log->getVersion()); $data = $log->getData(); diff --git a/tests/Gedmo/Loggable/LoggableEntityTest.php b/tests/Gedmo/Loggable/LoggableEntityTest.php index 21312c45a1..b846893f00 100644 --- a/tests/Gedmo/Loggable/LoggableEntityTest.php +++ b/tests/Gedmo/Loggable/LoggableEntityTest.php @@ -84,7 +84,7 @@ public function testLoggable(): void static::assertNotNull($log); static::assertSame('create', $log->getAction()); - static::assertSame(get_class($art0), $log->getObjectClass()); + static::assertSame($art0::class, $log->getObjectClass()); static::assertSame('jules', $log->getUsername()); static::assertSame(1, $log->getVersion()); $data = $log->getData(); @@ -132,7 +132,7 @@ public function testLoggableWithActorProvider(): void static::assertNotNull($log); static::assertSame('create', $log->getAction()); - static::assertSame(get_class($art0), $log->getObjectClass()); + static::assertSame($art0::class, $log->getObjectClass()); static::assertSame('testactor', $log->getUsername()); static::assertSame(1, $log->getVersion()); $data = $log->getData(); @@ -225,7 +225,7 @@ public function testComposite(): void static::assertNotNull($log); static::assertSame('create', $log->getAction()); - static::assertSame(get_class($cmp), $log->getObjectClass()); + static::assertSame($cmp::class, $log->getObjectClass()); static::assertSame('jules', $log->getUsername()); static::assertSame(1, $log->getVersion()); $data = $log->getData(); @@ -279,7 +279,7 @@ public function testCompositeRelation(): void static::assertNotNull($log); static::assertSame('create', $log->getAction()); - static::assertSame(get_class($cmp0), $log->getObjectClass()); + static::assertSame($cmp0::class, $log->getObjectClass()); static::assertSame('jules', $log->getUsername()); static::assertSame(1, $log->getVersion()); $data = $log->getData(); diff --git a/tests/Gedmo/Mapping/Annotation/BaseClassAnnotationTestCase.php b/tests/Gedmo/Mapping/Annotation/BaseClassAnnotationTestCase.php index 86c07a1276..5ab57f7d84 100644 --- a/tests/Gedmo/Mapping/Annotation/BaseClassAnnotationTestCase.php +++ b/tests/Gedmo/Mapping/Annotation/BaseClassAnnotationTestCase.php @@ -18,13 +18,9 @@ abstract class BaseClassAnnotationTestCase extends TestCase { /** - * @requires PHP 8 - * * @dataProvider getValidParameters - * - * @param mixed $expectedReturn */ - public function testLoadFromAttribute(string $annotationProperty, $expectedReturn): void + public function testLoadFromAttribute(string $annotationProperty, mixed $expectedReturn): void { $annotation = $this->getClassAnnotation(true); static::assertSame($annotation->$annotationProperty, $expectedReturn); @@ -32,10 +28,8 @@ public function testLoadFromAttribute(string $annotationProperty, $expectedRetur /** * @dataProvider getValidParameters - * - * @param mixed $expectedReturn */ - public function testLoadFromDoctrineAnnotation(string $annotationProperty, $expectedReturn): void + public function testLoadFromDoctrineAnnotation(string $annotationProperty, mixed $expectedReturn): void { $annotation = $this->getClassAnnotation(false); static::assertSame($annotation->$annotationProperty, $expectedReturn); diff --git a/tests/Gedmo/Mapping/Annotation/BasePropertyAnnotationTestCase.php b/tests/Gedmo/Mapping/Annotation/BasePropertyAnnotationTestCase.php index 094c439a57..19f3892f5f 100644 --- a/tests/Gedmo/Mapping/Annotation/BasePropertyAnnotationTestCase.php +++ b/tests/Gedmo/Mapping/Annotation/BasePropertyAnnotationTestCase.php @@ -18,13 +18,9 @@ abstract class BasePropertyAnnotationTestCase extends TestCase { /** - * @requires PHP 8 - * * @dataProvider getValidParameters - * - * @param mixed $expectedReturn */ - public function testLoadFromAttribute(string $annotationProperty, string $classProperty, $expectedReturn): void + public function testLoadFromAttribute(string $annotationProperty, string $classProperty, mixed $expectedReturn): void { $annotation = $this->getMethodAnnotation($classProperty, true); static::assertSame($annotation->$annotationProperty, $expectedReturn); @@ -32,10 +28,8 @@ public function testLoadFromAttribute(string $annotationProperty, string $classP /** * @dataProvider getValidParameters - * - * @param mixed $expectedReturn */ - public function testLoadFromDoctrineAnnotation(string $annotationProperty, string $classProperty, $expectedReturn): void + public function testLoadFromDoctrineAnnotation(string $annotationProperty, string $classProperty, mixed $expectedReturn): void { $annotation = $this->getMethodAnnotation($classProperty, false); static::assertSame($annotation->$annotationProperty, $expectedReturn); @@ -44,7 +38,7 @@ public function testLoadFromDoctrineAnnotation(string $annotationProperty, strin /** * @phpstan-return iterable */ - abstract public function getValidParameters(): iterable; + abstract public static function getValidParameters(): iterable; abstract protected function getAnnotationClass(): string; diff --git a/tests/Gedmo/Mapping/Annotation/TranslatablePropertyTestCase.php b/tests/Gedmo/Mapping/Annotation/TranslatablePropertyTestCase.php index 3b5049fb28..569e57b327 100644 --- a/tests/Gedmo/Mapping/Annotation/TranslatablePropertyTestCase.php +++ b/tests/Gedmo/Mapping/Annotation/TranslatablePropertyTestCase.php @@ -17,13 +17,11 @@ final class TranslatablePropertyTestCase extends BasePropertyAnnotationTestCase { - public function getValidParameters(): iterable + public static function getValidParameters(): \Generator { - return [ - ['fallback', 'title', null], - ['fallback', 'titleFallbackTrue', true], - ['fallback', 'titleFallbackFalse', false], - ]; + yield ['fallback', 'title', null]; + yield ['fallback', 'titleFallbackTrue', true]; + yield ['fallback', 'titleFallbackFalse', false]; } protected function getAnnotationClass(): string diff --git a/tests/Gedmo/Mapping/Annotation/TranslationEntityTestCase.php b/tests/Gedmo/Mapping/Annotation/TranslationEntityTestCase.php index d049b2d393..1d695632da 100644 --- a/tests/Gedmo/Mapping/Annotation/TranslationEntityTestCase.php +++ b/tests/Gedmo/Mapping/Annotation/TranslationEntityTestCase.php @@ -17,11 +17,9 @@ final class TranslationEntityTestCase extends BaseClassAnnotationTestCase { - public static function getValidParameters(): iterable + public static function getValidParameters(): \Iterator { - return [ - ['class', \stdClass::class], - ]; + yield ['class', \stdClass::class]; } protected function getAnnotationClass(): string diff --git a/tests/Gedmo/Mapping/ExtensionODMTest.php b/tests/Gedmo/Mapping/ExtensionODMTest.php index eda93dfa1b..b9a9c228ae 100644 --- a/tests/Gedmo/Mapping/ExtensionODMTest.php +++ b/tests/Gedmo/Mapping/ExtensionODMTest.php @@ -67,7 +67,6 @@ public function testEventAdapterUsed(): void { $mappedSubscriberClass = new \ReflectionClass(MappedEventSubscriber::class); $getEventAdapterMethod = $mappedSubscriberClass->getMethod('getEventAdapter'); - $getEventAdapterMethod->setAccessible(true); $loadClassMetadataEventArgs = new LoadClassMetadataEventArgs( $this->dm->getClassMetadata(User::class), diff --git a/tests/Gedmo/Mapping/ExtensionORMTest.php b/tests/Gedmo/Mapping/ExtensionORMTest.php index 1ad28a7784..251b543988 100644 --- a/tests/Gedmo/Mapping/ExtensionORMTest.php +++ b/tests/Gedmo/Mapping/ExtensionORMTest.php @@ -68,7 +68,6 @@ public function testEventAdapterUsed(): void { $mappedSubscriberClass = new \ReflectionClass(MappedEventSubscriber::class); $getEventAdapterMethod = $mappedSubscriberClass->getMethod('getEventAdapter'); - $getEventAdapterMethod->setAccessible(true); $loadClassMetadataEventArgs = new LoadClassMetadataEventArgs( $this->em->getClassMetadata(User::class), diff --git a/tests/Gedmo/Mapping/Fixture/Annotation/TranslatableModel.php b/tests/Gedmo/Mapping/Fixture/Annotation/TranslatableModel.php index 7d9bb024b2..9a94d0914d 100644 --- a/tests/Gedmo/Mapping/Fixture/Annotation/TranslatableModel.php +++ b/tests/Gedmo/Mapping/Fixture/Annotation/TranslatableModel.php @@ -16,23 +16,17 @@ class TranslatableModel { /** - * @var string|null - * * @Gedmo\Translatable */ - private $title; + private ?string $title = null; /** - * @var string|null - * * @Gedmo\Translatable(fallback=true) */ - private $titleFallbackTrue; + private ?string $titleFallbackTrue = null; /** - * @var string|null - * * @Gedmo\Translatable(fallback=false) */ - private $titleFallbackFalse; + private ?string $titleFallbackFalse = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Annotation/TranslationEntityModel.php b/tests/Gedmo/Mapping/Fixture/Annotation/TranslationEntityModel.php index 37fb345fa0..b09e9586a9 100644 --- a/tests/Gedmo/Mapping/Fixture/Annotation/TranslationEntityModel.php +++ b/tests/Gedmo/Mapping/Fixture/Annotation/TranslationEntityModel.php @@ -16,6 +16,4 @@ /** * @Gedmo\TranslationEntity(class="stdClass") */ -class TranslationEntityModel -{ -} +class TranslationEntityModel {} diff --git a/tests/Gedmo/Mapping/Fixture/Attribute/TranslationEntityModel.php b/tests/Gedmo/Mapping/Fixture/Attribute/TranslationEntityModel.php index a528fc2a62..372b70a6ec 100644 --- a/tests/Gedmo/Mapping/Fixture/Attribute/TranslationEntityModel.php +++ b/tests/Gedmo/Mapping/Fixture/Attribute/TranslationEntityModel.php @@ -14,6 +14,4 @@ use Gedmo\Mapping\Annotation as Gedmo; #[Gedmo\TranslationEntity(class: \stdClass::class)] -class TranslationEntityModel -{ -} +class TranslationEntityModel {} diff --git a/tests/Gedmo/Mapping/Fixture/BaseCategory.php b/tests/Gedmo/Mapping/Fixture/BaseCategory.php index b39c012029..fd26fcf5c3 100644 --- a/tests/Gedmo/Mapping/Fixture/BaseCategory.php +++ b/tests/Gedmo/Mapping/Fixture/BaseCategory.php @@ -80,9 +80,6 @@ public function setCreated(\DateTime $created): void $this->created = $created; } - /** - * @return \DateTime $created - */ public function getCreated(): ?\DateTime { return $this->created; diff --git a/tests/Gedmo/Mapping/Fixture/Category.php b/tests/Gedmo/Mapping/Fixture/Category.php index 84b49edb98..d531822904 100644 --- a/tests/Gedmo/Mapping/Fixture/Category.php +++ b/tests/Gedmo/Mapping/Fixture/Category.php @@ -19,7 +19,6 @@ use Gedmo\Mapping\Annotation as Gedmo; use Gedmo\Sluggable\Handler\RelativeSlugHandler; use Gedmo\Sluggable\Handler\TreeSlugHandler; -use Gedmo\Tests\Translatable\Fixture\CategoryTranslation; /** * @ORM\Entity @@ -37,8 +36,6 @@ class Category extends BaseCategory { /** - * @var int - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -46,7 +43,7 @@ class Category extends BaseCategory #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(type="string", length=64) @@ -89,7 +86,7 @@ class Category extends BaseCategory * @ORM\OneToMany(targetEntity="Gedmo\Tests\Mapping\Fixture\Category", mappedBy="parent") */ #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] - private $children; + private Collection $children; /** * @ORM\ManyToOne(targetEntity="Gedmo\Tests\Mapping\Fixture\Category", inversedBy="children") @@ -98,27 +95,22 @@ class Category extends BaseCategory */ #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] #[Gedmo\TreeParent] - private ?Category $parent = null; + private ?self $parent = null; /** - * @var \DateTime - * * @ORM\Column(type="date") * * @Gedmo\Timestampable(on="change", field="title", value="Test") */ #[ORM\Column(type: Types::DATE_MUTABLE)] #[Gedmo\Timestampable(on: 'change', field: 'title', value: 'Test')] - private $changed; + private ?\DateTime $changed = null; public function __construct() { $this->children = new ArrayCollection(); } - /** - * @return int $id - */ public function getId(): int { return $this->id; @@ -139,9 +131,6 @@ public function setSlug(string $slug): void $this->slug = $slug; } - /** - * @return string $slug - */ public function getSlug(): string { return $this->slug; @@ -153,9 +142,9 @@ public function addChildren(self $children): void } /** - * @return Collection $children + * @return Collection */ - public function getChildren() + public function getChildren(): Collection { return $this->children; } @@ -165,9 +154,6 @@ public function setParent(self $parent): void $this->parent = $parent; } - /** - * @return self $parent - */ public function getParent(): self { return $this->parent; diff --git a/tests/Gedmo/Mapping/Fixture/CategoryTranslation.php b/tests/Gedmo/Mapping/Fixture/CategoryTranslation.php new file mode 100644 index 0000000000..1764eeb46c --- /dev/null +++ b/tests/Gedmo/Mapping/Fixture/CategoryTranslation.php @@ -0,0 +1,40 @@ + http://www.gediminasm.org + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Gedmo\Tests\Mapping\Fixture; + +use Doctrine\ORM\Mapping as ORM; +use Gedmo\Translator\Entity\Translation; + +/** + * @ORM\Table( + * indexes={@ORM\Index(name="translations_lookup_idx", columns={ + * "locale", "translatable_id" + * })}, + * uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={ + * "locale", "translatable_id", "property" + * })} + * ) + * @ORM\Entity + */ +#[ORM\Entity] +#[ORM\Index(name: 'translations_lookup_idx', columns: ['locale', 'translatable_id'])] +#[ORM\UniqueConstraint(name: 'lookup_unique_idx', columns: ['locale', 'translatable_id', 'property'])] +class CategoryTranslation extends Translation +{ + /** + * @var Category|null + * + * @ORM\ManyToOne(targetEntity="Person", inversedBy="translations") + */ + #[ORM\ManyToOne(targetEntity: Category::class, inversedBy: 'translations')] + protected $translatable; +} diff --git a/tests/Gedmo/Mapping/Fixture/Document/User.php b/tests/Gedmo/Mapping/Fixture/Document/User.php index 420bbb9889..fdc55b3536 100644 --- a/tests/Gedmo/Mapping/Fixture/Document/User.php +++ b/tests/Gedmo/Mapping/Fixture/Document/User.php @@ -22,12 +22,10 @@ class User { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @Ext\Encode(type="sha1", secret="xxx") diff --git a/tests/Gedmo/Mapping/Fixture/Embedded.php b/tests/Gedmo/Mapping/Fixture/Embedded.php index 13f607680f..625eac86d3 100644 --- a/tests/Gedmo/Mapping/Fixture/Embedded.php +++ b/tests/Gedmo/Mapping/Fixture/Embedded.php @@ -25,10 +25,8 @@ class Embedded { /** - * @var string - * * @ORM\Column(type="string") */ #[ORM\Column(type: Types::STRING)] - private $subtitle; + private ?string $subtitle = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Loggable.php b/tests/Gedmo/Mapping/Fixture/Loggable.php index ddc27024d5..6bd20e24ff 100644 --- a/tests/Gedmo/Mapping/Fixture/Loggable.php +++ b/tests/Gedmo/Mapping/Fixture/Loggable.php @@ -24,8 +24,6 @@ class Loggable { /** - * @var int - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class Loggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Mapping/Fixture/LoggableComposite.php b/tests/Gedmo/Mapping/Fixture/LoggableComposite.php index 9af9f2116c..2782194a44 100644 --- a/tests/Gedmo/Mapping/Fixture/LoggableComposite.php +++ b/tests/Gedmo/Mapping/Fixture/LoggableComposite.php @@ -24,24 +24,20 @@ class LoggableComposite { /** - * @var int - * * @ORM\Id * @ORM\Column(type="integer") */ #[ORM\Id] #[ORM\Column(type: Types::INTEGER)] - private $one; + private ?int $one = null; /** - * @var int - * * @ORM\Id * @ORM\Column(type="integer") */ #[ORM\Id] #[ORM\Column(type: Types::INTEGER)] - private $two; + private ?int $two = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Mapping/Fixture/LoggableCompositeRelation.php b/tests/Gedmo/Mapping/Fixture/LoggableCompositeRelation.php index 6244fe9f5b..c8b181dd2e 100644 --- a/tests/Gedmo/Mapping/Fixture/LoggableCompositeRelation.php +++ b/tests/Gedmo/Mapping/Fixture/LoggableCompositeRelation.php @@ -24,24 +24,20 @@ class LoggableCompositeRelation { /** - * @var Loggable - * * @ORM\Id * @ORM\ManyToOne(targetEntity="Loggable") */ #[ORM\Id] #[ORM\ManyToOne(targetEntity: Loggable::class)] - private $one; + private ?Loggable $one = null; /** - * @var int - * * @ORM\Id * @ORM\Column(type="integer") */ #[ORM\Id] #[ORM\Column(type: Types::INTEGER)] - private $two; + private ?int $two = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Mapping/Fixture/LoggableWithEmbedded.php b/tests/Gedmo/Mapping/Fixture/LoggableWithEmbedded.php index 77c36f7a75..18632233fd 100644 --- a/tests/Gedmo/Mapping/Fixture/LoggableWithEmbedded.php +++ b/tests/Gedmo/Mapping/Fixture/LoggableWithEmbedded.php @@ -26,8 +26,6 @@ class LoggableWithEmbedded { /** - * @var int - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -35,27 +33,23 @@ class LoggableWithEmbedded #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** - * @var string - * * @ORM\Column(name="title", type="string") * * @Gedmo\Versioned */ #[ORM\Column(name: 'title', type: Types::STRING)] #[Gedmo\Versioned] - private $title; + private ?string $title = null; /** - * @var Embedded - * * @ORM\Embedded(class="Gedmo\Tests\Mapping\Fixture\Embedded") * * @Gedmo\Versioned */ #[ORM\Embedded(class: Embedded::class)] #[Gedmo\Versioned] - private $embedded; + private ?Embedded $embedded = null; } diff --git a/tests/Gedmo/Mapping/Fixture/MappedSuperClass.php b/tests/Gedmo/Mapping/Fixture/MappedSuperClass.php index 60592871d4..98e74360e8 100644 --- a/tests/Gedmo/Mapping/Fixture/MappedSuperClass.php +++ b/tests/Gedmo/Mapping/Fixture/MappedSuperClass.php @@ -22,8 +22,6 @@ class MappedSuperClass { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class MappedSuperClass #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=32) diff --git a/tests/Gedmo/Mapping/Fixture/Sluggable.php b/tests/Gedmo/Mapping/Fixture/Sluggable.php index 707d27acc8..6c1e4ce30d 100644 --- a/tests/Gedmo/Mapping/Fixture/Sluggable.php +++ b/tests/Gedmo/Mapping/Fixture/Sluggable.php @@ -24,8 +24,6 @@ class Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -54,8 +52,6 @@ class Sluggable private ?string $ean = null; /** - * @var string|null - * * @Gedmo\Slug(handlers={ * @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={ * @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"), @@ -74,23 +70,19 @@ class Sluggable #[Gedmo\SlugHandler(class: TreeSlugHandler::class, options: ['parentRelationField' => 'parent', 'separator' => '/'])] #[Gedmo\SlugHandler(class: RelativeSlugHandler::class, options: ['relationField' => 'parent', 'relationSlugField' => 'test', 'separator' => '-'])] #[ORM\Column(name: 'slug', type: Types::STRING, length: 64, unique: true)] - private $slug; + private ?string $slug = null; /** - * @var Sluggable|null - * * @ORM\ManyToOne(targetEntity="Sluggable") */ #[ORM\ManyToOne(targetEntity: self::class)] - private $parent; + private ?self $parent = null; /** - * @var User|null - * * @ORM\ManyToOne(targetEntity="User") */ #[ORM\ManyToOne(targetEntity: User::class)] - private $user; + private ?User $user = null; public function getId(): ?int { diff --git a/tests/Gedmo/Mapping/Fixture/SoftDeleteable.php b/tests/Gedmo/Mapping/Fixture/SoftDeleteable.php index 3e3372e786..d024bf9b58 100644 --- a/tests/Gedmo/Mapping/Fixture/SoftDeleteable.php +++ b/tests/Gedmo/Mapping/Fixture/SoftDeleteable.php @@ -25,8 +25,6 @@ class SoftDeleteable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -34,24 +32,19 @@ class SoftDeleteable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; private ?string $title = null; private ?string $code = null; - /** - * @var string|null - */ - private $slug; + private ?string $slug = null; /** - * @var \DateTime|null - * * @ORM\Column(name="deleted_at", type="datetime", nullable=true) */ #[ORM\Column(name: 'deleted_at', type: Types::DATETIME_MUTABLE, nullable: true)] - private $deletedAt; + private ?\DateTime $deletedAt = null; public function getId(): ?int { diff --git a/tests/Gedmo/Mapping/Fixture/Sortable.php b/tests/Gedmo/Mapping/Fixture/Sortable.php index ca03ce2c61..7a06479edb 100644 --- a/tests/Gedmo/Mapping/Fixture/Sortable.php +++ b/tests/Gedmo/Mapping/Fixture/Sortable.php @@ -26,8 +26,6 @@ class Sortable { /** - * @var int - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -35,48 +33,40 @@ class Sortable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** - * @var string - * * @ORM\Column(type="string", length=128) */ #[ORM\Column(type: Types::STRING, length: 128)] - private $title; + private ?string $title = null; /** - * @var int - * * @ORM\Column(type="integer") * * @Gedmo\SortablePosition */ #[ORM\Column(type: Types::INTEGER)] #[Gedmo\SortablePosition] - private $position; + private ?int $position = null; /** - * @var string - * * @ORM\Column(type="string", length=128) * * @Gedmo\SortableGroup */ #[ORM\Column(type: Types::STRING, length: 128)] #[Gedmo\SortableGroup] - private $grouping; + private ?string $grouping = null; /** - * @var SortableGroup - * * @ORM\ManyToOne(targetEntity="Sluggable") * * @Gedmo\SortableGroup */ #[ORM\ManyToOne(targetEntity: SortableGroup::class)] #[Gedmo\SortableGroup] - private $sortable_group; + private ?SortableGroup $sortable_group = null; /** * @var Collection diff --git a/tests/Gedmo/Mapping/Fixture/SortableGroup.php b/tests/Gedmo/Mapping/Fixture/SortableGroup.php index ff5e8485b0..395ad551ef 100644 --- a/tests/Gedmo/Mapping/Fixture/SortableGroup.php +++ b/tests/Gedmo/Mapping/Fixture/SortableGroup.php @@ -23,8 +23,6 @@ class SortableGroup { /** - * @var int - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,13 +30,11 @@ class SortableGroup #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** - * @var string - * * @ORM\Column(type="string", length=64) */ #[ORM\Column(type: Types::STRING, length: 64)] - private $name; + private ?string $name = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Unmapped/Timestampable.php b/tests/Gedmo/Mapping/Fixture/Unmapped/Timestampable.php index 08f921f5db..b9d07229ba 100644 --- a/tests/Gedmo/Mapping/Fixture/Unmapped/Timestampable.php +++ b/tests/Gedmo/Mapping/Fixture/Unmapped/Timestampable.php @@ -15,16 +15,11 @@ class Timestampable { - /** - * @var int - */ - private $id; + private ?int $id = null; /** - * @var \DateTime - * * @Tmsp(on="create") */ #[Tmsp(on: 'create')] - private $created; + private ?\DateTime $created = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Uploadable.php b/tests/Gedmo/Mapping/Fixture/Uploadable.php index 118ffe8ff2..0f7d84b556 100644 --- a/tests/Gedmo/Mapping/Fixture/Uploadable.php +++ b/tests/Gedmo/Mapping/Fixture/Uploadable.php @@ -26,8 +26,6 @@ class Uploadable { /** - * @var int - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -35,18 +33,16 @@ class Uploadable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** - * @var string - * * @ORM\Column(name="mime", type="string") * * @Gedmo\UploadableFileMimeType */ #[ORM\Column(name: 'mime', type: Types::STRING)] #[Gedmo\UploadableFileMimeType] - private $mimeType; + private ?string $mimeType = null; /** * @var array @@ -54,33 +50,27 @@ class Uploadable private $fileInfo; /** - * @var float - * * @ORM\Column(name="size", type="decimal", precision=10, scale=2) * * @Gedmo\UploadableFileSize */ #[ORM\Column(name: 'size', type: Types::DECIMAL, precision: 10, scale: 2)] #[Gedmo\UploadableFileSize] - private $size; + private ?float $size = null; /** - * @var string - * * @ORM\Column(name="path", type="string") * * @Gedmo\UploadableFilePath */ #[ORM\Column(name: 'path', type: Types::STRING)] #[Gedmo\UploadableFilePath] - private $path; + private ?string $path = null; public function getPath(): string { return $this->path; } - public function callbackMethod(): void - { - } + public function callbackMethod(): void {} } diff --git a/tests/Gedmo/Mapping/Fixture/User.php b/tests/Gedmo/Mapping/Fixture/User.php index 9a5a6058cd..ad51ecac5c 100644 --- a/tests/Gedmo/Mapping/Fixture/User.php +++ b/tests/Gedmo/Mapping/Fixture/User.php @@ -34,8 +34,6 @@ class User { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -43,7 +41,7 @@ class User #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Ext\Encode(type="sha1", secret="xxx") @@ -85,12 +83,10 @@ class User private ?string $company = null; /** - * @var string - * * @Gedmo\Locale */ #[Gedmo\Locale] - private $localeField; + private ?string $localeField = null; public function setName(?string $name): void { diff --git a/tests/Gedmo/Mapping/Fixture/Xml/ClosureTree.php b/tests/Gedmo/Mapping/Fixture/Xml/ClosureTree.php index 7f5ff9af87..e6aeaf5ce7 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/ClosureTree.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/ClosureTree.php @@ -13,23 +13,11 @@ class ClosureTree { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var string - */ - private $name; + private ?string $name = null; - /** - * @var ClosureTree|null - */ - private $parent; + private ?self $parent = null; - /** - * @var int - */ - private $level; + private ?int $level = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/Embedded.php b/tests/Gedmo/Mapping/Fixture/Xml/Embedded.php index 6da360a93b..e2e38610b9 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/Embedded.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/Embedded.php @@ -18,8 +18,5 @@ */ class Embedded { - /** - * @var string - */ - private $subtitle; + private ?string $subtitle = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/EmbeddedTranslatable.php b/tests/Gedmo/Mapping/Fixture/Xml/EmbeddedTranslatable.php index f499fee56c..5bb5ce90f9 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/EmbeddedTranslatable.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/EmbeddedTranslatable.php @@ -13,8 +13,5 @@ class EmbeddedTranslatable { - /** - * @var string - */ - private $subtitle; + private ?string $subtitle = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/Loggable.php b/tests/Gedmo/Mapping/Fixture/Xml/Loggable.php index 4d99010e1b..10890ce59e 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/Loggable.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/Loggable.php @@ -13,18 +13,9 @@ class Loggable { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var string - */ - private $title; + private ?string $title = null; - /** - * @var Status - */ - private $status; + private ?Status $status = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/LoggableComposite.php b/tests/Gedmo/Mapping/Fixture/Xml/LoggableComposite.php index 59ca1eadfd..f47c64f2bc 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/LoggableComposite.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/LoggableComposite.php @@ -11,18 +11,9 @@ class LoggableComposite { - /** - * @var int - */ - private $one; + private ?int $one = null; - /** - * @var int - */ - private $two; + private ?int $two = null; - /** - * @var string - */ - private $title; + private ?string $title = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/LoggableCompositeRelation.php b/tests/Gedmo/Mapping/Fixture/Xml/LoggableCompositeRelation.php index 0db9ba164f..6cbe7a8095 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/LoggableCompositeRelation.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/LoggableCompositeRelation.php @@ -11,18 +11,9 @@ class LoggableCompositeRelation { - /** - * @var Loggable - */ - private $one; + private ?Loggable $one = null; - /** - * @var int - */ - private $two; + private ?int $two = null; - /** - * @var string - */ - private $title; + private ?string $title = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/LoggableWithEmbedded.php b/tests/Gedmo/Mapping/Fixture/Xml/LoggableWithEmbedded.php index 7d1626ac81..fcd9e189d7 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/LoggableWithEmbedded.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/LoggableWithEmbedded.php @@ -13,23 +13,11 @@ class LoggableWithEmbedded { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var string - */ - private $title; + private ?string $title = null; - /** - * @var Status - */ - private $status; + private ?Status $status = null; - /** - * @var Embedded - */ - private $embedded; + private ?Embedded $embedded = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/MaterializedPathTree.php b/tests/Gedmo/Mapping/Fixture/Xml/MaterializedPathTree.php index 1a3d4e0b42..cdda275be7 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/MaterializedPathTree.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/MaterializedPathTree.php @@ -13,38 +13,17 @@ class MaterializedPathTree { - /** - * @var int - */ - private $id; - - /** - * @var string - */ - private $title; - - /** - * @var string - */ - private $path; - - /** - * @var \DateTime|null - */ - private $lockTime; - - /** - * @var string - */ - private $pathHash; - - /** - * @var MaterializedPathTree - */ - private $parent; - - /** - * @var int - */ - private $level; + private ?int $id = null; + + private ?string $title = null; + + private ?string $path = null; + + private ?\DateTime $lockTime = null; + + private ?string $pathHash = null; + + private ?MaterializedPathTree $parent = null; + + private ?int $level = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/NestedTree.php b/tests/Gedmo/Mapping/Fixture/Xml/NestedTree.php index 70baa2832d..998c12fd38 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/NestedTree.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/NestedTree.php @@ -13,38 +13,17 @@ class NestedTree { - /** - * @var int - */ - private $id; - - /** - * @var string - */ - private $name; - - /** - * @var NestedTree - */ - private $parent; - - /** - * @var int - */ - private $root; - - /** - * @var int - */ - private $level; - - /** - * @var int - */ - private $left; - - /** - * @var int - */ - private $right; + private ?int $id = null; + + private ?string $name = null; + + private ?NestedTree $parent = null; + + private ?int $root = null; + + private ?int $level = null; + + private ?int $left = null; + + private ?int $right = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/References.php b/tests/Gedmo/Mapping/Fixture/Xml/References.php index d18e62393c..49c4f8339d 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/References.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/References.php @@ -15,18 +15,12 @@ class References { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var string - */ - private $name; + private ?string $name = null; /** * @var User[] */ - private $users; + private array $users = []; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/Sluggable.php b/tests/Gedmo/Mapping/Fixture/Xml/Sluggable.php index 834b3f47e1..73886a6100 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/Sluggable.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/Sluggable.php @@ -13,33 +13,15 @@ class Sluggable { - /** - * @var int - */ - private $id; - - /** - * @var string - */ - private $title; - - /** - * @var string - */ - private $code; - - /** - * @var string - */ - private $ean; - - /** - * @var string - */ - private $slug; - - /** - * @var Sluggable - */ - private $parent; + private ?int $id = null; + + private ?string $title = null; + + private ?string $code = null; + + private ?string $ean = null; + + private ?string $slug = null; + + private ?Sluggable $parent = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/SoftDeleteable.php b/tests/Gedmo/Mapping/Fixture/Xml/SoftDeleteable.php index 9f1f6aa707..c09c95235b 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/SoftDeleteable.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/SoftDeleteable.php @@ -13,13 +13,7 @@ class SoftDeleteable { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var \DateTime|null - */ - private $deletedAt; + private ?\DateTime $deletedAt = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/Sortable.php b/tests/Gedmo/Mapping/Fixture/Xml/Sortable.php index 42a51ad463..0dd5cc3d7d 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/Sortable.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/Sortable.php @@ -16,33 +16,18 @@ class Sortable { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var string - */ - private $title; + private ?string $title = null; - /** - * @var int - */ - private $position; + private ?int $position = null; - /** - * @var string - */ - private $grouping; + private ?string $grouping = null; - /** - * @var SortableGroup - */ - private $sortable_group; + private ?SortableGroup $sortable_group = null; /** * @var Collection */ - private $sortable_groups; + private Collection $sortable_groups; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/Status.php b/tests/Gedmo/Mapping/Fixture/Xml/Status.php index 3407058bf7..c19b8b0f22 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/Status.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/Status.php @@ -13,13 +13,7 @@ class Status { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var string - */ - private $title; + private ?string $title = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/Timestampable.php b/tests/Gedmo/Mapping/Fixture/Xml/Timestampable.php index e7587c37ce..1a870e0302 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/Timestampable.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/Timestampable.php @@ -13,28 +13,13 @@ class Timestampable { - /** - * @var int - */ - private $id; - - /** - * @var \DateTime - */ - private $created; - - /** - * @var \DateTime - */ - private $updated; - - /** - * @var \DateTime - */ - private $published; - - /** - * @var Status - */ - private $status; + private ?int $id = null; + + private ?\DateTime $created = null; + + private ?\DateTime $updated = null; + + private ?\DateTime $published = null; + + private ?Status $status = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/Translatable.php b/tests/Gedmo/Mapping/Fixture/Xml/Translatable.php index c4f1c3d936..e96f5f916f 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/Translatable.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/Translatable.php @@ -13,33 +13,15 @@ class Translatable { - /** - * @var int - */ - private $id; - - /** - * @var string - */ - private $title; - - /** - * @var string - */ - private $content; - - /** - * @var string - */ - private $locale; - - /** - * @var string - */ - private $author; - - /** - * @var int - */ - private $views; + private ?int $id = null; + + private ?string $title = null; + + private ?string $content = null; + + private ?string $locale = null; + + private ?string $author = null; + + private ?int $views = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/TranslatableWithEmbedded.php b/tests/Gedmo/Mapping/Fixture/Xml/TranslatableWithEmbedded.php index 18c717e57d..42623e12ff 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/TranslatableWithEmbedded.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/TranslatableWithEmbedded.php @@ -13,38 +13,17 @@ class TranslatableWithEmbedded { - /** - * @var int - */ - private $id; - - /** - * @var string - */ - private $title; - - /** - * @var string - */ - private $content; - - /** - * @var string - */ - private $locale; - - /** - * @var string - */ - private $author; - - /** - * @var int - */ - private $views; - - /** - * @var EmbeddedTranslatable - */ - private $embedded; + private ?int $id = null; + + private ?string $title = null; + + private ?string $content = null; + + private ?string $locale = null; + + private ?string $author = null; + + private ?int $views = null; + + private ?EmbeddedTranslatable $embedded = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/Uploadable.php b/tests/Gedmo/Mapping/Fixture/Xml/Uploadable.php index 25774ea290..0cb26a07cc 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/Uploadable.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/Uploadable.php @@ -13,37 +13,23 @@ class Uploadable { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var string - */ - private $mimeType; + private ?string $mimeType = null; /** * @var array */ - private $fileInfo; + private array $fileInfo = []; - /** - * @var float - */ - private $size; + private ?float $size = null; - /** - * @var string - */ - private $path; + private ?string $path = null; - public function getPath(): string + public function getPath(): ?string { return $this->path; } - public function callbackMethod(): void - { - } + public function callbackMethod(): void {} } diff --git a/tests/Gedmo/Mapping/Fixture/Xml/User.php b/tests/Gedmo/Mapping/Fixture/Xml/User.php index 9972cc2844..bde2264a75 100644 --- a/tests/Gedmo/Mapping/Fixture/Xml/User.php +++ b/tests/Gedmo/Mapping/Fixture/Xml/User.php @@ -13,10 +13,7 @@ class User { - /** - * @var int - */ - private $id; + private ?int $id = null; private ?string $password = null; @@ -24,12 +21,9 @@ class User private ?string $company = null; - /** - * @var string - */ - private $localeField; + private ?string $localeField = null; - public function getId(): int + public function getId(): ?int { return $this->id; } @@ -39,7 +33,7 @@ public function setPassword(string $password): void $this->password = $password; } - public function getPassword(): string + public function getPassword(): ?string { return $this->password; } @@ -49,7 +43,7 @@ public function setUsername(string $username): void $this->username = $username; } - public function getUsername(): string + public function getUsername(): ?string { return $this->username; } @@ -59,7 +53,7 @@ public function setCompany(string $company): void $this->company = $company; } - public function getCompany(): string + public function getCompany(): ?string { return $this->company; } diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/BaseCategory.php b/tests/Gedmo/Mapping/Fixture/Yaml/BaseCategory.php index becc8bd0e0..c88bdf8195 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/BaseCategory.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/BaseCategory.php @@ -30,9 +30,6 @@ public function setCreated(\DateTime $created): void $this->created = $created; } - /** - * @return \DateTime $created - */ public function getCreated(): ?\DateTime { return $this->created; diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/Category.php b/tests/Gedmo/Mapping/Fixture/Yaml/Category.php index c92156f94d..47a75e2bfe 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/Category.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/Category.php @@ -16,10 +16,7 @@ class Category extends BaseCategory { - /** - * @var int - */ - private $id; + private ?int $id = null; private ?string $title = null; @@ -28,24 +25,18 @@ class Category extends BaseCategory /** * @var Collection */ - private $children; + private Collection $children; - private ?Category $parent = null; + private ?self $parent = null; - /** - * @var \DateTime - */ - private $changed; + private ?\DateTime $changed = null; public function __construct() { $this->children = new ArrayCollection(); } - /** - * @return int $id - */ - public function getId(): int + public function getId(): ?int { return $this->id; } @@ -65,9 +56,6 @@ public function setSlug(string $slug): void $this->slug = $slug; } - /** - * @return string $slug - */ public function getSlug(): string { return $this->slug; @@ -81,7 +69,7 @@ public function addChildren(self $children): void /** * @return Collection $children */ - public function getChildren() + public function getChildren(): Collection { return $this->children; } @@ -91,9 +79,6 @@ public function setParent(self $parent): void $this->parent = $parent; } - /** - * @return self $parent - */ public function getParent(): self { return $this->parent; diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/ClosureCategory.php b/tests/Gedmo/Mapping/Fixture/Yaml/ClosureCategory.php index 2225d2d1bb..efb11483d8 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/ClosureCategory.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/ClosureCategory.php @@ -16,19 +16,16 @@ class ClosureCategory { - /** - * @var int - */ - private $id; + private ?int $id = null; private ?string $title = null; /** * @var Collection */ - private $children; + private Collection $children; - private ?ClosureCategory $parent = null; + private ?self $parent = null; private ?int $level = null; diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/Embedded.php b/tests/Gedmo/Mapping/Fixture/Yaml/Embedded.php index ff4c78b136..4d4795c055 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/Embedded.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/Embedded.php @@ -18,8 +18,5 @@ */ class Embedded { - /** - * @var string - */ - private $subtitle; + private ?string $subtitle = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/Loggable.php b/tests/Gedmo/Mapping/Fixture/Yaml/Loggable.php index 7c4dcb506f..a5f06c9f78 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/Loggable.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/Loggable.php @@ -1,5 +1,7 @@ http://www.gediminasm.org @@ -11,13 +13,7 @@ class Loggable { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var string - */ - private $title; + private ?string $title = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/LoggableComposite.php b/tests/Gedmo/Mapping/Fixture/Yaml/LoggableComposite.php index 81036f0126..a0da948e6c 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/LoggableComposite.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/LoggableComposite.php @@ -11,18 +11,9 @@ class LoggableComposite { - /** - * @var int - */ - private $one; + private ?int $one = null; - /** - * @var int - */ - private $two; + private ?int $two = null; - /** - * @var string - */ - private $title; + private ?string $title = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/LoggableCompositeRelation.php b/tests/Gedmo/Mapping/Fixture/Yaml/LoggableCompositeRelation.php index 713708663d..f6991f6a26 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/LoggableCompositeRelation.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/LoggableCompositeRelation.php @@ -11,18 +11,9 @@ class LoggableCompositeRelation { - /** - * @var Loggable - */ - private $one; + private ?Loggable $one = null; - /** - * @var int - */ - private $two; + private ?int $two = null; - /** - * @var string - */ - private $title; + private ?string $title = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/LoggableWithEmbedded.php b/tests/Gedmo/Mapping/Fixture/Yaml/LoggableWithEmbedded.php index bd93e8efce..0737e0b13b 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/LoggableWithEmbedded.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/LoggableWithEmbedded.php @@ -13,18 +13,9 @@ class LoggableWithEmbedded { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var string - */ - private $title; + private ?string $title = null; - /** - * @var Embedded - */ - private $embedded; + private ?Embedded $embedded = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/MaterializedPathCategory.php b/tests/Gedmo/Mapping/Fixture/Yaml/MaterializedPathCategory.php index 67992e89b4..3c52686649 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/MaterializedPathCategory.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/MaterializedPathCategory.php @@ -16,10 +16,7 @@ class MaterializedPathCategory { - /** - * @var int - */ - private $id; + private ?int $id = null; private ?string $title = null; @@ -30,7 +27,7 @@ class MaterializedPathCategory /** * @var Collection */ - private $children; + private Collection $children; private ?MaterializedPathCategory $parent = null; diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/Referenced.php b/tests/Gedmo/Mapping/Fixture/Yaml/Referenced.php index 0e5eb55448..536cc688cd 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/Referenced.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/Referenced.php @@ -13,13 +13,7 @@ class Referenced { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var Referencer - */ - private $referencer; + private ?Referencer $referencer = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/Referencer.php b/tests/Gedmo/Mapping/Fixture/Yaml/Referencer.php index ba00640f8d..9e4d4473ad 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/Referencer.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/Referencer.php @@ -15,13 +15,10 @@ class Referencer { - /** - * @var int - */ - private $id; + private ?int $id = null; /** * @var Collection */ - private $referencedDocuments; + private Collection $referencedDocuments; } diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/SoftDeleteable.php b/tests/Gedmo/Mapping/Fixture/Yaml/SoftDeleteable.php index 188aa0f9ca..a2c5343e3f 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/SoftDeleteable.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/SoftDeleteable.php @@ -13,13 +13,7 @@ class SoftDeleteable { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var \DateTime|null - */ - private $deletedAt; + private ?\DateTime $deletedAt = null; } diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/Sortable.php b/tests/Gedmo/Mapping/Fixture/Yaml/Sortable.php index 94eb70e21c..b325f86bd8 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/Sortable.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/Sortable.php @@ -16,33 +16,18 @@ class Sortable { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var string - */ - private $title; + private ?string $title = null; - /** - * @var int - */ - private $position; + private ?int $position = null; - /** - * @var string - */ - private $grouping; + private ?string $grouping = null; - /** - * @var SortableGroup - */ - private $sortable_group; + private ?SortableGroup $sortable_group = null; /** * @var Collection */ - private $sortable_groups; + private Collection $sortable_groups; } diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/Uploadable.php b/tests/Gedmo/Mapping/Fixture/Yaml/Uploadable.php index d5d1ccc8e7..42108552cf 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/Uploadable.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/Uploadable.php @@ -13,37 +13,23 @@ class Uploadable { - /** - * @var int - */ - private $id; + private ?int $id = null; - /** - * @var string - */ - private $mimeType; + private ?string $mimeType = null; /** * @var array */ - private $fileInfo; + private array $fileInfo = []; - /** - * @var float - */ - private $size; + private ?float $size = null; - /** - * @var string - */ - private $path; + private ?string $path = null; - public function getPath(): string + public function getPath(): ?string { return $this->path; } - public function callbackMethod(): void - { - } + public function callbackMethod(): void {} } diff --git a/tests/Gedmo/Mapping/Fixture/Yaml/User.php b/tests/Gedmo/Mapping/Fixture/Yaml/User.php index 95e0f426cd..d4c59dbee8 100644 --- a/tests/Gedmo/Mapping/Fixture/Yaml/User.php +++ b/tests/Gedmo/Mapping/Fixture/Yaml/User.php @@ -13,10 +13,7 @@ class User { - /** - * @var int - */ - private $id; + private ?int $id = null; private ?string $password = null; @@ -24,12 +21,9 @@ class User private ?string $company = null; - /** - * @var string - */ - private $localeField; + private ?string $localeField = null; - public function getId(): int + public function getId(): ?int { return $this->id; } @@ -39,7 +33,7 @@ public function setPassword(string $password): void $this->password = $password; } - public function getPassword(): string + public function getPassword(): ?string { return $this->password; } @@ -49,7 +43,7 @@ public function setUsername(string $username): void $this->username = $username; } - public function getUsername(): string + public function getUsername(): ?string { return $this->username; } @@ -59,7 +53,7 @@ public function setCompany(string $company): void $this->company = $company; } - public function getCompany(): string + public function getCompany(): ?string { return $this->company; } diff --git a/tests/Gedmo/Mapping/LoggableORMMappingTest.php b/tests/Gedmo/Mapping/LoggableORMMappingTest.php index f2d07801e2..76590d4e34 100644 --- a/tests/Gedmo/Mapping/LoggableORMMappingTest.php +++ b/tests/Gedmo/Mapping/LoggableORMMappingTest.php @@ -12,7 +12,6 @@ namespace Gedmo\Tests\Mapping; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Loggable\Entity\LogEntry; use Gedmo\Loggable\LoggableListener; @@ -57,11 +56,7 @@ protected function setUp(): void */ public static function dataLoggableObject(): \Generator { - if (PHP_VERSION_ID >= 80000) { - yield 'Model with attributes' => [AnnotatedLoggable::class]; - } elseif (class_exists(AnnotationDriver::class)) { - yield 'Model with annotations' => [AnnotatedLoggable::class]; - } + yield 'Model with attributes' => [AnnotatedLoggable::class]; if (class_exists(YamlDriver::class)) { yield 'Model with YAML mapping' => [YamlLoggable::class]; @@ -117,11 +112,7 @@ public static function dataLoggableObjectWithCompositeKey(): \Generator { yield 'Model with XML mapping' => [XmlLoggableComposite::class]; - if (PHP_VERSION_ID >= 80000) { - yield 'Model with attributes' => [AnnotatedLoggableComposite::class]; - } elseif (class_exists(AnnotationDriver::class)) { - yield 'Model with annotations' => [AnnotatedLoggableComposite::class]; - } + yield 'Model with attributes' => [AnnotatedLoggableComposite::class]; if (class_exists(YamlDriver::class)) { yield 'Model with YAML mapping' => [YamlLoggableComposite::class]; @@ -160,11 +151,7 @@ public static function dataLoggableObjectWithCompositeKeyAndRelation(): \Generat { yield 'Model with XML mapping' => [XmlLoggableCompositeRelation::class]; - if (PHP_VERSION_ID >= 80000) { - yield 'Model with attributes' => [AnnotatedLoggableCompositeRelation::class]; - } elseif (class_exists(AnnotationDriver::class)) { - yield 'Model with annotations' => [AnnotatedLoggableCompositeRelation::class]; - } + yield 'Model with attributes' => [AnnotatedLoggableCompositeRelation::class]; if (class_exists(YamlDriver::class)) { yield 'Model with YAML mapping' => [YamlLoggableCompositeRelation::class]; @@ -206,11 +193,7 @@ public function testLoggableCompositeRelationMapping(string $className): void */ public static function dataLoggableObjectWithEmbedded(): \Generator { - if (PHP_VERSION_ID >= 80000) { - yield 'Model with attributes' => [AnnotatedLoggableWithEmbedded::class]; - } elseif (class_exists(AnnotationDriver::class)) { - yield 'Model with annotations' => [AnnotatedLoggableWithEmbedded::class]; - } + yield 'Model with attributes' => [AnnotatedLoggableWithEmbedded::class]; } /** diff --git a/tests/Gedmo/Mapping/MappingEventSubscriberTest.php b/tests/Gedmo/Mapping/MappingEventSubscriberTest.php index adbe71f8d6..f46cad4642 100644 --- a/tests/Gedmo/Mapping/MappingEventSubscriberTest.php +++ b/tests/Gedmo/Mapping/MappingEventSubscriberTest.php @@ -11,9 +11,7 @@ namespace Gedmo\Tests\Mapping; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory; use Gedmo\Mapping\ExtensionMetadataFactory; @@ -33,11 +31,7 @@ protected function setUp(): void $config = $this->getBasicConfiguration(); - if (PHP_VERSION_ID >= 80000) { - $config->setMetadataDriverImpl(new AttributeDriver([])); - } else { - $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader())); - } + $config->setMetadataDriverImpl(new AttributeDriver([])); $this->em = $this->getBasicEntityManager($config); } @@ -45,7 +39,7 @@ protected function setUp(): void public function testGetMetadataFactoryCacheFromDoctrineForSluggable(): void { $metadataFactory = $this->em->getMetadataFactory(); - $getCache = \Closure::bind(static fn (AbstractClassMetadataFactory $metadataFactory): ?CacheItemPoolInterface => $metadataFactory->getCache(), null, \get_class($metadataFactory)); + $getCache = \Closure::bind(static fn (AbstractClassMetadataFactory $metadataFactory): ?CacheItemPoolInterface => $metadataFactory->getCache(), null, $metadataFactory::class); $cache = $getCache($metadataFactory); @@ -63,7 +57,7 @@ public function testGetMetadataFactoryCacheFromDoctrineForSluggable(): void public function testGetMetadataFactoryCacheFromDoctrineForSuperClassExtension(): void { $metadataFactory = $this->em->getMetadataFactory(); - $getCache = \Closure::bind(static fn (AbstractClassMetadataFactory $metadataFactory): ?CacheItemPoolInterface => $metadataFactory->getCache(), null, \get_class($metadataFactory)); + $getCache = \Closure::bind(static fn (AbstractClassMetadataFactory $metadataFactory): ?CacheItemPoolInterface => $metadataFactory->getCache(), null, $metadataFactory::class); /** @var CacheItemPoolInterface $cache */ $cache = $getCache($metadataFactory); @@ -87,11 +81,7 @@ public function testGetMetadataFactoryCacheFromDoctrineForSuperClassExtension(): // Create new configuration to use new array cache $config = $this->getBasicConfiguration(); - if (PHP_VERSION_ID >= 80000) { - $config->setMetadataDriverImpl(new AttributeDriver([])); - } else { - $config->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader())); - } + $config->setMetadataDriverImpl(new AttributeDriver([])); $this->em = $this->getBasicEntityManager($config); diff --git a/tests/Gedmo/Mapping/MappingTest.php b/tests/Gedmo/Mapping/MappingTest.php index dcc152fcc2..08fe4c59fa 100644 --- a/tests/Gedmo/Mapping/MappingTest.php +++ b/tests/Gedmo/Mapping/MappingTest.php @@ -15,7 +15,6 @@ use Doctrine\DBAL\DriverManager; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Tools\SchemaTool; use Gedmo\Sluggable\SluggableListener; @@ -49,11 +48,7 @@ protected function setUp(): void $config->setProxyNamespace('Gedmo\Mapping\Proxy'); } - if (PHP_VERSION_ID >= 80000) { - $config->setMetadataDriverImpl(new AttributeDriver([])); - } else { - $config->setMetadataDriverImpl(new AnnotationDriver($_ENV['annotation_reader'])); - } + $config->setMetadataDriverImpl(new AttributeDriver([])); $conn = [ 'driver' => 'pdo_sqlite', diff --git a/tests/Gedmo/Mapping/MetadataFactory/CustomDriverTest.php b/tests/Gedmo/Mapping/MetadataFactory/CustomDriverTest.php index 47fea572c2..d2fd0e709f 100644 --- a/tests/Gedmo/Mapping/MetadataFactory/CustomDriverTest.php +++ b/tests/Gedmo/Mapping/MetadataFactory/CustomDriverTest.php @@ -11,12 +11,12 @@ namespace Gedmo\Tests\Mapping\MetadataFactory; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\EventManager; use Doctrine\DBAL\DriverManager; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\ClassMetadata as ORMClassMetadata; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\Mapping\Driver\MappingDriver; @@ -55,13 +55,9 @@ protected function setUp(): void ]; $evm = new EventManager(); - $this->timestampable = new TimestampableListener(); - if (PHP_VERSION >= 80000) { - $this->timestampable->setAnnotationReader(new AttributeReader()); - } elseif (class_exists(AnnotationReader::class)) { - $this->timestampable->setAnnotationReader($_ENV['annotation_reader']); - } + $this->timestampable = new TimestampableListener(); + $this->timestampable->setAnnotationReader(new AttributeReader()); $evm->addEventSubscriber($this->timestampable); $connection = DriverManager::getConnection($conn, $config); @@ -81,7 +77,7 @@ public function testShouldWork(): void $this->em, Timestampable::class ); - static::assertTrue(isset($conf['create'])); + static::assertArrayHasKey('create', $conf); $test = new Timestampable(); $this->em->persist($test); @@ -113,9 +109,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata): void $id['columnName'] = 'id'; $id['id'] = true; - $metadata->setIdGeneratorType( - constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_AUTO') - ); + $metadata->setIdGeneratorType(ORMClassMetadata::GENERATOR_TYPE_AUTO); $metadata->mapField($id); diff --git a/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php b/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php index 80f19d7162..551569990b 100644 --- a/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php +++ b/tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php @@ -19,7 +19,6 @@ use Doctrine\ORM\Events; use Doctrine\ORM\Id\IdentityGenerator; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Tools\SchemaTool; use Gedmo\Mapping\Driver\AttributeReader; @@ -50,19 +49,11 @@ protected function setUp(): void $config->setProxyNamespace('Gedmo\Mapping\Proxy'); } - if (PHP_VERSION_ID >= 80000) { - $config->setMetadataDriverImpl(new AttributeDriver([])); - } else { - $config->setMetadataDriverImpl(new AnnotationDriver($_ENV['annotation_reader'])); - } + $config->setMetadataDriverImpl(new AttributeDriver([])); $this->timestampable = new TimestampableListener(); - if (PHP_VERSION_ID >= 80000) { - $this->timestampable->setAnnotationReader(new AttributeReader()); - } else { - $this->timestampable->setAnnotationReader($_ENV['annotation_reader']); - } + $this->timestampable->setAnnotationReader(new AttributeReader()); $evm = new EventManager(); $evm->addEventSubscriber($this->timestampable); @@ -86,7 +77,7 @@ public function testShouldWork(): void ); // @todo: This assertion fails when run in isolation - static::assertTrue(isset($conf['create'])); + static::assertArrayHasKey('create', $conf); $test = new Timestampable(); $this->em->persist($test); diff --git a/tests/Gedmo/Mapping/Mock/Extension/Encoder/EncoderListener.php b/tests/Gedmo/Mapping/Mock/Extension/Encoder/EncoderListener.php index 2ad5e3be44..5830259b4f 100644 --- a/tests/Gedmo/Mapping/Mock/Extension/Encoder/EncoderListener.php +++ b/tests/Gedmo/Mapping/Mock/Extension/Encoder/EncoderListener.php @@ -53,7 +53,7 @@ public function onFlush(EventArgs $args): void // check all pending updates foreach ($ea->getScheduledObjectUpdates($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); // if it has our metadata lets encode the properties if ($config = $this->getConfiguration($om, $meta->getName())) { $this->encode($ea, $object, $config); @@ -61,7 +61,7 @@ public function onFlush(EventArgs $args): void } // check all pending insertions foreach ($ea->getScheduledObjectInsertions($uow) as $object) { - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); // if it has our metadata lets encode the properties if ($config = $this->getConfiguration($om, $meta->getName())) { $this->encode($ea, $object, $config); @@ -81,7 +81,7 @@ protected function getNamespace(): string private function encode(EventAdapterInterface $ea, object $object, array $config): void { $om = $ea->getObjectManager(); - $meta = $om->getClassMetadata(get_class($object)); + $meta = $om->getClassMetadata($object::class); $uow = $om->getUnitOfWork(); foreach ($config['encode'] as $field => $options) { $value = $meta->getReflectionProperty($field)->getValue($object); diff --git a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Annotation.php b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Annotation.php index 085648593c..2e2894264a 100644 --- a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Annotation.php +++ b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Annotation.php @@ -13,6 +13,4 @@ use Gedmo\Mapping\Driver\AnnotationDriverInterface; -class Annotation extends Attribute implements AnnotationDriverInterface -{ -} +class Annotation extends Attribute implements AnnotationDriverInterface {} diff --git a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Attribute.php b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Attribute.php index 2794af8934..1acd2910bb 100644 --- a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Attribute.php +++ b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Attribute.php @@ -16,7 +16,12 @@ class Attribute extends AbstractAnnotationDriver { - public function readExtendedMetadata($meta, array &$config) + /** + * @param array $config + * + * @return array + */ + public function readExtendedMetadata($meta, array &$config): array { $class = $meta->getReflectionClass(); diff --git a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Encode.php b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Encode.php index eb6c5ebc1e..f2489034fd 100644 --- a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Encode.php +++ b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Encode.php @@ -21,19 +21,5 @@ #[\Attribute(\Attribute::TARGET_PROPERTY)] final class Encode implements GedmoAnnotation { - /** - * @var string - */ - public $type = 'md5'; - - /** - * @var string|null - */ - public $secret; - - public function __construct(string $type = 'md5', ?string $secret = null) - { - $this->type = $type; - $this->secret = $secret; - } + public function __construct(public string $type = 'md5', public ?string $secret = null) {} } diff --git a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Event/Adapter/ODM.php b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Event/Adapter/ODM.php index 2a068ccc54..40c4eb7541 100644 --- a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Event/Adapter/ODM.php +++ b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Event/Adapter/ODM.php @@ -13,6 +13,4 @@ use Gedmo\Mapping\Event\Adapter\ODM as BaseAdapterODM; -final class ODM extends BaseAdapterODM -{ -} +final class ODM extends BaseAdapterODM {} diff --git a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Event/Adapter/ORM.php b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Event/Adapter/ORM.php index 2f0d345f3f..52b8490b54 100644 --- a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Event/Adapter/ORM.php +++ b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Event/Adapter/ORM.php @@ -13,6 +13,4 @@ use Gedmo\Mapping\Event\Adapter\ORM as BaseAdapterORM; -final class ORM extends BaseAdapterORM -{ -} +final class ORM extends BaseAdapterORM {} diff --git a/tests/Gedmo/Mapping/Mock/Mapping/Event/Adapter/ORM.php b/tests/Gedmo/Mapping/Mock/Mapping/Event/Adapter/ORM.php index bb3bf5d1f1..b880d7db7a 100644 --- a/tests/Gedmo/Mapping/Mock/Mapping/Event/Adapter/ORM.php +++ b/tests/Gedmo/Mapping/Mock/Mapping/Event/Adapter/ORM.php @@ -13,6 +13,4 @@ use Gedmo\Mapping\Event\Adapter\ORM as EventAdapterORM; -class ORM extends EventAdapterORM -{ -} +class ORM extends EventAdapterORM {} diff --git a/tests/Gedmo/Mapping/MultiManagerMappingTest.php b/tests/Gedmo/Mapping/MultiManagerMappingTest.php index a1f2175f35..f1b6857ba4 100644 --- a/tests/Gedmo/Mapping/MultiManagerMappingTest.php +++ b/tests/Gedmo/Mapping/MultiManagerMappingTest.php @@ -11,10 +11,8 @@ namespace Gedmo\Tests\Mapping; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; @@ -46,18 +44,9 @@ protected function setUp(): void ArticleEntity::class, ]); - // EM with XML and annotation/attribute mapping - if (PHP_VERSION_ID >= 80000) { - $annotationDriver = new AttributeDriver([]); - - $annotationDriver2 = new AttributeDriver([]); - } else { - $reader = new AnnotationReader(); - $annotationDriver = new AnnotationDriver($reader); - - $reader = new AnnotationReader(); - $annotationDriver2 = new AnnotationDriver($reader); - } + // EM with XML and attribute mapping + $annotationDriver = new AttributeDriver([]); + $annotationDriver2 = new AttributeDriver([]); $xmlDriver = new XmlDriver(__DIR__.'/Driver/Xml', XmlDriver::DEFAULT_FILE_EXTENSION, false); diff --git a/tests/Gedmo/Mapping/ORMMappingTestCase.php b/tests/Gedmo/Mapping/ORMMappingTestCase.php index f5270ce8e3..06feb6053f 100644 --- a/tests/Gedmo/Mapping/ORMMappingTestCase.php +++ b/tests/Gedmo/Mapping/ORMMappingTestCase.php @@ -11,13 +11,11 @@ namespace Gedmo\Tests\Mapping; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; @@ -57,7 +55,7 @@ final protected function getBasicConfiguration(): Configuration final protected function getBasicEntityManager(?Configuration $config = null, ?Connection $connection = null, ?EventManager $evm = null): EntityManager { - if (null === $config) { + if (!$config instanceof Configuration) { $config = $this->getBasicConfiguration(); $config->setMetadataDriverImpl($this->createChainedMappingDriver()); } @@ -80,11 +78,7 @@ final protected function createChainedMappingDriver(): MappingDriverChain $chain->addDriver(new YamlDriver(__DIR__.'/Driver/Yaml'), 'Gedmo\Tests\Mapping\Fixture\Yaml'); } - if (PHP_VERSION_ID >= 80000) { - $chain->addDriver(new AttributeDriver([]), 'Gedmo\Tests\Mapping\Fixture'); - } elseif (class_exists(AnnotationDriver::class) && class_exists(AnnotationReader::class)) { - $chain->addDriver(new AnnotationDriver(new AnnotationReader()), 'Gedmo\Tests\Mapping\Fixture'); - } + $chain->addDriver(new AttributeDriver([]), 'Gedmo\Tests\Mapping\Fixture'); return $chain; } diff --git a/tests/Gedmo/Mapping/SluggableMappingTest.php b/tests/Gedmo/Mapping/SluggableMappingTest.php index 9b9ad8cce6..5d91c2fcb6 100644 --- a/tests/Gedmo/Mapping/SluggableMappingTest.php +++ b/tests/Gedmo/Mapping/SluggableMappingTest.php @@ -12,7 +12,6 @@ namespace Gedmo\Tests\Mapping; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\Sluggable\Handler\RelativeSlugHandler; @@ -49,11 +48,7 @@ public static function dataSluggableObject(): \Generator { yield 'Model with XML mapping' => [XmlSluggable::class]; - if (PHP_VERSION_ID >= 80000) { - yield 'Model with attributes' => [AnnotatedSluggable::class]; - } elseif (class_exists(AnnotationDriver::class)) { - yield 'Model with annotations' => [AnnotatedSluggable::class]; - } + yield 'Model with attributes' => [AnnotatedSluggable::class]; } /** diff --git a/tests/Gedmo/Mapping/SoftDeleteableMappingTest.php b/tests/Gedmo/Mapping/SoftDeleteableMappingTest.php index 0b868de5c2..ac27da214d 100644 --- a/tests/Gedmo/Mapping/SoftDeleteableMappingTest.php +++ b/tests/Gedmo/Mapping/SoftDeleteableMappingTest.php @@ -12,7 +12,6 @@ namespace Gedmo\Tests\Mapping; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\SoftDeleteable\SoftDeleteableListener; @@ -48,11 +47,7 @@ public static function dataSoftDeleteableObject(): \Generator { yield 'Model with XML mapping' => [XmlSoftDeleteable::class]; - if (PHP_VERSION_ID >= 80000) { - yield 'Model with attributes' => [AnnotatedSoftDeleteable::class]; - } elseif (class_exists(AnnotationDriver::class)) { - yield 'Model with annotations' => [AnnotatedSoftDeleteable::class]; - } + yield 'Model with attributes' => [AnnotatedSoftDeleteable::class]; if (class_exists(YamlDriver::class)) { yield 'Model with YAML mapping' => [YamlSoftDeleteable::class]; diff --git a/tests/Gedmo/Mapping/SortableMappingTest.php b/tests/Gedmo/Mapping/SortableMappingTest.php index f95c8150f9..57790984f5 100644 --- a/tests/Gedmo/Mapping/SortableMappingTest.php +++ b/tests/Gedmo/Mapping/SortableMappingTest.php @@ -12,7 +12,6 @@ namespace Gedmo\Tests\Mapping; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\Sortable\SortableListener; @@ -47,11 +46,7 @@ public static function dataSortableObject(): \Generator { yield 'Model with XML mapping' => [XmlSortable::class]; - if (PHP_VERSION_ID >= 80000) { - yield 'Model with attributes' => [AnnotatedSortable::class]; - } elseif (class_exists(AnnotationDriver::class)) { - yield 'Model with annotations' => [AnnotatedSortable::class]; - } + yield 'Model with attributes' => [AnnotatedSortable::class]; if (class_exists(YamlDriver::class)) { yield 'Model with YAML mapping' => [YamlSortable::class]; diff --git a/tests/Gedmo/Mapping/TimestampableMappingTest.php b/tests/Gedmo/Mapping/TimestampableMappingTest.php index 91c3ec1d89..1cbc0a0e86 100644 --- a/tests/Gedmo/Mapping/TimestampableMappingTest.php +++ b/tests/Gedmo/Mapping/TimestampableMappingTest.php @@ -12,7 +12,6 @@ namespace Gedmo\Tests\Mapping; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\Tests\Mapping\Fixture\Category as AnnotatedCategory; @@ -47,11 +46,7 @@ protected function setUp(): void */ public static function dataTimestampableObject(): \Generator { - if (PHP_VERSION_ID >= 80000) { - yield 'Model with attributes' => [AnnotatedCategory::class]; - } elseif (class_exists(AnnotationDriver::class)) { - yield 'Model with annotations' => [AnnotatedCategory::class]; - } + yield 'Model with attributes' => [AnnotatedCategory::class]; if (class_exists(YamlDriver::class)) { yield 'Model with YAML mapping' => [YamlCategory::class]; diff --git a/tests/Gedmo/Mapping/TranslatableMappingTest.php b/tests/Gedmo/Mapping/TranslatableMappingTest.php index 4edec0a40e..4d962f63cf 100644 --- a/tests/Gedmo/Mapping/TranslatableMappingTest.php +++ b/tests/Gedmo/Mapping/TranslatableMappingTest.php @@ -12,7 +12,6 @@ namespace Gedmo\Tests\Mapping; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\Tests\Mapping\Fixture\User as AnnotatedUser; @@ -49,11 +48,7 @@ public static function dataSortableObject(): \Generator { yield 'Model with XML mapping' => [XmlUser::class]; - if (PHP_VERSION_ID >= 80000) { - yield 'Model with attributes' => [AnnotatedUser::class]; - } elseif (class_exists(AnnotationDriver::class)) { - yield 'Model with annotations' => [AnnotatedUser::class]; - } + yield 'Model with attributes' => [AnnotatedUser::class]; if (class_exists(YamlDriver::class)) { yield 'Model with YAML mapping' => [YamlUser::class]; diff --git a/tests/Gedmo/Mapping/TreeMappingTest.php b/tests/Gedmo/Mapping/TreeMappingTest.php index 6d7a850f16..9d2700b990 100644 --- a/tests/Gedmo/Mapping/TreeMappingTest.php +++ b/tests/Gedmo/Mapping/TreeMappingTest.php @@ -11,9 +11,7 @@ namespace Gedmo\Tests\Mapping; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; @@ -53,11 +51,7 @@ protected function setUp(): void // TODO - The ORM's YAML mapping is deprecated and removed in 3.0 $chain->addDriver(new YamlDriver(__DIR__.'/Driver/Yaml'), 'Gedmo\Tests\Mapping\Fixture\Yaml'); - if (PHP_VERSION_ID >= 80000) { - $annotationOrAttributeDriver = new AttributeDriver([]); - } else { - $annotationOrAttributeDriver = new AnnotationDriver(new AnnotationReader()); - } + $annotationOrAttributeDriver = new AttributeDriver([]); $chain->addDriver($annotationOrAttributeDriver, 'Gedmo\Tests\Tree\Fixture'); $chain->addDriver($annotationOrAttributeDriver, 'Gedmo\Tree'); diff --git a/tests/Gedmo/Mapping/UploadableMappingTest.php b/tests/Gedmo/Mapping/UploadableMappingTest.php index e76d13a6f0..1c0fd64f0f 100644 --- a/tests/Gedmo/Mapping/UploadableMappingTest.php +++ b/tests/Gedmo/Mapping/UploadableMappingTest.php @@ -12,7 +12,6 @@ namespace Gedmo\Tests\Mapping; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\YamlDriver; use Gedmo\Mapping\ExtensionMetadataFactory; use Gedmo\Tests\Mapping\Fixture\Uploadable as AnnotatedUploadable; @@ -52,11 +51,7 @@ public static function dataUploadableObject(): \Generator { yield 'Model with XML mapping' => [XmlUploadable::class]; - if (PHP_VERSION_ID >= 80000) { - yield 'Model with attributes' => [AnnotatedUploadable::class]; - } elseif (class_exists(AnnotationDriver::class)) { - yield 'Model with annotations' => [AnnotatedUploadable::class]; - } + yield 'Model with attributes' => [AnnotatedUploadable::class]; if (class_exists(YamlDriver::class)) { yield 'Model with YAML mapping' => [YamlUploadable::class]; diff --git a/tests/Gedmo/Mapping/Xml/ClosureTreeMappingTest.php b/tests/Gedmo/Mapping/Xml/ClosureTreeMappingTest.php index a8c140d826..c0f68dde3a 100644 --- a/tests/Gedmo/Mapping/Xml/ClosureTreeMappingTest.php +++ b/tests/Gedmo/Mapping/Xml/ClosureTreeMappingTest.php @@ -11,10 +11,8 @@ namespace Gedmo\Tests\Mapping\Xml; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\EventManager; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; @@ -38,11 +36,7 @@ protected function setUp(): void { parent::setUp(); - if (PHP_VERSION_ID >= 80000) { - $annotationDriver = new AttributeDriver([]); - } else { - $annotationDriver = new AnnotationDriver(new AnnotationReader()); - } + $annotationDriver = new AttributeDriver([]); $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml', XmlDriver::DEFAULT_FILE_EXTENSION, false); diff --git a/tests/Gedmo/Mapping/Xml/MaterializedPathTreeMappingTest.php b/tests/Gedmo/Mapping/Xml/MaterializedPathTreeMappingTest.php index a19de177b0..60213dc612 100644 --- a/tests/Gedmo/Mapping/Xml/MaterializedPathTreeMappingTest.php +++ b/tests/Gedmo/Mapping/Xml/MaterializedPathTreeMappingTest.php @@ -11,10 +11,8 @@ namespace Gedmo\Tests\Mapping\Xml; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\EventManager; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; @@ -38,11 +36,7 @@ protected function setUp(): void { parent::setUp(); - if (PHP_VERSION_ID >= 80000) { - $annotationDriver = new AttributeDriver([]); - } else { - $annotationDriver = new AnnotationDriver(new AnnotationReader()); - } + $annotationDriver = new AttributeDriver([]); $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml', XmlDriver::DEFAULT_FILE_EXTENSION, false); diff --git a/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php b/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php index 27a9d3fb96..b82ab6b825 100644 --- a/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php +++ b/tests/Gedmo/Mapping/Xml/ReferencesMappingTest.php @@ -11,10 +11,8 @@ namespace Gedmo\Tests\Mapping\Xml; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\EventManager; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; @@ -35,11 +33,7 @@ protected function setUp(): void { parent::setUp(); - if (PHP_VERSION_ID >= 80000) { - $annotationDriver = new AttributeDriver([]); - } else { - $annotationDriver = new AnnotationDriver(new AnnotationReader()); - } + $annotationDriver = new AttributeDriver([]); $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml', XmlDriver::DEFAULT_FILE_EXTENSION, false); diff --git a/tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php b/tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php index 3c58482c5d..0c69e5eac5 100644 --- a/tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php +++ b/tests/Gedmo/Mapping/Xml/TranslatableMappingTest.php @@ -11,10 +11,8 @@ namespace Gedmo\Tests\Mapping\Xml; -use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\EventManager; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; @@ -39,11 +37,7 @@ protected function setUp(): void { parent::setUp(); - if (PHP_VERSION_ID >= 80000) { - $annotationDriver = new AttributeDriver([]); - } else { - $annotationDriver = new AnnotationDriver(new AnnotationReader()); - } + $annotationDriver = new AttributeDriver([]); $xmlDriver = new XmlDriver(__DIR__.'/../Driver/Xml', XmlDriver::DEFAULT_FILE_EXTENSION, false); diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyNullify/Article.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyNullify/Article.php index 2c85195668..17e2237e6c 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyNullify/Article.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyNullify/Article.php @@ -21,12 +21,10 @@ class Article { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyNullify/Type.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyNullify/Type.php index fc8f1ecad8..5cecb867c7 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyNullify/Type.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyNullify/Type.php @@ -32,15 +32,13 @@ class Type */ #[ODM\ReferenceMany(targetDocument: Article::class, mappedBy: 'type')] #[Gedmo\ReferenceIntegrity(value: 'nullify')] - protected $articles; + protected Collection $articles; /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyPull/Article.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyPull/Article.php index 6a4562446d..7b504a3cf1 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyPull/Article.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyPull/Article.php @@ -23,12 +23,10 @@ class Article { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") @@ -42,7 +40,7 @@ class Article * @ODM\ReferenceMany(targetDocument="Gedmo\Tests\ReferenceIntegrity\Fixture\Document\ManyPull\Type", inversedBy="articles") */ #[ODM\ReferenceMany(targetDocument: Type::class, inversedBy: 'articles')] - private $types; + private Collection $types; public function __construct() { diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyPull/Type.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyPull/Type.php index 132ec46754..04e80c943b 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyPull/Type.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyPull/Type.php @@ -32,15 +32,13 @@ class Type */ #[ODM\ReferenceMany(targetDocument: Article::class, mappedBy: 'types')] #[Gedmo\ReferenceIntegrity(value: 'pull')] - protected $articles; + protected Collection $articles; /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyRestrict/Article.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyRestrict/Article.php index 02b237da59..21306d050d 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyRestrict/Article.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyRestrict/Article.php @@ -21,12 +21,10 @@ class Article { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyRestrict/Type.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyRestrict/Type.php index 92cd0f80f1..0beaeaa9b1 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyRestrict/Type.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/ManyRestrict/Type.php @@ -32,15 +32,13 @@ class Type */ #[ODM\ReferenceMany(targetDocument: Article::class, mappedBy: 'type')] #[Gedmo\ReferenceIntegrity(value: 'restrict')] - protected $articles; + protected Collection $articles; /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneNullify/Article.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneNullify/Article.php index 3f979db0db..70c93bbb69 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneNullify/Article.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneNullify/Article.php @@ -21,12 +21,10 @@ class Article { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneNullify/Type.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneNullify/Type.php index 3ee2dde2cf..46687b8f88 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneNullify/Type.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneNullify/Type.php @@ -22,23 +22,19 @@ class Type { /** - * @var Article - * * @ODM\ReferenceOne(targetDocument="Gedmo\Tests\ReferenceIntegrity\Fixture\Document\OneNullify\Article", mappedBy="type") * * @Gedmo\ReferenceIntegrity("nullify") */ #[ODM\ReferenceOne(targetDocument: Article::class, mappedBy: 'type')] #[Gedmo\ReferenceIntegrity(value: 'nullify')] - protected $article; + protected ?Article $article = null; /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OnePull/Article.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OnePull/Article.php index c66bc710dd..feec2cc343 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OnePull/Article.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OnePull/Article.php @@ -23,12 +23,10 @@ class Article { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") @@ -42,7 +40,7 @@ class Article * @ODM\ReferenceMany(targetDocument="Gedmo\Tests\ReferenceIntegrity\Fixture\Document\OnePull\Type", inversedBy="articles") */ #[ODM\ReferenceMany(targetDocument: Type::class, inversedBy: 'articles')] - private $types; + private Collection $types; public function __construct() { diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OnePull/Type.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OnePull/Type.php index cf6cb2737f..ae3b152ca5 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OnePull/Type.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OnePull/Type.php @@ -22,23 +22,19 @@ class Type { /** - * @var Article|null - * * @ODM\ReferenceOne(targetDocument="Gedmo\Tests\ReferenceIntegrity\Fixture\Document\OnePull\Article", mappedBy="types") * * @Gedmo\ReferenceIntegrity("pull") */ #[ODM\ReferenceOne(targetDocument: Article::class, mappedBy: 'types')] #[Gedmo\ReferenceIntegrity(value: 'pull')] - protected $article; + protected ?Article $article = null; /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneRestrict/Article.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneRestrict/Article.php index 0a0c1008a2..9fd6efcc37 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneRestrict/Article.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneRestrict/Article.php @@ -21,12 +21,10 @@ class Article { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneRestrict/Type.php b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneRestrict/Type.php index 62bd70b315..5c2e376f76 100644 --- a/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneRestrict/Type.php +++ b/tests/Gedmo/ReferenceIntegrity/Fixture/Document/OneRestrict/Type.php @@ -22,23 +22,19 @@ class Type { /** - * @var Article|null - * * @ODM\ReferenceOne(targetDocument="Gedmo\Tests\ReferenceIntegrity\Fixture\Document\OneRestrict\Article", mappedBy="type") * * @Gedmo\ReferenceIntegrity("restrict") */ #[ODM\ReferenceOne(targetDocument: Article::class, mappedBy: 'type')] #[Gedmo\ReferenceIntegrity(value: 'restrict')] - protected $article; + protected ?Article $article = null; /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/ReferenceIntegrity/ReferenceIntegrityDocumentTest.php b/tests/Gedmo/ReferenceIntegrity/ReferenceIntegrityDocumentTest.php index 1964011778..c88e262388 100644 --- a/tests/Gedmo/ReferenceIntegrity/ReferenceIntegrityDocumentTest.php +++ b/tests/Gedmo/ReferenceIntegrity/ReferenceIntegrityDocumentTest.php @@ -59,7 +59,7 @@ public function testOneNullify(): void $type = $this->dm->getRepository(TypeOneNullify::class) ->findOneBy(['title' => 'One Nullify Type']); - static::assertNotNull($type); + static::assertInstanceOf(TypeOneNullify::class, $type); static::assertIsObject($type); $this->dm->remove($type); @@ -67,12 +67,12 @@ public function testOneNullify(): void $type = $this->dm->getRepository(TypeOneNullify::class) ->findOneBy(['title' => 'One Nullify Type']); - static::assertNull($type); + static::assertNotInstanceOf(TypeOneNullify::class, $type); $article = $this->dm->getRepository(ArticleOneNullify::class) ->findOneBy(['title' => 'One Nullify Article']); - static::assertNull($article->getType()); + static::assertNotInstanceOf(TypeOneNullify::class, $article->getType()); $this->dm->clear(); } @@ -82,7 +82,7 @@ public function testManyNullify(): void $type = $this->dm->getRepository(TypeManyNullify::class) ->findOneBy(['title' => 'Many Nullify Type']); - static::assertNotNull($type); + static::assertInstanceOf(TypeManyNullify::class, $type); static::assertIsObject($type); $this->dm->remove($type); @@ -90,12 +90,12 @@ public function testManyNullify(): void $type = $this->dm->getRepository(TypeManyNullify::class) ->findOneBy(['title' => 'Many Nullify Type']); - static::assertNull($type); + static::assertNotInstanceOf(TypeManyNullify::class, $type); $article = $this->dm->getRepository(ArticleManyNullify::class) ->findOneBy(['title' => 'Many Nullify Article']); - static::assertNull($article->getType()); + static::assertNotInstanceOf(TypeManyNullify::class, $article->getType()); $this->dm->clear(); } @@ -107,10 +107,10 @@ public function testOnePull(): void $type2 = $this->dm->getRepository(TypeOnePull::class) ->findOneBy(['title' => 'One Pull Type 2']); - static::assertNotNull($type1); + static::assertInstanceOf(TypeOnePull::class, $type1); static::assertIsObject($type1); - static::assertNotNull($type2); + static::assertInstanceOf(TypeOnePull::class, $type2); static::assertIsObject($type2); $this->dm->remove($type2); @@ -118,7 +118,7 @@ public function testOnePull(): void $type2 = $this->dm->getRepository(TypeOnePull::class) ->findOneBy(['title' => 'One Pull Type 2']); - static::assertNull($type2); + static::assertNotInstanceOf(TypeOnePull::class, $type2); $article = $this->dm->getRepository(ArticleOnePull::class) ->findOneBy(['title' => 'One Pull Article']); @@ -137,10 +137,10 @@ public function testManyPull(): void $type2 = $this->dm->getRepository(TypeOnePull::class) ->findOneBy(['title' => 'Many Pull Type 2']); - static::assertNotNull($type1); + static::assertInstanceOf(TypeOnePull::class, $type1); static::assertIsObject($type1); - static::assertNotNull($type2); + static::assertInstanceOf(TypeOnePull::class, $type2); static::assertIsObject($type2); $this->dm->remove($type2); @@ -148,7 +148,7 @@ public function testManyPull(): void $type2 = $this->dm->getRepository(TypeManyPull::class) ->findOneBy(['title' => 'Many Pull Type 2']); - static::assertNull($type2); + static::assertNotInstanceOf(TypeManyPull::class, $type2); $article = $this->dm->getRepository(ArticleManyPull::class) ->findOneBy(['title' => 'Many Pull Article']); @@ -166,7 +166,7 @@ public function testOneRestrict(): void $type = $this->dm->getRepository(TypeOneRestrict::class) ->findOneBy(['title' => 'One Restrict Type']); - static::assertNotNull($type); + static::assertInstanceOf(TypeOneRestrict::class, $type); static::assertIsObject($type); $this->dm->remove($type); @@ -179,7 +179,7 @@ public function testManyRestrict(): void $type = $this->dm->getRepository(Type::class) ->findOneBy(['title' => 'Many Restrict Type']); - static::assertNotNull($type); + static::assertInstanceOf(Type::class, $type); static::assertIsObject($type); $this->dm->remove($type); diff --git a/tests/Gedmo/References/Fixture/ODM/MongoDB/Metadata.php b/tests/Gedmo/References/Fixture/ODM/MongoDB/Metadata.php index bb56a7cfd1..8f40420b92 100644 --- a/tests/Gedmo/References/Fixture/ODM/MongoDB/Metadata.php +++ b/tests/Gedmo/References/Fixture/ODM/MongoDB/Metadata.php @@ -24,12 +24,10 @@ class Metadata { /** - * @var string|null - * * @ODM\Field(type="string") */ #[ODM\Field(type: Type::STRING)] - private $name; + private ?string $name = null; /** * @Gedmo\ReferenceOne(type="entity", class="Gedmo\Tests\References\Fixture\ORM\Category", identifier="categoryId") diff --git a/tests/Gedmo/References/Fixture/ODM/MongoDB/Product.php b/tests/Gedmo/References/Fixture/ODM/MongoDB/Product.php index 56eb5bd369..e970b57386 100644 --- a/tests/Gedmo/References/Fixture/ODM/MongoDB/Product.php +++ b/tests/Gedmo/References/Fixture/ODM/MongoDB/Product.php @@ -42,7 +42,7 @@ class Product * @Gedmo\ReferenceMany(type="entity", class="Gedmo\Tests\References\Fixture\ORM\StockItem", mappedBy="product") */ #[Gedmo\ReferenceMany(type: 'entity', class: StockItem::class, mappedBy: 'product')] - private $stockItems; + private Collection $stockItems; /** * @var Collection @@ -50,7 +50,7 @@ class Product * @ODM\EmbedMany(targetDocument="Gedmo\Tests\References\Fixture\ODM\MongoDB\Metadata") */ #[ODM\EmbedMany(targetDocument: Metadata::class)] - private $metadatas; + private Collection $metadatas; public function __construct() { diff --git a/tests/Gedmo/References/Fixture/ORM/Category.php b/tests/Gedmo/References/Fixture/ORM/Category.php index da3e980d01..3f98c39b53 100644 --- a/tests/Gedmo/References/Fixture/ORM/Category.php +++ b/tests/Gedmo/References/Fixture/ORM/Category.php @@ -25,16 +25,14 @@ class Category { /** - * @var int|null - * * @ORM\Id - * @ORM\GeneratedValue(strategy="IDENTITY") + * @ORM\GeneratedValue * @ORM\Column(type="integer") */ #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'IDENTITY')] + #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="name", type="string", length=128) diff --git a/tests/Gedmo/References/Fixture/ORM/StockItem.php b/tests/Gedmo/References/Fixture/ORM/StockItem.php index 64e26a9cb9..b90d909901 100644 --- a/tests/Gedmo/References/Fixture/ORM/StockItem.php +++ b/tests/Gedmo/References/Fixture/ORM/StockItem.php @@ -23,16 +23,14 @@ class StockItem { /** - * @var int|null - * * @ORM\Id - * @ORM\GeneratedValue(strategy="IDENTITY") + * @ORM\GeneratedValue * @ORM\Column(type="integer") */ #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'IDENTITY')] + #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column diff --git a/tests/Gedmo/References/ReferencesListenerTest.php b/tests/Gedmo/References/ReferencesListenerTest.php index 9b0d352225..d182e010fa 100644 --- a/tests/Gedmo/References/ReferencesListenerTest.php +++ b/tests/Gedmo/References/ReferencesListenerTest.php @@ -94,7 +94,7 @@ public function testShouldPopulateReferenceOneWithProxyFromIdentifierField(): vo $this->em->flush(); $this->em->clear(); - $stockItem = $this->em->find(get_class($stockItem), $stockItem->getId()); + $stockItem = $this->em->find($stockItem::class, $stockItem->getId()); static::assertSame($product, $stockItem->getProduct()); } @@ -125,19 +125,19 @@ public function testShouldPopulateReferenceManyWithLazyCollectionInstance(): voi $this->em->persist($stockItem); $this->em->flush(); - $product = $this->dm->find(get_class($product), $product->getId()); + $product = $this->dm->find($product::class, $product->getId()); static::assertInstanceOf(Collection::class, $product->getStockItems()); - static::assertSame(2, $product->getStockItems()->count()); + static::assertCount(2, $product->getStockItems()); $first = $product->getStockItems()->first(); - static::assertInstanceOf(get_class($stockItem), $first); + static::assertInstanceOf($stockItem::class, $first); static::assertSame('APP-TV', $first->getSku()); $last = $product->getStockItems()->last(); - static::assertInstanceOf(get_class($stockItem), $last); + static::assertInstanceOf($stockItem::class, $last); static::assertSame('AMZN-APP-TV', $last->getSku()); } diff --git a/tests/Gedmo/Sluggable/CustomTransliteratorTest.php b/tests/Gedmo/Sluggable/CustomTransliteratorTest.php index eb6bf238b7..51affb6243 100644 --- a/tests/Gedmo/Sluggable/CustomTransliteratorTest.php +++ b/tests/Gedmo/Sluggable/CustomTransliteratorTest.php @@ -41,7 +41,7 @@ public function testCanUseCustomTransliterator(): void { $evm = new EventManager(); $sluggableListener = new SluggableListener(); - $sluggableListener->setTransliterator([Transliterator::class, 'transliterate']); + $sluggableListener->setTransliterator(Transliterator::transliterate(...)); $evm->addEventSubscriber($sluggableListener); $this->getDefaultMockSqliteEntityManager($evm); diff --git a/tests/Gedmo/Sluggable/Fixture/Article.php b/tests/Gedmo/Sluggable/Fixture/Article.php index 9ea26ec64a..50ab66918d 100644 --- a/tests/Gedmo/Sluggable/Fixture/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Article.php @@ -23,8 +23,6 @@ class Article implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Article implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/ArticleWithoutFields.php b/tests/Gedmo/Sluggable/Fixture/ArticleWithoutFields.php index 2939f64305..2da70d331c 100644 --- a/tests/Gedmo/Sluggable/Fixture/ArticleWithoutFields.php +++ b/tests/Gedmo/Sluggable/Fixture/ArticleWithoutFields.php @@ -23,8 +23,6 @@ class ArticleWithoutFields implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class ArticleWithoutFields implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Slug(separator="-", updatable=true) diff --git a/tests/Gedmo/Sluggable/Fixture/Comment.php b/tests/Gedmo/Sluggable/Fixture/Comment.php index f58df3fec2..a2e938ae06 100644 --- a/tests/Gedmo/Sluggable/Fixture/Comment.php +++ b/tests/Gedmo/Sluggable/Fixture/Comment.php @@ -21,8 +21,6 @@ class Comment { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -30,7 +28,7 @@ class Comment #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(type="text") diff --git a/tests/Gedmo/Sluggable/Fixture/ConfigurationArticle.php b/tests/Gedmo/Sluggable/Fixture/ConfigurationArticle.php index 63471b77d8..5a08fd3c2b 100644 --- a/tests/Gedmo/Sluggable/Fixture/ConfigurationArticle.php +++ b/tests/Gedmo/Sluggable/Fixture/ConfigurationArticle.php @@ -23,8 +23,6 @@ class ConfigurationArticle implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class ConfigurationArticle implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDate.php b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDate.php index c1155b94dc..f8b61eee66 100644 --- a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDate.php +++ b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDate.php @@ -23,8 +23,6 @@ class ArticleDate implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class ArticleDate implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateImmutable.php b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateImmutable.php index 8399a60982..b23380f396 100644 --- a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateImmutable.php +++ b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateImmutable.php @@ -23,8 +23,6 @@ class ArticleDateImmutable implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class ArticleDateImmutable implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTime.php b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTime.php index 59eff9d7c3..ac85427cea 100644 --- a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTime.php +++ b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTime.php @@ -23,8 +23,6 @@ class ArticleDateTime implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class ArticleDateTime implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeImmutable.php b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeImmutable.php index 732d626b0c..4530b19e69 100644 --- a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeImmutable.php +++ b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeImmutable.php @@ -23,8 +23,6 @@ class ArticleDateTimeImmutable implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class ArticleDateTimeImmutable implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeTz.php b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeTz.php index db5ce39860..336966b35e 100644 --- a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeTz.php +++ b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeTz.php @@ -23,8 +23,6 @@ class ArticleDateTimeTz implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class ArticleDateTimeTz implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeTzImmutable.php b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeTzImmutable.php index c6db077b74..6f3c4d22ed 100644 --- a/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeTzImmutable.php +++ b/tests/Gedmo/Sluggable/Fixture/DateTimeTypes/ArticleDateTimeTzImmutable.php @@ -23,8 +23,6 @@ class ArticleDateTimeTzImmutable implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class ArticleDateTimeTzImmutable implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Document/Article.php b/tests/Gedmo/Sluggable/Fixture/Document/Article.php index 90a332ecca..91606bf4fe 100644 --- a/tests/Gedmo/Sluggable/Fixture/Document/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Document/Article.php @@ -22,12 +22,10 @@ class Article { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Sluggable/Fixture/Document/Handler/Article.php b/tests/Gedmo/Sluggable/Fixture/Document/Handler/Article.php index 15f0f9c9d4..f96d6b68c6 100644 --- a/tests/Gedmo/Sluggable/Fixture/Document/Handler/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Document/Handler/Article.php @@ -23,12 +23,10 @@ class Article { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Sluggable/Fixture/Document/Handler/RelativeSlug.php b/tests/Gedmo/Sluggable/Fixture/Document/Handler/RelativeSlug.php index 042ac30b36..afe0df3197 100644 --- a/tests/Gedmo/Sluggable/Fixture/Document/Handler/RelativeSlug.php +++ b/tests/Gedmo/Sluggable/Fixture/Document/Handler/RelativeSlug.php @@ -23,12 +23,10 @@ class RelativeSlug { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Sluggable/Fixture/Document/Handler/TreeSlug.php b/tests/Gedmo/Sluggable/Fixture/Document/Handler/TreeSlug.php index c9a4545138..3bb2adec38 100644 --- a/tests/Gedmo/Sluggable/Fixture/Document/Handler/TreeSlug.php +++ b/tests/Gedmo/Sluggable/Fixture/Document/Handler/TreeSlug.php @@ -23,12 +23,10 @@ class TreeSlug { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") @@ -37,8 +35,6 @@ class TreeSlug private ?string $title = null; /** - * @var string|null - * * @Gedmo\Slug(handlers={ * @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={ * @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"), @@ -51,7 +47,7 @@ class TreeSlug #[Gedmo\Slug(separator: '-', updatable: true, fields: ['title'])] #[Gedmo\SlugHandler(class: TreeSlugHandler::class, options: ['parentRelationField' => 'parent', 'separator' => '/'])] #[ODM\Field(type: Type::STRING)] - private $alias; + private ?string $alias = null; /** * @ODM\ReferenceOne(targetDocument="Gedmo\Tests\Sluggable\Fixture\Document\Handler\TreeSlug") diff --git a/tests/Gedmo/Sluggable/Fixture/Handler/Article.php b/tests/Gedmo/Sluggable/Fixture/Handler/Article.php index 3c0770541e..60b6049388 100644 --- a/tests/Gedmo/Sluggable/Fixture/Handler/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Handler/Article.php @@ -24,8 +24,6 @@ class Article implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class Article implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -48,8 +46,6 @@ class Article implements Sluggable private ?string $code = null; /** - * @var string|null - * * @Gedmo\Slug(handlers={ * @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\InversedRelativeSlugHandler", options={ * @Gedmo\SlugHandlerOption(name="relationClass", value="Gedmo\Tests\Sluggable\Fixture\Handler\ArticleRelativeSlug"), @@ -63,7 +59,7 @@ class Article implements Sluggable #[Gedmo\Slug(separator: '-', updatable: true, fields: ['title', 'code'])] #[Gedmo\SlugHandler(class: InversedRelativeSlugHandler::class, options: ['relationClass' => ArticleRelativeSlug::class, 'mappedBy' => 'article', 'inverseSlugField' => 'slug'])] #[ORM\Column(name: 'slug', type: Types::STRING, length: 64, unique: true)] - private $slug; + private ?string $slug = null; public function getId(): ?int { diff --git a/tests/Gedmo/Sluggable/Fixture/Handler/ArticleRelativeSlug.php b/tests/Gedmo/Sluggable/Fixture/Handler/ArticleRelativeSlug.php index dda0412dec..d4dce64666 100644 --- a/tests/Gedmo/Sluggable/Fixture/Handler/ArticleRelativeSlug.php +++ b/tests/Gedmo/Sluggable/Fixture/Handler/ArticleRelativeSlug.php @@ -23,8 +23,6 @@ class ArticleRelativeSlug { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class ArticleRelativeSlug #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=64) @@ -41,8 +39,6 @@ class ArticleRelativeSlug private ?string $title = null; /** - * @var string|null - * * @Gedmo\Slug(handlers={ * @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\RelativeSlugHandler", options={ * @Gedmo\SlugHandlerOption(name="relationField", value="article"), @@ -56,7 +52,7 @@ class ArticleRelativeSlug #[Gedmo\Slug(separator: '-', updatable: true, fields: ['title'])] #[Gedmo\SlugHandler(class: RelativeSlugHandler::class, options: ['relationField' => 'article', 'relationSlugField' => 'slug', 'separator' => '/'])] #[ORM\Column(name: 'slug', type: Types::STRING, length: 64, unique: true)] - private $slug; + private ?string $slug = null; /** * @ORM\ManyToOne(targetEntity="Article") diff --git a/tests/Gedmo/Sluggable/Fixture/Handler/Company.php b/tests/Gedmo/Sluggable/Fixture/Handler/Company.php index 2070381905..141c2d4f43 100644 --- a/tests/Gedmo/Sluggable/Fixture/Handler/Company.php +++ b/tests/Gedmo/Sluggable/Fixture/Handler/Company.php @@ -23,8 +23,6 @@ class Company { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Company #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Handler/TreeSlug.php b/tests/Gedmo/Sluggable/Fixture/Handler/TreeSlug.php index 425f2bb8af..79c455d9f4 100644 --- a/tests/Gedmo/Sluggable/Fixture/Handler/TreeSlug.php +++ b/tests/Gedmo/Sluggable/Fixture/Handler/TreeSlug.php @@ -30,8 +30,6 @@ class TreeSlug implements Node { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -39,7 +37,7 @@ class TreeSlug implements Node #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -48,8 +46,6 @@ class TreeSlug implements Node private ?string $title = null; /** - * @var string|null - * * @Gedmo\Slug(fields={"title"}, handlers={ * @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={ * @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"), @@ -62,7 +58,7 @@ class TreeSlug implements Node #[Gedmo\Slug(fields: ['title'], separator: '-', updatable: true)] #[Gedmo\SlugHandler(class: TreeSlugHandler::class, options: ['parentRelationField' => 'parent', 'separator' => '/'])] #[ORM\Column(name: 'slug', type: Types::STRING, length: 64, unique: true)] - private $slug; + private ?string $slug = null; /** * @Gedmo\TreeParent @@ -81,48 +77,40 @@ class TreeSlug implements Node private Collection $children; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(type="integer") */ #[ORM\Column(type: Types::INTEGER)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(type="integer") */ #[ORM\Column(type: Types::INTEGER)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** - * @var int|null - * * @Gedmo\TreeRoot * * @ORM\Column(type="integer") */ #[ORM\Column(type: Types::INTEGER)] #[Gedmo\TreeRoot] - private $root; + private ?int $root = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer") */ #[ORM\Column(name: 'lvl', type: Types::INTEGER)] #[Gedmo\TreeLevel] - private $level; + private ?int $level = null; private ?Node $sibling = null; diff --git a/tests/Gedmo/Sluggable/Fixture/Handler/TreeSlugPrefixSuffix.php b/tests/Gedmo/Sluggable/Fixture/Handler/TreeSlugPrefixSuffix.php index 87c5c821d7..72cfab07fa 100644 --- a/tests/Gedmo/Sluggable/Fixture/Handler/TreeSlugPrefixSuffix.php +++ b/tests/Gedmo/Sluggable/Fixture/Handler/TreeSlugPrefixSuffix.php @@ -29,8 +29,6 @@ class TreeSlugPrefixSuffix { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -38,7 +36,7 @@ class TreeSlugPrefixSuffix #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -47,8 +45,6 @@ class TreeSlugPrefixSuffix private ?string $title = null; /** - * @var string|null - * * @Gedmo\Slug(fields={"title"}, handlers={ * @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={ * @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"), @@ -63,7 +59,7 @@ class TreeSlugPrefixSuffix #[Gedmo\Slug(fields: ['title'], separator: '-', updatable: true)] #[Gedmo\SlugHandler(class: TreeSlugHandler::class, options: ['parentRelationField' => 'parent', 'separator' => '/', 'prefix' => 'prefix.', 'suffix' => '.suffix'])] #[ORM\Column(name: 'slug', type: Types::STRING, length: 64, unique: true)] - private $slug; + private ?string $slug = null; /** * @Gedmo\TreeParent @@ -82,48 +78,40 @@ class TreeSlugPrefixSuffix private Collection $children; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(type="integer") */ #[ORM\Column(type: Types::INTEGER)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(type="integer") */ #[ORM\Column(type: Types::INTEGER)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** - * @var int|null - * * @Gedmo\TreeRoot * * @ORM\Column(type="integer") */ #[ORM\Column(type: Types::INTEGER)] #[Gedmo\TreeRoot] - private $root; + private ?int $root = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer") */ #[ORM\Column(name: 'lvl', type: Types::INTEGER)] #[Gedmo\TreeLevel] - private $level; + private ?int $level = null; public function __construct() { diff --git a/tests/Gedmo/Sluggable/Fixture/Handler/User.php b/tests/Gedmo/Sluggable/Fixture/Handler/User.php index 3096c4463f..1fb5e5146d 100644 --- a/tests/Gedmo/Sluggable/Fixture/Handler/User.php +++ b/tests/Gedmo/Sluggable/Fixture/Handler/User.php @@ -23,8 +23,6 @@ class User { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class User #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Inheritance/Vehicle.php b/tests/Gedmo/Sluggable/Fixture/Inheritance/Vehicle.php index 1f331e44ca..6f6d5e8cfb 100644 --- a/tests/Gedmo/Sluggable/Fixture/Inheritance/Vehicle.php +++ b/tests/Gedmo/Sluggable/Fixture/Inheritance/Vehicle.php @@ -31,8 +31,6 @@ class Vehicle { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -40,7 +38,7 @@ class Vehicle #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=128) diff --git a/tests/Gedmo/Sluggable/Fixture/Inheritance2/SportCar.php b/tests/Gedmo/Sluggable/Fixture/Inheritance2/SportCar.php index b77cd52dd3..9e29d2f434 100644 --- a/tests/Gedmo/Sluggable/Fixture/Inheritance2/SportCar.php +++ b/tests/Gedmo/Sluggable/Fixture/Inheritance2/SportCar.php @@ -17,6 +17,4 @@ * @ORM\Entity */ #[ORM\Entity] -class SportCar extends Car -{ -} +class SportCar extends Car {} diff --git a/tests/Gedmo/Sluggable/Fixture/Inheritance2/Vehicle.php b/tests/Gedmo/Sluggable/Fixture/Inheritance2/Vehicle.php index 46d5d056ae..381a6dc27e 100644 --- a/tests/Gedmo/Sluggable/Fixture/Inheritance2/Vehicle.php +++ b/tests/Gedmo/Sluggable/Fixture/Inheritance2/Vehicle.php @@ -28,8 +28,6 @@ abstract class Vehicle { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -37,7 +35,7 @@ abstract class Vehicle #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; public function getId(): ?int { diff --git a/tests/Gedmo/Sluggable/Fixture/Issue100/Article.php b/tests/Gedmo/Sluggable/Fixture/Issue100/Article.php index f285322886..7bf59f6079 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue100/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue100/Article.php @@ -24,8 +24,6 @@ class Article implements Sluggable, Translatable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class Article implements Sluggable, Translatable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Sluggable/Fixture/Issue104/Bus.php b/tests/Gedmo/Sluggable/Fixture/Issue104/Bus.php index 9dd995e6dc..38ba7e4e42 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue104/Bus.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue104/Bus.php @@ -21,8 +21,6 @@ class Bus { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -30,7 +28,7 @@ class Bus #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=128) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue104/Vehicle.php b/tests/Gedmo/Sluggable/Fixture/Issue104/Vehicle.php index d1db13f333..d00d890610 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue104/Vehicle.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue104/Vehicle.php @@ -30,8 +30,6 @@ class Vehicle protected $title; /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -39,7 +37,7 @@ class Vehicle #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @var string|null diff --git a/tests/Gedmo/Sluggable/Fixture/Issue1058/Page.php b/tests/Gedmo/Sluggable/Fixture/Issue1058/Page.php index 0786a46092..9813eaee70 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue1058/Page.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue1058/Page.php @@ -22,8 +22,6 @@ class Page { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Page #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue1058/User.php b/tests/Gedmo/Sluggable/Fixture/Issue1058/User.php index c27ab7733a..979ae72c32 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue1058/User.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue1058/User.php @@ -21,8 +21,6 @@ class User { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -30,7 +28,7 @@ class User #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; public function getId(): ?int { diff --git a/tests/Gedmo/Sluggable/Fixture/Issue116/Country.php b/tests/Gedmo/Sluggable/Fixture/Issue116/Country.php index b65364aa15..0157a0d118 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue116/Country.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue116/Country.php @@ -24,8 +24,6 @@ class Country { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,15 +31,13 @@ class Country #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** - * @var string|null - * * @ORM\Column(type="string", length=10, nullable=true) */ #[ORM\Column(type: Types::STRING, length: 10, nullable: true)] - private $languageCode; + private ?string $languageCode = null; /** * @ORM\Column(type="string", length=50) @@ -50,15 +46,13 @@ class Country private ?string $originalName = null; /** - * @var string|null - * * @ORM\Column(type="string", length=50) * * @Gedmo\Slug(separator="-", fields={"originalName"}) */ #[ORM\Column(type: Types::STRING, length: 50)] #[Gedmo\Slug(separator: '-', fields: ['originalName'])] - private $alias; + private ?string $alias = null; public function getId(): ?int { diff --git a/tests/Gedmo/Sluggable/Fixture/Issue1177/Article.php b/tests/Gedmo/Sluggable/Fixture/Issue1177/Article.php index 3cf85b95e8..c875755a9f 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue1177/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue1177/Article.php @@ -23,8 +23,6 @@ class Article implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Article implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue1240/Article.php b/tests/Gedmo/Sluggable/Fixture/Issue1240/Article.php index 5c7f96e079..dabd562baa 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue1240/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue1240/Article.php @@ -23,8 +23,6 @@ class Article implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Article implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue131/Article.php b/tests/Gedmo/Sluggable/Fixture/Issue131/Article.php index 0503bca60e..81490d97f6 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue131/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue131/Article.php @@ -22,8 +22,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue449/Article.php b/tests/Gedmo/Sluggable/Fixture/Issue449/Article.php index c8fb0f2508..557cf37ff6 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue449/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue449/Article.php @@ -26,8 +26,6 @@ class Article implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -35,7 +33,7 @@ class Article implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue633/Article.php b/tests/Gedmo/Sluggable/Fixture/Issue633/Article.php index 0dbe90d1f3..cfe8d0782d 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue633/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue633/Article.php @@ -22,8 +22,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="code", type="string", length=16) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue827/Article.php b/tests/Gedmo/Sluggable/Fixture/Issue827/Article.php index 0accb06459..4e7b7c27d6 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue827/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue827/Article.php @@ -22,8 +22,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue827/Category.php b/tests/Gedmo/Sluggable/Fixture/Issue827/Category.php index a5234c4bd8..6ecfdb263d 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue827/Category.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue827/Category.php @@ -24,8 +24,6 @@ class Category { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class Category #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue827/Comment.php b/tests/Gedmo/Sluggable/Fixture/Issue827/Comment.php index e464bc4748..4106926b74 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue827/Comment.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue827/Comment.php @@ -22,8 +22,6 @@ class Comment { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Comment #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue939/Article.php b/tests/Gedmo/Sluggable/Fixture/Issue939/Article.php index 0b6afe9d43..260c695b11 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue939/Article.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue939/Article.php @@ -22,8 +22,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue939/Category.php b/tests/Gedmo/Sluggable/Fixture/Issue939/Category.php index aa235ada52..e3bd7d8570 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue939/Category.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue939/Category.php @@ -24,8 +24,6 @@ class Category { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class Category #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Issue939/SluggableListener.php b/tests/Gedmo/Sluggable/Fixture/Issue939/SluggableListener.php index ac2b41aab2..95c84ae0b5 100644 --- a/tests/Gedmo/Sluggable/Fixture/Issue939/SluggableListener.php +++ b/tests/Gedmo/Sluggable/Fixture/Issue939/SluggableListener.php @@ -32,8 +32,8 @@ public function __construct() $this->originalTransliterator = $this->getTransliterator(); $this->originalUrlizer = $this->getUrlizer(); - $this->setTransliterator([$this, 'transliterator']); - $this->setUrlizer([$this, 'urlizer']); + $this->setTransliterator($this->transliterator(...)); + $this->setUrlizer($this->urlizer(...)); } public function transliterator(string $slug, string $separator, object $object): string diff --git a/tests/Gedmo/Sluggable/Fixture/MappedSuperclass/Car.php b/tests/Gedmo/Sluggable/Fixture/MappedSuperclass/Car.php index 1d3a5969de..dac5b39afa 100644 --- a/tests/Gedmo/Sluggable/Fixture/MappedSuperclass/Car.php +++ b/tests/Gedmo/Sluggable/Fixture/MappedSuperclass/Car.php @@ -21,8 +21,6 @@ class Car extends Vehicle { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -30,7 +28,7 @@ class Car extends Vehicle #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=128) diff --git a/tests/Gedmo/Sluggable/Fixture/Page.php b/tests/Gedmo/Sluggable/Fixture/Page.php index d409f2b6ad..178e35da85 100644 --- a/tests/Gedmo/Sluggable/Fixture/Page.php +++ b/tests/Gedmo/Sluggable/Fixture/Page.php @@ -24,8 +24,6 @@ class Page { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class Page #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(type="string", length=191) @@ -42,15 +40,13 @@ class Page private ?string $content = null; /** - * @var string|null - * * @Gedmo\Slug(style="camel", separator="_", fields={"content"}) * * @ORM\Column(type="string", length=128) */ #[Gedmo\Slug(style: 'camel', separator: '_', fields: ['content'])] #[ORM\Column(type: Types::STRING, length: 128)] - private $slug; + private ?string $slug = null; /** * @var Collection @@ -58,7 +54,7 @@ class Page * @ORM\OneToMany(targetEntity="TranslatableArticle", mappedBy="page") */ #[ORM\OneToMany(targetEntity: TranslatableArticle::class, mappedBy: 'page')] - private $articles; + private Collection $articles; public function __construct() { diff --git a/tests/Gedmo/Sluggable/Fixture/Position.php b/tests/Gedmo/Sluggable/Fixture/Position.php index f963510070..6bf34d024a 100644 --- a/tests/Gedmo/Sluggable/Fixture/Position.php +++ b/tests/Gedmo/Sluggable/Fixture/Position.php @@ -22,8 +22,6 @@ class Position { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Position #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @var string|null diff --git a/tests/Gedmo/Sluggable/Fixture/Prefix.php b/tests/Gedmo/Sluggable/Fixture/Prefix.php index fc057739a3..f29387da99 100644 --- a/tests/Gedmo/Sluggable/Fixture/Prefix.php +++ b/tests/Gedmo/Sluggable/Fixture/Prefix.php @@ -25,8 +25,6 @@ class Prefix implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Prefix implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/PrefixWithTreeHandler.php b/tests/Gedmo/Sluggable/Fixture/PrefixWithTreeHandler.php index 5185564055..a934ee5c7f 100644 --- a/tests/Gedmo/Sluggable/Fixture/PrefixWithTreeHandler.php +++ b/tests/Gedmo/Sluggable/Fixture/PrefixWithTreeHandler.php @@ -30,8 +30,6 @@ class PrefixWithTreeHandler implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -39,7 +37,7 @@ class PrefixWithTreeHandler implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/Suffix.php b/tests/Gedmo/Sluggable/Fixture/Suffix.php index afba9d6b3d..d6244c0248 100644 --- a/tests/Gedmo/Sluggable/Fixture/Suffix.php +++ b/tests/Gedmo/Sluggable/Fixture/Suffix.php @@ -25,8 +25,6 @@ class Suffix implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Suffix implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/SuffixWithTreeHandler.php b/tests/Gedmo/Sluggable/Fixture/SuffixWithTreeHandler.php index cfb310fd22..522166b8e7 100644 --- a/tests/Gedmo/Sluggable/Fixture/SuffixWithTreeHandler.php +++ b/tests/Gedmo/Sluggable/Fixture/SuffixWithTreeHandler.php @@ -30,8 +30,6 @@ class SuffixWithTreeHandler implements Sluggable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -39,7 +37,7 @@ class SuffixWithTreeHandler implements Sluggable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Sluggable/Fixture/TransArticleManySlug.php b/tests/Gedmo/Sluggable/Fixture/TransArticleManySlug.php index 559f7dfc9c..37c2f2656b 100644 --- a/tests/Gedmo/Sluggable/Fixture/TransArticleManySlug.php +++ b/tests/Gedmo/Sluggable/Fixture/TransArticleManySlug.php @@ -24,8 +24,6 @@ class TransArticleManySlug implements Sluggable, Translatable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class TransArticleManySlug implements Sluggable, Translatable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; private ?int $page = null; @@ -53,15 +51,13 @@ class TransArticleManySlug implements Sluggable, Translatable private ?string $uniqueTitle = null; /** - * @var string|null - * * @Gedmo\Slug(fields={"uniqueTitle"}) * * @ORM\Column(type="string", length=128) */ #[Gedmo\Slug(fields: ['uniqueTitle'])] #[ORM\Column(type: Types::STRING, length: 128)] - private $uniqueSlug; + private ?string $uniqueSlug = null; /** * @Gedmo\Translatable @@ -73,8 +69,6 @@ class TransArticleManySlug implements Sluggable, Translatable private ?string $code = null; /** - * @var string|null - * * @Gedmo\Translatable * @Gedmo\Slug(fields={"title", "code"}) * @@ -83,7 +77,7 @@ class TransArticleManySlug implements Sluggable, Translatable #[ORM\Column(type: Types::STRING, length: 128)] #[Gedmo\Slug(fields: ['title', 'code'])] #[Gedmo\Translatable] - private $slug; + private ?string $slug = null; /** * @Gedmo\Locale diff --git a/tests/Gedmo/Sluggable/Fixture/TranslatableArticle.php b/tests/Gedmo/Sluggable/Fixture/TranslatableArticle.php index 951a0a04fb..49ddb38225 100644 --- a/tests/Gedmo/Sluggable/Fixture/TranslatableArticle.php +++ b/tests/Gedmo/Sluggable/Fixture/TranslatableArticle.php @@ -26,8 +26,6 @@ class TranslatableArticle implements Sluggable, Translatable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -35,7 +33,7 @@ class TranslatableArticle implements Sluggable, Translatable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable @@ -56,8 +54,6 @@ class TranslatableArticle implements Sluggable, Translatable private ?string $code = null; /** - * @var string|null - * * @Gedmo\Translatable * @Gedmo\Slug(fields={"title", "code"}) * @@ -66,7 +62,7 @@ class TranslatableArticle implements Sluggable, Translatable #[ORM\Column(type: Types::STRING, length: 128)] #[Gedmo\Translatable] #[Gedmo\Slug(fields: ['title', 'code'])] - private $slug; + private ?string $slug = null; /** * @var Collection @@ -74,7 +70,7 @@ class TranslatableArticle implements Sluggable, Translatable * @ORM\OneToMany(targetEntity="Comment", mappedBy="article") */ #[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'article')] - private $comments; + private Collection $comments; /** * @ORM\ManyToOne(targetEntity="Page", inversedBy="articles") diff --git a/tests/Gedmo/Sluggable/Issue/Issue116Test.php b/tests/Gedmo/Sluggable/Issue/Issue116Test.php index 755a271fe4..5988d17233 100644 --- a/tests/Gedmo/Sluggable/Issue/Issue116Test.php +++ b/tests/Gedmo/Sluggable/Issue/Issue116Test.php @@ -12,10 +12,6 @@ namespace Gedmo\Tests\Sluggable\Issue; use Doctrine\Common\EventManager; -use Doctrine\ORM\Mapping\Driver\AttributeDriver; -use Doctrine\ORM\Mapping\Driver\YamlDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriver; -use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use Gedmo\Sluggable\SluggableListener; use Gedmo\Tests\Sluggable\Fixture\Issue116\Country; use Gedmo\Tests\Tool\BaseTestCaseORM; @@ -48,22 +44,6 @@ public function testSlugGeneration(): void static::assertSame('new-zealand', $country->getAlias()); } - protected function getMetadataDriverImplementation(): MappingDriver - { - $chain = new MappingDriverChain(); - - if (PHP_VERSION_ID >= 80000) { - $chain->addDriver(new AttributeDriver([]), 'Gedmo\Tests\Sluggable\Fixture\Issue116'); - } else { - $chain->addDriver( - new YamlDriver([__DIR__.'/../Fixture/Issue116/Mapping']), - 'Gedmo\Tests\Sluggable\Fixture\Issue116' - ); - } - - return $chain; - } - protected function getUsedEntityFixtures(): array { return [ diff --git a/tests/Gedmo/Sluggable/SluggableConfigurationTest.php b/tests/Gedmo/Sluggable/SluggableConfigurationTest.php index e56c204327..3c6d6e239e 100644 --- a/tests/Gedmo/Sluggable/SluggableConfigurationTest.php +++ b/tests/Gedmo/Sluggable/SluggableConfigurationTest.php @@ -71,7 +71,7 @@ public function testSlugLimit(): void $this->em->clear(); $shorten = $article->getSlug(); - static::assertSame(32, strlen($shorten)); + static::assertSame(32, strlen((string) $shorten)); } public function testNonUpdatableSlug(): void diff --git a/tests/Gedmo/Sluggable/SluggableTest.php b/tests/Gedmo/Sluggable/SluggableTest.php index 41cc07464b..b9cba1a2ae 100644 --- a/tests/Gedmo/Sluggable/SluggableTest.php +++ b/tests/Gedmo/Sluggable/SluggableTest.php @@ -85,7 +85,7 @@ public function testShouldHandleUniqueSlugLimitedLength(): void $this->em->clear(); $shorten = $article->getSlug(); - static::assertSame(64, strlen($shorten)); + static::assertSame(64, strlen((string) $shorten)); $expected = 'the-title-the-title-the-title-the-title-the-title-the-title-the-'; $expected = substr($expected, 0, 64 - (strlen($uniqueSuffix) + 1)).'-'.$uniqueSuffix; static::assertSame($shorten, $expected); diff --git a/tests/Gedmo/SoftDeleteable/CarbonTest.php b/tests/Gedmo/SoftDeleteable/CarbonTest.php index 3111abfd61..c72126facc 100644 --- a/tests/Gedmo/SoftDeleteable/CarbonTest.php +++ b/tests/Gedmo/SoftDeleteable/CarbonTest.php @@ -68,16 +68,16 @@ public function testSoftDeleteable(): void $art = $repo->findOneBy([$field => $value]); - static::assertNull($art->getDeletedAt()); - static::assertNull($comment->getDeletedAt()); + static::assertNotInstanceOf(\DateTime::class, $art->getDeletedAt()); + static::assertNotInstanceOf(\DateTime::class, $comment->getDeletedAt()); $this->em->remove($art); $this->em->flush(); $art = $repo->findOneBy([$field => $value]); - static::assertNull($art); + static::assertNotInstanceOf(Article::class, $art); $comment = $commentRepo->findOneBy([$commentField => $commentValue]); - static::assertNull($comment); + static::assertNotInstanceOf(Comment::class, $comment); // Now we deactivate the filter so we test if the entity appears in the result $this->em->getFilters()->disable(self::SOFT_DELETEABLE_FILTER_NAME); diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Document/User.php b/tests/Gedmo/SoftDeleteable/Fixture/Document/User.php index c17155b1e0..3766713246 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Document/User.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Document/User.php @@ -32,12 +32,10 @@ class User #[ODM\Field(type: Type::DATE)] protected $deletedAt; /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Document/UserTimeAware.php b/tests/Gedmo/SoftDeleteable/Fixture/Document/UserTimeAware.php index 0816f418a8..599c9535f7 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Document/UserTimeAware.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Document/UserTimeAware.php @@ -32,12 +32,10 @@ class UserTimeAware #[ODM\Field(type: Type::DATE)] protected $deletedAt; /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Address.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Address.php index fdb25f80c8..2a729d1834 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Address.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Address.php @@ -25,8 +25,6 @@ class Address { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Address #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=128) diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Article.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Article.php index bb467ef452..04601df763 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Article.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Article.php @@ -27,8 +27,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -36,7 +34,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string") @@ -56,7 +54,7 @@ class Article * @ORM\OneToMany(targetEntity="Comment", mappedBy="article", cascade={"persist", "remove"}) */ #[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'article', cascade: ['persist', 'remove'])] - private $comments; + private Collection $comments; public function __construct() { diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Comment.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Comment.php index e58dcda565..ae803b4fe9 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Comment.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Comment.php @@ -25,8 +25,6 @@ class Comment { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Comment #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="comment", type="string") @@ -49,12 +47,10 @@ class Comment private ?\DateTime $deletedAt = null; /** - * @var Article|null - * * @ORM\ManyToOne(targetEntity="Article", inversedBy="comments") */ #[ORM\ManyToOne(targetEntity: Article::class, inversedBy: 'comments')] - private $article; + private ?Article $article = null; public function getId(): ?int { diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/MappedSuperclass.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/MappedSuperclass.php index 93cb455692..c51e3294c2 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/MappedSuperclass.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/MappedSuperclass.php @@ -25,8 +25,6 @@ class MappedSuperclass { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class MappedSuperclass #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="deletedAt", type="datetime", nullable=true) diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/MegaPage.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/MegaPage.php index 2d52e30020..15003f4989 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/MegaPage.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/MegaPage.php @@ -17,6 +17,4 @@ * @ORM\Entity */ #[ORM\Entity] -class MegaPage extends Page -{ -} +class MegaPage extends Page {} diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Module.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Module.php index 7ced4c2876..96e52ca5a1 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Module.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Module.php @@ -25,8 +25,6 @@ class Module { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Module #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string") diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/OtherArticle.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/OtherArticle.php index f3692c3c7e..ed7ef19612 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/OtherArticle.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/OtherArticle.php @@ -27,8 +27,6 @@ class OtherArticle { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -36,7 +34,7 @@ class OtherArticle #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string") @@ -56,7 +54,7 @@ class OtherArticle * @ORM\OneToMany(targetEntity="OtherComment", mappedBy="article") */ #[ORM\OneToMany(targetEntity: OtherComment::class, mappedBy: 'article')] - private $comments; + private Collection $comments; public function __construct() { diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/OtherComment.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/OtherComment.php index d76529ce47..a1aed26875 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/OtherComment.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/OtherComment.php @@ -21,8 +21,6 @@ class OtherComment { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -30,7 +28,7 @@ class OtherComment #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="comment", type="string") diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Page.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Page.php index 8cf55a05a7..0272df25df 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Page.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Page.php @@ -33,8 +33,6 @@ class Page { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -42,7 +40,7 @@ class Page #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string") @@ -62,7 +60,7 @@ class Page * @ORM\OneToMany(targetEntity="Module", mappedBy="page", cascade={"persist", "remove"}) */ #[ORM\OneToMany(targetEntity: Module::class, mappedBy: 'page', cascade: ['persist', 'remove'])] - private $modules; + private Collection $modules; public function __construct() { diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Person.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Person.php index cbec15111f..4b419b48c1 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/Person.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/Person.php @@ -25,8 +25,6 @@ class Person { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Person #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=32) diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/User.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/User.php index d835d9b711..7a86498c2e 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/User.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/User.php @@ -25,8 +25,6 @@ class User { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class User #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string") diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Entity/UserNoHardDelete.php b/tests/Gedmo/SoftDeleteable/Fixture/Entity/UserNoHardDelete.php index d2e7409063..04e8fdaf9a 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Entity/UserNoHardDelete.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Entity/UserNoHardDelete.php @@ -25,8 +25,6 @@ class UserNoHardDelete { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class UserNoHardDelete #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string") diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithLifecycleEventArgsFromODMTypeListener.php b/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithLifecycleEventArgsFromODMTypeListener.php index fdc592d810..6662240584 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithLifecycleEventArgsFromODMTypeListener.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithLifecycleEventArgsFromODMTypeListener.php @@ -17,13 +17,9 @@ final class WithLifecycleEventArgsFromODMTypeListener implements EventSubscriber { - public function preSoftDelete(LifecycleEventArgs $args): void - { - } + public function preSoftDelete(LifecycleEventArgs $args): void {} - public function postSoftDelete(LifecycleEventArgs $args): void - { - } + public function postSoftDelete(LifecycleEventArgs $args): void {} public function getSubscribedEvents(): array { diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithLifecycleEventArgsFromORMTypeListener.php b/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithLifecycleEventArgsFromORMTypeListener.php index 5d936b7d5f..36aad3894e 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithLifecycleEventArgsFromORMTypeListener.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithLifecycleEventArgsFromORMTypeListener.php @@ -17,13 +17,9 @@ final class WithLifecycleEventArgsFromORMTypeListener implements EventSubscriber { - public function preSoftDelete(LifecycleEventArgs $args): void - { - } + public function preSoftDelete(LifecycleEventArgs $args): void {} - public function postSoftDelete(LifecycleEventArgs $args): void - { - } + public function postSoftDelete(LifecycleEventArgs $args): void {} public function getSubscribedEvents(): array { diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithPreAndPostSoftDeleteEventArgsTypeListener.php b/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithPreAndPostSoftDeleteEventArgsTypeListener.php index b24c51f6d7..93538e2919 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithPreAndPostSoftDeleteEventArgsTypeListener.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithPreAndPostSoftDeleteEventArgsTypeListener.php @@ -20,14 +20,10 @@ final class WithPreAndPostSoftDeleteEventArgsTypeListener implements EventSubscriber { /** @param PreSoftDeleteEventArgs $args */ - public function preSoftDelete(PreSoftDeleteEventArgs $args): void - { - } + public function preSoftDelete(PreSoftDeleteEventArgs $args): void {} /** @param PostSoftDeleteEventArgs $args */ - public function postSoftDelete(PostSoftDeleteEventArgs $args): void - { - } + public function postSoftDelete(PostSoftDeleteEventArgs $args): void {} public function getSubscribedEvents(): array { diff --git a/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithoutTypeListener.php b/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithoutTypeListener.php index 9ab5cf3a8e..cdae36a5ff 100644 --- a/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithoutTypeListener.php +++ b/tests/Gedmo/SoftDeleteable/Fixture/Listener/WithoutTypeListener.php @@ -20,14 +20,10 @@ final class WithoutTypeListener implements EventSubscriber { /** @param PreSoftDeleteEventArgs $args */ - public function preSoftDelete($args): void - { - } + public function preSoftDelete($args): void {} /** @param PostSoftDeleteEventArgs $args */ - public function postSoftDelete($args): void - { - } + public function postSoftDelete($args): void {} public function getSubscribedEvents(): array { diff --git a/tests/Gedmo/SoftDeleteable/HardRelationTest.php b/tests/Gedmo/SoftDeleteable/HardRelationTest.php index 09bbabbb78..50ecad1e24 100644 --- a/tests/Gedmo/SoftDeleteable/HardRelationTest.php +++ b/tests/Gedmo/SoftDeleteable/HardRelationTest.php @@ -50,7 +50,7 @@ public function testShouldCascadeSoftdeleteForHardRelations(): void $this->em->clear(); $person = $this->em->getRepository(Person::class)->findOneBy(['id' => $person->getId()]); - static::assertNull($person, 'Softdelete should cascade to hard relation entity'); + static::assertNotInstanceOf(Person::class, $person, 'Softdelete should cascade to hard relation entity'); } public function testShouldCascadeToInversedRelationAsWell(): void @@ -72,7 +72,7 @@ public function testShouldCascadeToInversedRelationAsWell(): void $this->em->clear(); $address = $this->em->getRepository(Address::class)->findOneBy(['id' => $address->getId()]); - static::assertNull($address, 'Softdelete should cascade to hard relation entity'); + static::assertNotInstanceOf(Address::class, $address, 'Softdelete should cascade to hard relation entity'); } public function testShouldHandleTimeAwareSoftDeleteable(): void @@ -91,7 +91,7 @@ public function testShouldHandleTimeAwareSoftDeleteable(): void $this->em->clear(); $person = $this->em->getRepository(Person::class)->findOneBy(['id' => $person->getId()]); - static::assertNotNull($person, 'Should not be softdeleted'); + static::assertInstanceOf(Person::class, $person, 'Should not be softdeleted'); $person->setDeletedAt(new \DateTime(date('Y-m-d H:i:s', time() - 15 * 3600))); // in an hour $this->em->persist($person); @@ -99,7 +99,7 @@ public function testShouldHandleTimeAwareSoftDeleteable(): void $this->em->clear(); $person = $this->em->getRepository(Person::class)->findOneBy(['id' => $person->getId()]); - static::assertNull($person, 'Should be softdeleted'); + static::assertNotInstanceOf(Person::class, $person, 'Should be softdeleted'); } protected function getUsedEntityFixtures(): array diff --git a/tests/Gedmo/SoftDeleteable/SoftDeletableDocumentTraitTest.php b/tests/Gedmo/SoftDeleteable/SoftDeletableDocumentTraitTest.php index 9ad3901397..0d7eab1237 100644 --- a/tests/Gedmo/SoftDeleteable/SoftDeletableDocumentTraitTest.php +++ b/tests/Gedmo/SoftDeleteable/SoftDeletableDocumentTraitTest.php @@ -21,17 +21,12 @@ */ final class SoftDeletableDocumentTraitTest extends TestCase { - /** - * @var UsingTrait - */ - protected $entity; - public function testGetSetDeletedAt(): void { $time = new \DateTime(); $entity = new UsingTrait(); - static::assertNull($entity->getDeletedAt(), 'deletedAt defaults to null'); + static::assertNotInstanceOf(\DateTime::class, $entity->getDeletedAt(), 'deletedAt defaults to null'); static::assertFalse($entity->isDeleted(), 'isDeleted defaults to false'); static::assertSame($entity, $entity->setDeletedAt($time), 'Setter has a fluid interface'); static::assertSame($time, $entity->getDeletedAt(), 'Getter returns a DateTime Object'); diff --git a/tests/Gedmo/SoftDeleteable/SoftDeletableEntityTraitTest.php b/tests/Gedmo/SoftDeleteable/SoftDeletableEntityTraitTest.php index aef5cdd6db..29b4d85a05 100644 --- a/tests/Gedmo/SoftDeleteable/SoftDeletableEntityTraitTest.php +++ b/tests/Gedmo/SoftDeleteable/SoftDeletableEntityTraitTest.php @@ -21,17 +21,12 @@ */ final class SoftDeletableEntityTraitTest extends TestCase { - /** - * @var UsingTrait - */ - protected $entity; - public function testGetSetDeletedAt(): void { $time = new \DateTime(); $entity = new UsingTrait(); - static::assertNull($entity->getDeletedAt(), 'deletedAt defaults to null'); + static::assertNotInstanceOf(\DateTime::class, $entity->getDeletedAt(), 'deletedAt defaults to null'); static::assertFalse($entity->isDeleted(), 'isDeleted defaults to false'); static::assertSame($entity, $entity->setDeletedAt($time), 'Setter has a fluid interface'); static::assertSame($time, $entity->getDeletedAt(), 'Getter returns a DateTime Object'); diff --git a/tests/Gedmo/SoftDeleteable/SoftDeleteableDocumentTest.php b/tests/Gedmo/SoftDeleteable/SoftDeleteableDocumentTest.php index b2c1fe4da6..fe02328c96 100644 --- a/tests/Gedmo/SoftDeleteable/SoftDeleteableDocumentTest.php +++ b/tests/Gedmo/SoftDeleteable/SoftDeleteableDocumentTest.php @@ -62,14 +62,14 @@ public function testShouldSoftlyDeleteIfColumnNameDifferFromPropertyName(): void $user = $repo->findOneBy(['username' => $username]); - static::assertNull($user->getDeletedAt()); + static::assertNotInstanceOf(\DateTime::class, $user->getDeletedAt()); $this->dm->remove($user); $this->dm->flush(); $user = $repo->findOneBy(['username' => $username]); - static::assertNull($user); + static::assertNotInstanceOf(User::class, $user); } /** @@ -92,18 +92,18 @@ public function testSoftDeleteableFilter(): void $user = $repo->findOneBy(['username' => $username]); - static::assertNull($user->getDeletedAt()); + static::assertNotInstanceOf(\DateTime::class, $user->getDeletedAt()); $this->dm->remove($user); $this->dm->flush(); $user = $repo->findOneBy(['username' => $username]); - static::assertNotNull($user->getDeletedAt()); + static::assertInstanceOf(\DateTime::class, $user->getDeletedAt()); $filter->enableForDocument(User::class); $user = $repo->findOneBy(['username' => $username]); - static::assertNull($user); + static::assertNotInstanceOf(User::class, $user); } /** @@ -144,7 +144,7 @@ public function shouldSupportSoftDeleteableFilterTimeAware(): void $user = $repo->findOneBy(['username' => $username]); - static::assertNull($user); + static::assertNotInstanceOf(UserTimeAware::class, $user); $this->dm->flush(); } @@ -177,7 +177,7 @@ private function doTestPostSoftDeleteEventIsDispatched(): void $user = $repo->findOneBy(['username' => 'test_user']); - static::assertNull($user->getDeletedAt()); + static::assertNotInstanceOf(\DateTime::class, $user->getDeletedAt()); $this->dm->remove($user); $this->dm->flush(); diff --git a/tests/Gedmo/Sortable/Fixture/AbstractNode.php b/tests/Gedmo/Sortable/Fixture/AbstractNode.php index 66dc4136f7..e846670564 100644 --- a/tests/Gedmo/Sortable/Fixture/AbstractNode.php +++ b/tests/Gedmo/Sortable/Fixture/AbstractNode.php @@ -22,8 +22,6 @@ class AbstractNode { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,37 +29,31 @@ class AbstractNode #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - protected $id; + protected ?int $id = null; /** - * @var string|null - * * @ORM\Column(type="string", length=191) */ #[ORM\Column(type: Types::STRING, length: 191)] - protected $name; + protected ?string $name = null; /** - * @var string|null - * * @Gedmo\SortableGroup * * @ORM\Column(type="string", length=191) */ #[Gedmo\SortableGroup] #[ORM\Column(type: Types::STRING, length: 191)] - protected $path; + protected ?string $path = null; /** - * @var int|null - * * @Gedmo\SortablePosition * * @ORM\Column(type="integer") */ #[Gedmo\SortablePosition] #[ORM\Column(type: Types::INTEGER)] - protected $position; + protected ?int $position = null; public function getId(): ?int { diff --git a/tests/Gedmo/Sortable/Fixture/Author.php b/tests/Gedmo/Sortable/Fixture/Author.php index 4e3722d760..3a0740189e 100644 --- a/tests/Gedmo/Sortable/Fixture/Author.php +++ b/tests/Gedmo/Sortable/Fixture/Author.php @@ -23,8 +23,6 @@ class Author { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Author #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="name", type="string") diff --git a/tests/Gedmo/Sortable/Fixture/Category.php b/tests/Gedmo/Sortable/Fixture/Category.php index bc46eb5ca5..6083cf41f5 100644 --- a/tests/Gedmo/Sortable/Fixture/Category.php +++ b/tests/Gedmo/Sortable/Fixture/Category.php @@ -23,8 +23,6 @@ class Category { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Category #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(type="string", length=191) diff --git a/tests/Gedmo/Sortable/Fixture/Customer.php b/tests/Gedmo/Sortable/Fixture/Customer.php index c5969a885d..457dbfdd81 100644 --- a/tests/Gedmo/Sortable/Fixture/Customer.php +++ b/tests/Gedmo/Sortable/Fixture/Customer.php @@ -21,8 +21,6 @@ class Customer { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -30,7 +28,7 @@ class Customer #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="name", type="string") diff --git a/tests/Gedmo/Sortable/Fixture/CustomerType.php b/tests/Gedmo/Sortable/Fixture/CustomerType.php index 9492aa443a..da3bbc90dc 100644 --- a/tests/Gedmo/Sortable/Fixture/CustomerType.php +++ b/tests/Gedmo/Sortable/Fixture/CustomerType.php @@ -29,8 +29,6 @@ class CustomerType { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -38,7 +36,7 @@ class CustomerType #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="name", type="string") diff --git a/tests/Gedmo/Sortable/Fixture/Document/Article.php b/tests/Gedmo/Sortable/Fixture/Document/Article.php index 82c0015957..17405623a6 100644 --- a/tests/Gedmo/Sortable/Fixture/Document/Article.php +++ b/tests/Gedmo/Sortable/Fixture/Document/Article.php @@ -33,12 +33,10 @@ class Article protected $position; /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Sortable/Fixture/Document/Category.php b/tests/Gedmo/Sortable/Fixture/Document/Category.php index ee803eb0a0..dfdabc39fd 100644 --- a/tests/Gedmo/Sortable/Fixture/Document/Category.php +++ b/tests/Gedmo/Sortable/Fixture/Document/Category.php @@ -21,12 +21,10 @@ class Category { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Sortable/Fixture/Document/Kid.php b/tests/Gedmo/Sortable/Fixture/Document/Kid.php index a74ad221e0..8426f13819 100644 --- a/tests/Gedmo/Sortable/Fixture/Document/Kid.php +++ b/tests/Gedmo/Sortable/Fixture/Document/Kid.php @@ -44,12 +44,10 @@ class Kid protected $birthdate; /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Sortable/Fixture/Document/Post.php b/tests/Gedmo/Sortable/Fixture/Document/Post.php index aaba8bf972..a6c17ed2e5 100644 --- a/tests/Gedmo/Sortable/Fixture/Document/Post.php +++ b/tests/Gedmo/Sortable/Fixture/Document/Post.php @@ -44,12 +44,10 @@ class Post protected $category; /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Sortable/Fixture/Event.php b/tests/Gedmo/Sortable/Fixture/Event.php index 9a1481ec97..e035d03e27 100644 --- a/tests/Gedmo/Sortable/Fixture/Event.php +++ b/tests/Gedmo/Sortable/Fixture/Event.php @@ -23,8 +23,6 @@ class Event { /** - * @var int - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Event #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\SortableGroup diff --git a/tests/Gedmo/Sortable/Fixture/Item.php b/tests/Gedmo/Sortable/Fixture/Item.php index 50ed86a013..1d67f67e06 100644 --- a/tests/Gedmo/Sortable/Fixture/Item.php +++ b/tests/Gedmo/Sortable/Fixture/Item.php @@ -23,8 +23,6 @@ class Item { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Item #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(type="string", length=191) diff --git a/tests/Gedmo/Sortable/Fixture/Node.php b/tests/Gedmo/Sortable/Fixture/Node.php index b904d7b93b..4d1b7425d7 100644 --- a/tests/Gedmo/Sortable/Fixture/Node.php +++ b/tests/Gedmo/Sortable/Fixture/Node.php @@ -20,6 +20,4 @@ * @ORM\Entity(repositoryClass="Gedmo\Sortable\Entity\Repository\SortableRepository") */ #[ORM\Entity(repositoryClass: SortableRepository::class)] -class Node extends AbstractNode -{ -} +class Node extends AbstractNode {} diff --git a/tests/Gedmo/Sortable/Fixture/NotifyNode.php b/tests/Gedmo/Sortable/Fixture/NotifyNode.php index 2f94c4de60..3b526ab269 100644 --- a/tests/Gedmo/Sortable/Fixture/NotifyNode.php +++ b/tests/Gedmo/Sortable/Fixture/NotifyNode.php @@ -31,18 +31,16 @@ class NotifyNode extends AbstractNode implements NotifyPropertyChanged * * @var PropertyChangedListener[] */ - private $_propertyChangedListeners = []; + private array $propertyChangedListeners = []; /** * Adds a listener that wants to be notified about property changes. * * @see \Doctrine\Common\NotifyPropertyChanged::addPropertyChangedListener() - * - * @return void */ - public function addPropertyChangedListener(PropertyChangedListener $listener) + public function addPropertyChangedListener(PropertyChangedListener $listener): void { - $this->_propertyChangedListeners[] = $listener; + $this->propertyChangedListeners[] = $listener; } public function setName(?string $name): void @@ -62,21 +60,15 @@ public function setPosition(?int $position): void /** * Notify property change event to listeners - * - * @param mixed $oldValue - * @param mixed $newValue */ - protected function triggerPropertyChanged(string $propName, $oldValue, $newValue): void + protected function triggerPropertyChanged(string $propName, mixed $oldValue, mixed $newValue): void { - foreach ($this->_propertyChangedListeners as $listener) { + foreach ($this->propertyChangedListeners as $listener) { $listener->propertyChanged($this, $propName, $oldValue, $newValue); } } - /** - * @param mixed $newValue - */ - protected function setProperty(string $property, $newValue): void + protected function setProperty(string $property, mixed $newValue): void { $oldValue = $this->{$property}; if ($oldValue !== $newValue) { diff --git a/tests/Gedmo/Sortable/Fixture/Paper.php b/tests/Gedmo/Sortable/Fixture/Paper.php index bb65485252..48038b7e1c 100644 --- a/tests/Gedmo/Sortable/Fixture/Paper.php +++ b/tests/Gedmo/Sortable/Fixture/Paper.php @@ -23,8 +23,6 @@ class Paper { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Paper #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="name", type="string") diff --git a/tests/Gedmo/Sortable/Fixture/SimpleListItem.php b/tests/Gedmo/Sortable/Fixture/SimpleListItem.php index 8ec6e67242..fbbcef8dd5 100644 --- a/tests/Gedmo/Sortable/Fixture/SimpleListItem.php +++ b/tests/Gedmo/Sortable/Fixture/SimpleListItem.php @@ -23,8 +23,6 @@ class SimpleListItem { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class SimpleListItem #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(type="string", length=191) diff --git a/tests/Gedmo/Sortable/Fixture/Transport/Bus.php b/tests/Gedmo/Sortable/Fixture/Transport/Bus.php index 940f12a2fc..7045113a94 100644 --- a/tests/Gedmo/Sortable/Fixture/Transport/Bus.php +++ b/tests/Gedmo/Sortable/Fixture/Transport/Bus.php @@ -17,6 +17,4 @@ * @ORM\Entity */ #[ORM\Entity] -class Bus extends Vehicle -{ -} +class Bus extends Vehicle {} diff --git a/tests/Gedmo/Sortable/Fixture/Transport/Engine.php b/tests/Gedmo/Sortable/Fixture/Transport/Engine.php index d8407f2b56..d5c297a85d 100644 --- a/tests/Gedmo/Sortable/Fixture/Transport/Engine.php +++ b/tests/Gedmo/Sortable/Fixture/Transport/Engine.php @@ -21,8 +21,6 @@ class Engine { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -30,7 +28,7 @@ class Engine #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=32) diff --git a/tests/Gedmo/Sortable/Fixture/Transport/Reservation.php b/tests/Gedmo/Sortable/Fixture/Transport/Reservation.php index 2c0ac1823a..ab5bff7498 100644 --- a/tests/Gedmo/Sortable/Fixture/Transport/Reservation.php +++ b/tests/Gedmo/Sortable/Fixture/Transport/Reservation.php @@ -22,8 +22,6 @@ class Reservation { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Reservation #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\ManyToOne(targetEntity="Bus") diff --git a/tests/Gedmo/Sortable/Fixture/Transport/Vehicle.php b/tests/Gedmo/Sortable/Fixture/Transport/Vehicle.php index 7b6d789f62..b6a4c539a1 100644 --- a/tests/Gedmo/Sortable/Fixture/Transport/Vehicle.php +++ b/tests/Gedmo/Sortable/Fixture/Transport/Vehicle.php @@ -32,8 +32,6 @@ class Vehicle { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -41,7 +39,7 @@ class Vehicle #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\SortableGroup diff --git a/tests/Gedmo/Sortable/SortableGroupTest.php b/tests/Gedmo/Sortable/SortableGroupTest.php index 8b928b5727..263294ad92 100644 --- a/tests/Gedmo/Sortable/SortableGroupTest.php +++ b/tests/Gedmo/Sortable/SortableGroupTest.php @@ -123,15 +123,15 @@ public function testShouldBeAbleToChangeGroupWhenMultiGroups(): void for ($i = 0; $i < self::SEATS; ++$i) { $reservation = $repo->findOneBy(['name' => 'Bratislava Today '.$i]); - static::assertNotNull($reservation); + static::assertInstanceOf(Reservation::class, $reservation); static::assertSame($i, $reservation->getSeat()); $reservation = $repo->findOneBy(['name' => 'Bratislava Tomorrow '.$i]); - static::assertNotNull($reservation); + static::assertInstanceOf(Reservation::class, $reservation); static::assertSame($i, $reservation->getSeat()); $reservation = $repo->findOneBy(['name' => 'Prague Today '.$i]); - static::assertNotNull($reservation); + static::assertInstanceOf(Reservation::class, $reservation); static::assertSame($i, $reservation->getSeat()); } @@ -150,7 +150,7 @@ public function testShouldBeAbleToChangeGroupWhenMultiGroups(): void static::assertCount(self::SEATS - 1, $bratislavaToday); // Test seat numbers // Should be [ 0, 1 ] - $seats = array_map(static fn ($r) => $r->getSeat(), $bratislavaToday); + $seats = array_map(static fn ($r): ?int => $r->getSeat(), $bratislavaToday); static::assertSame(range(0, self::SEATS - 2), $seats, 'Should be seats [ 0, 1 ] to Bratislava Today'); // Bratislava Tomorrow should have 4 seats @@ -161,7 +161,7 @@ public function testShouldBeAbleToChangeGroupWhenMultiGroups(): void static::assertCount(self::SEATS + 1, $bratislavaTomorrow); // Test seat numbers // Should be [ 0, 1, 2, 3 ] - $seats = array_map(static fn ($r) => $r->getSeat(), $bratislavaTomorrow); + $seats = array_map(static fn ($r): ?int => $r->getSeat(), $bratislavaTomorrow); static::assertSame(range(0, self::SEATS), $seats, 'Should be seats [ 0, 1, 2, 3 ] to Bratislava Tomorrow'); // Prague Today should have 3 seats @@ -171,7 +171,7 @@ public function testShouldBeAbleToChangeGroupWhenMultiGroups(): void ], ['seat' => 'asc']); static::assertCount(self::SEATS, $pragueToday); // Test seat numbers - $seats = array_map(static fn ($r) => $r->getSeat(), $pragueToday); + $seats = array_map(static fn ($r): ?int => $r->getSeat(), $pragueToday); static::assertSame(range(0, self::SEATS - 1), $seats, 'Should be seats [ 0, 1, 2 ] to Prague Today'); } diff --git a/tests/Gedmo/Sortable/SortableTest.php b/tests/Gedmo/Sortable/SortableTest.php index eada6f2304..33d145c845 100644 --- a/tests/Gedmo/Sortable/SortableTest.php +++ b/tests/Gedmo/Sortable/SortableTest.php @@ -71,12 +71,12 @@ public function testMoveLastPosition(): void for ($i = 0; $i <= 8; ++$i) { $node = $repo->findOneBy(['position' => $i]); - static::assertNotNull($node); + static::assertInstanceOf(Node::class, $node); static::assertSame('Node'.($i + 2), $node->getName()); } $node = $repo->findOneBy(['position' => 9]); - static::assertNotNull($node); + static::assertInstanceOf(Node::class, $node); static::assertSame('Node1', $node->getName()); } @@ -140,8 +140,9 @@ public function testShouldShiftPositionForward(): void static::assertSame('Node4', $nodes[2]->getName()); static::assertSame('Node2', $nodes[3]->getName()); static::assertSame('Node5', $nodes[4]->getName()); + $counter = count($nodes); - for ($i = 0; $i < count($nodes); ++$i) { + for ($i = 0; $i < $counter; ++$i) { static::assertSame($i, $nodes[$i]->getPosition()); } } @@ -185,8 +186,9 @@ public function testShouldShiftPositionsProperlyWhenMoreThanOneWasUpdated(): voi static::assertSame('Node5', $nodes[2]->getName()); static::assertSame('Node2', $nodes[3]->getName()); static::assertSame('Node3', $nodes[4]->getName()); + $counter = count($nodes); - for ($i = 0; $i < count($nodes); ++$i) { + for ($i = 0; $i < $counter; ++$i) { static::assertSame($i, $nodes[$i]->getPosition()); } } @@ -229,8 +231,9 @@ public function testShouldShiftPositionBackward(): void static::assertSame('Node2', $nodes[2]->getName()); static::assertSame('Node3', $nodes[3]->getName()); static::assertSame('Node5', $nodes[4]->getName()); + $counter = count($nodes); - for ($i = 0; $i < count($nodes); ++$i) { + for ($i = 0; $i < $counter; ++$i) { static::assertSame($i, $nodes[$i]->getPosition()); } } @@ -419,7 +422,7 @@ public function testShouldRollbackPositionAfterExceptionOnDelete(): void $this->em->flush(); static::fail('Foreign key constraint violation exception not thrown.'); - } catch (ForeignKeyConstraintViolationException $e) { + } catch (ForeignKeyConstraintViolationException) { $customerTypes = $repo->findAll(); static::assertCount(3, $customerTypes); diff --git a/tests/Gedmo/TestActorProvider.php b/tests/Gedmo/TestActorProvider.php index 6bf03c3d73..2eadeac693 100644 --- a/tests/Gedmo/TestActorProvider.php +++ b/tests/Gedmo/TestActorProvider.php @@ -15,27 +15,9 @@ final class TestActorProvider implements ActorProviderInterface { - /** - * @var object|string|null - */ - private $actor; + public function __construct(private readonly string|object|null $actor) {} - /** - * @param object|string|null $actor - */ - public function __construct($actor) - { - if (!is_string($actor) && !is_object($actor) && null !== $actor) { - throw new \TypeError(sprintf('The actor must be a string, an object, or null, "%s" given.', gettype($actor))); - } - - $this->actor = $actor; - } - - /** - * @return object|string|null - */ - public function getActor() + public function getActor(): string|object|null { return $this->actor; } diff --git a/tests/Gedmo/TestIpAddressProvider.php b/tests/Gedmo/TestIpAddressProvider.php index bc6283e857..30af40c3b8 100644 --- a/tests/Gedmo/TestIpAddressProvider.php +++ b/tests/Gedmo/TestIpAddressProvider.php @@ -15,12 +15,7 @@ final class TestIpAddressProvider implements IpAddressProviderInterface { - private ?string $address; - - public function __construct(?string $address) - { - $this->address = $address; - } + public function __construct(private readonly ?string $address) {} public function getAddress(): ?string { diff --git a/tests/Gedmo/Timestampable/AttributeChangeTest.php b/tests/Gedmo/Timestampable/AttributeChangeTest.php index 25fecb00d8..052a175c74 100644 --- a/tests/Gedmo/Timestampable/AttributeChangeTest.php +++ b/tests/Gedmo/Timestampable/AttributeChangeTest.php @@ -24,16 +24,11 @@ * * @license MIT License (http://www.opensource.org/licenses/mit-license.php) * - * @requires PHP >= 8.0 - * * @todo This test requires {@see ChangeTest} to have been run first to load the {@see TimestampableListenerStub} */ final class AttributeChangeTest extends BaseTestCaseORM { - /** - * @var TimestampableListenerStub - */ - protected $listener; + protected TimestampableListenerStub $listener; protected function setUp(): void { @@ -69,14 +64,8 @@ public function testChange(): void $this->em->flush(); $this->em->clear(); // Changed. - static::assertSame( - $currentDate->format('Y-m-d H:i:s'), - $test->getChtitle()->format('Y-m-d H:i:s') - ); - static::assertSame( - $currentDate->format('Y-m-d H:i:s'), - $test->getClosed()->format('Y-m-d H:i:s') - ); + static::assertSame($currentDate->format('Y-m-d H:i:s'), $test->getChtitle()->format('Y-m-d H:i:s')); + static::assertSame($currentDate->format('Y-m-d H:i:s'), $test->getClosed()->format('Y-m-d H:i:s')); $anotherDate = \DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-01 00:00:00'); $this->listener->eventAdapter->setDateValue($anotherDate); @@ -88,14 +77,8 @@ public function testChange(): void $this->em->flush(); $this->em->clear(); // Not Changed. - static::assertSame( - $currentDate->format('Y-m-d H:i:s'), - $test->getChtitle()->format('Y-m-d H:i:s') - ); - static::assertSame( - $currentDate->format('Y-m-d H:i:s'), - $test->getClosed()->format('Y-m-d H:i:s') - ); + static::assertSame($currentDate->format('Y-m-d H:i:s'), $test->getChtitle()->format('Y-m-d H:i:s')); + static::assertSame($currentDate->format('Y-m-d H:i:s'), $test->getClosed()->format('Y-m-d H:i:s')); $test = $this->em->getRepository(TitledArticle::class)->findOneBy(['title' => 'New Title']); $test->setState('Published'); @@ -103,10 +86,7 @@ public function testChange(): void $this->em->flush(); $this->em->clear(); // Changed. - static::assertSame( - $anotherDate->format('Y-m-d H:i:s'), - $test->getClosed()->format('Y-m-d H:i:s') - ); + static::assertSame($anotherDate->format('Y-m-d H:i:s'), $test->getClosed()->format('Y-m-d H:i:s')); } protected function getUsedEntityFixtures(): array diff --git a/tests/Gedmo/Timestampable/CarbonTest.php b/tests/Gedmo/Timestampable/CarbonTest.php index 4d55c2f7ac..888f68f6b5 100644 --- a/tests/Gedmo/Timestampable/CarbonTest.php +++ b/tests/Gedmo/Timestampable/CarbonTest.php @@ -11,11 +11,11 @@ use Carbon\Carbon; use Carbon\CarbonImmutable; -use Carbon\Doctrine\DateTimeImmutableType; -use Carbon\Doctrine\DateTimeType; -use DateTime; +use Carbon\Doctrine\DateTimeImmutableType as CarbonDateTimeImmutableType; +use Carbon\Doctrine\DateTimeType as CarbonDateTimeType; use Doctrine\Common\EventManager; -use Doctrine\DBAL\Types\DateType; +use Doctrine\DBAL\Types\DateTimeImmutableType as DoctrineDateTimeImmutableType; +use Doctrine\DBAL\Types\DateType as DoctrineDateType; use Doctrine\DBAL\Types\Type as DoctrineType; use Doctrine\DBAL\Types\Types; use Gedmo\Tests\Timestampable\Fixture\ArticleCarbon; @@ -38,19 +38,19 @@ protected function setUp(): void /** * DATE_MUTABLE => Carbon - * DATETIME_MUTABLE => CarbonImmutable + * DATETIME_IMMUTABLE => CarbonImmutable * TIME_MUTABLE => DateTime */ - DoctrineType::overrideType(Types::DATE_MUTABLE, DateTimeType::class); - DoctrineType::overrideType(Types::DATETIME_MUTABLE, DateTimeImmutableType::class); + DoctrineType::overrideType(Types::DATE_MUTABLE, CarbonDateTimeType::class); + DoctrineType::overrideType(Types::DATETIME_IMMUTABLE, CarbonDateTimeImmutableType::class); } protected function tearDown(): void { parent::tearDown(); - DoctrineType::overrideType(Types::DATE_MUTABLE, DateType::class); - DoctrineType::overrideType(Types::DATETIME_MUTABLE, \Doctrine\DBAL\Types\DateTimeType::class); + DoctrineType::overrideType(Types::DATE_MUTABLE, DoctrineDateType::class); + DoctrineType::overrideType(Types::DATETIME_IMMUTABLE, DoctrineDateTimeImmutableType::class); } public function testShouldHandleStandardBehavior(): void @@ -76,12 +76,12 @@ public function testShouldHandleStandardBehavior(): void /** @var ArticleCarbon $sport */ $sport = $this->em->getRepository(ArticleCarbon::class)->findOneBy(['title' => 'Sport']); - static::assertInstanceOf(CarbonImmutable::class, $su = $sport->getUpdated(), 'Type DATETIME_MUTABLE should become CarbonImmutable'); + static::assertInstanceOf(CarbonImmutable::class, $su = $sport->getUpdated(), 'Type DATETIME_IMMUTABLE should become CarbonImmutable'); static::assertInstanceOf(Carbon::class, $sc = $sport->getCreated(), 'Type DATE_MUTABLE should become Carbon'); - static::assertNull($sport->getContentChanged()); - static::assertNull($sport->getPublished()); - static::assertNull($sport->getAuthorChanged()); + static::assertNotInstanceOf(CarbonImmutable::class, $sport->getContentChanged()); + static::assertNotInstanceOf(CarbonImmutable::class, $sport->getPublished()); + static::assertNotInstanceOf(CarbonImmutable::class, $sport->getAuthorChanged()); $author = $sport->getAuthor(); $author->setName('New author'); @@ -92,7 +92,7 @@ public function testShouldHandleStandardBehavior(): void static::assertInstanceOf(\DateTime::class, $sportComment->getModified(), 'Type TIME_MUTABLE should stay DateTime'); static::assertNotNull($sportComment->getModified()); - static::assertNull($sportComment->getClosed()); + static::assertNotInstanceOf(\DateTime::class, $sportComment->getClosed()); $sportComment->setStatus(1); $published = new Type(); @@ -105,9 +105,9 @@ public function testShouldHandleStandardBehavior(): void $this->em->flush(); $sportComment = $this->em->getRepository(CommentCarbon::class)->findOneBy(['message' => 'hello']); - static::assertInstanceOf(CarbonImmutable::class, $scc = $sportComment->getClosed(), 'Type DATETIME_MUTABLE should become CarbonImmutable'); - static::assertInstanceOf(CarbonImmutable::class, $sp = $sport->getPublished(), 'Type DATETIME_MUTABLE should become CarbonImmutable'); - static::assertInstanceOf(CarbonImmutable::class, $sa = $sport->getAuthorChanged(), 'Type DATETIME_MUTABLE should become CarbonImmutable'); + static::assertInstanceOf(\DateTime::class, $scc = $sportComment->getClosed(), 'Type DATETIME_MUTABLE should become DateTime'); + static::assertInstanceOf(CarbonImmutable::class, $sp = $sport->getPublished(), 'Type DATETIME_IMMUTABLE should become CarbonImmutable'); + static::assertInstanceOf(CarbonImmutable::class, $sa = $sport->getAuthorChanged(), 'Type DATETIME_IMMUTABLE should become CarbonImmutable'); $sport->setTitle('Updated'); $this->em->persist($sport); @@ -117,10 +117,10 @@ public function testShouldHandleStandardBehavior(): void static::assertSame($sport->getCreated(), $sc, 'Date created should remain same after update'); static::assertNotSame($su2 = $sport->getUpdated(), $su, 'Date updated should change after update'); - static::assertInstanceOf(CarbonImmutable::class, $sport->getUpdated(), 'Type DATETIME_MUTABLE should become CarbonImmutable'); + static::assertInstanceOf(CarbonImmutable::class, $sport->getUpdated(), 'Type DATETIME_IMMUTABLE should become CarbonImmutable'); static::assertSame($sport->getPublished(), $sp, 'Date published should remain the same after update'); static::assertNotSame($scc2 = $sport->getContentChanged(), $scc, 'Content must have changed after update'); - static::assertInstanceOf(CarbonImmutable::class, $sport->getContentChanged(), 'Type DATETIME_MUTABLE should become CarbonImmutable'); + static::assertInstanceOf(CarbonImmutable::class, $sport->getContentChanged(), 'Type DATETIME_IMMUTABLE should become CarbonImmutable'); static::assertSame($sport->getAuthorChanged(), $sa, 'Author should remain same after update'); $author = $sport->getAuthor(); diff --git a/tests/Gedmo/Timestampable/ChangeTest.php b/tests/Gedmo/Timestampable/ChangeTest.php index 192ea84a1f..10bba2250a 100644 --- a/tests/Gedmo/Timestampable/ChangeTest.php +++ b/tests/Gedmo/Timestampable/ChangeTest.php @@ -66,14 +66,8 @@ public function testChange(): void $this->em->flush(); $this->em->clear(); // Changed - static::assertSame( - $currentDate->format('Y-m-d H:i:s'), - $test->getChtitle()->format('Y-m-d H:i:s') - ); - static::assertSame( - $currentDate->format('Y-m-d H:i:s'), - $test->getClosed()->format('Y-m-d H:i:s') - ); + static::assertSame($currentDate->format('Y-m-d H:i:s'), $test->getChtitle()->format('Y-m-d H:i:s')); + static::assertSame($currentDate->format('Y-m-d H:i:s'), $test->getClosed()->format('Y-m-d H:i:s')); $anotherDate = \DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-01 00:00:00'); $this->listener->eventAdapter->setDateValue($anotherDate); @@ -85,14 +79,8 @@ public function testChange(): void $this->em->flush(); $this->em->clear(); // Not Changed - static::assertSame( - $currentDate->format('Y-m-d H:i:s'), - $test->getChtitle()->format('Y-m-d H:i:s') - ); - static::assertSame( - $currentDate->format('Y-m-d H:i:s'), - $test->getClosed()->format('Y-m-d H:i:s') - ); + static::assertSame($currentDate->format('Y-m-d H:i:s'), $test->getChtitle()->format('Y-m-d H:i:s')); + static::assertSame($currentDate->format('Y-m-d H:i:s'), $test->getClosed()->format('Y-m-d H:i:s')); $test = $this->em->getRepository(TitledArticle::class)->findOneBy(['title' => 'New Title']); $test->setState('Published'); @@ -100,10 +88,7 @@ public function testChange(): void $this->em->flush(); $this->em->clear(); // Changed - static::assertSame( - $anotherDate->format('Y-m-d H:i:s'), - $test->getClosed()->format('Y-m-d H:i:s') - ); + static::assertSame($anotherDate->format('Y-m-d H:i:s'), $test->getClosed()->format('Y-m-d H:i:s')); } protected function getUsedEntityFixtures(): array @@ -137,13 +122,12 @@ public function getDateValue($meta, $field): ?\DateTime */ final class TimestampableListenerStub extends AbstractTrackingListener { - /** - * @var EventAdapterORMStub - */ - public $eventAdapter; + public ?EventAdapterORMStub $eventAdapter = null; protected function getEventAdapter(EventArgs $args) { + \assert($this->eventAdapter instanceof EventAdapterORMStub); + $this->eventAdapter->setEventArgs($args); return $this->eventAdapter; @@ -153,12 +137,12 @@ protected function getEventAdapter(EventArgs $args) * @param ClassMetadata $meta * @param EventAdapterORMStub $eventAdapter */ - protected function getFieldValue($meta, $field, $eventAdapter) + protected function getFieldValue($meta, $field, $eventAdapter): ?\DateTime { return $eventAdapter->getDateValue($meta, $field); } - protected function getNamespace() + protected function getNamespace(): string { return 'Gedmo\Timestampable'; } diff --git a/tests/Gedmo/Timestampable/Fixture/Article.php b/tests/Gedmo/Timestampable/Fixture/Article.php index ed1fd49314..36bf53787e 100644 --- a/tests/Gedmo/Timestampable/Fixture/Article.php +++ b/tests/Gedmo/Timestampable/Fixture/Article.php @@ -25,8 +25,6 @@ class Article implements Timestampable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Article implements Timestampable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=128) @@ -54,7 +52,7 @@ class Article implements Timestampable * @ORM\OneToMany(targetEntity="Gedmo\Tests\Timestampable\Fixture\Comment", mappedBy="article") */ #[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'article')] - private $comments; + private Collection $comments; /** * @ORM\Embedded(class="Gedmo\Tests\Timestampable\Fixture\Author") @@ -97,16 +95,15 @@ class Article implements Timestampable #[ORM\Column(name: 'content_changed', type: Types::DATETIME_MUTABLE, nullable: true)] #[Gedmo\Timestampable(on: 'change', field: ['title', 'body'])] private ?\DateTime $contentChanged = null; + /** - * @var \DateTime|null - * * @ORM\Column(name="author_changed", type="datetime", nullable=true) * * @Gedmo\Timestampable(on="change", field={"author.name", "author.email"}) */ #[ORM\Column(name: 'author_changed', type: Types::DATETIME_MUTABLE, nullable: true)] #[Gedmo\Timestampable(on: 'change', field: ['author.name', 'author.email'])] - private $authorChanged; + private ?\DateTime $authorChanged = null; /** * @ORM\ManyToOne(targetEntity="Type", inversedBy="articles") @@ -123,15 +120,13 @@ class Article implements Timestampable /** * We use the value "10" as string here in order to check the behavior of `AbstractTrackingListener` * - * @var \DateTimeInterface|null - * * @ORM\Column(name="reached_relevant_level", type="datetime", nullable=true) * * @Gedmo\Timestampable(on="change", field="level", value="10") */ #[ORM\Column(name: 'reached_relevant_level', type: Types::DATE_MUTABLE, nullable: true)] #[Gedmo\Timestampable(on: 'change', field: 'level', value: '10')] - private $reachedRelevantLevel; + private ?\DateTime $reachedRelevantLevel = null; public function __construct() { @@ -247,7 +242,7 @@ public function getLevel(): int return $this->level; } - public function getReachedRelevantLevel(): ?\DateTimeInterface + public function getReachedRelevantLevel(): ?\DateTime { return $this->reachedRelevantLevel; } diff --git a/tests/Gedmo/Timestampable/Fixture/ArticleCarbon.php b/tests/Gedmo/Timestampable/Fixture/ArticleCarbon.php index 56d0d2ff32..fea32ef525 100644 --- a/tests/Gedmo/Timestampable/Fixture/ArticleCarbon.php +++ b/tests/Gedmo/Timestampable/Fixture/ArticleCarbon.php @@ -49,11 +49,11 @@ class ArticleCarbon implements Timestampable private ?string $body = null; /** - * @var Collection + * @var Collection * - * @ORM\OneToMany(targetEntity="Gedmo\Tests\Timestampable\Fixture\Comment", mappedBy="article") + * @ORM\OneToMany(targetEntity="Gedmo\Tests\Timestampable\Fixture\CommentCarbon", mappedBy="article") */ - #[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'article')] + #[ORM\OneToMany(targetEntity: CommentCarbon::class, mappedBy: 'article')] private Collection $comments; /** @@ -63,55 +63,47 @@ class ArticleCarbon implements Timestampable private ?Author $author = null; /** - * @var \DateTime|Carbon|null - * * @Gedmo\Timestampable(on="create") * * @ORM\Column(name="created", type="date") */ #[Gedmo\Timestampable(on: 'create')] #[ORM\Column(name: 'created', type: Types::DATE_MUTABLE)] - private $created; + private ?Carbon $created = null; /** - * @var \DateTime|CarbonImmutable|null - * - * @ORM\Column(name="updated", type="datetime") + * @ORM\Column(name="updated", type="datetime_immutable") * * @Gedmo\Timestampable */ - #[ORM\Column(name: 'updated', type: Types::DATETIME_MUTABLE)] + #[ORM\Column(name: 'updated', type: Types::DATETIME_IMMUTABLE)] #[Gedmo\Timestampable] - private $updated; + private ?CarbonImmutable $updated = null; /** - * @var \DateTime|CarbonImmutable|null - * - * @ORM\Column(name="published", type="datetime", nullable=true) + * @ORM\Column(name="published", type="datetime_immutable", nullable=true) * * @Gedmo\Timestampable(on="change", field="type.title", value="Published") */ - #[ORM\Column(name: 'published', type: Types::DATETIME_MUTABLE, nullable: true)] + #[ORM\Column(name: 'published', type: Types::DATETIME_IMMUTABLE, nullable: true)] #[Gedmo\Timestampable(on: 'change', field: 'type.title', value: 'Published')] - private $published; + private ?CarbonImmutable $published = null; /** - * @var \DateTime|CarbonImmutable|null - * - * @ORM\Column(name="content_changed", type="datetime", nullable=true) + * @ORM\Column(name="content_changed", type="datetime_immutable", nullable=true) * * @Gedmo\Timestampable(on="change", field={"title", "body"}) */ - #[ORM\Column(name: 'content_changed', type: Types::DATETIME_MUTABLE, nullable: true)] + #[ORM\Column(name: 'content_changed', type: Types::DATETIME_IMMUTABLE, nullable: true)] #[Gedmo\Timestampable(on: 'change', field: ['title', 'body'])] - private $contentChanged; + private ?CarbonImmutable $contentChanged = null; /** - * @ORM\Column(name="author_changed", type="datetime", nullable=true) + * @ORM\Column(name="author_changed", type="datetime_immutable", nullable=true) * * @Gedmo\Timestampable(on="change", field={"author.name", "author.email"}) */ - #[ORM\Column(name: 'author_changed', type: Types::DATETIME_MUTABLE, nullable: true)] + #[ORM\Column(name: 'author_changed', type: Types::DATETIME_IMMUTABLE, nullable: true)] #[Gedmo\Timestampable(on: 'change', field: ['author.name', 'author.email'])] private ?CarbonImmutable $authorChanged = null; @@ -136,7 +128,7 @@ class ArticleCarbon implements Timestampable */ #[ORM\Column(name: 'reached_relevant_level', type: Types::DATE_MUTABLE, nullable: true)] #[Gedmo\Timestampable(on: 'change', field: 'level', value: '10')] - private ?\DateTimeInterface $reachedRelevantLevel = null; + private ?Carbon $reachedRelevantLevel = null; public function __construct() { @@ -173,14 +165,14 @@ public function getBody(): ?string return $this->body; } - public function addComment(Comment $comment): void + public function addComment(CommentCarbon $comment): void { $comment->setArticle($this); $this->comments[] = $comment; } /** - * @return Collection + * @return Collection */ public function getComments(): Collection { @@ -202,8 +194,7 @@ public function getCreated(): ?Carbon return $this->created; } - /** @param CarbonImmutable|\DateTime $created */ - public function setCreated($created): void + public function setCreated(Carbon $created): void { $this->created = $created; } @@ -213,8 +204,7 @@ public function getPublished(): ?CarbonImmutable return $this->published; } - /** @param CarbonImmutable|\DateTime $published */ - public function setPublished($published): void + public function setPublished(CarbonImmutable $published): void { $this->published = $published; } @@ -224,14 +214,12 @@ public function getUpdated(): ?CarbonImmutable return $this->updated; } - /** @param CarbonImmutable|\DateTime $updated */ - public function setUpdated($updated): void + public function setUpdated(CarbonImmutable $updated): void { $this->updated = $updated; } - /** @param CarbonImmutable|\DateTime $contentChanged */ - public function setContentChanged($contentChanged): void + public function setContentChanged(CarbonImmutable $contentChanged): void { $this->contentChanged = $contentChanged; } @@ -256,7 +244,7 @@ public function getLevel(): int return $this->level; } - public function getReachedRelevantLevel(): ?\DateTimeInterface + public function getReachedRelevantLevel(): ?Carbon { return $this->reachedRelevantLevel; } diff --git a/tests/Gedmo/Timestampable/Fixture/Comment.php b/tests/Gedmo/Timestampable/Fixture/Comment.php index 2631fd345d..44d33c87c0 100644 --- a/tests/Gedmo/Timestampable/Fixture/Comment.php +++ b/tests/Gedmo/Timestampable/Fixture/Comment.php @@ -23,8 +23,6 @@ class Comment implements Timestampable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Comment implements Timestampable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="message", type="text") @@ -41,12 +39,10 @@ class Comment implements Timestampable private ?string $message = null; /** - * @var Article|null - * * @ORM\ManyToOne(targetEntity="Gedmo\Tests\Timestampable\Fixture\Article", inversedBy="comments") */ #[ORM\ManyToOne(targetEntity: Article::class, inversedBy: 'comments')] - private $article; + private ?Article $article = null; /** * @ORM\Column(type="integer") @@ -55,31 +51,24 @@ class Comment implements Timestampable private ?int $status = null; /** - * @var \DateTime|null - * * @ORM\Column(name="closed", type="datetime", nullable=true) * * @Gedmo\Timestampable(on="change", field="status", value=1) */ #[ORM\Column(name: 'closed', type: Types::DATETIME_MUTABLE, nullable: true)] #[Gedmo\Timestampable(on: 'change', field: 'status', value: 1)] - private $closed; + private ?\DateTime $closed = null; /** - * @var \DateTime|null - * * @ORM\Column(name="modified", type="time") * * @Gedmo\Timestampable(on="update") */ #[ORM\Column(name: 'modified', type: Types::TIME_MUTABLE)] #[Gedmo\Timestampable(on: 'update')] - private $modified; + private ?\DateTime $modified = null; - /** - * @param Article|ArticleCarbon $article - */ - public function setArticle(?Timestampable $article): void + public function setArticle(Article $article): void { $this->article = $article; } diff --git a/tests/Gedmo/Timestampable/Fixture/CommentCarbon.php b/tests/Gedmo/Timestampable/Fixture/CommentCarbon.php index 94057e5d3e..682adfff43 100644 --- a/tests/Gedmo/Timestampable/Fixture/CommentCarbon.php +++ b/tests/Gedmo/Timestampable/Fixture/CommentCarbon.php @@ -11,7 +11,6 @@ namespace Gedmo\Tests\Timestampable\Fixture; -use Carbon\CarbonImmutable; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; @@ -24,8 +23,6 @@ class CommentCarbon implements Timestampable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +30,7 @@ class CommentCarbon implements Timestampable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="message", type="text") @@ -54,26 +51,22 @@ class CommentCarbon implements Timestampable private ?int $status = null; /** - * @var CarbonImmutable|null - * * @ORM\Column(name="closed", type="datetime", nullable=true) * * @Gedmo\Timestampable(on="change", field="status", value=1) */ #[ORM\Column(name: 'closed', type: Types::DATETIME_MUTABLE, nullable: true)] #[Gedmo\Timestampable(on: 'change', field: 'status', value: 1)] - private $closed; + private ?\DateTime $closed = null; /** - * @var \DateTime|null - * * @ORM\Column(name="modified", type="time") * * @Gedmo\Timestampable(on="update") */ #[ORM\Column(name: 'modified', type: Types::TIME_MUTABLE)] #[Gedmo\Timestampable(on: 'update')] - private $modified; + private ?\DateTime $modified = null; public function setArticle(?ArticleCarbon $article): void { @@ -110,7 +103,7 @@ public function getModified(): ?\DateTime return $this->modified; } - public function getClosed(): ?CarbonImmutable + public function getClosed(): ?\DateTime { return $this->closed; } diff --git a/tests/Gedmo/Timestampable/Fixture/Document/Article.php b/tests/Gedmo/Timestampable/Fixture/Document/Article.php index 09c779f0b6..1dd59d31d3 100644 --- a/tests/Gedmo/Timestampable/Fixture/Document/Article.php +++ b/tests/Gedmo/Timestampable/Fixture/Document/Article.php @@ -23,12 +23,10 @@ class Article { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Timestampable/Fixture/Document/Type.php b/tests/Gedmo/Timestampable/Fixture/Document/Type.php index c8b71df081..d5869598dd 100644 --- a/tests/Gedmo/Timestampable/Fixture/Document/Type.php +++ b/tests/Gedmo/Timestampable/Fixture/Document/Type.php @@ -21,12 +21,10 @@ class Type { /** - * @var string|null - * * @ODM\Id */ #[ODM\Id] - private $id; + private ?string $id = null; /** * @ODM\Field(type="string") diff --git a/tests/Gedmo/Timestampable/Fixture/MappedSupperClass.php b/tests/Gedmo/Timestampable/Fixture/MappedSupperClass.php index 1118ac7e0b..ccd916d486 100644 --- a/tests/Gedmo/Timestampable/Fixture/MappedSupperClass.php +++ b/tests/Gedmo/Timestampable/Fixture/MappedSupperClass.php @@ -22,50 +22,39 @@ class MappedSupperClass { /** - * @var int|null - * - * @ORM\Column(name="id", type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") - */ - #[ORM\Column(name: 'id', type: Types::INTEGER)] - #[ORM\Id] - #[ORM\GeneratedValue(strategy: 'AUTO')] - protected $id; - - /** - * @var string|null - * * @Gedmo\Locale */ #[Gedmo\Locale] - protected $locale; + protected ?string $locale = null; /** - * @var string|null - * * @Gedmo\Translatable * * @ORM\Column(name="name", type="string", length=191) */ #[Gedmo\Translatable] #[ORM\Column(name: 'name', type: Types::STRING, length: 191)] - protected $name; + protected ?string $name = null; /** - * @var \DateTime|null - * * @ORM\Column(name="created_at", type="datetime") * * @Gedmo\Timestampable(on="create") */ #[ORM\Column(name: 'created_at', type: Types::DATETIME_MUTABLE)] #[Gedmo\Timestampable(on: 'create')] - protected $createdAt; + protected ?\DateTime $createdAt = null; /** - * @codeCoverageIgnore + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: Types::INTEGER)] + private ?int $id = null; + public function getId(): ?int { return $this->id; diff --git a/tests/Gedmo/Timestampable/Fixture/Type.php b/tests/Gedmo/Timestampable/Fixture/Type.php index 4a77ef3fde..7cdb86a0fd 100644 --- a/tests/Gedmo/Timestampable/Fixture/Type.php +++ b/tests/Gedmo/Timestampable/Fixture/Type.php @@ -23,8 +23,6 @@ class Type { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Type #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=128) diff --git a/tests/Gedmo/Timestampable/Fixture/UsingTrait.php b/tests/Gedmo/Timestampable/Fixture/UsingTrait.php index 44d14d3ffa..36dcc69889 100644 --- a/tests/Gedmo/Timestampable/Fixture/UsingTrait.php +++ b/tests/Gedmo/Timestampable/Fixture/UsingTrait.php @@ -28,8 +28,6 @@ class UsingTrait use TimestampableEntity; /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -37,7 +35,7 @@ class UsingTrait #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=128) diff --git a/tests/Gedmo/Timestampable/Fixture/WithoutInterface.php b/tests/Gedmo/Timestampable/Fixture/WithoutInterface.php index e1de7f07f1..ce3734bddc 100644 --- a/tests/Gedmo/Timestampable/Fixture/WithoutInterface.php +++ b/tests/Gedmo/Timestampable/Fixture/WithoutInterface.php @@ -22,8 +22,6 @@ class WithoutInterface { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class WithoutInterface #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(type="string", length=128) @@ -40,26 +38,22 @@ class WithoutInterface private ?string $title = null; /** - * @var \DateTime|null - * * @Gedmo\Timestampable(on="create") * * @ORM\Column(type="date") */ #[Gedmo\Timestampable(on: 'create')] #[ORM\Column(type: Types::DATE_MUTABLE)] - private $created; + private ?\DateTime $created = null; /** - * @var \DateTime|null - * * @ORM\Column(type="datetime") * * @Gedmo\Timestampable(on="update") */ #[ORM\Column(type: Types::DATETIME_MUTABLE)] #[Gedmo\Timestampable(on: 'update')] - private $updated; + private ?\DateTime $updated = null; public function getId(): ?int { diff --git a/tests/Gedmo/Timestampable/NoInterfaceTest.php b/tests/Gedmo/Timestampable/NoInterfaceTest.php index 8af81a9560..1ac237826d 100644 --- a/tests/Gedmo/Timestampable/NoInterfaceTest.php +++ b/tests/Gedmo/Timestampable/NoInterfaceTest.php @@ -44,14 +44,8 @@ public function testTimestampableNoInterface(): void $this->em->clear(); $test = $this->em->getRepository(WithoutInterface::class)->findOneBy(['title' => 'Test']); - static::assertSame( - $date->format('Y-m-d 00:00:00'), - $test->getCreated()->format('Y-m-d H:i:s') - ); - static::assertSame( - $date->format('Y-m-d H:i'), - $test->getUpdated()->format('Y-m-d H:i') - ); + static::assertSame($date->format('Y-m-d 00:00:00'), $test->getCreated()->format('Y-m-d H:i:s')); + static::assertSame($date->format('Y-m-d H:i'), $test->getUpdated()->format('Y-m-d H:i')); } protected function getUsedEntityFixtures(): array diff --git a/tests/Gedmo/Timestampable/TimestampableDocumentTest.php b/tests/Gedmo/Timestampable/TimestampableDocumentTest.php index a3547f6518..8f6da59a46 100644 --- a/tests/Gedmo/Timestampable/TimestampableDocumentTest.php +++ b/tests/Gedmo/Timestampable/TimestampableDocumentTest.php @@ -43,10 +43,7 @@ public function testTimestampable(): void $now = time(); $created = $article->getCreated()->getTimestamp(); static::assertTrue($created > $now - 5 && $created < $now + 5); // 5 seconds interval if lag - static::assertSame( - $date->format('Y-m-d H:i'), - $article->getUpdated()->format('Y-m-d H:i') - ); + static::assertSame($date->format('Y-m-d H:i'), $article->getUpdated()->format('Y-m-d H:i')); $published = new Type(); $published->setIdentifier('published'); @@ -60,10 +57,7 @@ public function testTimestampable(): void $article = $repo->findOneBy(['title' => 'Timestampable Article']); $date = new \DateTime(); - static::assertSame( - $date->format('Y-m-d H:i'), - $article->getPublished()->format('Y-m-d H:i') - ); + static::assertSame($date->format('Y-m-d H:i'), $article->getPublished()->format('Y-m-d H:i')); } public function testForcedValues(): void @@ -80,14 +74,8 @@ public function testForcedValues(): void $repo = $this->dm->getRepository(Article::class); $sport = $repo->findOneBy(['title' => 'sport forced']); - static::assertSame( - $created, - $sport->getCreated()->getTimestamp() - ); - static::assertSame( - '2000-01-01 12:00:00', - $sport->getUpdated()->format('Y-m-d H:i:s') - ); + static::assertSame($created, $sport->getCreated()->getTimestamp()); + static::assertSame('2000-01-01 12:00:00', $sport->getUpdated()->format('Y-m-d H:i:s')); $published = new Type(); $published->setIdentifier('published'); @@ -101,10 +89,7 @@ public function testForcedValues(): void $this->dm->clear(); $sport = $repo->findOneBy(['title' => 'sport forced']); - static::assertSame( - '2000-01-01 12:00:00', - $sport->getPublished()->format('Y-m-d H:i:s') - ); + static::assertSame('2000-01-01 12:00:00', $sport->getPublished()->format('Y-m-d H:i:s')); } public function testShouldHandleOnChangeWithBooleanValue(): void @@ -112,13 +97,13 @@ public function testShouldHandleOnChangeWithBooleanValue(): void $repo = $this->dm->getRepository(Article::class); $article = $repo->findOneBy(['title' => 'Timestampable Article']); - static::assertNull($article->getReady()); + static::assertNotInstanceOf(\DateTime::class, $article->getReady()); $article->setIsReady(true); $this->dm->persist($article); $this->dm->flush(); - static::assertNotNull($article->getReady()); + static::assertInstanceOf(\DateTime::class, $article->getReady()); } private function populate(): void diff --git a/tests/Gedmo/Timestampable/TimestampableEmbeddedDocumentTest.php b/tests/Gedmo/Timestampable/TimestampableEmbeddedDocumentTest.php index 756d65f08c..31306811b5 100644 --- a/tests/Gedmo/Timestampable/TimestampableEmbeddedDocumentTest.php +++ b/tests/Gedmo/Timestampable/TimestampableEmbeddedDocumentTest.php @@ -54,28 +54,16 @@ public function testPersistEmbeddedDocumentWithParent(): void $bookFromRepo = $repo->findOneBy(['title' => 'Cats & Dogs']); - static::assertNotNull($bookFromRepo); + static::assertInstanceOf(Book::class, $bookFromRepo); $date = new \DateTime(); - static::assertSame( - $date->format('Y-m-d H:i'), - $book->getTags()->get(0)->getCreated()->format('Y-m-d H:i') - ); - - static::assertSame( - $date->format('Y-m-d H:i'), - $book->getTags()->get(1)->getCreated()->format('Y-m-d H:i') - ); - - static::assertSame( - $date->format('Y-m-d H:i'), - $book->getTags()->get(0)->getUpdated()->format('Y-m-d H:i') - ); - - static::assertSame( - $date->format('Y-m-d H:i'), - $book->getTags()->get(1)->getUpdated()->format('Y-m-d H:i') - ); + static::assertSame($date->format('Y-m-d H:i'), $book->getTags()->get(0)->getCreated()->format('Y-m-d H:i')); + + static::assertSame($date->format('Y-m-d H:i'), $book->getTags()->get(1)->getCreated()->format('Y-m-d H:i')); + + static::assertSame($date->format('Y-m-d H:i'), $book->getTags()->get(0)->getUpdated()->format('Y-m-d H:i')); + + static::assertSame($date->format('Y-m-d H:i'), $book->getTags()->get(1)->getUpdated()->format('Y-m-d H:i')); } } diff --git a/tests/Gedmo/Timestampable/TimestampableTest.php b/tests/Gedmo/Timestampable/TimestampableTest.php index 593c0f5b3b..a7eaefbd08 100644 --- a/tests/Gedmo/Timestampable/TimestampableTest.php +++ b/tests/Gedmo/Timestampable/TimestampableTest.php @@ -116,19 +116,19 @@ public function testShouldHandleStandardBehavior(): void $this->em->flush(); $sport = $this->em->getRepository(Article::class)->findOneBy(['title' => 'Sport']); - static::assertNotNull($sc = $sport->getCreated()); - static::assertNotNull($su = $sport->getUpdated()); - static::assertNull($sport->getContentChanged()); - static::assertNull($sport->getPublished()); - static::assertNull($sport->getAuthorChanged()); + static::assertInstanceOf(\DateTime::class, $sc = $sport->getCreated()); + static::assertInstanceOf(\DateTime::class, $su = $sport->getUpdated()); + static::assertNotInstanceOf(\DateTime::class, $sport->getContentChanged()); + static::assertNotInstanceOf(\DateTime::class, $sport->getPublished()); + static::assertNotInstanceOf(\DateTime::class, $sport->getAuthorChanged()); $author = $sport->getAuthor(); $author->setName('New author'); $sport->setAuthor($author); $sportComment = $this->em->getRepository(Comment::class)->findOneBy(['message' => 'hello']); - static::assertNotNull($sportComment->getModified()); - static::assertNull($sportComment->getClosed()); + static::assertInstanceOf(\DateTime::class, $sportComment->getModified()); + static::assertNotInstanceOf(\DateTime::class, $sportComment->getClosed()); $sportComment->setStatus(1); $published = new Type(); @@ -141,9 +141,9 @@ public function testShouldHandleStandardBehavior(): void $this->em->flush(); $sportComment = $this->em->getRepository(Comment::class)->findOneBy(['message' => 'hello']); - static::assertNotNull($scc = $sportComment->getClosed()); - static::assertNotNull($sp = $sport->getPublished()); - static::assertNotNull($sa = $sport->getAuthorChanged()); + static::assertInstanceOf(\DateTime::class, $scc = $sportComment->getClosed()); + static::assertInstanceOf(\DateTime::class, $sp = $sport->getPublished()); + static::assertInstanceOf(\DateTime::class, $sa = $sport->getAuthorChanged()); $sport->setTitle('Updated'); $this->em->persist($sport); @@ -188,18 +188,9 @@ public function testShouldBeAbleToForceDates(): void $repo = $this->em->getRepository(Article::class); $sport = $repo->findOneBy(['title' => 'sport forced']); - static::assertSame( - '2000-01-01', - $sport->getCreated()->format('Y-m-d') - ); - static::assertSame( - '2000-01-01 12:00:00', - $sport->getUpdated()->format('Y-m-d H:i:s') - ); - static::assertSame( - '2000-01-01 12:00:00', - $sport->getContentChanged()->format('Y-m-d H:i:s') - ); + static::assertSame('2000-01-01', $sport->getCreated()->format('Y-m-d')); + static::assertSame('2000-01-01 12:00:00', $sport->getUpdated()->format('Y-m-d H:i:s')); + static::assertSame('2000-01-01 12:00:00', $sport->getContentChanged()->format('Y-m-d H:i:s')); $published = new Type(); $published->setTitle('Published'); @@ -211,10 +202,7 @@ public function testShouldBeAbleToForceDates(): void $this->em->flush(); $sport = $repo->findOneBy(['title' => 'sport forced']); - static::assertSame( - '2000-01-01 12:00:00', - $sport->getPublished()->format('Y-m-d H:i:s') - ); + static::assertSame('2000-01-01 12:00:00', $sport->getPublished()->format('Y-m-d H:i:s')); $this->em->clear(); } @@ -241,7 +229,7 @@ public function testShouldSolveIssue767(): void $art->setType($type); $this->em->flush(); // in v2.4.x will work on insert too - static::assertNotNull($art->getPublished()); + static::assertInstanceOf(\DateTime::class, $art->getPublished()); } /** @@ -253,7 +241,7 @@ public function testHandledTypes(): void $timespampable->setTitle('My article'); $timespampable->setBody('My article body.'); - static::assertNull($timespampable->getReachedRelevantLevel()); + static::assertNotInstanceOf(\DateTimeInterface::class, $timespampable->getReachedRelevantLevel()); $timespampable->setLevel(8); $this->em->persist($timespampable); @@ -262,7 +250,7 @@ public function testHandledTypes(): void $repo = $this->em->getRepository(Article::class); $found = $repo->findOneBy(['body' => 'My article body.']); - static::assertNull($found->getReachedRelevantLevel()); + static::assertNotInstanceOf(\DateTimeInterface::class, $found->getReachedRelevantLevel()); $timespampable->setLevel(9); @@ -271,7 +259,7 @@ public function testHandledTypes(): void $found = $repo->findOneBy(['body' => 'My article body.']); - static::assertNull($found->getReachedRelevantLevel()); + static::assertNotInstanceOf(\DateTimeInterface::class, $found->getReachedRelevantLevel()); $timespampable->setLevel(10); diff --git a/tests/Gedmo/Timestampable/TraitUsageTest.php b/tests/Gedmo/Timestampable/TraitUsageTest.php index 5a354e8020..697ffe0b8e 100644 --- a/tests/Gedmo/Timestampable/TraitUsageTest.php +++ b/tests/Gedmo/Timestampable/TraitUsageTest.php @@ -41,8 +41,8 @@ public function testShouldTimestampUsingTrait(): void $this->em->persist($sport); $this->em->flush(); - static::assertNotNull($sport->getCreatedAt()); - static::assertNotNull($sport->getUpdatedAt()); + static::assertInstanceOf(\DateTime::class, $sport->getCreatedAt()); + static::assertInstanceOf(\DateTime::class, $sport->getUpdatedAt()); } public function testTraitMethodthShouldReturnObject(): void diff --git a/tests/Gedmo/Tool/BaseTestCaseMongoODM.php b/tests/Gedmo/Tool/BaseTestCaseMongoODM.php index 7fe53d6ac8..079ff4b032 100644 --- a/tests/Gedmo/Tool/BaseTestCaseMongoODM.php +++ b/tests/Gedmo/Tool/BaseTestCaseMongoODM.php @@ -99,11 +99,7 @@ protected function getMockMappedDocumentManager(?EventManager $evm = null, ?Conf */ protected function getMetadataDriverImplementation(): MappingDriver { - if (PHP_VERSION_ID >= 80000) { - return new AttributeDriver(); - } - - return new AnnotationDriver($_ENV['annotation_reader']); + return new AttributeDriver(); } /** @@ -145,7 +141,7 @@ protected function getDefaultConfiguration(): Configuration private function getMetadataDefaultDriverImplementation(): MappingDriver { - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (class_exists(AttributeDriver::class)) { return new AttributeDriver([]); } diff --git a/tests/Gedmo/Tool/BaseTestCaseOM.php b/tests/Gedmo/Tool/BaseTestCaseOM.php index 73b2e18129..9fe8250043 100644 --- a/tests/Gedmo/Tool/BaseTestCaseOM.php +++ b/tests/Gedmo/Tool/BaseTestCaseOM.php @@ -23,7 +23,6 @@ use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\DefaultNamingStrategy; use Doctrine\ORM\Mapping\DefaultQuoteStrategy; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver as AnnotationDriverORM; use Doctrine\ORM\Mapping\Driver\AttributeDriver as AttributeDriverORM; use Doctrine\ORM\Repository\DefaultRepositoryFactory as DefaultRepositoryFactoryORM; use Doctrine\ORM\Tools\SchemaTool; @@ -47,10 +46,7 @@ */ abstract class BaseTestCaseOM extends TestCase { - /** - * @var EventManager - */ - protected $evm; + protected ?EventManager $evm = null; /** * Initialized document managers @@ -59,9 +55,7 @@ abstract class BaseTestCaseOM extends TestCase */ private array $dms = []; - protected function setUp(): void - { - } + protected function setUp(): void {} protected function tearDown(): void { @@ -77,7 +71,7 @@ protected function tearDown(): void */ protected function getMongoDBDriver(array $paths = []): MappingDriver { - if (PHP_VERSION_ID >= 80000 && class_exists(AttributeDriver::class)) { + if (class_exists(AttributeDriver::class)) { return new AttributeDriver($paths); } @@ -89,11 +83,7 @@ protected function getMongoDBDriver(array $paths = []): MappingDriver */ protected function getORMDriver(array $paths = []): MappingDriver { - if (PHP_VERSION_ID >= 80000) { - return new AttributeDriverORM($paths); - } - - return new AnnotationDriverORM($_ENV['annotation_reader'], $paths); + return new AttributeDriverORM($paths); } /** @@ -107,7 +97,7 @@ protected function getMockDocumentManager(string $dbName, ?MappingDriver $mappin } $client = new Client($_ENV['MONGODB_SERVER'], [], ['typeMap' => DocumentManager::CLIENT_TYPEMAP]); - $config = $this->getMockODMMongoDBConfig($dbName, $mappingDriver); + $config = $this->getMockODMMongoDBConfig($mappingDriver); return DocumentManager::create($client, $config, $this->getEventManager()); } @@ -150,7 +140,7 @@ protected function getDefaultMockSqliteEntityManager(array $fixtures, ?MappingDr */ private function getEventManager(): EventManager { - if (null === $this->evm) { + if (!$this->evm instanceof EventManager) { $this->evm = new EventManager(); $this->evm->addEventSubscriber(new TreeListener()); $this->evm->addEventSubscriber(new SluggableListener()); @@ -165,11 +155,8 @@ private function getEventManager(): EventManager /** * Get annotation mapping configuration */ - private function getMockODMMongoDBConfig(string $dbName, ?MappingDriver $mappingDriver = null): Configuration + private function getMockODMMongoDBConfig(?MappingDriver $mappingDriver = null): Configuration { - if (null === $mappingDriver) { - $mappingDriver = $this->getMongoDBDriver(); - } $config = new Configuration(); $config->addFilter('softdeleteable', SoftDeleteableFilter::class); $config->setProxyDir(TESTS_TEMP_DIR); @@ -179,7 +166,7 @@ private function getMockODMMongoDBConfig(string $dbName, ?MappingDriver $mapping $config->setDefaultDB('gedmo_extensions_test'); $config->setAutoGenerateProxyClasses(Configuration::AUTOGENERATE_EVAL); $config->setAutoGenerateHydratorClasses(Configuration::AUTOGENERATE_EVAL); - $config->setMetadataDriverImpl($mappingDriver); + $config->setMetadataDriverImpl($mappingDriver ?? $this->getMongoDBDriver()); $config->setMetadataCache(new ArrayAdapter()); return $config; diff --git a/tests/Gedmo/Tool/BaseTestCaseORM.php b/tests/Gedmo/Tool/BaseTestCaseORM.php index c85341b97b..e24c1d38c5 100644 --- a/tests/Gedmo/Tool/BaseTestCaseORM.php +++ b/tests/Gedmo/Tool/BaseTestCaseORM.php @@ -17,7 +17,6 @@ use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Persistence\Mapping\Driver\MappingDriver; @@ -77,11 +76,7 @@ protected function getDefaultMockSqliteEntityManager(?EventManager $evm = null, */ protected function getMetadataDriverImplementation(): MappingDriver { - if (PHP_VERSION_ID >= 80000) { - return new AttributeDriver([]); - } - - return new AnnotationDriver($_ENV['annotation_reader']); + return new AttributeDriver([]); } /** diff --git a/tests/Gedmo/Translatable/AttributeEntityTranslationTableTest.php b/tests/Gedmo/Translatable/AttributeEntityTranslationTableTest.php index 63e62122ee..87c36865d4 100644 --- a/tests/Gedmo/Translatable/AttributeEntityTranslationTableTest.php +++ b/tests/Gedmo/Translatable/AttributeEntityTranslationTableTest.php @@ -23,8 +23,6 @@ * These are tests for translatable behavior * * @author Gediminas Morkevicius - * - * @requires PHP >= 8.0 */ final class AttributeEntityTranslationTableTest extends BaseTestCaseORM { diff --git a/tests/Gedmo/Translatable/Fixture/Article.php b/tests/Gedmo/Translatable/Fixture/Article.php index 0b766544bb..caf7909d33 100644 --- a/tests/Gedmo/Translatable/Fixture/Article.php +++ b/tests/Gedmo/Translatable/Fixture/Article.php @@ -25,8 +25,6 @@ class Article implements Translatable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Article implements Translatable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable @@ -88,7 +86,7 @@ class Article implements Translatable * @ORM\OneToMany(targetEntity="Comment", mappedBy="article") */ #[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'article')] - private $comments; + private Collection $comments; public function __construct() { diff --git a/tests/Gedmo/Translatable/Fixture/Attribute/PersonTranslation.php b/tests/Gedmo/Translatable/Fixture/Attribute/PersonTranslation.php index 1920a3ba0c..5ab36eca99 100644 --- a/tests/Gedmo/Translatable/Fixture/Attribute/PersonTranslation.php +++ b/tests/Gedmo/Translatable/Fixture/Attribute/PersonTranslation.php @@ -19,6 +19,4 @@ #[ORM\Table(name: 'ext_translations')] #[ORM\Index(name: 'translations_lookup_idx', columns: ['locale', 'object_Class', 'foreign_key'])] #[ORM\UniqueConstraint(name: 'lookup_unique_idx', columns: ['locale', 'object_Class', 'foreign_key', 'field'])] -class PersonTranslation extends AbstractTranslation -{ -} +class PersonTranslation extends AbstractTranslation {} diff --git a/tests/Gedmo/Translatable/Fixture/Comment.php b/tests/Gedmo/Translatable/Fixture/Comment.php index 8f0bcc2869..ac0f53688e 100644 --- a/tests/Gedmo/Translatable/Fixture/Comment.php +++ b/tests/Gedmo/Translatable/Fixture/Comment.php @@ -22,8 +22,6 @@ class Comment { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Comment #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/Company.php b/tests/Gedmo/Translatable/Fixture/Company.php index 18cc9a62dd..2ba10f714a 100644 --- a/tests/Gedmo/Translatable/Fixture/Company.php +++ b/tests/Gedmo/Translatable/Fixture/Company.php @@ -23,8 +23,6 @@ class Company implements Translatable { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Company implements Translatable #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=128) diff --git a/tests/Gedmo/Translatable/Fixture/CompanyEmbedLink.php b/tests/Gedmo/Translatable/Fixture/CompanyEmbedLink.php index a2d7d74094..67be2583f3 100644 --- a/tests/Gedmo/Translatable/Fixture/CompanyEmbedLink.php +++ b/tests/Gedmo/Translatable/Fixture/CompanyEmbedLink.php @@ -22,26 +22,22 @@ class CompanyEmbedLink { /** - * @var string - * * @ORM\Column(name="website", type="string", length=191, nullable=true) * * @Gedmo\Translatable */ #[Gedmo\Translatable] #[ORM\Column(name: 'website', type: Types::STRING, length: 191, nullable: true)] - protected $website; + protected ?string $website = null; /** - * @var string - * * @ORM\Column(name="facebook", type="string", length=191, nullable=true) * * @Gedmo\Translatable */ #[Gedmo\Translatable] #[ORM\Column(name: 'facebook', type: Types::STRING, length: 191, nullable: true)] - protected $facebook; + protected ?string $facebook = null; public function getWebsite(): string { diff --git a/tests/Gedmo/Translatable/Fixture/Document/Personal/Article.php b/tests/Gedmo/Translatable/Fixture/Document/Personal/Article.php index b83f2d4f18..cce7b11802 100644 --- a/tests/Gedmo/Translatable/Fixture/Document/Personal/Article.php +++ b/tests/Gedmo/Translatable/Fixture/Document/Personal/Article.php @@ -27,12 +27,10 @@ class Article { /** - * @var string|null - * * @MongoODM\Id */ #[MongoODM\Id] - private $id; + private ?string $id = null; /** * @Gedmo\Translatable @@ -49,14 +47,11 @@ class Article * @MongoODM\ReferenceMany(targetDocument="Gedmo\Tests\Translatable\Fixture\Document\Personal\ArticleTranslation", mappedBy="object") */ #[MongoODM\ReferenceMany(targetDocument: ArticleTranslation::class, mappedBy: 'object')] - private $translations; + private Collection $translations; private ?string $code = null; - /** - * @var string - */ - private $slug; + private ?string $slug = null; public function __construct() { diff --git a/tests/Gedmo/Translatable/Fixture/File.php b/tests/Gedmo/Translatable/Fixture/File.php index 4e4dc983a4..5489e70bd8 100644 --- a/tests/Gedmo/Translatable/Fixture/File.php +++ b/tests/Gedmo/Translatable/Fixture/File.php @@ -28,8 +28,6 @@ class File { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -37,7 +35,7 @@ class File #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/Issue1123/BaseEntity.php b/tests/Gedmo/Translatable/Fixture/Issue1123/BaseEntity.php index 709fa23ca9..1131e3b9b2 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue1123/BaseEntity.php +++ b/tests/Gedmo/Translatable/Fixture/Issue1123/BaseEntity.php @@ -32,8 +32,6 @@ abstract class BaseEntity { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -41,5 +39,5 @@ abstract class BaseEntity #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - protected $id; + protected ?int $id = null; } diff --git a/tests/Gedmo/Translatable/Fixture/Issue114/Article.php b/tests/Gedmo/Translatable/Fixture/Issue114/Article.php index 1955b0ec65..ec0e8f2c72 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue114/Article.php +++ b/tests/Gedmo/Translatable/Fixture/Issue114/Article.php @@ -22,8 +22,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/Issue114/Category.php b/tests/Gedmo/Translatable/Fixture/Issue114/Category.php index 9e7f1be879..89b8d893e6 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue114/Category.php +++ b/tests/Gedmo/Translatable/Fixture/Issue114/Category.php @@ -24,8 +24,6 @@ class Category { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class Category #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable @@ -50,7 +48,7 @@ class Category * @ORM\OneToMany(targetEntity="Article", mappedBy="category", cascade={"persist", "remove"}) */ #[ORM\OneToMany(targetEntity: Article::class, mappedBy: 'category', cascade: ['persist', 'remove'])] - private $articles; + private Collection $articles; public function __construct() { diff --git a/tests/Gedmo/Translatable/Fixture/Issue138/Article.php b/tests/Gedmo/Translatable/Fixture/Issue138/Article.php index 3245cbb668..26c08080f8 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue138/Article.php +++ b/tests/Gedmo/Translatable/Fixture/Issue138/Article.php @@ -22,8 +22,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/Issue173/Article.php b/tests/Gedmo/Translatable/Fixture/Issue173/Article.php index d9405d0c36..0c7233252a 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue173/Article.php +++ b/tests/Gedmo/Translatable/Fixture/Issue173/Article.php @@ -22,8 +22,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/Issue173/Category.php b/tests/Gedmo/Translatable/Fixture/Issue173/Category.php index 13497f4be2..e17541b6e3 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue173/Category.php +++ b/tests/Gedmo/Translatable/Fixture/Issue173/Category.php @@ -24,8 +24,6 @@ class Category { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class Category #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable @@ -50,7 +48,7 @@ class Category * @ORM\OneToMany(targetEntity="Article", mappedBy="category", cascade={"persist", "remove"}) */ #[ORM\OneToMany(targetEntity: Article::class, mappedBy: 'category', cascade: ['persist', 'remove'])] - private $articles; + private Collection $articles; /** * @var Collection @@ -58,7 +56,7 @@ class Category * @ORM\OneToMany(targetEntity="Product", mappedBy="category", cascade={"persist", "remove"}) */ #[ORM\OneToMany(targetEntity: Product::class, mappedBy: 'category', cascade: ['persist', 'remove'])] - private $products; + private Collection $products; public function __construct() { diff --git a/tests/Gedmo/Translatable/Fixture/Issue173/Product.php b/tests/Gedmo/Translatable/Fixture/Issue173/Product.php index 53c720539c..eb00066038 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue173/Product.php +++ b/tests/Gedmo/Translatable/Fixture/Issue173/Product.php @@ -22,8 +22,6 @@ class Product { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Product #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/Issue2152/EntityWithTranslatableBoolean.php b/tests/Gedmo/Translatable/Fixture/Issue2152/EntityWithTranslatableBoolean.php index cc038c4be4..1a2978e40b 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue2152/EntityWithTranslatableBoolean.php +++ b/tests/Gedmo/Translatable/Fixture/Issue2152/EntityWithTranslatableBoolean.php @@ -27,13 +27,11 @@ class EntityWithTranslatableBoolean * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") - * - * @var int */ #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/Issue2167/Article.php b/tests/Gedmo/Translatable/Fixture/Issue2167/Article.php index 8c8ae28e96..6db015ba78 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue2167/Article.php +++ b/tests/Gedmo/Translatable/Fixture/Issue2167/Article.php @@ -22,8 +22,6 @@ class Article { /** - * @var int - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/Issue75/Article.php b/tests/Gedmo/Translatable/Fixture/Issue75/Article.php index 427648edd7..9cce56d45a 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue75/Article.php +++ b/tests/Gedmo/Translatable/Fixture/Issue75/Article.php @@ -24,8 +24,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable @@ -57,7 +55,7 @@ class Article #[ORM\JoinTable(name: 'article_images')] #[ORM\JoinColumn(name: 'image_id', referencedColumnName: 'id')] #[ORM\InverseJoinColumn(name: 'article_id', referencedColumnName: 'id')] - private $images; + private Collection $images; /** * @var Collection @@ -65,7 +63,7 @@ class Article * @ORM\ManyToMany(targetEntity="File") */ #[ORM\ManyToMany(targetEntity: File::class)] - private $files; + private Collection $files; public function __construct() { diff --git a/tests/Gedmo/Translatable/Fixture/Issue75/File.php b/tests/Gedmo/Translatable/Fixture/Issue75/File.php index 7367544ab9..de0ff5aa65 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue75/File.php +++ b/tests/Gedmo/Translatable/Fixture/Issue75/File.php @@ -22,8 +22,6 @@ class File { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class File #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/Issue75/Image.php b/tests/Gedmo/Translatable/Fixture/Issue75/Image.php index 1c1d085f55..28ee7ef994 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue75/Image.php +++ b/tests/Gedmo/Translatable/Fixture/Issue75/Image.php @@ -24,8 +24,6 @@ class Image { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class Image #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable @@ -50,7 +48,7 @@ class Image * @ORM\ManyToMany(targetEntity="Article", mappedBy="images") */ #[ORM\ManyToMany(targetEntity: Article::class, mappedBy: 'images')] - private $articles; + private Collection $articles; public function __construct() { diff --git a/tests/Gedmo/Translatable/Fixture/Issue922/Post.php b/tests/Gedmo/Translatable/Fixture/Issue922/Post.php index c59a434205..4e17202c75 100644 --- a/tests/Gedmo/Translatable/Fixture/Issue922/Post.php +++ b/tests/Gedmo/Translatable/Fixture/Issue922/Post.php @@ -22,8 +22,6 @@ class Post { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Post #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/MixedValue.php b/tests/Gedmo/Translatable/Fixture/MixedValue.php index 7c1cf709ff..8e3138ff7a 100644 --- a/tests/Gedmo/Translatable/Fixture/MixedValue.php +++ b/tests/Gedmo/Translatable/Fixture/MixedValue.php @@ -22,8 +22,6 @@ class MixedValue { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class MixedValue #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/Person.php b/tests/Gedmo/Translatable/Fixture/Person.php index 2c336b1add..20d1209956 100644 --- a/tests/Gedmo/Translatable/Fixture/Person.php +++ b/tests/Gedmo/Translatable/Fixture/Person.php @@ -25,8 +25,6 @@ class Person { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Person #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/PersonTranslation.php b/tests/Gedmo/Translatable/Fixture/PersonTranslation.php index cf1fc6d81b..b71fc7a104 100644 --- a/tests/Gedmo/Translatable/Fixture/PersonTranslation.php +++ b/tests/Gedmo/Translatable/Fixture/PersonTranslation.php @@ -31,6 +31,4 @@ #[ORM\Table(name: 'ext_translations')] #[ORM\Index(name: 'translations_lookup_idx', columns: ['locale', 'object_Class', 'foreign_key'])] #[ORM\UniqueConstraint(name: 'lookup_unique_idx', columns: ['locale', 'object_Class', 'foreign_key', 'field'])] -class PersonTranslation extends AbstractTranslation -{ -} +class PersonTranslation extends AbstractTranslation {} diff --git a/tests/Gedmo/Translatable/Fixture/Personal/Article.php b/tests/Gedmo/Translatable/Fixture/Personal/Article.php index dfd92456be..62852afe2d 100644 --- a/tests/Gedmo/Translatable/Fixture/Personal/Article.php +++ b/tests/Gedmo/Translatable/Fixture/Personal/Article.php @@ -27,8 +27,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -36,7 +34,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable @@ -53,7 +51,7 @@ class Article * @ORM\OneToMany(targetEntity="PersonalArticleTranslation", mappedBy="object") */ #[ORM\OneToMany(targetEntity: PersonalArticleTranslation::class, mappedBy: 'object')] - private $translations; + private Collection $translations; public function __construct() { diff --git a/tests/Gedmo/Translatable/Fixture/Sport.php b/tests/Gedmo/Translatable/Fixture/Sport.php index 85e556eaad..654110559c 100644 --- a/tests/Gedmo/Translatable/Fixture/Sport.php +++ b/tests/Gedmo/Translatable/Fixture/Sport.php @@ -22,8 +22,6 @@ class Sport { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,7 +29,7 @@ class Sport #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/TemplatedArticle.php b/tests/Gedmo/Translatable/Fixture/TemplatedArticle.php index 2d791058fb..367335a758 100644 --- a/tests/Gedmo/Translatable/Fixture/TemplatedArticle.php +++ b/tests/Gedmo/Translatable/Fixture/TemplatedArticle.php @@ -23,8 +23,6 @@ class TemplatedArticle extends ArticleTemplate { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class TemplatedArticle extends ArticleTemplate #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable diff --git a/tests/Gedmo/Translatable/Fixture/Type/Custom.php b/tests/Gedmo/Translatable/Fixture/Type/Custom.php index 246dd5087f..c57172c738 100644 --- a/tests/Gedmo/Translatable/Fixture/Type/Custom.php +++ b/tests/Gedmo/Translatable/Fixture/Type/Custom.php @@ -13,6 +13,8 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ArrayType; +use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use Doctrine\DBAL\Types\Type; if (class_exists(ArrayType::class)) { @@ -26,30 +28,24 @@ abstract class CompatType extends Type { /** * @param array $column - * - * @return string */ - public function getSQLDeclaration(array $column, AbstractPlatform $platform) + public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { return $this->doGetSQLDeclaration($column, $platform); } /** * @param mixed $value - * - * @return mixed */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed { return $this->doConvertToDatabaseValue($value, $platform); } /** * @param mixed $value - * - * @return mixed */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue($value, AbstractPlatform $platform): mixed { return $this->doConvertToPHPValue($value, $platform); } @@ -59,19 +55,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ abstract protected function doGetSQLDeclaration(array $column, AbstractPlatform $platform): string; - /** - * @param mixed $value - * - * @return mixed - */ - abstract protected function doConvertToDatabaseValue($value, AbstractPlatform $platform); + abstract protected function doConvertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed; - /** - * @param mixed $value - * - * @return mixed - */ - abstract protected function doConvertToPHPValue($value, AbstractPlatform $platform); + abstract protected function doConvertToPHPValue(mixed $value, AbstractPlatform $platform): mixed; } } else { // DBAL 4.x @@ -105,19 +91,9 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mix */ abstract protected function doGetSQLDeclaration(array $column, AbstractPlatform $platform): string; - /** - * @param mixed $value - * - * @return mixed - */ - abstract protected function doConvertToDatabaseValue($value, AbstractPlatform $platform); + abstract protected function doConvertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed; - /** - * @param mixed $value - * - * @return mixed - */ - abstract protected function doConvertToPHPValue($value, AbstractPlatform $platform); + abstract protected function doConvertToPHPValue(mixed $value, AbstractPlatform $platform): mixed; } } @@ -138,22 +114,12 @@ protected function doGetSQLDeclaration(array $column, AbstractPlatform $platform return $platform->getClobTypeDeclarationSQL($column); } - /** - * @param mixed $value - * - * @return mixed - */ - protected function doConvertToDatabaseValue($value, AbstractPlatform $platform) + protected function doConvertToDatabaseValue(mixed $value, AbstractPlatform $platform): string { return serialize($value); } - /** - * @param mixed $value - * - * @return mixed - */ - protected function doConvertToPHPValue($value, AbstractPlatform $platform) + protected function doConvertToPHPValue(mixed $value, AbstractPlatform $platform): mixed { if (null === $value) { return null; @@ -162,7 +128,11 @@ protected function doConvertToPHPValue($value, AbstractPlatform $platform) $value = (is_resource($value)) ? stream_get_contents($value) : $value; $val = unserialize($value); if (false === $val && 'b:0;' !== $value) { - throw new \Exception('Conversion failed'); + if (!class_exists(ValueNotConvertible::class)) { + throw ConversionException::conversionFailed($value, $this->getName()); + } + + throw ValueNotConvertible::new($value, $this->getName()); } return $val; diff --git a/tests/Gedmo/Translatable/PersonalTranslationTest.php b/tests/Gedmo/Translatable/PersonalTranslationTest.php index 5383545775..81a704e8de 100644 --- a/tests/Gedmo/Translatable/PersonalTranslationTest.php +++ b/tests/Gedmo/Translatable/PersonalTranslationTest.php @@ -93,7 +93,7 @@ public function testShouldTranslateTheRecord(): void public function testShouldCascadeDeletionsByForeignKeyConstraints(): void { // Uses normalized comparison due to case differences between versions - if ('doctrine\dbal\platforms\sqliteplatform' === strtolower(get_class($this->em->getConnection()->getDatabasePlatform()))) { + if ('doctrine\dbal\platforms\sqliteplatform' === strtolower($this->em->getConnection()->getDatabasePlatform()::class)) { static::markTestSkipped('Foreign key constraints do not map in SQLite.'); } diff --git a/tests/Gedmo/Translatable/TranslatableTest.php b/tests/Gedmo/Translatable/TranslatableTest.php index dc3b1d5a17..688e060aec 100644 --- a/tests/Gedmo/Translatable/TranslatableTest.php +++ b/tests/Gedmo/Translatable/TranslatableTest.php @@ -159,7 +159,7 @@ public function testShouldGenerateTranslations(): void $comments = $article->getComments(); foreach ($comments as $comment) { - $number = preg_replace("@[^\d]+@", '', $comment->getSubject()); + $number = preg_replace("@[^\d]+@", '', (string) $comment->getSubject()); $comment->setTranslatableLocale('de_de'); $comment->setSubject("subject{$number} in de"); $comment->setMessage("message{$number} in de"); @@ -188,7 +188,7 @@ public function testShouldGenerateTranslations(): void static::assertCount(1, $translations); static::assertArrayHasKey('de_de', $translations); - $number = preg_replace("@[^\d]+@", '', $comment->getSubject()); + $number = preg_replace("@[^\d]+@", '', (string) $comment->getSubject()); static::assertArrayHasKey('subject', $translations['de_de']); $expected = "subject{$number} in de"; static::assertSame($expected, $translations['de_de']['subject']); @@ -204,7 +204,7 @@ public function testShouldGenerateTranslations(): void $comments = $article->getComments(); foreach ($comments as $comment) { - $number = preg_replace("@[^\d]+@", '', $comment->getSubject()); + $number = preg_replace("@[^\d]+@", '', (string) $comment->getSubject()); static::assertSame("subject{$number} in en", $comment->getSubject()); static::assertSame("message{$number} in en", $comment->getMessage()); diff --git a/tests/Gedmo/Translator/Fixture/Person.php b/tests/Gedmo/Translator/Fixture/Person.php index 7db47153da..178f52cf38 100644 --- a/tests/Gedmo/Translator/Fixture/Person.php +++ b/tests/Gedmo/Translator/Fixture/Person.php @@ -25,32 +25,24 @@ class Person { /** - * @var string|null - * * @ORM\Column(name="name", type="string", length=128) */ #[ORM\Column(name: 'name', type: Types::STRING, length: 128)] - public $name; + public ?string $name = null; /** - * @var string|null - * * @ORM\Column(name="desc", type="string", length=128) */ #[ORM\Column(name: 'desc', type: Types::STRING, length: 128)] - public $description; + public ?string $description = null; /** - * @var string|null - * * @ORM\Column(name="last_name", type="string", length=128, nullable=true) */ #[ORM\Column(name: 'last_name', type: Types::STRING, length: 128, nullable: true)] - public $lastName; + public ?string $lastName = null; /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -58,7 +50,7 @@ class Person #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @var Collection @@ -124,10 +116,7 @@ public function getParent(): ?self return $this->parent; } - /** - * @return self|TranslationProxy - */ - public function translate(string $locale = 'en') + public function translate(string $locale = 'en'): self|TranslationProxy { if ('en' === $locale) { return $this; diff --git a/tests/Gedmo/Translator/Fixture/PersonCustom.php b/tests/Gedmo/Translator/Fixture/PersonCustom.php index dd7395fdfa..d17b26a4a9 100644 --- a/tests/Gedmo/Translator/Fixture/PersonCustom.php +++ b/tests/Gedmo/Translator/Fixture/PersonCustom.php @@ -24,8 +24,6 @@ class PersonCustom { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -33,7 +31,7 @@ class PersonCustom #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="name", type="string", length=128) @@ -85,10 +83,7 @@ public function getDescription(): ?string return $this->description; } - /** - * @return self|CustomProxy - */ - public function translate(?string $locale = null) + public function translate(?string $locale = null): self|CustomProxy { if (null === $locale) { return $this; diff --git a/tests/Gedmo/Translator/Fixture/PersonCustomTranslation.php b/tests/Gedmo/Translator/Fixture/PersonCustomTranslation.php index 5a12baf6d5..35eeb1befc 100644 --- a/tests/Gedmo/Translator/Fixture/PersonCustomTranslation.php +++ b/tests/Gedmo/Translator/Fixture/PersonCustomTranslation.php @@ -31,8 +31,6 @@ class PersonCustomTranslation extends Translation { /** - * @var PersonCustom|null - * * @ORM\ManyToOne(targetEntity="PersonCustom", inversedBy="translations") */ #[ORM\ManyToOne(targetEntity: PersonCustom::class, inversedBy: 'translations')] diff --git a/tests/Gedmo/Translator/Fixture/PersonTranslation.php b/tests/Gedmo/Translator/Fixture/PersonTranslation.php index 8a920b0b3f..4247b6d754 100644 --- a/tests/Gedmo/Translator/Fixture/PersonTranslation.php +++ b/tests/Gedmo/Translator/Fixture/PersonTranslation.php @@ -31,8 +31,6 @@ class PersonTranslation extends Translation { /** - * @var Person|null - * * @ORM\ManyToOne(targetEntity="Person", inversedBy="translations") */ #[ORM\ManyToOne(targetEntity: Person::class, inversedBy: 'translations')] diff --git a/tests/Gedmo/Tree/ClosureTreeRepositoryTest.php b/tests/Gedmo/Tree/ClosureTreeRepositoryTest.php index d05ab778b6..255337d52a 100644 --- a/tests/Gedmo/Tree/ClosureTreeRepositoryTest.php +++ b/tests/Gedmo/Tree/ClosureTreeRepositoryTest.php @@ -211,7 +211,7 @@ public function testSingleNodeRemoval(): void $vegitables = $repo->findOneBy(['title' => 'Vegitables']); static::assertSame(2, $repo->childCount($vegitables, true)); - static::assertNull($vegitables->getParent()); + static::assertNotInstanceOf(Category::class, $vegitables->getParent()); $repo->removeFromTree($lemons); static::assertCount(5, $repo->children(null, true)); @@ -241,7 +241,7 @@ public function testHavingLevelPropertyAvoidsSubqueryInSelectInGetNodesHierarchy $config = $this->listener->getConfiguration($this->em, $meta->getName()); $qb = $repo->getNodesHierarchyQueryBuilder($roots[0], false, $config); - static::assertFalse(strpos($qb->getQuery()->getDql(), '(SELECT MAX(')); + static::assertStringNotContainsString('(SELECT MAX(', (string) $qb->getQuery()->getDql()); } public function testNotHavingLevelPropertyUsesASubqueryInSelectInGetNodesHierarchy(): void @@ -254,7 +254,7 @@ public function testNotHavingLevelPropertyUsesASubqueryInSelectInGetNodesHierarc $config = $this->listener->getConfiguration($this->em, $meta->getName()); $qb = $repo->getNodesHierarchyQueryBuilder($roots[0], false, $config); - static::assertTrue((bool) strpos($qb->getQuery()->getDql(), '(SELECT MAX(')); + static::assertTrue((bool) strpos((string) $qb->getQuery()->getDql(), '(SELECT MAX(')); } public function testChangeChildrenIndex(): void @@ -475,7 +475,7 @@ protected function buildTreeTests(string $class): void array_merge($sortOption, ['decorate' => true]), $includeNode ); - $getTreeHtml = static function ($includeNode) { + $getTreeHtml = static function ($includeNode): string { $baseHtml = '
  • Boring Food
    • Vegitables
      • Cabbages
      • Carrots
  • Fruits
    • Berries
      • Strawberries
    • Lemons
    • Oranges
  • Milk
    • Cheese
      • Mould cheese
  • '; return $includeNode ? '
    • Food
        '.$baseHtml.'
      ' : '
        '.$baseHtml; diff --git a/tests/Gedmo/Tree/ClosureTreeTest.php b/tests/Gedmo/Tree/ClosureTreeTest.php index 8da031620c..dff8d26ce5 100644 --- a/tests/Gedmo/Tree/ClosureTreeTest.php +++ b/tests/Gedmo/Tree/ClosureTreeTest.php @@ -325,9 +325,9 @@ public function testClosuresCreatedMustNotBeAffectedByPersistOrder(Category $fir } /** - * @return array> + * @return \Generator> */ - public static function provideNodeOrders(): array + public static function provideNodeOrders(): \Generator { $grandpa = new Category(); $grandpa->setTitle('grandpa'); @@ -340,14 +340,12 @@ public static function provideNodeOrders(): array $son->setTitle('son'); $son->setParent($father); - return [ - 'order-123' => [$grandpa, $father, $son], - 'order-132' => [$grandpa, $son, $father], - 'order-213' => [$father, $grandpa, $son], - 'order-231' => [$father, $son, $grandpa], - 'order-312' => [$son, $grandpa, $father], - 'order-321' => [$son, $father, $grandpa], - ]; + yield 'order-123' => [$grandpa, $father, $son]; + yield 'order-132' => [$grandpa, $son, $father]; + yield 'order-213' => [$father, $grandpa, $son]; + yield 'order-231' => [$father, $son, $grandpa]; + yield 'order-312' => [$son, $grandpa, $father]; + yield 'order-321' => [$son, $father, $grandpa]; } protected function getUsedEntityFixtures(): array diff --git a/tests/Gedmo/Tree/Fixture/ANode.php b/tests/Gedmo/Tree/Fixture/ANode.php index 05789a9ca0..277e81937e 100644 --- a/tests/Gedmo/Tree/Fixture/ANode.php +++ b/tests/Gedmo/Tree/Fixture/ANode.php @@ -22,8 +22,6 @@ class ANode { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -31,29 +29,25 @@ class ANode #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(type="integer", nullable=true) */ #[ORM\Column(type: Types::INTEGER, nullable: true)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(type="integer", nullable=true) */ #[ORM\Column(type: Types::INTEGER, nullable: true)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** * @Gedmo\TreeParent diff --git a/tests/Gedmo/Tree/Fixture/Article.php b/tests/Gedmo/Tree/Fixture/Article.php index 626b55bd1b..995c69ab2a 100644 --- a/tests/Gedmo/Tree/Fixture/Article.php +++ b/tests/Gedmo/Tree/Fixture/Article.php @@ -23,8 +23,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=128) @@ -46,7 +44,7 @@ class Article * @ORM\OneToMany(targetEntity="Comment", mappedBy="article") */ #[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'article')] - private $comments; + private Collection $comments; /** * @ORM\ManyToOne(targetEntity="Category", inversedBy="articles") diff --git a/tests/Gedmo/Tree/Fixture/BaseNode.php b/tests/Gedmo/Tree/Fixture/BaseNode.php index 7b9bbac406..53c82a6631 100644 --- a/tests/Gedmo/Tree/Fixture/BaseNode.php +++ b/tests/Gedmo/Tree/Fixture/BaseNode.php @@ -42,15 +42,13 @@ class BaseNode extends ANode private Collection $children; /** - * @var \DateTime|null - * * @Gedmo\Timestampable(on="create") * * @ORM\Column(type="datetime") */ #[ORM\Column(type: Types::DATETIME_MUTABLE)] #[Gedmo\Timestampable(on: 'create')] - private $created; + private ?\DateTime $created = null; /** * @ORM\Column(length=128, unique=true) @@ -59,15 +57,13 @@ class BaseNode extends ANode private ?string $identifier = null; /** - * @var \DateTime|null - * * @ORM\Column(type="datetime") * * @Gedmo\Timestampable */ #[ORM\Column(type: Types::DATETIME_MUTABLE)] #[Gedmo\Timestampable] - private $updated; + private ?\DateTime $updated = null; public function __construct() { diff --git a/tests/Gedmo/Tree/Fixture/BehavioralCategory.php b/tests/Gedmo/Tree/Fixture/BehavioralCategory.php index 4e927a25b0..cd06ee42be 100644 --- a/tests/Gedmo/Tree/Fixture/BehavioralCategory.php +++ b/tests/Gedmo/Tree/Fixture/BehavioralCategory.php @@ -28,8 +28,6 @@ class BehavioralCategory { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -37,7 +35,7 @@ class BehavioralCategory #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\Translatable @@ -49,26 +47,22 @@ class BehavioralCategory private ?string $title = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(name="lft", type="integer", nullable=true) */ #[ORM\Column(name: 'lft', type: Types::INTEGER, nullable: true)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(name="rgt", type="integer", nullable=true) */ #[ORM\Column(name: 'rgt', type: Types::INTEGER, nullable: true)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** * @Gedmo\TreeParent @@ -92,8 +86,6 @@ class BehavioralCategory private Collection $children; /** - * @var string|null - * * @Gedmo\Translatable * @Gedmo\Slug(fields={"title"}) * @@ -102,7 +94,7 @@ class BehavioralCategory #[ORM\Column(name: 'slug', type: Types::STRING, length: 128, unique: true)] #[Gedmo\Translatable] #[Gedmo\Slug(fields: ['title'])] - private $slug; + private ?string $slug = null; public function __construct() { diff --git a/tests/Gedmo/Tree/Fixture/Category.php b/tests/Gedmo/Tree/Fixture/Category.php index 0f81b41999..62708eff83 100644 --- a/tests/Gedmo/Tree/Fixture/Category.php +++ b/tests/Gedmo/Tree/Fixture/Category.php @@ -29,8 +29,6 @@ class Category implements NodeInterface { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -38,7 +36,7 @@ class Category implements NodeInterface #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -47,26 +45,22 @@ class Category implements NodeInterface private ?string $title = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(name="lft", type="integer") */ #[ORM\Column(name: 'lft', type: Types::INTEGER)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(name="rgt", type="integer") */ #[ORM\Column(name: 'rgt', type: Types::INTEGER)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** * @Gedmo\TreeParent @@ -82,15 +76,13 @@ class Category implements NodeInterface private ?Category $parentId = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer") */ #[ORM\Column(name: 'lvl', type: Types::INTEGER)] #[Gedmo\TreeLevel] - private $level; + private ?int $level = null; /** * @var Collection diff --git a/tests/Gedmo/Tree/Fixture/CategoryUuid.php b/tests/Gedmo/Tree/Fixture/CategoryUuid.php index 5526add92e..01f4dea4d8 100644 --- a/tests/Gedmo/Tree/Fixture/CategoryUuid.php +++ b/tests/Gedmo/Tree/Fixture/CategoryUuid.php @@ -48,26 +48,22 @@ class CategoryUuid implements NodeInterface private ?string $title = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(name="lft", type="integer") */ #[ORM\Column(name: 'lft', type: Types::INTEGER)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(name="rgt", type="integer") */ #[ORM\Column(name: 'rgt', type: Types::INTEGER)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** * @Gedmo\TreeParent @@ -83,26 +79,22 @@ class CategoryUuid implements NodeInterface private ?CategoryUuid $parentId = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer") */ #[ORM\Column(name: 'lvl', type: Types::INTEGER)] #[Gedmo\TreeLevel] - private $level; + private ?int $level = null; /** - * @var string|null - * * @Gedmo\TreeRoot * * @ORM\Column(name="root", type="string") */ #[ORM\Column(name: 'root', type: Types::STRING)] #[Gedmo\TreeRoot] - private $root; + private ?string $root = null; /** * @var Collection diff --git a/tests/Gedmo/Tree/Fixture/Closure/Category.php b/tests/Gedmo/Tree/Fixture/Closure/Category.php index 89c54fc77f..1c8f0c4694 100644 --- a/tests/Gedmo/Tree/Fixture/Closure/Category.php +++ b/tests/Gedmo/Tree/Fixture/Closure/Category.php @@ -30,8 +30,6 @@ class Category { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -39,7 +37,7 @@ class Category #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -70,7 +68,7 @@ class Category /** * @var Collection */ - private $closures; + private Collection $closures; public function __construct() { diff --git a/tests/Gedmo/Tree/Fixture/Closure/CategoryClosureWithoutMapping.php b/tests/Gedmo/Tree/Fixture/Closure/CategoryClosureWithoutMapping.php index 065a83f9e0..c0cfe081b4 100644 --- a/tests/Gedmo/Tree/Fixture/Closure/CategoryClosureWithoutMapping.php +++ b/tests/Gedmo/Tree/Fixture/Closure/CategoryClosureWithoutMapping.php @@ -18,6 +18,4 @@ * @ORM\Entity */ #[ORM\Entity] -class CategoryClosureWithoutMapping extends AbstractClosure -{ -} +class CategoryClosureWithoutMapping extends AbstractClosure {} diff --git a/tests/Gedmo/Tree/Fixture/Closure/CategoryWithoutLevel.php b/tests/Gedmo/Tree/Fixture/Closure/CategoryWithoutLevel.php index e4e57a8b28..8078b39f44 100644 --- a/tests/Gedmo/Tree/Fixture/Closure/CategoryWithoutLevel.php +++ b/tests/Gedmo/Tree/Fixture/Closure/CategoryWithoutLevel.php @@ -30,8 +30,6 @@ class CategoryWithoutLevel { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -39,7 +37,7 @@ class CategoryWithoutLevel #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -61,7 +59,7 @@ class CategoryWithoutLevel /** * @var Collection */ - private $closures; + private Collection $closures; public function __construct() { diff --git a/tests/Gedmo/Tree/Fixture/Closure/News.php b/tests/Gedmo/Tree/Fixture/Closure/News.php index 7bba467bb1..f750a60ba7 100644 --- a/tests/Gedmo/Tree/Fixture/Closure/News.php +++ b/tests/Gedmo/Tree/Fixture/Closure/News.php @@ -23,8 +23,6 @@ class News { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -32,25 +30,20 @@ class News #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; - - /** - * @ORM\Column(name="title", type="string", length=64) - */ - #[ORM\Column(name: 'title', type: Types::STRING, length: 64)] - private string $title; - - /** - * @ORM\OneToOne(targetEntity="Gedmo\Tests\Tree\Fixture\Closure\Category", cascade={"persist"}) - * @ORM\JoinColumn(name="category_id", referencedColumnName="id") - */ - #[ORM\OneToOne(targetEntity: Category::class, cascade: ['persist'])] - #[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id')] - private Category $category; - - public function __construct(string $title, Category $category) - { - $this->title = $title; - $this->category = $category; - } + private ?int $id = null; + + public function __construct( + /** + * @ORM\Column(name="title", type="string", length=64) + */ + #[ORM\Column(name: 'title', type: Types::STRING, length: 64)] + private string $title, + /** + * @ORM\OneToOne(targetEntity="Gedmo\Tests\Tree\Fixture\Closure\Category", cascade={"persist"}) + * @ORM\JoinColumn(name="category_id", referencedColumnName="id") + */ + #[ORM\OneToOne(targetEntity: Category::class, cascade: ['persist'])] + #[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id')] + private Category $category + ) {} } diff --git a/tests/Gedmo/Tree/Fixture/Closure/Person.php b/tests/Gedmo/Tree/Fixture/Closure/Person.php index b2ab62fc89..44818c3a9a 100644 --- a/tests/Gedmo/Tree/Fixture/Closure/Person.php +++ b/tests/Gedmo/Tree/Fixture/Closure/Person.php @@ -36,8 +36,6 @@ abstract class Person { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -45,7 +43,7 @@ abstract class Person #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="full_name", type="string", length=64) diff --git a/tests/Gedmo/Tree/Fixture/Comment.php b/tests/Gedmo/Tree/Fixture/Comment.php index 8ab467b147..5761705491 100644 --- a/tests/Gedmo/Tree/Fixture/Comment.php +++ b/tests/Gedmo/Tree/Fixture/Comment.php @@ -21,8 +21,6 @@ class Comment { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -30,7 +28,7 @@ class Comment #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="message", type="text") diff --git a/tests/Gedmo/Tree/Fixture/ForeignRootCategory.php b/tests/Gedmo/Tree/Fixture/ForeignRootCategory.php index 55a545ff65..2cab6e94f1 100644 --- a/tests/Gedmo/Tree/Fixture/ForeignRootCategory.php +++ b/tests/Gedmo/Tree/Fixture/ForeignRootCategory.php @@ -28,8 +28,6 @@ class ForeignRootCategory { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -37,7 +35,7 @@ class ForeignRootCategory #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -46,26 +44,22 @@ class ForeignRootCategory private ?string $title = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(name="lft", type="integer") */ #[ORM\Column(name: 'lft', type: Types::INTEGER)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(name="rgt", type="integer") */ #[ORM\Column(name: 'rgt', type: Types::INTEGER)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** * @Gedmo\TreeParent @@ -81,26 +75,22 @@ class ForeignRootCategory private ?ForeignRootCategory $parent = null; /** - * @var int|null - * * @Gedmo\TreeRoot(identifierMethod="getRoot") * * @ORM\Column(type="integer") */ #[ORM\Column(type: Types::INTEGER)] #[Gedmo\TreeRoot(identifierMethod: 'getRoot')] - private $root; + private ?int $root = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer") */ #[ORM\Column(name: 'lvl', type: Types::INTEGER)] #[Gedmo\TreeLevel] - private $level; + private ?int $level = null; /** * @var Collection @@ -108,7 +98,7 @@ class ForeignRootCategory * @ORM\OneToMany(targetEntity="ForeignRootCategory", mappedBy="parent") */ #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] - private $children; + private Collection $children; public function __construct() { diff --git a/tests/Gedmo/Tree/Fixture/Genealogy/Man.php b/tests/Gedmo/Tree/Fixture/Genealogy/Man.php index 8665aa9b59..164c39fc2b 100644 --- a/tests/Gedmo/Tree/Fixture/Genealogy/Man.php +++ b/tests/Gedmo/Tree/Fixture/Genealogy/Man.php @@ -18,6 +18,4 @@ * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository") */ #[ORM\Entity(repositoryClass: NestedTreeRepository::class)] -class Man extends Person -{ -} +class Man extends Person {} diff --git a/tests/Gedmo/Tree/Fixture/Genealogy/Person.php b/tests/Gedmo/Tree/Fixture/Genealogy/Person.php index 98d94adaa6..faaf48004b 100644 --- a/tests/Gedmo/Tree/Fixture/Genealogy/Person.php +++ b/tests/Gedmo/Tree/Fixture/Genealogy/Person.php @@ -41,11 +41,9 @@ abstract class Person * @ORM\OneToMany(targetEntity="Person", mappedBy="parent") */ #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] - protected $children; + protected Collection $children; /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -53,7 +51,7 @@ abstract class Person #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\TreeParent @@ -65,47 +63,39 @@ abstract class Person private ?Person $parent = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(name="lft", type="integer") */ #[ORM\Column(name: 'lft', type: Types::INTEGER)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(name="rgt", type="integer") */ #[ORM\Column(name: 'rgt', type: Types::INTEGER)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer") */ #[ORM\Column(name: 'lvl', type: Types::INTEGER)] #[Gedmo\TreeLevel] - private $lvl; - - /** - * @ORM\Column(name="name", type="string", length=191, nullable=false) - */ - #[ORM\Column(name: 'name', type: Types::STRING, length: 191, nullable: false)] - private string $name; - - public function __construct(string $name) - { - $this->name = $name; + private ?int $lvl = null; + + public function __construct( + /** + * @ORM\Column(name="name", type="string", length=191, nullable=false) + */ + #[ORM\Column(name: 'name', type: Types::STRING, length: 191, nullable: false)] + private string $name + ) { $this->children = new ArrayCollection(); } diff --git a/tests/Gedmo/Tree/Fixture/Genealogy/Woman.php b/tests/Gedmo/Tree/Fixture/Genealogy/Woman.php index 16a6b7a87d..e307ce8c18 100644 --- a/tests/Gedmo/Tree/Fixture/Genealogy/Woman.php +++ b/tests/Gedmo/Tree/Fixture/Genealogy/Woman.php @@ -18,6 +18,4 @@ * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository") */ #[ORM\Entity(repositoryClass: NestedTreeRepository::class)] -class Woman extends Person -{ -} +class Woman extends Person {} diff --git a/tests/Gedmo/Tree/Fixture/Issue2408/Category.php b/tests/Gedmo/Tree/Fixture/Issue2408/Category.php index 8cc5480463..b7afb3a685 100644 --- a/tests/Gedmo/Tree/Fixture/Issue2408/Category.php +++ b/tests/Gedmo/Tree/Fixture/Issue2408/Category.php @@ -30,8 +30,6 @@ class Category { /** - * @var int|null - * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue @@ -39,7 +37,7 @@ class Category #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -48,41 +46,33 @@ class Category private ?string $title = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(name="lft", type="integer") */ #[ORM\Column(name: 'lft', type: Types::INTEGER)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(name="rgt", type="integer") */ #[ORM\Column(name: 'rgt', type: Types::INTEGER)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer") */ #[ORM\Column(name: 'lvl', type: Types::INTEGER)] #[Gedmo\TreeLevel] - private $lvl; + private ?int $lvl = null; /** - * @var self|null - * * @Gedmo\TreeRoot * * @ORM\ManyToOne(targetEntity="Category") @@ -91,7 +81,7 @@ class Category #[Gedmo\TreeRoot] #[ORM\ManyToOne(targetEntity: self::class)] #[ORM\JoinColumn(name: 'tree_root', referencedColumnName: 'id', onDelete: 'CASCADE')] - private $root; + private ?Category $root = null; /** * @Gedmo\TreeParent diff --git a/tests/Gedmo/Tree/Fixture/Issue2517/Category.php b/tests/Gedmo/Tree/Fixture/Issue2517/Category.php index c00494078b..74e4dd30fa 100644 --- a/tests/Gedmo/Tree/Fixture/Issue2517/Category.php +++ b/tests/Gedmo/Tree/Fixture/Issue2517/Category.php @@ -30,8 +30,6 @@ class Category { /** - * @var int|null - * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue @@ -39,7 +37,7 @@ class Category #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -48,41 +46,33 @@ class Category private ?string $title = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(name="lft", type="integer") */ #[ORM\Column(name: 'lft', type: Types::INTEGER)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(name="rgt", type="integer") */ #[ORM\Column(name: 'rgt', type: Types::INTEGER)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer") */ #[ORM\Column(name: 'lvl', type: Types::INTEGER)] #[Gedmo\TreeLevel] - private $lvl; + private ?int $lvl = null; /** - * @var self|null - * * @Gedmo\TreeRoot * * @ORM\ManyToOne(targetEntity="Category") @@ -91,7 +81,7 @@ class Category #[Gedmo\TreeRoot] #[ORM\ManyToOne(targetEntity: self::class)] #[ORM\JoinColumn(name: 'tree_root', referencedColumnName: 'id', onDelete: 'CASCADE')] - private $root; + private ?Category $root = null; /** * @Gedmo\TreeParent diff --git a/tests/Gedmo/Tree/Fixture/Issue2616/Category.php b/tests/Gedmo/Tree/Fixture/Issue2616/Category.php index ab90a9906c..0a5380f6d7 100644 --- a/tests/Gedmo/Tree/Fixture/Issue2616/Category.php +++ b/tests/Gedmo/Tree/Fixture/Issue2616/Category.php @@ -9,6 +9,8 @@ namespace Gedmo\Tests\Tree\Fixture\Issue2616; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; @@ -29,32 +31,27 @@ class Category * @ORM\JoinColumn(name="parent_id", referencedColumnName="category_id", onDelete="cascade") * * @Gedmo\TreeParent - * - * @var Category|null */ #[Gedmo\TreeParent] #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'category_id', onDelete: 'cascade')] #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] - protected $parent; + protected ?Category $parent = null; /** * @ORM\OneToMany(targetEntity="\Gedmo\Tests\Tree\Fixture\Issue2616\Category", mappedBy="parent", fetch="EXTRA_LAZY") * - * @var Category[]|null + * @var Collection */ #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class, fetch: 'EXTRA_LAZY')] - protected $children; + protected Collection $children; /** * @ORM\OneToOne(targetEntity="\Gedmo\Tests\Tree\Fixture\Issue2616\Page", mappedBy="category", cascade={"remove"}) - * - * @var Page|null */ #[ORM\OneToOne(targetEntity: Page::class, mappedBy: 'category', cascade: ['remove'])] - protected $page; + protected ?Page $page = null; + /** - * @var int|null - * * @ORM\Column(name="category_id", type="integer") * @ORM\Id * @ORM\GeneratedValue @@ -65,7 +62,7 @@ class Category #[ORM\Column(name: 'category_id', type: Types::INTEGER)] #[ORM\GeneratedValue] #[ORM\Id] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -77,49 +74,41 @@ class Category * @Gedmo\TreeLevel * * @ORM\Column(name="level", type="integer", nullable=true) - * - * @var int|null */ #[Gedmo\TreeLevel] #[ORM\Column(name: 'level', type: Types::INTEGER, nullable: true)] - private $level; + private ?int $level = null; /** * @Gedmo\TreePath(separator="/", endsWithSeparator=false) * * @ORM\Column(name="path", type="string", nullable=true) - * - * @var string|null */ #[ORM\Column(name: 'path', type: Types::STRING, nullable: true)] #[Gedmo\TreePath(separator: '/', endsWithSeparator: false)] - private $path; + private ?string $path = null; + + public function __construct() + { + $this->children = new ArrayCollection(); + } public function getId(): ?int { return $this->id; } - /** - * @return Category|null - */ - public function getParent() + public function getParent(): ?self { return $this->parent; } - /** - * @param Category|null $parent - */ - public function setParent($parent): void + public function setParent(?self $parent): void { $this->parent = $parent; } - /** - * @return Page|null - */ - public function getPage() + public function getPage(): ?Page { return $this->page; } @@ -130,36 +119,22 @@ public function setPage(Page $page): void $page->setCategory($this); } - /** - * @return int - */ - public function getLevel() + public function getLevel(): ?int { return $this->level; } - /** - * @param int $level - */ - public function setLevel($level): void + public function setLevel(?int $level): void { $this->level = $level; } - /** - * @return string|null - */ - public function getPath() + public function getPath(): ?string { return $this->path; } - /** - * @param string $path - * - * @return void - */ - public function setPath($path) + public function setPath(?string $path): void { $this->path = $path; } diff --git a/tests/Gedmo/Tree/Fixture/Issue2616/Page.php b/tests/Gedmo/Tree/Fixture/Issue2616/Page.php index 6f15d52d55..ded6635a20 100644 --- a/tests/Gedmo/Tree/Fixture/Issue2616/Page.php +++ b/tests/Gedmo/Tree/Fixture/Issue2616/Page.php @@ -20,17 +20,13 @@ class Page { /** - * @var Category|null - * * @ORM\OneToOne(targetEntity="Category", inversedBy="page") * @ORM\JoinColumn(name="entity_id", referencedColumnName="category_id", nullable=false) */ #[ORM\JoinColumn(name: 'entity_id', referencedColumnName: 'category_id', nullable: false)] #[ORM\OneToOne(targetEntity: Category::class, inversedBy: 'page')] - protected $category; + protected ?Category $category = null; /** - * @var int|null - * * @ORM\Column(name="page_id", type="integer") * @ORM\Id * @ORM\GeneratedValue @@ -38,7 +34,7 @@ class Page #[ORM\Column(name: 'page_id', type: Types::INTEGER)] #[ORM\GeneratedValue] #[ORM\Id] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) diff --git a/tests/Gedmo/Tree/Fixture/MPCategory.php b/tests/Gedmo/Tree/Fixture/MPCategory.php index 1d5ee194c2..dcde3704eb 100644 --- a/tests/Gedmo/Tree/Fixture/MPCategory.php +++ b/tests/Gedmo/Tree/Fixture/MPCategory.php @@ -28,8 +28,6 @@ class MPCategory { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -37,7 +35,7 @@ class MPCategory #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\TreePath @@ -71,26 +69,22 @@ class MPCategory private ?MPCategory $parentId = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer", nullable=true) */ #[ORM\Column(name: 'lvl', type: Types::INTEGER, nullable: true)] #[Gedmo\TreeLevel] - private $level; + private ?int $level = null; /** - * @var string|null - * * @Gedmo\TreeRoot * * @ORM\Column(name="tree_root_value", type="string", nullable=true) */ #[ORM\Column(name: 'tree_root_value', type: Types::STRING, nullable: true)] #[Gedmo\TreeRoot] - private $treeRootValue; + private ?string $treeRootValue = null; /** * @var Collection diff --git a/tests/Gedmo/Tree/Fixture/MPCategoryUuid.php b/tests/Gedmo/Tree/Fixture/MPCategoryUuid.php index b0b517da78..a5befdc1c6 100644 --- a/tests/Gedmo/Tree/Fixture/MPCategoryUuid.php +++ b/tests/Gedmo/Tree/Fixture/MPCategoryUuid.php @@ -68,26 +68,22 @@ class MPCategoryUuid private ?MPCategoryUuid $parentId = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer", nullable=true) */ #[ORM\Column(name: 'lvl', type: Types::INTEGER, nullable: true)] #[Gedmo\TreeLevel] - private $level; + private ?int $level = null; /** - * @var string|null - * * @Gedmo\TreeRoot * * @ORM\Column(name="tree_root_value", type="string", nullable=true) */ #[ORM\Column(name: 'tree_root_value', type: Types::STRING, nullable: true)] #[Gedmo\TreeRoot] - private $treeRootValue; + private ?string $treeRootValue = null; /** * @var Collection diff --git a/tests/Gedmo/Tree/Fixture/MPCategoryWithRootAssociation.php b/tests/Gedmo/Tree/Fixture/MPCategoryWithRootAssociation.php index 7afe346ad1..6ac1029c93 100644 --- a/tests/Gedmo/Tree/Fixture/MPCategoryWithRootAssociation.php +++ b/tests/Gedmo/Tree/Fixture/MPCategoryWithRootAssociation.php @@ -28,8 +28,6 @@ class MPCategoryWithRootAssociation { /** - * @var int|null - * * @Gedmo\TreePathSource * * @ORM\Id @@ -40,7 +38,7 @@ class MPCategoryWithRootAssociation #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] #[Gedmo\TreePathSource] - private $id; + private ?int $id = null; /** * @Gedmo\TreePath @@ -71,19 +69,15 @@ class MPCategoryWithRootAssociation private ?MPCategoryWithRootAssociation $parentId = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer", nullable=true) */ #[ORM\Column(name: 'lvl', type: Types::INTEGER, nullable: true)] #[Gedmo\TreeLevel] - private $level; + private ?int $level = null; /** - * @var self|null - * * @Gedmo\TreeRoot * * @ORM\ManyToOne(targetEntity="MPCategoryWithRootAssociation") @@ -94,7 +88,7 @@ class MPCategoryWithRootAssociation #[ORM\ManyToOne(targetEntity: self::class)] #[ORM\JoinColumn(name: 'tree_root_entity', referencedColumnName: 'id', onDelete: 'CASCADE')] #[Gedmo\TreeRoot] - private $treeRootEntity; + private ?MPCategoryWithRootAssociation $treeRootEntity = null; /** * @var Collection diff --git a/tests/Gedmo/Tree/Fixture/MPCategoryWithTrimmedSeparator.php b/tests/Gedmo/Tree/Fixture/MPCategoryWithTrimmedSeparator.php index 28d3ca8fd9..9d8c21ad45 100644 --- a/tests/Gedmo/Tree/Fixture/MPCategoryWithTrimmedSeparator.php +++ b/tests/Gedmo/Tree/Fixture/MPCategoryWithTrimmedSeparator.php @@ -28,8 +28,6 @@ class MPCategoryWithTrimmedSeparator { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -37,7 +35,7 @@ class MPCategoryWithTrimmedSeparator #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\TreePath(appendId=false, startsWithSeparator=false, endsWithSeparator=false) @@ -71,15 +69,13 @@ class MPCategoryWithTrimmedSeparator private ?MPCategoryWithTrimmedSeparator $parentId = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer", nullable=true) */ #[ORM\Column(name: 'lvl', type: Types::INTEGER, nullable: true)] #[Gedmo\TreeLevel] - private $level; + private ?int $level = null; /** * @var Collection diff --git a/tests/Gedmo/Tree/Fixture/MPFeaturesCategory.php b/tests/Gedmo/Tree/Fixture/MPFeaturesCategory.php index c88e428e49..29f4df80e7 100644 --- a/tests/Gedmo/Tree/Fixture/MPFeaturesCategory.php +++ b/tests/Gedmo/Tree/Fixture/MPFeaturesCategory.php @@ -28,8 +28,6 @@ class MPFeaturesCategory { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -37,7 +35,7 @@ class MPFeaturesCategory #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\TreePath(appendId=false, startsWithSeparator=true, endsWithSeparator=false) @@ -49,15 +47,13 @@ class MPFeaturesCategory private ?string $path = null; /** - * @var string|null - * * @Gedmo\TreePathHash * * @ORM\Column(name="pathhash", type="string", length=32, nullable=true) */ #[ORM\Column(name: 'pathhash', type: Types::STRING, length: 32, nullable: true)] #[Gedmo\TreePathHash] - private $pathHash; + private ?string $pathHash = null; /** * @Gedmo\TreePathSource @@ -82,26 +78,22 @@ class MPFeaturesCategory private ?MPFeaturesCategory $parentId = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer", nullable=true) */ #[ORM\Column(name: 'lvl', type: Types::INTEGER, nullable: true)] #[Gedmo\TreeLevel] - private $level; + private ?int $level = null; /** - * @var string|null - * * @Gedmo\TreeRoot * * @ORM\Column(name="tree_root_value", type="string", nullable=true) */ #[ORM\Column(name: 'tree_root_value', type: Types::STRING, nullable: true)] #[Gedmo\TreeRoot] - private $treeRootValue; + private ?string $treeRootValue = null; /** * @var Collection diff --git a/tests/Gedmo/Tree/Fixture/Mock/TreeListenerMock.php b/tests/Gedmo/Tree/Fixture/Mock/TreeListenerMock.php index a47c5051dc..0af74f75bd 100644 --- a/tests/Gedmo/Tree/Fixture/Mock/TreeListenerMock.php +++ b/tests/Gedmo/Tree/Fixture/Mock/TreeListenerMock.php @@ -23,17 +23,11 @@ */ final class TreeListenerMock extends TreeListener { - /** - * @var bool - */ - public $releaseLocks = false; + public bool $releaseLocks = false; - /** - * @var MaterializedPathMock - */ - protected $strategy; + protected ?MaterializedPathMock $strategy = null; - public function getStrategy(ObjectManager $om, $class) + public function getStrategy(ObjectManager $om, $class): MaterializedPathMock { if (null === $this->strategy) { $this->strategy = new MaterializedPathMock($this); diff --git a/tests/Gedmo/Tree/Fixture/Node.php b/tests/Gedmo/Tree/Fixture/Node.php index a003c02627..1b3b8c2040 100644 --- a/tests/Gedmo/Tree/Fixture/Node.php +++ b/tests/Gedmo/Tree/Fixture/Node.php @@ -32,8 +32,6 @@ class Node extends BaseNode private ?string $title = null; /** - * @var string|null - * * @Gedmo\Translatable * @Gedmo\Slug(fields={"title"}) * @@ -42,7 +40,7 @@ class Node extends BaseNode #[ORM\Column(name: 'slug', type: Types::STRING, length: 128)] #[Gedmo\Translatable] #[Gedmo\Slug(fields: ['title'])] - private $slug; + private ?string $slug = null; public function getSlug(): ?string { diff --git a/tests/Gedmo/Tree/Fixture/Repository/BehavioralCategoryRepository.php b/tests/Gedmo/Tree/Fixture/Repository/BehavioralCategoryRepository.php index a3ce3ff266..3f7f25ea8f 100644 --- a/tests/Gedmo/Tree/Fixture/Repository/BehavioralCategoryRepository.php +++ b/tests/Gedmo/Tree/Fixture/Repository/BehavioralCategoryRepository.php @@ -17,6 +17,4 @@ /** * @template-extends NestedTreeRepository */ -final class BehavioralCategoryRepository extends NestedTreeRepository -{ -} +final class BehavioralCategoryRepository extends NestedTreeRepository {} diff --git a/tests/Gedmo/Tree/Fixture/Role.php b/tests/Gedmo/Tree/Fixture/Role.php index ebad728ecf..fdf5d83062 100644 --- a/tests/Gedmo/Tree/Fixture/Role.php +++ b/tests/Gedmo/Tree/Fixture/Role.php @@ -33,7 +33,7 @@ #[ORM\DiscriminatorColumn(name: 'discr', type: Types::STRING)] #[ORM\DiscriminatorMap(['user' => User::class, 'usergroup' => UserGroup::class, 'userldap' => UserLDAP::class])] #[Gedmo\Tree(type: 'nested')] -abstract class Role +abstract class Role implements \Stringable { /** * @var Collection @@ -41,11 +41,9 @@ abstract class Role * @ORM\OneToMany(targetEntity="Role", mappedBy="parent") */ #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] - protected $children; + protected Collection $children; /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -53,7 +51,7 @@ abstract class Role #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @Gedmo\TreeParent @@ -65,37 +63,31 @@ abstract class Role private ?UserGroup $parent = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(name="lft", type="integer") */ #[ORM\Column(name: 'lft', type: Types::INTEGER)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(name="rgt", type="integer") */ #[ORM\Column(name: 'rgt', type: Types::INTEGER)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer") */ #[ORM\Column(name: 'lvl', type: Types::INTEGER)] #[Gedmo\TreeLevel] - private $lvl; + private ?int $lvl = null; /** * @ORM\Column(name="role", type="string", length=191, nullable=false) diff --git a/tests/Gedmo/Tree/Fixture/RootAssociationCategory.php b/tests/Gedmo/Tree/Fixture/RootAssociationCategory.php index bf1e9342d0..4c86e8ca6f 100644 --- a/tests/Gedmo/Tree/Fixture/RootAssociationCategory.php +++ b/tests/Gedmo/Tree/Fixture/RootAssociationCategory.php @@ -33,10 +33,9 @@ class RootAssociationCategory * @ORM\OneToMany(targetEntity="RootAssociationCategory", mappedBy="parent") */ #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] - protected $children; + protected Collection $children; + /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -44,7 +43,7 @@ class RootAssociationCategory #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -53,26 +52,22 @@ class RootAssociationCategory private ?string $title = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(name="lft", type="integer") */ #[ORM\Column(name: 'lft', type: Types::INTEGER)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(name="rgt", type="integer") */ #[ORM\Column(name: 'rgt', type: Types::INTEGER)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** * @Gedmo\TreeParent @@ -88,8 +83,6 @@ class RootAssociationCategory private ?RootAssociationCategory $parent = null; /** - * @var self|null - * * @Gedmo\TreeRoot * * @ORM\ManyToOne(targetEntity="RootAssociationCategory") @@ -100,18 +93,16 @@ class RootAssociationCategory #[ORM\ManyToOne(targetEntity: self::class)] #[ORM\JoinColumn(name: 'tree_root', referencedColumnName: 'id', onDelete: 'CASCADE')] #[Gedmo\TreeRoot] - private $root; + private ?RootAssociationCategory $root = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer") */ #[ORM\Column(name: 'lvl', type: Types::INTEGER)] #[Gedmo\TreeLevel] - private $level; + private ?int $level = null; public function __construct() { diff --git a/tests/Gedmo/Tree/Fixture/RootCategory.php b/tests/Gedmo/Tree/Fixture/RootCategory.php index 53bee18358..8ce72b65a1 100644 --- a/tests/Gedmo/Tree/Fixture/RootCategory.php +++ b/tests/Gedmo/Tree/Fixture/RootCategory.php @@ -34,10 +34,9 @@ class RootCategory implements Node * @ORM\OneToMany(targetEntity="RootCategory", mappedBy="parent") */ #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] - protected $children; + protected Collection $children; + /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -45,7 +44,7 @@ class RootCategory implements Node #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", length=64) @@ -54,26 +53,22 @@ class RootCategory implements Node private ?string $title = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(name="lft", type="integer") */ #[ORM\Column(name: 'lft', type: Types::INTEGER)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(name="rgt", type="integer") */ #[ORM\Column(name: 'rgt', type: Types::INTEGER)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** * @Gedmo\TreeParent @@ -89,26 +84,22 @@ class RootCategory implements Node private ?RootCategory $parent = null; /** - * @var int|null - * * @Gedmo\TreeRoot * * @ORM\Column(type="integer") */ #[ORM\Column(type: Types::INTEGER)] #[Gedmo\TreeRoot] - private $root; + private ?int $root = null; /** - * @var int|null - * * @Gedmo\TreeLevel(base=1) * * @ORM\Column(name="lvl", type="integer") */ #[ORM\Column(name: 'lvl', type: Types::INTEGER)] #[Gedmo\TreeLevel(base: 1)] - private $level; + private ?int $level = null; private ?Node $sibling = null; diff --git a/tests/Gedmo/Tree/Fixture/Transport/Bus.php b/tests/Gedmo/Tree/Fixture/Transport/Bus.php index 45466f0c26..3f0a923227 100644 --- a/tests/Gedmo/Tree/Fixture/Transport/Bus.php +++ b/tests/Gedmo/Tree/Fixture/Transport/Bus.php @@ -17,6 +17,4 @@ * @ORM\Entity */ #[ORM\Entity] -class Bus extends Vehicle -{ -} +class Bus extends Vehicle {} diff --git a/tests/Gedmo/Tree/Fixture/Transport/Car.php b/tests/Gedmo/Tree/Fixture/Transport/Car.php index 69b8a0a01e..af87deb355 100644 --- a/tests/Gedmo/Tree/Fixture/Transport/Car.php +++ b/tests/Gedmo/Tree/Fixture/Transport/Car.php @@ -33,7 +33,7 @@ class Car extends Vehicle * @ORM\OneToMany(targetEntity="Car", mappedBy="parent") */ #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] - protected $children; + protected Collection $children; /** * @Gedmo\TreeParent @@ -49,48 +49,40 @@ class Car extends Vehicle private ?Car $parent = null; /** - * @var int|null - * * @Gedmo\TreeLeft * * @ORM\Column(type="integer", nullable=true) */ #[ORM\Column(type: Types::INTEGER, nullable: true)] #[Gedmo\TreeLeft] - private $lft; + private ?int $lft = null; /** - * @var int|null - * * @Gedmo\TreeRight * * @ORM\Column(type="integer", nullable=true) */ #[ORM\Column(type: Types::INTEGER, nullable: true)] #[Gedmo\TreeRight] - private $rgt; + private ?int $rgt = null; /** - * @var int|null - * * @Gedmo\TreeRoot * * @ORM\Column(type="integer", nullable=true) */ #[ORM\Column(type: Types::INTEGER, nullable: true)] #[Gedmo\TreeRoot] - private $root; + private ?int $root = null; /** - * @var int|null - * * @Gedmo\TreeLevel * * @ORM\Column(name="lvl", type="integer", nullable=true) */ #[ORM\Column(name: 'lvl', type: Types::INTEGER, nullable: true)] #[Gedmo\TreeLevel] - private $classLevel; + private ?int $classLevel = null; public function __construct() { diff --git a/tests/Gedmo/Tree/Fixture/Transport/Engine.php b/tests/Gedmo/Tree/Fixture/Transport/Engine.php index e13cf0bb23..baa9f69363 100644 --- a/tests/Gedmo/Tree/Fixture/Transport/Engine.php +++ b/tests/Gedmo/Tree/Fixture/Transport/Engine.php @@ -21,8 +21,6 @@ class Engine { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -30,7 +28,7 @@ class Engine #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=32) diff --git a/tests/Gedmo/Tree/Fixture/Transport/Vehicle.php b/tests/Gedmo/Tree/Fixture/Transport/Vehicle.php index f3aa0d9100..ac0f340853 100644 --- a/tests/Gedmo/Tree/Fixture/Transport/Vehicle.php +++ b/tests/Gedmo/Tree/Fixture/Transport/Vehicle.php @@ -31,8 +31,6 @@ class Vehicle { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -40,7 +38,7 @@ class Vehicle #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\OneToOne(targetEntity="Engine") diff --git a/tests/Gedmo/Tree/Issue/Issue2616Test.php b/tests/Gedmo/Tree/Issue/Issue2616Test.php index 788be2f705..26908f5b71 100644 --- a/tests/Gedmo/Tree/Issue/Issue2616Test.php +++ b/tests/Gedmo/Tree/Issue/Issue2616Test.php @@ -67,8 +67,8 @@ public function testGetNextSiblingsWithoutIdentifierMethod(): void $this->em->remove($food); $this->em->flush(); - static::assertNull($categoryRepo->findOneBy(['title' => 'Fruits'])); - static::assertNull($categoryRepo->findOneBy(['title' => 'Vegetables'])); + static::assertNotInstanceOf(Category::class, $categoryRepo->findOneBy(['title' => 'Fruits'])); + static::assertNotInstanceOf(Category::class, $categoryRepo->findOneBy(['title' => 'Vegetables'])); // Page should be removed as well, because children Fruits/Vegetables are removed and they have Page with cascade remove. static::assertEmpty($this->em->getRepository(Page::class)->findAll()); diff --git a/tests/Gedmo/Tree/MaterializedPathODMMongoDBRepositoryTest.php b/tests/Gedmo/Tree/MaterializedPathODMMongoDBRepositoryTest.php index 026f45e8a7..91cf92304a 100644 --- a/tests/Gedmo/Tree/MaterializedPathODMMongoDBRepositoryTest.php +++ b/tests/Gedmo/Tree/MaterializedPathODMMongoDBRepositoryTest.php @@ -50,7 +50,7 @@ public function testGetRootNodes(): void $result = $this->repo->getRootNodes('title'); static::assertInstanceOf(Iterator::class, $result); - static::assertSame(3, \iterator_count($result)); + static::assertCount(3, $result); $result->rewind(); static::assertSame('Drinks', $result->current()->getTitle()); @@ -68,7 +68,7 @@ public function testGetChildren(): void $result = $this->repo->getChildren($root, false, 'title', 'asc', true); static::assertInstanceOf(Iterator::class, $result); - static::assertSame(5, \iterator_count($result)); + static::assertCount(5, $result); $result->rewind(); static::assertSame('Carrots', $result->current()->getTitle()); @@ -85,7 +85,7 @@ public function testGetChildren(): void $result = $this->repo->getChildren($root, false, 'title', 'asc', false); static::assertInstanceOf(Iterator::class, $result); - static::assertSame(4, \iterator_count($result)); + static::assertCount(4, $result); $result->rewind(); static::assertSame('Carrots', $result->current()->getTitle()); $result->next(); @@ -99,7 +99,7 @@ public function testGetChildren(): void $result = $this->repo->getChildren($root, true, 'title', 'asc', true); static::assertInstanceOf(Iterator::class, $result); - static::assertSame(3, \iterator_count($result)); + static::assertCount(3, $result); $result->rewind(); static::assertSame('Food', $result->current()->getTitle()); $result->next(); @@ -111,7 +111,7 @@ public function testGetChildren(): void $result = $this->repo->getChildren($root, true, 'title', 'asc', false); static::assertInstanceOf(Iterator::class, $result); - static::assertSame(2, \iterator_count($result)); + static::assertCount(2, $result); $result->rewind(); static::assertSame('Fruits', $result->current()->getTitle()); $result->next(); @@ -121,7 +121,7 @@ public function testGetChildren(): void $result = $this->repo->getChildren(null, false, 'title'); static::assertInstanceOf(Iterator::class, $result); - static::assertSame(9, \iterator_count($result)); + static::assertCount(9, $result); $result->rewind(); static::assertSame('Best Whisky', $result->current()->getTitle()); $result->next(); @@ -145,7 +145,7 @@ public function testGetChildren(): void $result = $this->repo->getChildren(null, true, 'title'); static::assertInstanceOf(Iterator::class, $result); - static::assertSame(3, \iterator_count($result)); + static::assertCount(3, $result); $result->rewind(); static::assertSame('Drinks', $result->current()->getTitle()); $result->next(); @@ -158,7 +158,7 @@ public function testGetTree(): void { $tree = $this->repo->getTree(); - static::assertSame(9, \iterator_count($tree)); + static::assertCount(9, $tree); $tree->rewind(); static::assertSame('Drinks', $tree->current()->getTitle()); $tree->next(); @@ -183,7 +183,7 @@ public function testGetTree(): void static::assertInstanceOf(Iterator::class, $roots); $tree = $this->repo->getTree($roots->current()); - static::assertSame(3, \iterator_count($tree)); + static::assertCount(3, $tree); $tree->rewind(); static::assertSame('Drinks', $tree->current()->getTitle()); $tree->next(); diff --git a/tests/Gedmo/Tree/MaterializedPathODMMongoDBTest.php b/tests/Gedmo/Tree/MaterializedPathODMMongoDBTest.php index b8da9f6691..be8b047169 100644 --- a/tests/Gedmo/Tree/MaterializedPathODMMongoDBTest.php +++ b/tests/Gedmo/Tree/MaterializedPathODMMongoDBTest.php @@ -23,18 +23,17 @@ * * @author Gustavo Falco * @author Gediminas Morkevicius + * + * @phpstan-import-type TreeConfiguration from TreeListener */ final class MaterializedPathODMMongoDBTest extends BaseTestCaseMongoODM { /** - * @var array + * @phpstan-var TreeConfiguration */ - protected $config; + private array $config; - /** - * @var TreeListener - */ - protected $listener; + private TreeListener $listener; protected function setUp(): void { diff --git a/tests/Gedmo/Tree/MaterializedPathODMMongoDBTreeLockingTest.php b/tests/Gedmo/Tree/MaterializedPathODMMongoDBTreeLockingTest.php index 60e2a9a85d..ee5b955403 100644 --- a/tests/Gedmo/Tree/MaterializedPathODMMongoDBTreeLockingTest.php +++ b/tests/Gedmo/Tree/MaterializedPathODMMongoDBTreeLockingTest.php @@ -25,15 +25,7 @@ */ final class MaterializedPathODMMongoDBTreeLockingTest extends BaseTestCaseMongoODM { - /** - * @var array - */ - protected $config; - - /** - * @var TreeListenerMock - */ - protected $listener; + private TreeListenerMock $listener; protected function setUp(): void { @@ -45,9 +37,6 @@ protected function setUp(): void $evm->addEventSubscriber($this->listener); $this->getDefaultDocumentManager($evm); - - $meta = $this->dm->getClassMetadata(Article::class); - $this->config = $this->listener->getConfiguration($this->dm, $meta->getName()); } public function testModifyingANodeWhileItsTreeIsLockedShouldThrowAnException(): void diff --git a/tests/Gedmo/Tree/MaterializedPathORMFeaturesTest.php b/tests/Gedmo/Tree/MaterializedPathORMFeaturesTest.php index 92c4a2df01..0dc7c49354 100644 --- a/tests/Gedmo/Tree/MaterializedPathORMFeaturesTest.php +++ b/tests/Gedmo/Tree/MaterializedPathORMFeaturesTest.php @@ -21,18 +21,17 @@ * * @author Gustavo Falco * @author Gediminas Morkevicius + * + * @phpstan-import-type TreeConfiguration from TreeListener */ final class MaterializedPathORMFeaturesTest extends BaseTestCaseORM { /** - * @var array + * @phpstan-var TreeConfiguration */ - protected $config; + private array $config; - /** - * @var TreeListener - */ - protected $listener; + private TreeListener $listener; protected function setUp(): void { @@ -110,7 +109,7 @@ private function createCategory(): MPFeaturesCategory private function generatePath(array $sources): string { $path = ''; - foreach ($sources as $p => $id) { + foreach (array_keys($sources) as $p) { $path .= $this->config['path_separator'].$p; } diff --git a/tests/Gedmo/Tree/MaterializedPathORMRootAssociationTest.php b/tests/Gedmo/Tree/MaterializedPathORMRootAssociationTest.php index a1067b16b3..1006a47932 100644 --- a/tests/Gedmo/Tree/MaterializedPathORMRootAssociationTest.php +++ b/tests/Gedmo/Tree/MaterializedPathORMRootAssociationTest.php @@ -21,18 +21,17 @@ * * @author Gustavo Falco * @author Gediminas Morkevicius + * + * @phpstan-import-type TreeConfiguration from TreeListener */ final class MaterializedPathORMRootAssociationTest extends BaseTestCaseORM { /** - * @var array + * @phpstan-var TreeConfiguration */ - protected $config; + private array $config; - /** - * @var TreeListener - */ - protected $listener; + private TreeListener $listener; protected function setUp(): void { diff --git a/tests/Gedmo/Tree/MaterializedPathORMTest.php b/tests/Gedmo/Tree/MaterializedPathORMTest.php index e06905d3f3..2ed2645d85 100644 --- a/tests/Gedmo/Tree/MaterializedPathORMTest.php +++ b/tests/Gedmo/Tree/MaterializedPathORMTest.php @@ -22,18 +22,17 @@ * * @author Gustavo Falco * @author Gediminas Morkevicius + * + * @phpstan-import-type TreeConfiguration from TreeListener */ final class MaterializedPathORMTest extends BaseTestCaseORM { /** - * @var array + * @phpstan-var TreeConfiguration */ - protected $config; + private array $config; - /** - * @var TreeListener - */ - protected $listener; + private TreeListener $listener; protected function setUp(): void { @@ -169,7 +168,7 @@ private function generatePath(array $sources): string private function getTreeRootValueOfRootNode(MPCategory $category): string { - while (null !== $category->getParent()) { + while ($category->getParent() instanceof MPCategory) { $category = $category->getParent(); } diff --git a/tests/Gedmo/Tree/MaterializedPathUuidORMTest.php b/tests/Gedmo/Tree/MaterializedPathUuidORMTest.php index dc62f4b5d7..fb32b656de 100644 --- a/tests/Gedmo/Tree/MaterializedPathUuidORMTest.php +++ b/tests/Gedmo/Tree/MaterializedPathUuidORMTest.php @@ -23,15 +23,17 @@ * @author Gustavo Falco * @author Gediminas Morkevicius * @author Andrea Bergamasco + * + * @phpstan-import-type TreeConfiguration from TreeListener */ final class MaterializedPathUuidORMTest extends BaseTestCaseORM { /** - * @var array + * @phpstan-var TreeConfiguration */ - protected array $config; + private array $config; - protected TreeListener $listener; + private TreeListener $listener; protected function setUp(): void { @@ -53,16 +55,16 @@ public function testInsertUpdateAndRemove(): void // Insert $category = $this->createCategory(); $category->setTitle('1'); - static::assertNotNull($category->getId()); + static::assertInstanceOf(UuidV4::class, $category->getId()); $category2 = $this->createCategory(); $category2->setTitle('2'); - static::assertNotNull($category2->getId()); + static::assertInstanceOf(UuidV4::class, $category2->getId()); $category3 = $this->createCategory(); $category3->setTitle('3'); - static::assertNotNull($category3->getId()); + static::assertInstanceOf(UuidV4::class, $category3->getId()); $category4 = $this->createCategory(); $category4->setTitle('4'); - static::assertNotNull($category4->getId()); + static::assertInstanceOf(UuidV4::class, $category4->getId()); $category2->setParent($category); $category3->setParent($category2); @@ -162,7 +164,7 @@ private function generatePath(array $sources): string private function getTreeRootValueOfRootNode(MPCategoryUuid $category): string { - while (null !== $category->getParent()) { + while ($category->getParent() instanceof MPCategoryUuid) { $category = $category->getParent(); } diff --git a/tests/Gedmo/Tree/NestedTreeRootTest.php b/tests/Gedmo/Tree/NestedTreeRootTest.php index e53f7fa00f..e758217973 100644 --- a/tests/Gedmo/Tree/NestedTreeRootTest.php +++ b/tests/Gedmo/Tree/NestedTreeRootTest.php @@ -398,13 +398,13 @@ public function testTreeWithRootPointingAtAnotherTable(): void static::assertSame(4, $fact->getRight()); static::assertSame(0, $fact->getLevel()); static::assertSame(1, $fact->getRoot()); - static::assertNull($fact->getParent()); + static::assertNotInstanceOf(ForeignRootCategory::class, $fact->getParent()); static::assertSame(5, $fiction->getLeft()); static::assertSame(10, $fiction->getRight()); static::assertSame(0, $fiction->getLevel()); static::assertSame(1, $fiction->getRoot()); - static::assertNull($fiction->getParent()); + static::assertNotInstanceOf(ForeignRootCategory::class, $fiction->getParent()); static::assertSame(6, $lotr->getLeft()); static::assertSame(7, $lotr->getRight()); @@ -428,19 +428,19 @@ public function testTreeWithRootPointingAtAnotherTable(): void static::assertSame(2, $comedy->getRight()); static::assertSame(0, $comedy->getLevel()); static::assertSame(2, $comedy->getRoot()); - static::assertNull($comedy->getParent()); + static::assertNotInstanceOf(ForeignRootCategory::class, $comedy->getParent()); static::assertSame(3, $horror->getLeft()); static::assertSame(8, $horror->getRight()); static::assertSame(0, $horror->getLevel()); static::assertSame(2, $horror->getRoot()); - static::assertNull($horror->getParent()); + static::assertNotInstanceOf(ForeignRootCategory::class, $horror->getParent()); static::assertSame(9, $action->getLeft()); static::assertSame(10, $action->getRight()); static::assertSame(0, $action->getLevel()); static::assertSame(2, $action->getRoot()); - static::assertNull($action->getParent()); + static::assertNotInstanceOf(ForeignRootCategory::class, $action->getParent()); static::assertSame(4, $dracula->getLeft()); static::assertSame(5, $dracula->getRight()); @@ -473,7 +473,7 @@ public function testTreeWithRootPointingAtAnotherTable(): void static::assertSame(10, $horror->getRight()); static::assertSame(0, $horror->getLevel()); static::assertSame(2, $horror->getRoot()); - static::assertNull($horror->getParent()); + static::assertNotInstanceOf(ForeignRootCategory::class, $horror->getParent()); static::assertSame(6, $dracula->getLeft()); static::assertSame(7, $dracula->getRight()); diff --git a/tests/Gedmo/Tree/RepositoryTest.php b/tests/Gedmo/Tree/RepositoryTest.php index cd7f6629e7..defe4dbb61 100644 --- a/tests/Gedmo/Tree/RepositoryTest.php +++ b/tests/Gedmo/Tree/RepositoryTest.php @@ -262,7 +262,7 @@ public function testAdvancedFunctions(): void $vegies = $this->em->getRepository(Category::class) ->findOneBy(['title' => 'Vegitables']); - static::assertNull($vegies); + static::assertNotInstanceOf(Category::class, $vegies); $node = $this->em->getRepository(Category::class) ->findOneBy(['title' => 'Fruits']); @@ -294,7 +294,7 @@ public function testRootRemoval(): void $this->em->clear(); $food = $repo->findOneBy(['title' => 'Food']); - static::assertNull($food); + static::assertNotInstanceOf(Category::class, $food); $node = $repo->findOneBy(['title' => 'Fruits']); $left = $meta->getReflectionProperty('lft')->getValue($node); @@ -302,7 +302,7 @@ public function testRootRemoval(): void static::assertSame(1, $left); static::assertSame(2, $right); - static::assertNull($node->getParent()); + static::assertNotInstanceOf(Category::class, $node->getParent()); $node = $repo->findOneBy(['title' => 'Vegitables']); $left = $meta->getReflectionProperty('lft')->getValue($node); @@ -310,7 +310,7 @@ public function testRootRemoval(): void static::assertSame(3, $left); static::assertSame(12, $right); - static::assertNull($node->getParent()); + static::assertNotInstanceOf(Category::class, $node->getParent()); } public function testVerificationAndRecover(): void @@ -372,7 +372,7 @@ public function testMoveRootNode(): void static::assertSame(3, $left); static::assertSame(12, $right); - static::assertNull($food->getParent()); + static::assertNotInstanceOf(Category::class, $food->getParent()); static::assertTrue($repo->verify()); } diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/Article.php b/tests/Gedmo/Uploadable/Fixture/Entity/Article.php index 6eb19de9fa..0943a36946 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/Article.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/Article.php @@ -23,8 +23,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -32,7 +30,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string") @@ -46,7 +44,7 @@ class Article * @ORM\OneToMany(targetEntity="File", mappedBy="article", cascade={"persist", "remove"}) */ #[ORM\OneToMany(targetEntity: File::class, mappedBy: 'article', cascade: ['persist', 'remove'])] - private $files; + private Collection $files; private ?string $filePath = null; diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/File.php b/tests/Gedmo/Uploadable/Fixture/Entity/File.php index 708cddb82a..b9ac44cedf 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/File.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/File.php @@ -30,8 +30,6 @@ class File public $callbackWasCalled = false; /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -39,7 +37,7 @@ class File #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", nullable=true) diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/FileAppendNumber.php b/tests/Gedmo/Uploadable/Fixture/Entity/FileAppendNumber.php index a9ab73d6b4..fc01b0bfbe 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/FileAppendNumber.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/FileAppendNumber.php @@ -25,8 +25,6 @@ class FileAppendNumber { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class FileAppendNumber #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", nullable=true) diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/FileAppendNumberRelative.php b/tests/Gedmo/Uploadable/Fixture/Entity/FileAppendNumberRelative.php index 721869362c..b3de0c65d9 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/FileAppendNumberRelative.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/FileAppendNumberRelative.php @@ -26,8 +26,6 @@ class FileAppendNumberRelative { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -35,7 +33,7 @@ class FileAppendNumberRelative #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", nullable=true) diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithAllowedTypes.php b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithAllowedTypes.php index d670b6886c..97ad31dfde 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithAllowedTypes.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithAllowedTypes.php @@ -25,8 +25,6 @@ class FileWithAllowedTypes { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class FileWithAllowedTypes #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", nullable=true) diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithAlphanumericName.php b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithAlphanumericName.php index 40ffede720..5638296264 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithAlphanumericName.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithAlphanumericName.php @@ -26,8 +26,6 @@ class FileWithAlphanumericName { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -35,7 +33,7 @@ class FileWithAlphanumericName #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="path", type="string", nullable=true) diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithCustomFilenameGenerator.php b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithCustomFilenameGenerator.php index 043b3b1e9d..529aee2112 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithCustomFilenameGenerator.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithCustomFilenameGenerator.php @@ -26,8 +26,6 @@ class FileWithCustomFilenameGenerator { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -35,7 +33,7 @@ class FileWithCustomFilenameGenerator #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="path", type="string", nullable=true) diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithDisallowedTypes.php b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithDisallowedTypes.php index d88a9cb6e4..ea637e03eb 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithDisallowedTypes.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithDisallowedTypes.php @@ -25,8 +25,6 @@ class FileWithDisallowedTypes { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class FileWithDisallowedTypes #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", nullable=true) diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithMaxSize.php b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithMaxSize.php index 0c71229b6f..e0c37bf20a 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithMaxSize.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithMaxSize.php @@ -24,14 +24,9 @@ #[Gedmo\Uploadable(allowOverwrite: true, pathMethod: 'getPath', callback: 'callbackMethod', maxSize: '2')] class FileWithMaxSize { - /** - * @var bool - */ - public $callbackWasCalled = false; + public bool $callbackWasCalled = false; /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -39,7 +34,7 @@ class FileWithMaxSize #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string", nullable=true) diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithSha1Name.php b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithSha1Name.php index 95b03ee790..91b2c77096 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithSha1Name.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithSha1Name.php @@ -26,8 +26,6 @@ class FileWithSha1Name { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -35,7 +33,7 @@ class FileWithSha1Name #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="path", type="string", nullable=true) diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithoutPath.php b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithoutPath.php index 125ea9da36..567f90f689 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/FileWithoutPath.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/FileWithoutPath.php @@ -25,8 +25,6 @@ class FileWithoutPath { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class FileWithoutPath #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="path", type="string", nullable=true) diff --git a/tests/Gedmo/Uploadable/Fixture/Entity/Image.php b/tests/Gedmo/Uploadable/Fixture/Entity/Image.php index 1d524b98dc..e776e6d082 100644 --- a/tests/Gedmo/Uploadable/Fixture/Entity/Image.php +++ b/tests/Gedmo/Uploadable/Fixture/Entity/Image.php @@ -25,8 +25,6 @@ class Image { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") @@ -34,7 +32,7 @@ class Image #[ORM\Id] #[ORM\GeneratedValue(strategy: 'IDENTITY')] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(name="title", type="string") diff --git a/tests/Gedmo/Uploadable/Mapping/ValidatorTest.php b/tests/Gedmo/Uploadable/Mapping/ValidatorTest.php index b6de1b07dd..e72633f370 100644 --- a/tests/Gedmo/Uploadable/Mapping/ValidatorTest.php +++ b/tests/Gedmo/Uploadable/Mapping/ValidatorTest.php @@ -29,9 +29,9 @@ final class ValidatorTest extends TestCase { /** - * @var ClassMetadata&MockObject + * @var MockObject&ClassMetadata */ - protected $meta; + protected MockObject&ClassMetadata $meta; protected function setUp(): void { @@ -52,7 +52,7 @@ public function testValidateFieldIfFieldIsNotOfAValidTypeThrowException(): void $this->expectException(InvalidMappingException::class); $this->meta->expects(static::once()) ->method('getFieldMapping') - ->willReturnCallback(static function (string $fieldName) { + ->willReturnCallback(static function (string $fieldName): FieldMapping|array { if (class_exists(FieldMapping::class)) { return FieldMapping::fromMappingArray(['type' => 'someType', 'fieldName' => $fieldName, 'columnName' => $fieldName]); } @@ -129,7 +129,7 @@ public function testValidateConfigurationIfFilenameGeneratorValueIsNotValidThrow ->willReturn(new \ReflectionClass(new FakeEntity())); $this->meta ->method('getFieldMapping') - ->willReturnCallback(static function (string $fieldName) { + ->willReturnCallback(static function (string $fieldName): FieldMapping|array { if (class_exists(FieldMapping::class)) { return FieldMapping::fromMappingArray(['type' => 'someType', 'fieldName' => $fieldName, 'columnName' => $fieldName]); } @@ -164,7 +164,7 @@ public function testValidateConfigurationIfFilenameGeneratorValueIsValidButDoesn ->willReturn(new \ReflectionClass(new FakeEntity())); $this->meta ->method('getFieldMapping') - ->willReturnCallback(static function (string $fieldName) { + ->willReturnCallback(static function (string $fieldName): FieldMapping|array { if (class_exists(FieldMapping::class)) { return FieldMapping::fromMappingArray(['type' => 'someType', 'fieldName' => $fieldName, 'columnName' => $fieldName]); } @@ -198,7 +198,7 @@ public function testValidateConfigurationIfFilenameGeneratorValueIsValidThenDont ->willReturn(new \ReflectionClass(new FakeEntity())); $this->meta ->method('getFieldMapping') - ->willReturnCallback(static function (string $fieldName) { + ->willReturnCallback(static function (string $fieldName): FieldMapping|array { if (class_exists(FieldMapping::class)) { return FieldMapping::fromMappingArray(['type' => 'string', 'fieldName' => $fieldName, 'columnName' => $fieldName]); } @@ -232,7 +232,7 @@ public function testValidateConfigurationIfFilenameGeneratorValueIsAValidClassTh ->willReturn(new \ReflectionClass(new FakeEntity())); $this->meta ->method('getFieldMapping') - ->willReturnCallback(static function (string $fieldName) { + ->willReturnCallback(static function (string $fieldName): FieldMapping|array { if (class_exists(FieldMapping::class)) { return FieldMapping::fromMappingArray(['type' => 'string', 'fieldName' => $fieldName, 'columnName' => $fieldName]); } @@ -310,6 +310,4 @@ public function testValidateConfigurationIfAllowedTypesAndDisallowedTypesAreSetT } } -class FakeEntity -{ -} +class FakeEntity {} diff --git a/tests/Gedmo/Uploadable/Stub/FileInfoStub.php b/tests/Gedmo/Uploadable/Stub/FileInfoStub.php index d8a797e9e4..716b169486 100644 --- a/tests/Gedmo/Uploadable/Stub/FileInfoStub.php +++ b/tests/Gedmo/Uploadable/Stub/FileInfoStub.php @@ -15,32 +15,32 @@ final class FileInfoStub implements FileInfoInterface { - public function getTmpName() + public function getTmpName(): never { throw new \BadMethodCallException('Not implemented.'); } - public function getName() + public function getName(): never { throw new \BadMethodCallException('Not implemented.'); } - public function getSize() + public function getSize(): never { throw new \BadMethodCallException('Not implemented.'); } - public function getType() + public function getType(): never { throw new \BadMethodCallException('Not implemented.'); } - public function getError() + public function getError(): never { throw new \BadMethodCallException('Not implemented.'); } - public function isUploadedFile() + public function isUploadedFile(): never { throw new \BadMethodCallException('Not implemented.'); } diff --git a/tests/Gedmo/Uploadable/Stub/MimeTypeGuesserStub.php b/tests/Gedmo/Uploadable/Stub/MimeTypeGuesserStub.php index 0a53a0e99e..b928d4b863 100644 --- a/tests/Gedmo/Uploadable/Stub/MimeTypeGuesserStub.php +++ b/tests/Gedmo/Uploadable/Stub/MimeTypeGuesserStub.php @@ -15,17 +15,9 @@ class MimeTypeGuesserStub implements MimeTypeGuesserInterface { - /** - * @var string|null - */ - protected $mimeType; + public function __construct(protected ?string $mimeType) {} - public function __construct(?string $mimeType) - { - $this->mimeType = $mimeType; - } - - public function guess($path): ?string + public function guess($filePath): ?string { return $this->mimeType; } diff --git a/tests/Gedmo/Uploadable/Stub/UploadableListenerStub.php b/tests/Gedmo/Uploadable/Stub/UploadableListenerStub.php index a8181be78e..b47c84b39e 100644 --- a/tests/Gedmo/Uploadable/Stub/UploadableListenerStub.php +++ b/tests/Gedmo/Uploadable/Stub/UploadableListenerStub.php @@ -15,10 +15,7 @@ final class UploadableListenerStub extends UploadableListener { - /** - * @var bool - */ - public $returnFalseOnMoveUploadedFile = false; + public bool $returnFalseOnMoveUploadedFile = false; public function doMoveFile($source, $dest, $isUploadedFile = true): bool { diff --git a/tests/Gedmo/Uploadable/UploadableEntityTest.php b/tests/Gedmo/Uploadable/UploadableEntityTest.php index 0b496238b6..40111ee55b 100644 --- a/tests/Gedmo/Uploadable/UploadableEntityTest.php +++ b/tests/Gedmo/Uploadable/UploadableEntityTest.php @@ -320,6 +320,8 @@ public function testCallbackIsCalledIfItsSetOnEntity(): void } /** + * @param class-string $exceptionClass + * * @dataProvider uploadExceptionsProvider */ public function testUploadExceptions(int $error, string $exceptionClass): void @@ -363,7 +365,7 @@ public function testFileWithFilenameSha1Generator(): void $this->em->refresh($file); - $sha1String = substr($file->getFilePath(), strrpos($file->getFilePath(), '/') + 1); + $sha1String = substr((string) $file->getFilePath(), strrpos((string) $file->getFilePath(), '/') + 1); $sha1String = str_replace('.txt', '', $sha1String); static::assertMatchesRegularExpression('/[a-z0-9]{40}/', $sha1String); @@ -381,7 +383,7 @@ public function testFileWithFilenameAlphanumericGenerator(): void $this->em->refresh($file); - $filename = substr($file->getFilePath(), strrpos($file->getFilePath(), '/') + 1); + $filename = substr((string) $file->getFilePath(), strrpos((string) $file->getFilePath(), '/') + 1); static::assertSame('test-3.txt', $filename); } @@ -398,7 +400,7 @@ public function testFileWithCustomFilenameGenerator(): void $this->em->refresh($file); - $filename = substr($file->getFilePath(), strrpos($file->getFilePath(), '/') + 1); + $filename = substr((string) $file->getFilePath(), strrpos((string) $file->getFilePath(), '/') + 1); static::assertSame('123.txt', $filename); } @@ -479,19 +481,17 @@ public function testRemoveFileIfItsNotAFileThenReturnFalse(): void } /** - * @return array> + * @return \Iterator> */ - public static function dataProvider_testMoveFileUsingAppendNumberOptionAppendsNumberToFilenameIfItAlreadyExists(): array + public static function dataProvider_testMoveFileUsingAppendNumberOptionAppendsNumberToFilenameIfItAlreadyExists(): \Iterator { - return [ - 'With extension' => [ - 'Filename' => 'test.txt', - 'Expected filename' => 'test-2.txt', - ], - 'Without extension' => [ - 'Filename' => 'test', - 'Expected filename' => 'test-2', - ], + yield 'With extension' => [ + 'Filename' => 'test.txt', + 'Expected filename' => 'test-2.txt', + ]; + yield 'Without extension' => [ + 'Filename' => 'test', + 'Expected filename' => 'test-2', ]; } @@ -520,7 +520,7 @@ public function testMoveFileUsingAppendNumberOptionAppendsNumberToFilenameIfItAl $this->em->refresh($file2); - static::assertSame($expectedFilename, basename($file2->getFilePath())); + static::assertSame($expectedFilename, basename((string) $file2->getFilePath())); } public function testMoveFileUsingAppendNumberOptionAppendsNumberToFilenameIfItAlreadyExistsRelativePath(): void @@ -663,11 +663,9 @@ public function testDisallowedTypesOptionIfMimeTypeIsInvalidThrowException(): vo } /** - * @param mixed $class - * * @dataProvider invalidFileInfoClassesProvider */ - public function testSetDefaultFileInfoClassThrowExceptionIfInvalidClassArePassed($class): void + public function testSetDefaultFileInfoClassThrowExceptionIfInvalidClassArePassed(mixed $class): void { $this->expectException(InvalidArgumentException::class); $this->listener->setDefaultFileInfoClass($class); @@ -714,37 +712,31 @@ public function testUseGeneratedFilenameWhenAppendingNumbers(): void // Data Providers /** - * @return list + * @return \Generator */ - public static function invalidFileInfoClassesProvider(): array + public static function invalidFileInfoClassesProvider(): \Generator { - return [ - [''], - [false], - [null], - ['FakeFileInfo'], - [[]], - [new \DateTime()], - ]; + yield ['']; + yield [false]; + yield [null]; + yield ['FakeFileInfo']; + yield [[]]; + yield [new \DateTime()]; } /** - * @return list - * - * @phpstan-return list}> + * @phpstan-return \Generator}> */ - public static function uploadExceptionsProvider(): array + public static function uploadExceptionsProvider(): \Generator { - return [ - [1, UploadableIniSizeException::class], - [2, UploadableFormSizeException::class], - [3, UploadablePartialException::class], - [4, UploadableNoFileException::class], - [6, UploadableNoTmpDirException::class], - [7, UploadableCantWriteException::class], - [8, UploadableExtensionException::class], - [999, UploadableUploadException::class], - ]; + yield [1, UploadableIniSizeException::class]; + yield [2, UploadableFormSizeException::class]; + yield [3, UploadablePartialException::class]; + yield [4, UploadableNoFileException::class]; + yield [6, UploadableNoTmpDirException::class]; + yield [7, UploadableCantWriteException::class]; + yield [8, UploadableExtensionException::class]; + yield [999, UploadableUploadException::class]; } protected function getUsedEntityFixtures(): array @@ -804,9 +796,7 @@ private function clearFilesAndDirectories(): void } } -class FakeFileInfo -{ -} +class FakeFileInfo {} class FakeFilenameGenerator implements FilenameGeneratorInterface { diff --git a/tests/Gedmo/Wrapper/Fixture/Document/Article.php b/tests/Gedmo/Wrapper/Fixture/Document/Article.php index eaca534c08..55fbbac9c0 100644 --- a/tests/Gedmo/Wrapper/Fixture/Document/Article.php +++ b/tests/Gedmo/Wrapper/Fixture/Document/Article.php @@ -21,12 +21,10 @@ class Article { /** - * @var string|null - * * @MongoODM\Id */ #[MongoODM\Id] - private $id; + private ?string $id = null; /** * @MongoODM\Field(type="string") diff --git a/tests/Gedmo/Wrapper/Fixture/Entity/Article.php b/tests/Gedmo/Wrapper/Fixture/Entity/Article.php index 2e302dd7b3..ff271aae38 100644 --- a/tests/Gedmo/Wrapper/Fixture/Entity/Article.php +++ b/tests/Gedmo/Wrapper/Fixture/Entity/Article.php @@ -21,8 +21,6 @@ class Article { /** - * @var int|null - * * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") @@ -30,7 +28,7 @@ class Article #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: Types::INTEGER)] - private $id; + private ?int $id = null; /** * @ORM\Column(length=128) diff --git a/tests/Gedmo/Wrapper/Fixture/Entity/Composite.php b/tests/Gedmo/Wrapper/Fixture/Entity/Composite.php index d750772a41..2db2d507b2 100644 --- a/tests/Gedmo/Wrapper/Fixture/Entity/Composite.php +++ b/tests/Gedmo/Wrapper/Fixture/Entity/Composite.php @@ -18,33 +18,28 @@ #[ORM\Entity] class Composite { - /** - * @ORM\Id - * @ORM\Column(type="integer") - */ - #[ORM\Id] - #[ORM\Column(type: Types::INTEGER)] - private int $one; - - /** - * @ORM\Id - * @ORM\Column(type="integer") - */ - #[ORM\Id] - #[ORM\Column(type: Types::INTEGER)] - private int $two; - /** * @ORM\Column(length=128) */ #[ORM\Column(length: 128)] private ?string $title = null; - public function __construct(int $one, int $two) - { - $this->one = $one; - $this->two = $two; - } + public function __construct( + /** + * @ORM\Id + * @ORM\Column(type="integer") + */ + #[ORM\Id] + #[ORM\Column(type: Types::INTEGER)] + private int $one, + /** + * @ORM\Id + * @ORM\Column(type="integer") + */ + #[ORM\Id] + #[ORM\Column(type: Types::INTEGER)] + private int $two + ) {} public function getOne(): int { diff --git a/tests/Gedmo/Wrapper/Fixture/Entity/CompositeRelation.php b/tests/Gedmo/Wrapper/Fixture/Entity/CompositeRelation.php index 1158e756bc..7b2e7c1480 100644 --- a/tests/Gedmo/Wrapper/Fixture/Entity/CompositeRelation.php +++ b/tests/Gedmo/Wrapper/Fixture/Entity/CompositeRelation.php @@ -44,9 +44,9 @@ class CompositeRelation #[ORM\Column(length: 128)] private ?string $title = null; - public function __construct(Article $articleOne, int $status) + public function __construct(Article $article, int $status) { - $this->article = $articleOne; + $this->article = $article; $this->status = $status; } diff --git a/tests/Gedmo/Wrapper/MongoDocumentWrapperTest.php b/tests/Gedmo/Wrapper/MongoDocumentWrapperTest.php index d0656bab03..a75c87891e 100644 --- a/tests/Gedmo/Wrapper/MongoDocumentWrapperTest.php +++ b/tests/Gedmo/Wrapper/MongoDocumentWrapperTest.php @@ -50,7 +50,7 @@ public function testProxy(): void { $this->dm->clear(); $test = $this->dm->getReference(Article::class, $this->articleId); - static::assertStringStartsWith('Proxy', get_class($test)); + static::assertStringStartsWith('Proxy', $test::class); static::assertInstanceOf(Article::class, $test); $wrapped = new MongoDocumentWrapper($test, $this->dm); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e5fa0eabe6..f9485f876b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -29,7 +29,7 @@ define('TESTS_TEMP_DIR', sys_get_temp_dir().'/doctrine-extension-tests'); if (!is_dir(TESTS_TEMP_DIR)) { - mkdir(TESTS_TEMP_DIR, 0755, true); + mkdir(TESTS_TEMP_DIR, 0o755, true); } require dirname(__DIR__).'/vendor/autoload.php';