1 | <?php |
||
2 | |||
3 | namespace Furic\GameEssentials\Http\Controllers; |
||
4 | |||
5 | use Furic\GameEssentials\Models\Player; |
||
6 | use Furic\GameEssentials\Models\GamePlayer; |
||
7 | use App\Http\Controllers\Controller; |
||
0 ignored issues
–
show
|
|||
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 | try { |
||
22 | return response(Player::findOrFail($id), 200); |
||
23 | } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { |
||
24 | return response([ |
||
25 | 'error' => 'No player found.' |
||
26 | ], 400); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Display the specified player resource with a given name. |
||
32 | * |
||
33 | * @param string $name |
||
34 | * @return \Illuminate\Http\Response |
||
35 | */ |
||
36 | public function showWithName($name) |
||
37 | { |
||
38 | $player = Player::findByName($name); |
||
39 | if ($player != NULL) { |
||
40 | return response($player, 200); |
||
41 | } |
||
42 | return response([ |
||
43 | 'error' => 'No player found.' |
||
44 | ], 400); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Store a newly created player resource in storage. |
||
49 | * |
||
50 | * @param Request $request |
||
51 | * @return \Illuminate\Http\Response |
||
52 | */ |
||
53 | public function create(Request $request) |
||
54 | { |
||
55 | // Check if an old player |
||
56 | $player = NULL; |
||
57 | if ($request->has('facebook_id') && !empty($request->facebook_id)) { |
||
58 | $player = Player::findByFacebookId($request->facebook_id); |
||
59 | } else if ($request->has('playgames_id') && !empty($request->playgames_id)) { |
||
60 | $player = Player::findByPlayGamesId($request->playgames_id); |
||
61 | } else if ($request->has('gamecenter_id') && !empty($request->gamecenter_id)) { |
||
62 | $player = Player::findByGameCenterId($request->gamecenter_id); |
||
63 | } else if ($request->has('udid') && !empty($request->udid)) { |
||
64 | $player = Player::findByUdid($request->udid); |
||
65 | } |
||
66 | |||
67 | // Create or update |
||
68 | $data = $request->all(); |
||
69 | $data['ip'] = filter_input(INPUT_SERVER, "REMOTE_ADDR"); |
||
70 | if ($player) { |
||
71 | $player->update($data); |
||
72 | } else { |
||
73 | $player = Player::create($data); |
||
74 | } |
||
75 | |||
76 | // Update/create GamePlayer entry if not exists |
||
77 | if ($request->has('game_id')) { |
||
78 | $playerGame = GamePlayer::findByGamePlayer($request->game_id, $player->id); |
||
79 | if ($playerGame) { |
||
80 | $playerGame->update($request->all()); |
||
81 | } else { |
||
82 | $data = $request->all(); |
||
83 | $data['player_id'] = $player->id; |
||
84 | GamePlayer::create($data); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | return response($player, 200); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Update the specified player resource in storage. |
||
93 | * |
||
94 | * @param Request $request |
||
95 | * @param int $id |
||
96 | * @return \Illuminate\Http\Response |
||
97 | */ |
||
98 | public function update(Request $request, $id) |
||
99 | { |
||
100 | try { |
||
101 | $player = Player::findOrFail($id); |
||
102 | $player->update($request->all()); |
||
103 | // Update/create GamePlayer entry |
||
104 | if ($request->has('game_id')) { |
||
105 | $playerGame = GamePlayer::findByPlayerGame($request->game_id, $id); |
||
106 | if ($playerGame) { |
||
107 | $playerGame->update($request->all()); |
||
108 | } else { |
||
109 | $data = $request->all(); |
||
110 | $data['player_id'] = $player->id; |
||
111 | PlayerGame::create($data); |
||
0 ignored issues
–
show
The type
Furic\GameEssentials\Http\Controllers\PlayerGame 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
112 | } |
||
113 | } |
||
114 | return response($player, 200); |
||
115 | } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { |
||
116 | return response([ |
||
117 | 'error' => 'No player found.' |
||
118 | ], 400); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Display a listing of the game resource by a given player ID. |
||
124 | * |
||
125 | * @param Request $request |
||
126 | * @param int $id |
||
127 | * @return \Illuminate\Http\Response |
||
128 | */ |
||
129 | public function showGames(Request $request, $id) |
||
130 | { |
||
131 | try { |
||
132 | if ($request->limit <= 0) { |
||
133 | return response(Player::findOrFail($id)->games, 200); |
||
134 | } else { |
||
135 | return response(Player::findOrFail($id)->games->take($request->limit), 200); |
||
136 | } |
||
137 | } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { |
||
138 | return response([ |
||
139 | 'error' => 'No player found.' |
||
140 | ], 400); |
||
141 | } |
||
142 | } |
||
143 | |||
144 | } |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths