Passed
Push — feature/initial-implementation ( 0c2c6c...79751f )
by Fike
01:54
created

MappingProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getMapping() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Mapping;
6
7
use AmaTeam\ElasticSearch\API\Mapping\DocumentMappingInterface;
8
use AmaTeam\ElasticSearch\API\Mapping\DocumentMappingProviderInterface;
9
use AmaTeam\ElasticSearch\Mapping\Annotation\Reader;
10
11
class MappingProvider implements DocumentMappingProviderInterface
12
{
13
    /**
14
     * @var Reader
15
     */
16
    private $reader;
17
    /**
18
     * @var DocumentMappingInterface[]
19
     */
20
    private $registry;
21
22
    /**
23
     * @param Reader $reader
24
     */
25
    public function __construct(Reader $reader = null)
26
    {
27
        $this->reader = $reader ?? new Reader();
28
    }
29
30
    public function getMapping(string $className): DocumentMappingInterface
31
    {
32
        if (isset($this->registry[$className])) {
33
            return $this->registry[$className];
34
        }
35
        $mapping = $this->reader->read($className);
36
        $this->registry[$className] = $mapping;
37
        return $mapping;
38
    }
39
}
40