Completed
Pull Request — master (#1569)
by
unknown
03:33
created

Index::getOriginalName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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
     * Returns the original name of the index if the index has been renamed for reindexing
27
     * or realiasing purposes.
28
     */
29
    public function getOriginalName(): string
30
    {
31
        return $this->originalName ?? $this->_name;
32
    }
33
34
    /**
35
     * Reassign index name.
36
     *
37
     * While it's technically a regular setter for name property, it's specifically named overrideName, but not setName
38
     * since it's used for a very specific case and normally should not be used
39
     */
40
    public function overrideName(string $name)
41
    {
42
        $this->originalName = $this->_name;
43
        $this->_name = $name;
44
    }
45
}
46