Completed
Pull Request — master (#992)
by David
05:34
created

Index::getOriginalName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 2
eloc 2
nc 2
nop 0
crap 6
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