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

BrowserPackageListHandler::__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\Output\HtmlOutput;
6
use \SSpkS\Output\UrlFixer;
7
use \SSpkS\Package\PackageFilter;
8
use \SSpkS\Package\PackageFinder;
9
10
class BrowserPackageListHandler implements HandlerInterface
11
{
12
    private $config;
13
14
    public function __construct(\SSpkS\Config $config)
15
    {
16
        $this->config = $config;
17
    }
18
19
    public function handle()
20
    {
21
        // Architecture is set --> show packages for that arch
22
        $arch     = trim($_GET['arch']);
23
        $channel  = trim($_GET['channel']);
24
        if ($channel != 'beta') {
25
            $channel = 'stable';
26
        }
27
        $packagesAvailable = array();
0 ignored issues
show
Unused Code introduced by
$packagesAvailable is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28
29
        $output = new HtmlOutput($this->config);
30
        $output->setVariable('arch', $arch);
31
        $output->setVariable('channel', ($channel == 'beta'));
32
33
        $pkgs = new PackageFinder($this->config->paths['packages']);
34
        $pkgf = new PackageFilter($pkgs->getAllPackages());
35
        $pkgf->setArchitectureFilter($arch);
36
        $pkgf->setChannelFilter($channel);
37
        $pkgf->setFirmwareVersionFilter(false);
38
        $pkgf->setOldVersionFilter(true);
39
        $filteredPkgList = $pkgf->getFilteredPackageList();
40
41
        $uf = new UrlFixer($this->config->baseUrl);
42
        $uf->fixPackageList($filteredPkgList);
43
44
        $packages = array();
45
        foreach ($filteredPkgList as $pkg) {
46
            $packages[] = $pkg->getMetadata();
47
        }
48
49
        $output->setVariable('packagelist', array_values($packages));
50
        $output->setTemplate('html_packagelist');
51
        $output->output();
52
    }
53
}
54