GamesController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
eloc 18
dl 0
loc 62
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 5 1
A store() 0 5 1
A __construct() 0 5 1
A show() 0 3 1
A index() 0 5 1
A destroy() 0 5 1
A upgrade() 0 8 2
1
<?php
2
3
namespace Gameap\Http\Controllers\API;
4
5
use Gameap\Http\Controllers\AuthController;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Gameap\Http\Controllers\API\AuthController. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use Gameap\Models\Game;
7
use Gameap\Repositories\GameRepository;
8
use Illuminate\Http\Request;
9
10
class GamesController extends AuthController
11
{
12
    /**
13
     * The GameRepository instance.
14
     *
15
     * @var \Gameap\Repositories\GameRepository
16
     */
17
    public $repository;
18
19
    /**
20
     * GamesController constructor.
21
     * @param GameRepository $repository
22
     */
23
    public function __construct(GameRepository $repository)
24
    {
25
        parent::__construct();
26
27
        $this->repository = $repository;
28
    }
29
30
    public function index()
31
    {
32
        $games = Game::all();
33
34
        return response()->json($games);
35
    }
36
37
    public function store(Request $request)
38
    {
39
        $game = Game::create($request->all());
40
41
        return response()->json($game, 201);
42
    }
43
44
    public function show(Game $game)
45
    {
46
        return response()->json($game);
47
    }
48
49
    public function update(Request $request, Game $game)
50
    {
51
        $game->update($request->all());
52
53
        return response()->json($game, 200);
54
    }
55
56
    public function upgrade()
57
    {
58
        $result = $this->repository->upgradeFromRepo();
59
60
        if ($result) {
61
            return response()->json(['message' => 'Games and Game Mods upgraded'], 200);
62
        } else {
63
            return response()->json(['message' => 'Error while upgrading Games and Game Mods'], 500);
64
        }
65
    }
66
67
    public function destroy(Game $game)
68
    {
69
        $game->delete();
70
71
        return response()->json(null, 204);
72
    }
73
}
74