TypeContext::getDocuments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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