Passed
Push — scrutinizer-test ( 6f2f69...953bdc )
by Pascal
02:22
created

Handler::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 3
b 0
f 0
nc 3
nop 0
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 12
rs 10
1
<?php
2
3
// Starting point, handle incoming request and hand over to more specific handler
4
5
namespace SSpkS;
6
7
class Handler
8
{
9
    private $config;
10
    private $handlerList;
11
12
    public function __construct(\SSpkS\Config $config)
13
    {
14
        $this->config = $config;
15
16
        // ordered by priority (top to bottom)
17
        $this->handlerList = array(
18
            'SynologyHandler',
19
            'BrowserRedirectHandler',
20
            'BrowserPackageListHandler',
21
            'BrowserAllPackagesListHandler',
22
            'BrowserDeviceListHandler',
23
            'NotFoundHandler'
24
        );
25
    }
26
27
    public function handle()
28
    {
29
        foreach ($this->handlerList as $possibleHandler) {
30
            // Add namespace to class name
31
            $possibleHandler = '\\SSpkS\\Handler\\' . $possibleHandler;
32
            $handler = new $possibleHandler($this->config);
33
            if ($handler->canHandle()) {
34
                $handler->handle();
35
                break;
36
            }
37
        }
38
    }
39
}
40