Completed
Push — rework ( b64e66...30a2d6 )
by Markus
02:47
created

BrowserDeviceListHandler::__construct()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
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 implements HandlerInterface
9
{
10
    private $config;
11
12
    public function __construct(\SSpkS\Config $config)
13
    {
14
        $this->config = $config;
15
    }
16
17
    public function handle()
18
    {
19
        // Nothing requested --> show models overview
20
        $output = new HtmlOutput($this->config);
21
        try {
22
            $deviceList = new DeviceList($this->config->paths['models']);
23
            $models = $deviceList->getDevices();
24
            if (count($models) == 0) {
25
                $output->setTemplate('html_modellist_none');
26
            } else {
27
                $output->setVariable('modellist', $models);
28
                $output->setTemplate('html_modellist');
29
            }
30
        } catch (\Exception $e) {
31
            $output->setVariable('errorMessage', $e->getMessage());
32
            $output->setTemplate('html_modellist_error');
33
        }
34
        $output->output();
35
    }
36
}
37