AbstractInheritance::map()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 2
crap 3
1
<?php
2
3
namespace LaravelDoctrine\Fluent\Builders\Inheritance;
4
5
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
6
7
/**
8
 * @method $this addDiscriminatorMapClass($name, $class)
9
 * @method $this setDiscriminatorColumn($column, $type = 'string', $length = 255)
10
 */
11
abstract class AbstractInheritance implements Inheritance
12
{
13
    /**
14
     * @var ClassMetadataBuilder
15
     */
16
    protected $builder;
17
18
    /**
19
     * @param ClassMetadataBuilder $builder
20
     */
21 19
    public function __construct(ClassMetadataBuilder $builder)
22
    {
23 19
        $this->builder = $builder;
24 19
        $this->setType();
25 19
    }
26
27
    /**
28
     * Set inheritance type
29
     */
30
    abstract protected function setType();
31
32
    /**
33
     * Add the discriminator column
34
     *
35
     * @param string $column
36
     * @param string $type
37
     * @param int    $length
38
     *
39
     * @return Inheritance
40
     */
41 4
    public function column($column, $type = 'string', $length = 255)
42
    {
43 4
        $this->builder->setDiscriminatorColumn($column, $type, $length);
44
45 4
        return $this;
46
    }
47
48
    /**
49
     * @param string      $name
50
     * @param string|null $class
51
     *
52
     * @return Inheritance
53
     */
54 6
    public function map($name, $class = null)
55
    {
56 6
        if (is_array($name)) {
57 2
            foreach ($name as $name => $class) {
58 2
                $this->map($name, $class);
59 2
            }
60
61 2
            return $this;
62
        }
63
64 6
        $this->builder->addDiscriminatorMapClass($name, $class);
65
66 6
        return $this;
67
    }
68
}
69