GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 0a41a9...718635 )
by Steeven
03:33 queued 11s
created

Resources::route()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 35
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 28
c 1
b 0
f 0
nc 8
nop 0
dl 0
loc 35
rs 9.1608
1
<?php
2
/**
3
 * This file is part of the O2System Reactor package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Reactor\Http\Controllers;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Filesystem\Handlers\Downloader;
19
use O2System\Reactor\Http\Controller;
20
use O2System\Spl\Info\SplFileInfo;
21
22
/**
23
 * Class Resources
24
 *
25
 * @package O2System\Reactor\Http\Controllers
26
 */
27
class Resources extends Controller
28
{
29
    /**
30
     * Resources::$inherited
31
     *
32
     * Controller inherited flag.
33
     *
34
     * @var bool
35
     */
36
    static public $inherited = true;
37
38
    /**
39
     * Resources::$directoryPath
40
     *
41
     * @var string
42
     */
43
    public $directoryPath;
44
45
    /**
46
     * Resources::$speedLimit
47
     *
48
     * @var int
49
     */
50
    public $speedLimit = 1024;
51
52
    /**
53
     * Resources::$resumeable
54
     *
55
     * @var bool
56
     */
57
    public $resumeable = true;
58
59
    // ------------------------------------------------------------------------
60
61
    /**
62
     * Resources::__construct
63
     */
64
    public function __construct()
65
    {
66
        $this->directoryPath = PATH_RESOURCES;
0 ignored issues
show
Bug introduced by
The constant O2System\Reactor\Http\Controllers\PATH_RESOURCES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
67
    }
68
69
    // ------------------------------------------------------------------------
70
71
    /**
72
     * Resources::route
73
     */
74
    public function route()
75
    {
76
        $segments = server_request()->getUri()->segments->getArrayCopy();
77
        array_shift($segments);
78
79
        $download = false;
80
        if (false !== ($key = array_search('download', $segments))) {
81
            $download = true;
82
            unset($segments[ $key ]);
83
            $segments = array_values($segments);
84
        }
85
86
        if (count($segments)) {
87
            $filePath = $this->directoryPath . implode(DIRECTORY_SEPARATOR, $segments);
88
            if (is_file($filePath)) {
89
                if ($download) {
90
                    $downloader = new Downloader($filePath);
91
                    $downloader
92
                        ->speedLimit($this->speedLimit)
93
                        ->resumeable($this->resumeable)
94
                        ->download();
95
                } else {
96
                    $fileInfo = new SplFileInfo($filePath);
97
                    header('Content-Disposition: filename=' . $fileInfo->getFilename());
98
                    header('Content-Transfer-Encoding: binary');
99
                    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
100
                    header('Content-Type: ' . $fileInfo->getMime());
101
                    echo @readfile($filePath);
102
                    exit(EXIT_SUCCESS);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
103
                }
104
            } else {
105
                redirect_url('error/404');
106
            }
107
        } else {
108
            redirect_url('error/403');
109
        }
110
    }
111
}
112