Passed
Push — main ( 30a05e...00708c )
by Richard
04:14
created

PlayerController   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 15
eloc 31
c 1
b 0
f 0
dl 0
loc 82
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A show() 0 3 1
A showWithName() 0 4 1
A update() 0 5 1
C create() 0 36 12
1
<?php
2
3
namespace Furic\GameEssentials\Http\Controllers;
4
5
use Furic\GameEssentials\Models\Player;
6
use Furic\GameEssentials\Models\PlayerGame;
7
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...
8
use Illuminate\Http\Request;
9
10
class PlayerController extends Controller
11
{
12
13
    /**
14
     * Display the specified player resource.
15
     *
16
     * @param  int  $id
17
     * @return \Illuminate\Http\Response
18
     */
19
    public function show($id)
20
    {
21
        return response(Player::findOrFail($id), 200);
22
    }
23
24
    /**
25
     * Display the specified player resource with a given name.
26
     *
27
     * @param  string  $name
28
     * @return \Illuminate\Http\Response
29
     */
30
    public function showWithName($name)
31
    {
32
        $player = Player::findByName($name);
33
        return response($player, 200);
34
    }
35
36
    /**
37
     * Store a newly created player resource in storage.
38
     *
39
     * @param  Request  $request
40
     * @return \Illuminate\Http\Response
41
     */
42
    public function create(Request $request)
43
    {
44
        // Check if an old player
45
        $player = NULL;
46
        if ($request->has('facebook_id') && !empty($request->facebook_id)) {
47
            $player = Player::findByFacebookId($request->facebook_id);
48
        } else if ($request->has('playgames_id') && !empty($request->playgames_id)) {
49
            $player = Player::findByPlayGamesId($request->playgames_id);
50
        } else if ($request->has('gamecenter_id') && !empty($request->gamecenter_id)) {
51
            $player = Player::findByGameCenterId($request->gamecenter_id);
52
        } else if ($request->has('udid') && !empty($request->udid)) {
53
            $player = Player::findByUdid($request->udid);
54
        }
55
        
56
        // Create or update
57
        $data = $request->all();
58
        $data['ip'] = filter_input(INPUT_SERVER, "REMOTE_ADDR");
59
        if ($player) {
60
            $player->update($data);
61
        } else {
62
            $player = Player::create($data);
63
        }
64
        
65
        // Create playerGame if not exists
66
        if ($request->has('game_id')) {
67
            $playerGame = PlayerGame::findByPlayerGame($player->id, $request->game_id);
68
            if ($playerGame) {
69
                $playerGame->update($request->all());
70
            } else {
71
                $data = $request->all();
72
                $data['player_id'] = $player->id;
73
                PlayerGame::create($data);
74
            }
75
        }
76
        
77
        return response($player, 200);
78
    }
79
    
80
    /**
81
     * Update the specified player resource in storage.
82
     *
83
     * @param  Request  $request
84
     * @param  int  $id
85
     * @return \Illuminate\Http\Response
86
     */
87
    public function update(Request $request, $id)
88
    {
89
        $player = Player::findOrFail($id);
90
        $player->update($request->all());
91
        return response($player, 200);
92
    }
93
94
}