TypeContext   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 4
A getType() 0 4 1
A getMapping() 0 8 2
A getDocuments() 0 4 1
1
<?php
2
3
namespace Zenstruck\ElasticaBundle\Elastica;
4
5
use Elastica\Document;
6
use Elastica\Type;
7
use Elastica\Type\Mapping;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
class TypeContext
13
{
14
    private $type;
15
    private $documentProvider;
16
    private $mapping;
17
18
    /**
19
     * @param Type                  $type
20
     * @param DocumentProvider      $documentProvider
21
     * @param MappingProvider|array $mapping
22
     */
23 12
    public function __construct(Type $type, DocumentProvider $documentProvider, $mapping)
24
    {
25 12
        if (!is_array($mapping) && !$mapping instanceof MappingProvider && !$mapping instanceof Mapping) {
26 1
            throw new \InvalidArgumentException('The mapping must be an array, an instance of Zenstruck\ElasticaBundle\Elastica\MappingProvider or an instance of Elastica\Type\Mapping.');
27
        }
28
29 11
        $this->type = $type;
30 11
        $this->documentProvider = $documentProvider;
31 11
        $this->mapping = $mapping;
32 11
    }
33
34
    /**
35
     * @return Type
36
     */
37 5
    public function getType()
38
    {
39 5
        return $this->type;
40
    }
41
42
    /**
43
     * @return array|Mapping
44
     */
45 7
    public function getMapping()
46
    {
47 7
        if ($this->mapping instanceof MappingProvider) {
48 1
            return $this->mapping->getMapping();
49
        }
50
51 6
        return $this->mapping;
52
    }
53
54
    /**
55
     * @return Document[]
56
     */
57 5
    public function getDocuments()
58
    {
59 5
        return $this->documentProvider->getDocuments();
60
    }
61
}
62