Passed
Pull Request — master (#188)
by David
05:15
created

getNonScalarReferencedPropertyDescriptor()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 3
nc 2
nop 0
1
<?php
2
3
4
namespace TheCodingMachine\TDBM\Utils;
5
6
use Doctrine\DBAL\Schema\Column;
7
use Doctrine\DBAL\Schema\Table;
8
use TheCodingMachine\TDBM\Utils\Annotation\AnnotationParser;
9
10
/**
11
 * This class represents a reference to a AbstractBeanPropertyDescriptor used in an inheritance schema
12
 */
13
class InheritanceReferencePropertyDescriptor extends ScalarBeanPropertyDescriptor
14
{
15
    /** @var AbstractBeanPropertyDescriptor */
16
    private $referencedPropertyDescriptor;
17
18
    public function __construct(
19
        Table $table,
20
        Column $column,
21
        NamingStrategyInterface $namingStrategy,
22
        AnnotationParser $annotationParser,
23
        AbstractBeanPropertyDescriptor $referencedPropertyDescriptor
24
    ) {
25
        parent::__construct($table, $column, $namingStrategy, $annotationParser);
26
        $this->referencedPropertyDescriptor = $referencedPropertyDescriptor;
27
    }
28
29
    /**
30
     * @return ScalarBeanPropertyDescriptor|ObjectBeanPropertyDescriptor
31
     */
32
    public function getNonScalarReferencedPropertyDescriptor(): AbstractBeanPropertyDescriptor
33
    {
34
        if ($this->referencedPropertyDescriptor instanceof InheritanceReferencePropertyDescriptor) {
35
            return $this->referencedPropertyDescriptor->getNonScalarReferencedPropertyDescriptor();
36
        }
37
        assert($this->referencedPropertyDescriptor instanceof ScalarBeanPropertyDescriptor || $this->referencedPropertyDescriptor instanceof ObjectBeanPropertyDescriptor);
38
        return $this->referencedPropertyDescriptor;
39
    }
40
41
    public function getJsonSerializeCode(): string
42
    {
43
        return $this->getNonScalarReferencedPropertyDescriptor()->getJsonSerializeCode();
44
    }
45
}
46