Mapping   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 76
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDocumentIndex() 0 7 3
A setDocumentType() 0 3 1
A setDocumentIndex() 0 3 1
A getDocumentType() 0 3 2
A __construct() 0 6 1
1
<?php
2
namespace Triadev\Leopard\Business\Mapping;
3
4
use Illuminate\Database\Eloquent\Model;
5
use Triadev\Leopard\Business\Helper\IsModelSearchable;
6
use Triadev\Leopard\Facade\Leopard;
7
use Triadev\Leopard\Searchable;
8
9
abstract class Mapping
10
{
11
    use IsModelSearchable;
12
    
13
    /** @var Model|Searchable */
14
    protected $model;
15
    
16
    /** @var string */
17
    protected $index;
18
    
19
    /** @var string */
20
    protected $type;
21
    
22
    /**
23
     * Mapping constructor.
24
     *
25
     * @throws \InvalidArgumentException
26
     */
27 14
    public function __construct()
28
    {
29 14
        $modelClass = $this->model();
30 14
        $this->model = new $modelClass();
31
    
32 14
        $this->isModelSearchable($this->model);
33 13
    }
34
    
35
    /**
36
     * Get mapped eloquent model class
37
     *
38
     * @return string
39
     */
40
    abstract public function model() : string;
41
    
42
    /**
43
     * Map
44
     */
45
    abstract public function map();
46
    
47
    /**
48
     * @param string $index
49
     */
50 3
    public function setDocumentIndex(string $index): void
51
    {
52 3
        $this->index = $index;
53 3
    }
54
    
55
    /**
56
     * @param string $type
57
     */
58 3
    public function setDocumentType(string $type): void
59
    {
60 3
        $this->type = $type;
61 3
    }
62
    
63
    /**
64
     * Get es index
65
     *
66
     * @return string
67
     */
68 13
    public function getDocumentIndex() : string
69
    {
70 13
        if ($this->index) {
71 3
            return $this->index;
72
        }
73
        
74 11
        return $this->model->getDocumentIndex() ?: Leopard::getEsDefaultIndex();
75
    }
76
    
77
    /**
78
     * Get es type
79
     *
80
     * @return string
81
     */
82 12
    public function getDocumentType() : string
83
    {
84 12
        return $this->type ?: $this->model->getDocumentType();
85
    }
86
}
87