Completed
Push — master ( 0f71cc...99d0b0 )
by Karel
15:42
created

Index   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 40%

Importance

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

3 Methods

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