Passed
Push — master ( 334afa...1ec06c )
by Sergey
08:34
created

Index::findSource()   C

Complexity

Conditions 7
Paths 18

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 0
cts 0
cp 0
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 14
nc 18
nop 0
crap 56
1
<?php
2
/**
3
 * @author: Viskov Sergey
4
 * @date  : 3/18/16
5
 * @time  : 5:32 PM
6
 */
7
8
namespace LTDBeget\sphinx\configurator\configurationEntities\sections;
9
10
use LTDBeget\sphinx\configurator\configurationEntities\base\Definition;
11
use LTDBeget\sphinx\configurator\configurationEntities\Option;
12
use LTDBeget\sphinx\enums\options\eIndexOption;
13
14
/**
15
 * Class Index
16
 *
17
 * @package LTDBeget\sphinx\configurator\configurationEntities\base\sections
18
 */
19
class Index extends Definition
20
{
21
    /**
22
     * @param eIndexOption $name
23
     * @param string       $value
24
     *
25
     * @return Option
26
     * @throws \LogicException
27
     * @throws \InvalidArgumentException
28
     * @throws \LTDBeget\sphinx\informer\exceptions\InformerRuntimeException
29
     */
30 7
    public function addOption(eIndexOption $name, string $value) : Option
31
    {
32 7
        return $this->addOptionInternal($name, $value);
33
    }
34
35
    /**
36
     * @return Source
37
     */
38
    public function findSource() : Source
39
    {
40
        $source_name = NULL;
41
        $index       = $this;
42
43
        do {
44
            foreach ($index->iterateOptions() as $option) {
45
                if(eIndexOption::SOURCE()->is($option->getName()) ) {
46
                    $source_name = $option->getValue();
47
                }
48
            }
49
            if($index->isHasInheritance()) {
50
                $index = $index->getInheritance();
51
            }
52
        } while($index->isHasInheritance());
53
54
        foreach ($this->getConfiguration()->iterateSource() as $source) {
55
            if($source->getName() === $source_name) {
56
                return $source;
57
            }
58
        }
59
60
        throw new \RuntimeException('Source for index does not found');
61
    }
62
}