Completed
Push — 3.1.x ( b8b6d2...fd2df9 )
by Karel
14:12 queued 11:28
created

Index   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 40%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
lcom 2
cbo 1
dl 0
loc 48
c 1
b 1
f 0
ccs 4
cts 10
cp 0.4
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getOriginalName() 0 4 2
A getType() 0 8 2
A overrideName() 0 5 1
1
<?php
2
3
namespace FOS\ElasticaBundle\Elastica;
4
5
use Elastica\Index as BaseIndex;
6
7
/**
8
 * Overridden Elastica Index class that provides dynamic index name changes.
9
 *
10
 * @author Konstantin Tjuterev <[email protected]>
11
 */
12
class Index extends BaseIndex
13
{
14
    private $originalName;
15
16
    /**
17
     * Stores created types to avoid recreation.
18
     *
19
     * @var array
20
     */
21
    private $typeCache = array();
22
23
    /**
24
     * Returns the original name of the index if the index has been renamed for reindexing
25
     * or realiasing purposes.
26
     *
27
     * @return string
28
     */
29
    public function getOriginalName()
30
    {
31
        return $this->originalName ?: $this->_name;
32
    }
33
34
    /**
35
     * @param string $type
36
     */
37 4
    public function getType($type)
38
    {
39 4
        if (isset($this->typeCache[$type])) {
40 1
            return $this->typeCache[$type];
41
        }
42
43 4
        return $this->typeCache[$type] = parent::getType($type);
44
    }
45
46
    /**
47
     * Reassign index name.
48
     *
49
     * While it's technically a regular setter for name property, it's specifically named overrideName, but not setName
50
     * since it's used for a very specific case and normally should not be used
51
     *
52
     * @param string $name Index name
53
     */
54
    public function overrideName($name)
55
    {
56
        $this->originalName = $this->_name;
57
        $this->_name = $name;
58
    }
59
}
60