Total Complexity | 9 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Coverage | 52.38% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class SectionDetector |
||
10 | { |
||
11 | /** |
||
12 | * @param SectionsCollection $collection |
||
13 | * @return string |
||
14 | */ |
||
15 | public static function run($collection) |
||
16 | { |
||
17 | $detector = new static(); |
||
18 | return $detector->detect($collection); |
||
|
|||
19 | } |
||
20 | |||
21 | /** |
||
22 | * @param $collection |
||
23 | * @return bool|int|mixed|string |
||
24 | */ |
||
25 | 1 | public function detect($collection) |
|
26 | { |
||
27 | 1 | $current = $this->detectFromConstant(); |
|
28 | 1 | if ($current) { |
|
29 | return $current; |
||
30 | } |
||
31 | 1 | $current = $this->detectFromSubdomain($collection); |
|
32 | 1 | if ($current) { |
|
33 | 1 | return $current; |
|
34 | } |
||
35 | |||
36 | return 'main'; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @return bool|string |
||
41 | */ |
||
42 | protected function detectFromConstant() |
||
45 | // return (defined('SPORTIC_SECTION')) ? SPORTIC_SECTION : false; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param $collection |
||
50 | * @return bool|mixed |
||
51 | */ |
||
52 | 1 | protected function detectFromSubdomain($collection) |
|
53 | { |
||
54 | 1 | $subDomain = $this->getCurrentSubdomain(); |
|
55 | 1 | foreach ($collection as $key => $section) { |
|
56 | 1 | if ($subDomain == $section->getSubdomain()) { |
|
57 | 1 | return $key; |
|
58 | } |
||
59 | } |
||
60 | |||
61 | return $subDomain; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @return bool|mixed |
||
66 | */ |
||
67 | protected function getCurrentSubdomain() |
||
70 | } |
||
71 | } |
||
72 |