GameController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
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\GamesDeveloper;
13
use Dingo\Api\Routing\Helpers;
14
use App\Http\Controllers\Controller;
15
16
class GameController extends Controller
17
{
18
    use Helpers;
19
20
    public function index()
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...
21
    {
22
        $games = Game::select([
23
            'id',
24
            'title',
25
            'subtitle',
26
            ])
27
            ->get();
28
29
        return $games;
30
    }
31
32
    public function show($id)
33
    {
34
        //Lade Spielinformationen
35
        $game = Game::whereId($id)->first();
36
37
        //Fülle Array
38
        $array = [
39
            'type'      => 'RpgGame',
40
            'version'   => 'rmapi_v1',
41
            'data_date' => Carbon::now()->toDateTimeString(),
42
            'game'      => [
43
                'title'        => $game->title,
44
                'subtitle'     => $game->subtitle,
45
                'release_date' => $game->release_date,
46
                'developers'   => '',
47
                'language'     => $game->language->short,
48
                'engine'       => $game->maker->short,
49
            ],
50
        ];
51
52
        //Lade Entwickler
53
        $developer = GamesDeveloper::whereGameId($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...
54
        $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...
55
        foreach ($developer as $dev) {
56
            $t[] = $dev->developer->name;
57
        }
58
        $array['game']['developer'] = $t;
59
60
        //Lade Tags
61
62
        return $array;
63
    }
64
65
    public function show_app()
66
    {
67
        $games = Game::with('developers', 'user', 'maker', 'screenshots')->orderBy('created_at')->limit(25)->get();
0 ignored issues
show
Unused Code introduced by
$games is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
68
69
        $jason = [
70
            '$jason' => [
71
                'head' => [
72
                    'title'       => 'rmarchiv',
73
                    'description' => 'description',
74
                    'offline'     => true,
75
                    'body'        => [
76
                        'type'  => 'label',
77
                        'text'  => 'Dies ist Zeile 1',
78
                        'style' => [
79
                            'font'    => 'HelveticaNeue',
80
                            'size'    => 20,
81
                            'color'   => '#ff0000',
82
                            'padding' => '10',
83
                        ],
84
                    ],
85
                ],
86
            ],
87
        ];
88
89
        return $jason;
90
    }
91
}
92