Completed
Push — master ( 033f01...59cf45 )
by Markus
02:32
created

lib/SSpkS/Handler/SynologyHandler.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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']);
0 ignored issues
show
$language 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...
40
        $timezone = trim($_REQUEST['timezone']);
0 ignored issues
show
$timezone 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...
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']);
0 ignored issues
show
$unique 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...
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);
67
        $jo->setExcludedServices($this->config->excludedSynoServices);
68
        $jo->outputPackages($filteredPkgList);
69
    }
70
}
71