AbstractInheritance   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 58
ccs 15
cts 15
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
setType() 0 1 ?
A __construct() 0 5 1
A column() 0 6 1
A map() 0 14 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