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