Completed
Push — master ( 59cf45...89a6d0 )
by Markus
02:34
created

BrowserDeviceListHandler::canHandle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SSpkS\Handler;
4
5
use \SSpkS\Device\DeviceList;
6
use \SSpkS\Output\HtmlOutput;
7
8
class BrowserDeviceListHandler extends AbstractHandler
9
{
10
    public function canHandle()
11
    {
12
        return ($_SERVER['REQUEST_METHOD'] == 'GET');
13
    }
14
15
    public function handle()
16
    {
17
        // Nothing requested --> show models overview
18
        $output = new HtmlOutput($this->config);
19
        try {
20
            $deviceList = new DeviceList($this->config->paths['models']);
21
            $models = $deviceList->getDevices();
22
            if (count($models) == 0) {
23
                $output->setTemplate('html_modellist_none');
24
            } else {
25
                $output->setVariable('modellist', $models);
26
                $output->setTemplate('html_modellist');
27
            }
28
        } catch (\Exception $e) {
29
            $output->setVariable('errorMessage', $e->getMessage());
30
            $output->setTemplate('html_modellist_error');
31
        }
32
        $output->setVariable('is_devicelist', true);
33
        $output->output();
34
    }
35
}
36