diff --git a/lib/Doctrine/ORM/Sequencing/BigIntegerIdentityGenerator.php b/lib/Doctrine/ORM/Sequencing/BigIntegerIdentityGenerator.php index 63373fb088c..2e169fded3e 100644 --- a/lib/Doctrine/ORM/Sequencing/BigIntegerIdentityGenerator.php +++ b/lib/Doctrine/ORM/Sequencing/BigIntegerIdentityGenerator.php @@ -25,7 +25,7 @@ class BigIntegerIdentityGenerator implements Generator * to obtain the last generated identifier within the current * database session/connection, if any. */ - public function __construct($sequenceName = null) + public function __construct(?string $sequenceName = null) { $this->sequenceName = $sequenceName; } @@ -33,7 +33,7 @@ public function __construct($sequenceName = null) /** * {@inheritdoc} */ - public function generate(EntityManagerInterface $em, $entity) + public function generate(EntityManagerInterface $em, ?object $entity) { return (string) $em->getConnection()->lastInsertId($this->sequenceName); } @@ -41,7 +41,7 @@ public function generate(EntityManagerInterface $em, $entity) /** * {@inheritdoc} */ - public function isPostInsertGenerator() + public function isPostInsertGenerator() : bool { return true; } diff --git a/lib/Doctrine/ORM/Sequencing/Generator.php b/lib/Doctrine/ORM/Sequencing/Generator.php index 8431bbe94ac..4a5f1a34b43 100644 --- a/lib/Doctrine/ORM/Sequencing/Generator.php +++ b/lib/Doctrine/ORM/Sequencing/Generator.php @@ -11,11 +11,9 @@ interface Generator /** * Generates an identifier for an entity. * - * @param object $entity - * - * @return \Generator + * @return string|int */ - public function generate(EntityManagerInterface $em, $entity); + public function generate(EntityManagerInterface $em, ?object $entity); /** * Gets whether this generator is a post-insert generator which means that @@ -24,8 +22,6 @@ public function generate(EntityManagerInterface $em, $entity); * * By default, this method returns FALSE. Generators that have this requirement * must override this method and return TRUE. - * - * @return bool */ - public function isPostInsertGenerator(); + public function isPostInsertGenerator() : bool; } diff --git a/lib/Doctrine/ORM/Sequencing/IdentityGenerator.php b/lib/Doctrine/ORM/Sequencing/IdentityGenerator.php index e029716ae8a..aa4c0e96cd9 100644 --- a/lib/Doctrine/ORM/Sequencing/IdentityGenerator.php +++ b/lib/Doctrine/ORM/Sequencing/IdentityGenerator.php @@ -25,7 +25,7 @@ class IdentityGenerator implements Generator * to obtain the last generated identifier within the current * database session/connection, if any. */ - public function __construct($sequenceName = null) + public function __construct(?string $sequenceName = null) { $this->sequenceName = $sequenceName; } @@ -33,7 +33,7 @@ public function __construct($sequenceName = null) /** * {@inheritDoc} */ - public function generate(EntityManagerInterface $em, $entity) + public function generate(EntityManagerInterface $em, ?object $entity) { return (int) $em->getConnection()->lastInsertId($this->sequenceName); } @@ -41,7 +41,7 @@ public function generate(EntityManagerInterface $em, $entity) /** * {@inheritdoc} */ - public function isPostInsertGenerator() + public function isPostInsertGenerator() : bool { return true; } diff --git a/lib/Doctrine/ORM/Sequencing/Planning/ColumnValueGeneratorExecutor.php b/lib/Doctrine/ORM/Sequencing/Planning/ColumnValueGeneratorExecutor.php index 0d79b672338..404be4fd0c8 100644 --- a/lib/Doctrine/ORM/Sequencing/Planning/ColumnValueGeneratorExecutor.php +++ b/lib/Doctrine/ORM/Sequencing/Planning/ColumnValueGeneratorExecutor.php @@ -25,7 +25,7 @@ public function __construct(LocalColumnMetadata $column, Generator $generator) /** * @return mixed[] */ - public function execute(EntityManagerInterface $entityManager, /*object*/ $entity) : array + public function execute(EntityManagerInterface $entityManager, object $entity) : array { $value = $this->generator->generate($entityManager, $entity); diff --git a/lib/Doctrine/ORM/Sequencing/Planning/CompositeValueGenerationPlan.php b/lib/Doctrine/ORM/Sequencing/Planning/CompositeValueGenerationPlan.php index 7cf91505fa1..2397e1efdf7 100644 --- a/lib/Doctrine/ORM/Sequencing/Planning/CompositeValueGenerationPlan.php +++ b/lib/Doctrine/ORM/Sequencing/Planning/CompositeValueGenerationPlan.php @@ -25,7 +25,7 @@ public function __construct(ClassMetadata $metadata, array $executors) $this->executors = $executors; } - public function executeImmediate(EntityManagerInterface $entityManager, /*object*/ $entity) : void + public function executeImmediate(EntityManagerInterface $entityManager, object $entity) : void { foreach ($this->executors as $executor) { if ($executor->isDeferred()) { @@ -36,7 +36,7 @@ public function executeImmediate(EntityManagerInterface $entityManager, /*object } } - public function executeDeferred(EntityManagerInterface $entityManager, /*object*/ $entity) : void + public function executeDeferred(EntityManagerInterface $entityManager, object $entity) : void { foreach ($this->executors as $executor) { if (! $executor->isDeferred()) { @@ -47,8 +47,11 @@ public function executeDeferred(EntityManagerInterface $entityManager, /*object* } } - private function dispatchExecutor(ValueGenerationExecutor $executor, /*object*/ $entity, EntityManagerInterface $entityManager) : void - { + private function dispatchExecutor( + ValueGenerationExecutor $executor, + object $entity, + EntityManagerInterface $entityManager + ) : void { foreach ($executor->execute($entityManager, $entity) as $columnName => $value) { // TODO LocalColumnMetadata are currently shadowed and only exposed as FieldMetadata /** @var FieldMetadata $column */ diff --git a/lib/Doctrine/ORM/Sequencing/Planning/NoopValueGenerationPlan.php b/lib/Doctrine/ORM/Sequencing/Planning/NoopValueGenerationPlan.php index 75a73153f57..053fc29cadd 100644 --- a/lib/Doctrine/ORM/Sequencing/Planning/NoopValueGenerationPlan.php +++ b/lib/Doctrine/ORM/Sequencing/Planning/NoopValueGenerationPlan.php @@ -8,12 +8,12 @@ class NoopValueGenerationPlan implements ValueGenerationPlan { - public function executeImmediate(EntityManagerInterface $entityManager, /*object*/ $entity) : void + public function executeImmediate(EntityManagerInterface $entityManager, object $entity) : void { // no-op } - public function executeDeferred(EntityManagerInterface $entityManager, /*object*/ $entity) : void + public function executeDeferred(EntityManagerInterface $entityManager, object $entity) : void { // no-op } diff --git a/lib/Doctrine/ORM/Sequencing/Planning/SingleValueGenerationPlan.php b/lib/Doctrine/ORM/Sequencing/Planning/SingleValueGenerationPlan.php index 5dbbb2a64fe..02323a28d56 100644 --- a/lib/Doctrine/ORM/Sequencing/Planning/SingleValueGenerationPlan.php +++ b/lib/Doctrine/ORM/Sequencing/Planning/SingleValueGenerationPlan.php @@ -22,20 +22,21 @@ public function __construct(ClassMetadata $class, ValueGenerationExecutor $execu $this->executor = $executor; } - public function executeImmediate(EntityManagerInterface $entityManager, /*object*/ $entity) : void + public function executeImmediate(EntityManagerInterface $entityManager, object $entity) : void { if (! $this->executor->isDeferred()) { $this->dispatchExecutor($entity, $entityManager); } } - public function executeDeferred(EntityManagerInterface $entityManager, /*object*/ $entity) : void + public function executeDeferred(EntityManagerInterface $entityManager, object $entity) : void { if ($this->executor->isDeferred()) { $this->dispatchExecutor($entity, $entityManager); } } - private function dispatchExecutor($entity, EntityManagerInterface $entityManager) : void + + private function dispatchExecutor(object $entity, EntityManagerInterface $entityManager) : void { foreach ($this->executor->execute($entityManager, $entity) as $columnName => $value) { // TODO LocalColumnMetadata are currently shadowed and only exposed as FieldMetadata diff --git a/lib/Doctrine/ORM/Sequencing/Planning/ValueGenerationExecutor.php b/lib/Doctrine/ORM/Sequencing/Planning/ValueGenerationExecutor.php index 635e95651fa..73fe8a4786d 100644 --- a/lib/Doctrine/ORM/Sequencing/Planning/ValueGenerationExecutor.php +++ b/lib/Doctrine/ORM/Sequencing/Planning/ValueGenerationExecutor.php @@ -11,7 +11,7 @@ interface ValueGenerationExecutor /** * @return mixed[] */ - public function execute(EntityManagerInterface $entityManager, /*object*/ $entity) : array; + public function execute(EntityManagerInterface $entityManager, object $entity) : array; public function isDeferred() : bool; } diff --git a/lib/Doctrine/ORM/Sequencing/Planning/ValueGenerationPlan.php b/lib/Doctrine/ORM/Sequencing/Planning/ValueGenerationPlan.php index fff9006d21e..5634f085901 100644 --- a/lib/Doctrine/ORM/Sequencing/Planning/ValueGenerationPlan.php +++ b/lib/Doctrine/ORM/Sequencing/Planning/ValueGenerationPlan.php @@ -8,9 +8,9 @@ interface ValueGenerationPlan { - public function executeImmediate(EntityManagerInterface $entityManager, /*object*/ $entity) : void; + public function executeImmediate(EntityManagerInterface $entityManager, object $entity) : void; - public function executeDeferred(EntityManagerInterface $entityManager, /*object*/ $entity) : void; + public function executeDeferred(EntityManagerInterface $entityManager, object $entity) : void; public function containsDeferred() : bool; } diff --git a/lib/Doctrine/ORM/Sequencing/SequenceGenerator.php b/lib/Doctrine/ORM/Sequencing/SequenceGenerator.php index 3f9485632c6..d15039d210d 100644 --- a/lib/Doctrine/ORM/Sequencing/SequenceGenerator.php +++ b/lib/Doctrine/ORM/Sequencing/SequenceGenerator.php @@ -38,13 +38,7 @@ class SequenceGenerator implements Generator, Serializable */ private $maxValue; - /** - * Initializes a new sequence generator. - * - * @param string $sequenceName The name of the sequence. - * @param int $allocationSize The allocation size of the sequence. - */ - public function __construct($sequenceName, $allocationSize) + public function __construct(string $sequenceName, int $allocationSize) { $this->sequenceName = $sequenceName; $this->allocationSize = $allocationSize; @@ -53,7 +47,7 @@ public function __construct($sequenceName, $allocationSize) /** * {@inheritdoc} */ - public function generate(EntityManagerInterface $em, $entity) + public function generate(EntityManagerInterface $em, ?object $entity) { if ($this->maxValue === null || $this->nextValue === $this->maxValue) { // Allocate new values @@ -70,33 +64,26 @@ public function generate(EntityManagerInterface $em, $entity) /** * Gets the maximum value of the currently allocated bag of values. - * - * @return int|null */ - public function getCurrentMaxValue() + public function getCurrentMaxValue() : ?int { return $this->maxValue; } /** * Gets the next value that will be returned by generate(). - * - * @return int */ - public function getNextValue() + public function getNextValue() : int { return $this->nextValue; } - /** - * @return string - */ - public function serialize() + public function serialize() : string { return serialize( [ - 'allocationSize' => $this->allocationSize, - 'sequenceName' => $this->sequenceName, + 'allocationSize' => $this->allocationSize, + 'sequenceName' => $this->sequenceName, ] ); } @@ -104,7 +91,7 @@ public function serialize() /** * @param string $serialized */ - public function unserialize($serialized) + public function unserialize($serialized) : void { $array = unserialize($serialized); @@ -115,7 +102,7 @@ public function unserialize($serialized) /** * {@inheritdoc} */ - public function isPostInsertGenerator() + public function isPostInsertGenerator() : bool { return false; } diff --git a/lib/Doctrine/ORM/Sequencing/TableGenerator.php b/lib/Doctrine/ORM/Sequencing/TableGenerator.php index 04988f04883..165b94aeb82 100644 --- a/lib/Doctrine/ORM/Sequencing/TableGenerator.php +++ b/lib/Doctrine/ORM/Sequencing/TableGenerator.php @@ -36,12 +36,7 @@ class TableGenerator implements Generator */ private $maxValue; - /** - * @param string $tableName - * @param string $sequenceName - * @param int $allocationSize - */ - public function __construct($tableName, $sequenceName = 'default', $allocationSize = 10) + public function __construct(string $tableName, string $sequenceName = 'default', int $allocationSize = 10) { $this->tableName = $tableName; $this->sequenceName = $sequenceName; @@ -51,7 +46,7 @@ public function __construct($tableName, $sequenceName = 'default', $allocationSi /** * {@inheritdoc} */ - public function generate(EntityManagerInterface $em, $entity) + public function generate(EntityManagerInterface $em, ?object $entity) { if ($this->maxValue === null || $this->nextValue === $this->maxValue) { // Allocate new values @@ -91,7 +86,7 @@ public function generate(EntityManagerInterface $em, $entity) /** * {@inheritdoc} */ - public function isPostInsertGenerator() + public function isPostInsertGenerator() : bool { return false; } diff --git a/lib/Doctrine/ORM/Sequencing/UuidGenerator.php b/lib/Doctrine/ORM/Sequencing/UuidGenerator.php index 6feeb54b0e3..b27fa10d86d 100644 --- a/lib/Doctrine/ORM/Sequencing/UuidGenerator.php +++ b/lib/Doctrine/ORM/Sequencing/UuidGenerator.php @@ -14,7 +14,7 @@ class UuidGenerator implements Generator /** * {@inheritdoc} */ - public function generate(EntityManagerInterface $em, $entity) + public function generate(EntityManagerInterface $em, ?object $entity) { $conn = $em->getConnection(); $sql = 'SELECT ' . $conn->getDatabasePlatform()->getGuidExpression(); @@ -25,7 +25,7 @@ public function generate(EntityManagerInterface $em, $entity) /** * {@inheritdoc} */ - public function isPostInsertGenerator() + public function isPostInsertGenerator() : bool { return false; } diff --git a/tests/Doctrine/Tests/Mocks/SequenceMock.php b/tests/Doctrine/Tests/Mocks/SequenceMock.php index d06ccdba337..151f062be33 100644 --- a/tests/Doctrine/Tests/Mocks/SequenceMock.php +++ b/tests/Doctrine/Tests/Mocks/SequenceMock.php @@ -20,7 +20,7 @@ class SequenceMock extends SequenceGenerator /** * {@inheritdoc} */ - public function generate(EntityManagerInterface $em, $entity) + public function generate(EntityManagerInterface $em, ?object $entity) { return $this->sequenceNumber++; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php index 15b820785e9..5fed3824763 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php @@ -47,7 +47,7 @@ final class GH5804Generator implements Generator /** * {@inheritdoc} */ - public function generate(EntityManagerInterface $em, $entity) + public function generate(EntityManagerInterface $em, ?object $entity) { return 'test5804'; } @@ -55,7 +55,7 @@ public function generate(EntityManagerInterface $em, $entity) /** * {@inheritdoc} */ - public function isPostInsertGenerator() + public function isPostInsertGenerator() : bool { return false; } @@ -100,7 +100,7 @@ class GH5804Article * @ORM\Id * @ORM\Column(type="GH5804Type") * @ORM\GeneratedValue(strategy="CUSTOM") - * @ORM\CustomIdGenerator(class=\Doctrine\Tests\ORM\Functional\Ticket\GH5804Generator::class) + * @ORM\CustomIdGenerator(class=GH5804Generator::class) */ public $id; diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 9436fc95f09..cd5613c6ca7 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -510,14 +510,14 @@ class CustomIdGenerator implements Generator /** * {@inheritdoc} */ - public function generate(EntityManagerInterface $em, $entity): \Generator + public function generate(EntityManagerInterface $em, ?object $entity) { } /** * {@inheritdoc} */ - public function isPostInsertGenerator() + public function isPostInsertGenerator() : bool { return false; }