Passed
Push — main ( e80760...ee0f4a )
by Richard
05:13
created

GameController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 27
c 2
b 0
f 0
dl 0
loc 61
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A showVersions() 0 13 2
A show() 0 8 2
A showPlayers() 0 12 3
1
<?php
2
3
namespace Furic\GameEssentials\Http\Controllers;
4
5
use Furic\GameEssentials\Models\Game;
6
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Illuminate\Http\Request;
8
9
class GameController extends Controller
10
{
11
12
    /**
13
     * Display the specified game resource.
14
     *
15
     * @param  int  $id
16
     * @return \Illuminate\Http\Response
17
     */
18
    public function show($id)
19
    {
20
        try {
21
            return response(Game::findOrFail($id), 200);
22
        } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
23
            return response([
24
                'error' => 'No game found.'
25
            ], 400);
26
        }
27
    }
28
29
    /**
30
     * Display the versions of a specified game resource.
31
     *
32
     * @param  int  $id
33
     * @return \Illuminate\Http\Response
34
     */
35
    public function showVersions($id) // Depricated
36
    {
37
        try {
38
            $game = Game::findOrFail($id);
39
            return response([
40
                'ios' => $game->version_ios,
41
                'android' => $game->version_android,
42
                'tvos' => $game->version_tvos
43
            ], 200);
44
        } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
45
            return response([
46
                'error' => 'No game found.'
47
            ], 400);
48
        }
49
    }
50
51
    /**
52
     * Display a listing of the player resource by a given game ID.
53
     *
54
     * @param  Request  $request
55
     * @param  int  $id
56
     * @return \Illuminate\Http\Response
57
     */
58
    public function showPlayers(Request $request, $id)
59
    {
60
        try {
61
            if ($request->limit <= 0) {
62
                return response(Game::findOrFail($id)->players, 200);
63
            } else {
64
                return response(Game::findOrFail($id)->players->take($request->limit), 200);
65
            }
66
        } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
67
            return response([
68
                'error' => 'No game found.'
69
            ], 400);
70
        }
71
    }
72
73
}