Failed Conditions
Pull Request — develop (#6947)
by Filippo
10:01
created

AbstractEntityInheritancePersister   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSelectJoinColumnSQL() 0 17 1
A prepareInsertData() 0 14 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Persisters\Entity;
6
7
use Doctrine\ORM\Mapping\JoinColumnMetadata;
8
9
/**
10
 * Base class for entity persisters that implement a certain inheritance mapping strategy.
11
 * All these persisters are assumed to use a discriminator column to discriminate entity
12
 * types in the hierarchy.
13
 *
14
 * @author Roman Borschel <[email protected]>
15
 * @author Benjamin Eberlei <[email protected]>
16
 * @since 2.0
17
 */
18
abstract class AbstractEntityInheritancePersister extends BasicEntityPersister
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23 328
    protected function prepareInsertData($entity) : array
24
    {
25 328
        $data = parent::prepareInsertData($entity);
26
27
        // Populate the discriminator column
28 328
        $discColumn = $this->class->discriminatorColumn;
29 328
        $tableName  = $discColumn->getTableName();
30 328
        $columnName = $discColumn->getColumnName();
31
32 328
        $this->columns[$columnName] = $discColumn;
33
34 328
        $data[$tableName][$columnName] = $this->class->discriminatorValue;
35
36 328
        return $data;
37
    }
38
39
    /**
40
     * @param JoinColumnMetadata $joinColumnMetadata
41
     *
42
     * @return string
43
     */
44 59
    protected function getSelectJoinColumnSQL(JoinColumnMetadata $joinColumnMetadata)
45
    {
46 59
        $tableAlias       = $this->getSQLTableAlias($joinColumnMetadata->getTableName());
47 59
        $columnAlias      = $this->getSQLColumnAlias();
48 59
        $columnType       = $joinColumnMetadata->getType();
49 59
        $quotedColumnName = $this->platform->quoteIdentifier($joinColumnMetadata->getColumnName());
50 59
        $sql              = sprintf('%s.%s', $tableAlias, $quotedColumnName);
51
52 59
        $this->currentPersisterContext->rsm->addMetaResult(
53 59
            'r',
54 59
            $columnAlias,
55 59
            $joinColumnMetadata->getColumnName(),
56 59
            $joinColumnMetadata->isPrimaryKey(),
57 59
            $columnType
58
        );
59
60 59
        return $columnType->convertToPHPValueSQL($sql, $this->platform) . ' AS ' . $columnAlias;
61
    }
62
}
63