Skip to content

Commit

Permalink
Merge pull request #7092 from lcobucci/declare-some-types
Browse files Browse the repository at this point in the history
Declare some types
  • Loading branch information
Ocramius authored Feb 25, 2018
2 parents 46ea9d1 + 408704b commit 3e1d124
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 64 deletions.
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Sequencing/BigIntegerIdentityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ 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;
}

/**
* {@inheritdoc}
*/
public function generate(EntityManagerInterface $em, $entity)
public function generate(EntityManagerInterface $em, ?object $entity)
{
return (string) $em->getConnection()->lastInsertId($this->sequenceName);
}

/**
* {@inheritdoc}
*/
public function isPostInsertGenerator()
public function isPostInsertGenerator() : bool
{
return true;
}
Expand Down
10 changes: 3 additions & 7 deletions lib/Doctrine/ORM/Sequencing/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Sequencing/IdentityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ 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;
}

/**
* {@inheritDoc}
*/
public function generate(EntityManagerInterface $em, $entity)
public function generate(EntityManagerInterface $em, ?object $entity)
{
return (int) $em->getConnection()->lastInsertId($this->sequenceName);
}

/**
* {@inheritdoc}
*/
public function isPostInsertGenerator()
public function isPostInsertGenerator() : bool
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand All @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Sequencing/Planning/ValueGenerationPlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
31 changes: 9 additions & 22 deletions lib/Doctrine/ORM/Sequencing/SequenceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -70,41 +64,34 @@ 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,
]
);
}

/**
* @param string $serialized
*/
public function unserialize($serialized)
public function unserialize($serialized) : void
{
$array = unserialize($serialized);

Expand All @@ -115,7 +102,7 @@ public function unserialize($serialized)
/**
* {@inheritdoc}
*/
public function isPostInsertGenerator()
public function isPostInsertGenerator() : bool
{
return false;
}
Expand Down
11 changes: 3 additions & 8 deletions lib/Doctrine/ORM/Sequencing/TableGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -91,7 +86,7 @@ public function generate(EntityManagerInterface $em, $entity)
/**
* {@inheritdoc}
*/
public function isPostInsertGenerator()
public function isPostInsertGenerator() : bool
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Sequencing/UuidGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -25,7 +25,7 @@ public function generate(EntityManagerInterface $em, $entity)
/**
* {@inheritdoc}
*/
public function isPostInsertGenerator()
public function isPostInsertGenerator() : bool
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Mocks/SequenceMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ final class GH5804Generator implements Generator
/**
* {@inheritdoc}
*/
public function generate(EntityManagerInterface $em, $entity)
public function generate(EntityManagerInterface $em, ?object $entity)
{
return 'test5804';
}

/**
* {@inheritdoc}
*/
public function isPostInsertGenerator()
public function isPostInsertGenerator() : bool
{
return false;
}
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 3e1d124

Please sign in to comment.