Test Failed
Pull Request — master (#31)
by
unknown
02:34
created

SynologyHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 6
1
<?php
2
3
namespace SSpkS\Handler;
4
5
use \SSpkS\Output\JsonOutput;
6
use \SSpkS\Output\UrlFixer;
7
use \SSpkS\Package\PackageFinder;
8
use \SSpkS\Package\PackageFilter;
9
10
/*
11
example data passed by a syno
12
13
language = enu
14
timezone = Brussels
15
unique = synology_cedarview_412
16
arch = cedarview
17
major = 4
18
minor = 1
19
build = 2636
20
package_update_channel = stable
21
22
    [package_update_channel] => beta
23
    [unique] => synology_avoton_415+
24
    [build] => 7393
25
    [language] => enu
26
    [major] => 6
27
    [arch] => avoton
28
    [minor] => 0
29
    [timezone] => Amsterdam
30
*/
31
32
// if (isset($_REQUEST['unique']) && substr($_REQUEST['unique'], 0, 8) == 'synology') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
34
class SynologyHandler extends AbstractHandler
35
{
36
    public function handle()
37
    {
38
        // Synology request --> show JSON
39
        $language = trim($_REQUEST['language']);
40
        $timezone = trim($_REQUEST['timezone']);
41
        $arch     = trim($_REQUEST['arch']);
42
        $major    = trim($_REQUEST['major']);
43
        $minor    = trim($_REQUEST['minor']);
44
        $build    = trim($_REQUEST['build']);
45
        $channel  = trim($_REQUEST['package_update_channel']);
46
        $unique   = trim($_REQUEST['unique']);
47
48
        if ($arch == '88f6282') {
49
            $arch = '88f6281';
50
        }
51
52
        // Make sure, that the "client" knows that output is sent in JSON format
53
        header('Content-type: application/json');
54
        $fw_version = $major . '.' . $minor . '.' . $build;
55
        $pkgs = new PackageFinder($this->config->paths['packages']);
56
        $pkgf = new PackageFilter($pkgs->getAllPackages());
57
        $pkgf->setArchitectureFilter($arch);
58
        $pkgf->setChannelFilter($channel);
59
        $pkgf->setFirmwareVersionFilter($fw_version);
60
        $pkgf->setOldVersionFilter(true);
61
        $filteredPkgList = $pkgf->getFilteredPackageList();
62
63
        $uf = new UrlFixer($this->config->baseUrl);
64
        $uf->fixPackageList($filteredPkgList);
65
66
        $jo = new JsonOutput(this->config);
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ')'
Loading history...
67
        $jo->setExcludedServices($this->config->excludedSynoServices);
68
        $jo->outputPackages($filteredPkgList);
69
    }
70
}
71