Completed
Pull Request — master (#1134)
by Istvan
14:27
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

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 2
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
     * @return mixed
38
     */
39 13
    public function getType($type)
40
    {
41 13
        if (isset($this->typeCache[$type])) {
42 2
            return $this->typeCache[$type];
43
        }
44
45 13
        return $this->typeCache[$type] = parent::getType($type);
46
    }
47
48
    /**
49
     * Reassign index name.
50
     *
51
     * While it's technically a regular setter for name property, it's specifically named overrideName, but not setName
52
     * since it's used for a very specific case and normally should not be used
53
     *
54
     * @param string $name Index name
55
     */
56
    public function overrideName($name)
57
    {
58
        $this->originalName = $this->_name;
59
        $this->_name = $name;
60
    }
61
}
62