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 ( 890c9c...35b399 )
by
unknown
02:03
created

Resources::route()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 35
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 28
nc 8
nop 0
dl 0
loc 35
rs 9.1608
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System Framework 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\Framework\Http\Controllers;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Filesystem\Handlers\Downloader;
19
use O2System\Framework\Http\Controller;
20
use O2System\Spl\Info\SplFileInfo;
21
22
/**
23
 * Class Resources
24
 *
25
 * @package O2System\Framework\Http\Controllers
26
 */
27
class Resources extends Controller
28
{
29
    /**
30
     * Resources::$directoryPath
31
     *
32
     * @var string
33
     */
34
    public $directoryPath;
35
36
    /**
37
     * Resources::$speedLimit
38
     *
39
     * @var int
40
     */
41
    public $speedLimit = 1024;
42
43
    /**
44
     * Resources::$resumeable
45
     *
46
     * @var bool
47
     */
48
    public $resumeable = true;
49
50
    // ------------------------------------------------------------------------
51
52
    /**
53
     * Resources::__construct
54
     */
55
    public function __construct()
56
    {
57
        $this->directoryPath = PATH_RESOURCES;
58
    }
59
60
    // ------------------------------------------------------------------------
61
62
    /**
63
     * Resources::route
64
     */
65
    public function route()
66
    {
67
        $segments = server_request()->getUri()->getSegments()->getParts();
68
        array_shift($segments);
69
70
        $download = false;
71
        if (false !== ($key = array_search('download', $segments))) {
72
            $download = true;
73
            unset($segments[ $key ]);
74
            $segments = array_values($segments);
75
        }
76
77
        if (count($segments)) {
78
            $filePath = $this->directoryPath . implode(DIRECTORY_SEPARATOR, $segments);
79
            if (is_file($filePath)) {
80
                if ($download) {
81
                    $downloader = new Downloader($filePath);
82
                    $downloader
83
                        ->speedLimit($this->speedLimit)
84
                        ->resumeable($this->resumeable)
85
                        ->download();
86
                } else {
87
                    $fileInfo = new SplFileInfo($filePath);
88
                    header('Content-Disposition: filename=' . $fileInfo->getFilename());
89
                    header('Content-Transfer-Encoding: binary');
90
                    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
91
                    header('Content-Type: ' . $fileInfo->getMime());
92
                    echo @readfile($filePath);
93
                    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...
94
                }
95
            } else {
96
                redirect_url('error/404');
97
            }
98
        } else {
99
            redirect_url('error/403');
100
        }
101
    }
102
}
103