MapperSet   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 8
c 4
b 0
f 0
lcom 1
cbo 2
dl 0
loc 83
ccs 23
cts 23
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A hasMapperFor() 0 4 1
A hasMappers() 0 4 1
A getMappers() 0 4 1
A getClassNames() 0 4 1
A addMapper() 0 4 1
A getMapperFor() 0 14 2
1
<?php
2
3
namespace LaravelDoctrine\Fluent\Mappers;
4
5
use Doctrine\ORM\Mapping\MappingException;
6
use LaravelDoctrine\Fluent\EmbeddableMapping;
7
use LaravelDoctrine\Fluent\EntityMapping;
8
use LaravelDoctrine\Fluent\MappedSuperClassMapping;
9
use LaravelDoctrine\Fluent\Mapping;
10
11
class MapperSet
12
{
13
    /**
14
     * @type Mapper[]
15
     */
16
    protected $mappers = [];
17
18
    /**
19
     * @param Mapping $mapping
20
     *
21
     * @throws MappingException
22
     */
23 15
    public function add(Mapping $mapping)
24
    {
25 15
        $mapping->addMapperTo($this);
26 15
    }
27
28
    /**
29
     * @param string $className
30
     *
31
     * @throws MappingException
32
     * @return Mapper
33
     */
34 11
    public function getMapperFor($className)
35
    {
36 11
        if (!$this->hasMapperFor($className)) {
37 2
            throw new MappingException(
38 2
                "Class [$className] does not have a mapping configuration. " .
39 2
                "Make sure you create a Mapping class that extends either " .
40 2
                EntityMapping::class . ", " . EmbeddableMapping::class . " or " . MappedSuperClassMapping::class . ". " .
41 2
                "If you are using inheritance mapping, remember to create mappings for " .
42
                "every child of the inheritance tree."
43 2
            );
44
        }
45
46 9
        return $this->mappers[$className];
47
    }
48
49
    /**
50
     * @param string $className
51
     *
52
     * @return bool
53
     */
54 13
    public function hasMapperFor($className)
55
    {
56 13
        return isset($this->mappers[$className]);
57
    }
58
59
    /**
60
     * @return bool
61
     */
62 1
    public function hasMappers()
63
    {
64 1
        return count($this->mappers) > 0;
65
    }
66
67
    /**
68
     * @return Mapper[]
69
     */
70 1
    public function getMappers()
71
    {
72 1
        return $this->mappers;
73
    }
74
75
    /**
76
     * @return string[]
77
     */
78 4
    public function getClassNames()
79
    {
80 4
        return array_keys($this->mappers);
81
    }
82
83
    /**
84
     * Add a mapper to the given class.
85
     *
86
     * @param string $class
87
     * @param Mapper $mapper
88
     */
89 16
    public function addMapper($class, Mapper $mapper)
90
    {
91 16
        $this->mappers[$class] = $mapper;
92 16
    }
93
}
94