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

BrowserPackageListHandler::canHandle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SSpkS\Handler;
4
5
use \SSpkS\Output\HtmlOutput;
6
use \SSpkS\Output\UrlFixer;
7
use \SSpkS\Package\PackageFilter;
8
use \SSpkS\Package\PackageFinder;
9
10
class BrowserPackageListHandler extends AbstractHandler
11
{
12
    public function canHandle()
13
    {
14
        return ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty(trim($_GET['arch'])));
15
    }
16
17
    public function handle()
18
    {
19
        // Architecture is set --> show packages for that arch
20
        $arch     = trim($_GET['arch']);
21
22
        $output = new HtmlOutput($this->config);
23
        $output->setVariable('arch', $arch);
24
25
        $pkgs = new PackageFinder($this->config->paths['packages']);
26
        $pkgf = new PackageFilter($pkgs->getAllPackages());
27
        $pkgf->setArchitectureFilter($arch);
28
        $pkgf->setFirmwareVersionFilter(false);
29
        $pkgf->setOldVersionFilter(true);
30
        $filteredPkgList = $pkgf->getFilteredPackageList();
31
32
        $uf = new UrlFixer($this->config->baseUrl);
33
        $uf->fixPackageList($filteredPkgList);
34
35
        $packages = array();
36
        foreach ($filteredPkgList as $pkg) {
37
            $packages[] = $pkg->getMetadata();
38
        }
39
40
        $output->setVariable('packagelist', array_values($packages));
41
        $output->setTemplate('html_packagelist');
42
        $output->output();
43
    }
44
}
45