SynologyHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 28
c 5
b 0
f 0
dl 0
loc 45
ccs 0
cts 28
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canHandle() 0 3 2
A handle() 0 38 3
1
<?php
2
3
namespace SSpkS\Handler;
4
5
use \SSpkS\Output\JsonOutput;
0 ignored issues
show
Bug introduced by
The type \SSpkS\Output\JsonOutput was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use \SSpkS\Output\UrlFixer;
0 ignored issues
show
Bug introduced by
The type \SSpkS\Output\UrlFixer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use \SSpkS\Package\PackageFinder;
0 ignored issues
show
Bug introduced by
The type \SSpkS\Package\PackageFinder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use \SSpkS\Package\PackageFilter;
0 ignored issues
show
Bug introduced by
The type \SSpkS\Package\PackageFilter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
class SynologyHandler extends AbstractHandler
33
{
34
    public function canHandle()
35
    {
36
        return (isset($_REQUEST['unique']) && substr($_REQUEST['unique'], 0, 8) == 'synology');
37
    }
38
39
    public function handle()
40
    {
41
        // Synology request --> show JSON
42
        $arch = trim($_REQUEST['arch']);
43
        $major = trim($_REQUEST['major']);
44
        $minor = trim($_REQUEST['minor']);
45
        $build = trim($_REQUEST['build']);
46
        $channel = trim($_REQUEST['package_update_channel']);
47
        if (isset($_REQUEST['language'])) {
48
            $language = trim($_REQUEST['language']);
49
        } else {
50
            $language = '';
51
        }
52
53
        // more parameters: timezone and unique
54
55
        // Make sure, that the "client" knows that output is sent in JSON format
56
        header('Content-type: application/json');
57
        $fw_version = $major . '.' . $minor . '.' . $build;
58
        $pkgs = new PackageFinder($this->config);
59
        $pkgf = new PackageFilter($this->config, $pkgs->getAllPackages());
60
        $pkgf->setArchitectureFilter($arch);
61
        $pkgf->setChannelFilter($channel);
62
        $pkgf->setFirmwareVersionFilter($fw_version);
63
        $pkgf->setOldVersionFilter(true);
64
        $filteredPkgList = $pkgf->getFilteredPackageList();
65
66
        $uf = new UrlFixer($this->config->baseUrl);
67
        $uf->fixPackageList($filteredPkgList);
68
69
        $jo = new JsonOutput($this->config);
70
        $jo->setExcludedServices($this->config->excludedSynoServices);
71
        $hideKeys = array();
72
        if ($major >= 7) {
73
            // DSM7 does always hides packages marked as beta
74
            array_push($hideKeys, 'beta');
75
        }
76
        $jo->outputPackages($filteredPkgList, $language, $hideKeys);
77
    }
78
}
79