Passed
Push — master ( 1ec06c...616254 )
by Sergey
08:02 queued 03:42
created

Index::isDistributed()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 0
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 0
crap 20
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
63
    /**
64
     * @return bool
65
     */
66
    public function isDistributed() : bool
67
    {
68
        $indexWithoutSource = false;
69
        foreach ($this->iterateOptions() as $option) {
70
            if ($option->getName()->is(eIndexOption::TYPE()) && $option->getValue() === 'distributed') {
71
                $indexWithoutSource = true;
72
            }
73
        }
74
75
        return $indexWithoutSource;
76
    }
77
}