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.

Storage   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 34
c 2
b 0
f 0
dl 0
loc 83
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A route() 0 36 5
A __construct() 0 3 1
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 Storage
24
 *
25
 * @package O2System\Reactor\Http\Controllers
26
 */
27
class Storage extends Controller
28
{
29
    /**
30
     * Storage::$inherited
31
     *
32
     * Controller inherited flag.
33
     *
34
     * @var bool
35
     */
36
    static public $inherited = true;
37
38
    /**
39
     * Storage::$directoryPath
40
     *
41
     * @var string
42
     */
43
    public $directoryPath;
44
45
    /**
46
     * Storage::$speedLimit
47
     *
48
     * @var int
49
     */
50
    public $speedLimit = 1024;
51
52
    /**
53
     * Storage::$resumeable
54
     *
55
     * @var bool
56
     */
57
    public $resumeable = true;
58
59
    // ------------------------------------------------------------------------
60
61
    /**
62
     * Storage::__construct
63
     */
64
    public function __construct()
65
    {
66
        $this->directoryPath = PATH_STORAGE;
67
    }
68
69
    // ------------------------------------------------------------------------
70
71
    /**
72
     * Storage::route
73
     */
74
    public function route()
75
    {
76
        $segments = server_request()->getUri()->segments->getArrayCopy();
77
        array_shift($segments);
78
79
        $download = false;
80
81
        if (false !== ($key = array_search('download', $segments))) {
82
            $download = true;
83
            unset($segments[ $key ]);
84
            $segments = array_values($segments);
85
        }
86
87
        if (count($segments)) {
88
            $filePath = $this->directoryPath . implode(DIRECTORY_SEPARATOR, $segments);
89
            if (is_file($filePath)) {
90
                if ($download) {
91
                    $downloader = new Downloader($filePath);
92
                    $downloader
93
                        ->speedLimit($this->speedLimit)
94
                        ->resumeable($this->resumeable)
95
                        ->download();
96
                } else {
97
                    $fileInfo = new SplFileInfo($filePath);
98
                    header('Content-Disposition: filename=' . $fileInfo->getFilename());
99
                    header('Content-Transfer-Encoding: binary');
100
                    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
101
                    header('Content-Type: ' . $fileInfo->getMime());
102
                    echo readfile($filePath);
103
                    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...
104
                }
105
            } else {
106
                redirect_url('error/404');
107
            }
108
        } else {
109
            redirect_url('error/403');
110
        }
111
    }
112
}