EasyRPGController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 7
dl 0
loc 75
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 18 1
B show() 0 45 3
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Http\Controllers\Api\v1;
9
10
use Carbon\Carbon;
11
use App\Models\Game;
12
use App\Models\GamesFile;
13
use App\Models\GamesDeveloper;
14
use App\Models\PlayerFileHash;
15
use App\Http\Controllers\Controller;
16
use App\Models\PlayerFileGamefileRel;
17
18
/**
19
 * Class EasyRPGController
20
 * @package App\Http\Controllers\Api\v1
21
 *
22
 * Class for EasyRPG related stuff
23
 */
24
class EasyRPGController extends Controller
25
{
26
    /**
27
     * return index of all gamefile_ids with filehash
28
     * @return array
29
     */
30
    public function index()
31
    {
32
        $hashes = PlayerFileGamefileRel::where('orig_filename', 'like', '%rpg_rt.ldb%')
33
            ->join('player_file_hashes', 'player_file_hashes.id', 'player_file_gamefile_rel.file_hash_id')
34
            ->select([
35
                'player_file_gamefile_rel.gamefile_id',
36
                'player_file_hashes.filehash',
37
            ])
38
            ->get();
39
40
        $array = [
41
            'type'  => 'hashlist',
42
            'count' => $hashes->count(),
43
            'data'  => $hashes->toArray(),
44
        ];
45
46
        return $array;
47
    }
48
49
    /**
50
     * @param $ldbhash
51
     * @return array
52
     */
53
    public function show($ldbhash)
54
    {
55
        $hashid = PlayerFileHash::whereFilehash($ldbhash)->first()->id;
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...
56
        $gamefileid = PlayerFileGamefileRel::whereFileHashId($hashid)->first()->gamefile_id;
57
        $gamefile = GamesFile::whereId($gamefileid)->first();
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...
58
59
        //Lade Spielinformationen
60
        $game = Game::whereId($gamefile->game_id)->first();
61
62
        //Fülle Array
63
        $array = [
64
            'type'      => 'RpgGame',
65
            'version'   => 'rmapi_v1',
66
            'data_date' => Carbon::now()->toDateTimeString(),
67
            'data'      => [
68
                'identifier'   => $ldbhash,
69
                'title'        => $game->title,
70
                'subtitle'     => $game->subtitle,
71
                'release_date' => Carbon::create($gamefile->release_year, $gamefile->release_month, $gamefile->release_day)->toDateString(),
72
                'developers'   => '',
73
                'language'     => $game->language->short,
74
                'engine'       => $game->maker->short,
75
                'release_type' => $gamefile->gamefiletype->short,
76
                'files'        => '',
77
            ],
78
        ];
79
80
        //Lade Entwickler
81
        $developer = GamesDeveloper::whereGameId($game->id)->get();
0 ignored issues
show
Bug introduced by
The method get does only exist in Illuminate\Database\Query\Builder, but not in App\Models\GamesDeveloper.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
82
        $t = [];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
83
        foreach ($developer as $dev) {
84
            $t[] = $dev->developer->name;
85
        }
86
        $array['data']['developers'] = $t;
87
88
        //Lade Dateien
89
        $files = PlayerFileGamefileRel::whereGamefileId($gamefileid)->get();
0 ignored issues
show
Bug introduced by
The method get does only exist in Illuminate\Database\Query\Builder, but not in App\Models\PlayerFileGamefileRel.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
90
        $t = [];
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...
91
        foreach ($files as $f) {
92
            $t[$f->orig_filename] = $f->filehash->filehash;
93
        }
94
        $array['data']['files'] = $t;
95
96
        return $array;
97
    }
98
}
99