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

BrowserDeviceListHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 28
ccs 0
cts 17
cp 0
rs 10
c 1
b 0
f 0
wmc 4
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canHandle() 0 4 1
A handle() 0 20 3
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