PlayerMvController::index()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 2
eloc 15
nc 2
nop 1
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 * (c) 2018 by Gabriel 'Ghabry' Kind
7
 */
8
9
namespace App\Http\Controllers;
10
11
use App\Models\Game;
12
use App\Models\GamesFile;
13
use App\Models\PlayerIndexjson;
14
15
class PlayerMvController extends Controller
16
{
17
    public function index($gamefileid)
18
    {
19
        if (\Auth::check()) {
20
            $gamefile = GamesFile::whereId($gamefileid)->first();
21
            $path = storage_path('app/public/'.$gamefile->filename);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
22
            $game = Game::whereId($gamefile->game_id)->first();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
23
24
            $index = PlayerIndexjson::whereGamefileId($gamefileid)->first();
25
            $zip = new \ZipArchive();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
26
            $zip->open($path);
27
            $fp = $zip->getFromName($index->value.'index.html');
28
29
            return view('playermv.index', [
30
                'gamefileid' => $gamefileid,
31
                'game'       => $game,
32
                'index'      => $fp,
33
            ]);
34
        } else {
35
            return redirect()->action('IndexController@index');
36
        }
37
    }
38
39
    public function deliver($gamefileid, $filename)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
40
    {
41
        // OrangeMouseData is broken outside of Chrome browser -_-
42
        if ($filename == 'js/plugins/OrangeMouseData.js') {
43
            $path = public_path('mv/'.$filename);
44
45
            return response()->download($path);
46
        }
47
48
        $gf = GamesFile::whereId($gamefileid)->first();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
49
        $index = PlayerIndexjson::whereGamefileId($gamefileid)->first();
50
51
        $path = storage_path('app/public/'.$gf->filename);
52
53
        $zip = new \ZipArchive();
54
        $zip->open($path);
55
        $fp = $zip->getFromName($index->value.$filename);
56
57
        $t = 'application/octet-stream';
58
        // Loading fails when js or css have wrong mimetype
59
        if (ends_with($filename, '.js') == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
60
            $t = 'application/javascript';
61
        } elseif (ends_with($filename, '.css') == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
62
            $t = 'text/css';
63
        }
64
65
        return response($fp, 200)->header('Content-Type', $t);
0 ignored issues
show
Bug introduced by
The method header() does not exist on Symfony\Component\HttpFoundation\Response. Did you maybe mean sendHeaders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
66
    }
67
}
68