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
|
|
|
* @throws \RuntimeException |
38
|
|
|
*/ |
39
|
|
|
public function findSource() : Source |
40
|
|
|
{ |
41
|
|
|
$source_name = NULL; |
42
|
|
|
$index = $this; |
43
|
|
|
|
44
|
|
View Code Duplication |
do { |
|
|
|
|
45
|
|
|
foreach ($index->iterateOptions() as $option) { |
46
|
|
|
if(eIndexOption::SOURCE()->is($option->getName()) ) { |
47
|
|
|
$source_name = $option->getValue(); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
if($index->isHasInheritance()) { |
51
|
|
|
$index = $index->getInheritance(); |
52
|
|
|
} |
53
|
|
|
} while($index->isHasInheritance()); |
54
|
|
|
|
55
|
|
|
foreach ($this->getConfiguration()->iterateSource() as $source) { |
56
|
|
|
if($source->getName() === $source_name) { |
57
|
|
|
return $source; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
throw new \RuntimeException('Source for index does not found'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return bool |
66
|
|
|
*/ |
67
|
|
|
public function isHasSource() : bool |
68
|
|
|
{ |
69
|
|
|
$isHasSource = false; |
70
|
|
|
$index = $this; |
71
|
|
|
|
72
|
|
View Code Duplication |
do { |
|
|
|
|
73
|
|
|
foreach ($index->iterateOptions() as $option) { |
74
|
|
|
if (eIndexOption::SOURCE()->is($option->getName())) { |
75
|
|
|
$isHasSource = true; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
if ($index->isHasInheritance()) { |
79
|
|
|
$index = $index->getInheritance(); |
80
|
|
|
} |
81
|
|
|
} while ($index->isHasInheritance()); |
82
|
|
|
|
83
|
|
|
return $isHasSource; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function isDistributed() : bool |
90
|
|
|
{ |
91
|
|
|
$indexWithoutSource = false; |
92
|
|
|
foreach ($this->iterateOptions() as $option) { |
93
|
|
|
if ($option->getName()->is(eIndexOption::TYPE()) && $option->getValue() === 'distributed') { |
94
|
|
|
$indexWithoutSource = true; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $indexWithoutSource; |
99
|
|
|
} |
100
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.