Metadata   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 55
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntityMetadatas() 0 4 1
A setEntityMetadatas() 0 8 2
A addEntityMetadata() 0 10 2
A getEntityMetadata() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\DoctrineDDM\Configuration;
6
7
use Facile\DoctrineDDM\Exception;
8
9
/**
10
 * Class Metadata.
11
 */
12
class Metadata
13
{
14
    /**
15
     * @var EntityMetadata[]
16
     */
17
    protected $entityMetadatas = [];
18
19
    /**
20
     * @return EntityMetadata[]
21
     */
22 5
    public function getEntityMetadatas(): array
23
    {
24 5
        return $this->entityMetadatas;
25
    }
26
27
    /**
28
     * @param EntityMetadata[] $entityMetadatas
29
     *
30
     * @throws \Facile\DoctrineDDM\Exception\InvalidArgumentException
31
     */
32 6
    public function setEntityMetadatas(array $entityMetadatas)
33
    {
34 6
        $this->entityMetadatas = [];
35
36 6
        foreach ($entityMetadatas as $entityMetadata) {
37 5
            $this->addEntityMetadata($entityMetadata);
38
        }
39 6
    }
40
41
    /**
42
     * @param EntityMetadata $entityMetadata
43
     *
44
     * @throws \Facile\DoctrineDDM\Exception\InvalidArgumentException
45
     */
46 6
    public function addEntityMetadata(EntityMetadata $entityMetadata)
47
    {
48 6
        if (array_key_exists($entityMetadata->getEntityClass(), $this->entityMetadatas)) {
49 1
            throw new Exception\InvalidArgumentException(sprintf(
50 1
                'Entity "%s" is already defined',
51 1
                $entityMetadata->getEntityClass()
52
            ));
53
        }
54 6
        $this->entityMetadatas[$entityMetadata->getEntityClass()] = $entityMetadata;
55 6
    }
56
57
    /**
58
     * @param string $entityClass
59
     *
60
     * @return EntityMetadata|null
61
     */
62 5
    public function getEntityMetadata(string $entityClass)
63
    {
64 5
        return $this->entityMetadatas[$entityClass] ?? null;
65
    }
66
}
67