Failed Conditions
Push — master ( fa7802...d60694 )
by Guilherme
09:27
created

ColumnValueGeneratorExecutor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 30
ccs 11
cts 11
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 8 1
A isDeferred() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Sequencing\Executor;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\ORM\Mapping\LocalColumnMetadata;
9
use Doctrine\ORM\Sequencing\Generator\Generator;
10
11
class ColumnValueGeneratorExecutor implements ValueGenerationExecutor
12
{
13
    /** @var LocalColumnMetadata */
14
    private $column;
15
16
    /** @var Generator */
17
    private $generator;
18
19 292
    public function __construct(LocalColumnMetadata $column, Generator $generator)
20
    {
21 292
        $this->column    = $column;
22 292
        $this->generator = $generator;
23 292
    }
24
25
    /**
26
     * @return mixed[]
27
     */
28 916
    public function execute(EntityManagerInterface $entityManager, object $entity) : array
29
    {
30 916
        $value = $this->generator->generate($entityManager, $entity);
31
32 916
        $platform       = $entityManager->getConnection()->getDatabasePlatform();
33 916
        $convertedValue = $this->column->getType()->convertToPHPValue($value, $platform);
34
35 916
        return [$this->column->getColumnName() => $convertedValue];
36
    }
37
38 934
    public function isDeferred() : bool
39
    {
40 934
        return $this->generator->isPostInsertGenerator();
41
    }
42
}
43