Passed
Push — develop ( aa9ac7...096b8e )
by Nikita
05:39
created

GamesController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
dl 0
loc 122
ccs 0
cts 25
cp 0
rs 10
c 1
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 3 1
A store() 0 6 1
A edit() 0 3 1
A show() 0 3 1
A index() 0 4 1
A update() 0 6 1
A destroy() 0 5 1
A upgrade() 0 10 2
1
<?php
2
3
namespace Gameap\Http\Controllers\Admin;
4
5
use Gameap\Http\Controllers\AuthController;
6
use Gameap\Models\Game;
7
use Gameap\Repositories\GameRepository;
8
use Gameap\Http\Requests\GameRequest;
9
10
class GamesController extends AuthController
11
{
12
    /**
13
     * The GameRepository instance.
14
     *
15
     * @var \Gameap\Repositories\GameRepository
16
     */
17
    protected $repository;
18
19
    /**
20
     * Create a new GameController instance.
21
     *
22
     * @param  \Gameap\Repositories\GameRepository $repository
23
     */
24
    public function __construct(GameRepository $repository)
25
    {
26
        $this->repository = $repository;
27
28
        parent::__construct();
29
    }
30
31
    /**
32
     * Display a listing of the games.
33
     *
34
     * @return \Illuminate\View\View
35
     */
36
    public function index()
37
    {
38
        return view('admin.games.list',[
39
            'games' => $this->repository->getAll()
40
        ]);
41
    }
42
43
    /**
44
     * Display new create game page
45
     *
46
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
47
     */
48
    public function create()
49
    {
50
        return view('admin.games.create');
51
    }
52
53
    /**
54
     * Store a newly created game in storage.
55
     *
56
     * @param  \Gameap\Http\Requests\GameRequest  $request
57
     * @return \Illuminate\Http\RedirectResponse
58
     */
59
    public function store(GameRequest $request)
60
    {
61
        Game::create($request->all());
62
63
        return redirect()->route('admin.games.index')
64
            ->with('success', __('games.create_success_msg'));
65
    }
66
67
    /**
68
     * Display the specified resource.
69
     *
70
     * @param  \Gameap\Models\Game  $game
71
     * @return \Illuminate\View\View
72
     */
73
    public function show(Game $game)
74
    {
75
        return view('admin.games.view', compact('game'));
76
    }
77
78
    /**
79
     * Show the form for editing the specified resource.
80
     *
81
     * @param  \Gameap\Models\Game  $game
82
     * @return \Illuminate\View\View
83
     */
84
    public function edit(Game $game)
85
    {
86
        return view('admin.games.edit', compact('game'));
87
    }
88
89
    /**
90
     * Update the specified resource in storage.
91
     *
92
     * @param  \Gameap\Http\Requests\GameRequest  $request
93
     * @param  \Gameap\Models\Game  $game
94
     * @return \Illuminate\Http\RedirectResponse
95
     */
96
    public function update(GameRequest $request, Game $game)
97
    {
98
        $game->update($request->all());
99
100
        return redirect()->route('admin.games.index')
101
            ->with('success', __('games.update_success_msg'));
102
    }
103
104
    /**
105
     * Upgrade games and game mods from GameAP Repository
106
     *
107
     */
108
    public function upgrade()
109
    {
110
        $result = $this->repository->upgradeFromRepo();
111
112
        if ($result) {
0 ignored issues
show
introduced by
The condition $result is always true.
Loading history...
113
            return redirect()->route('admin.games.index')
114
                ->with('success', __('games.upgrade_success_msg'));
115
        } else {
116
            return redirect()->route('admin.games.index')
117
                ->with('error', __('games.upgrade_fail_msg'));
118
        }
119
    }
120
121
    /**
122
     * Remove the specified resource from storage.
123
     *
124
     * @param  \Gameap\Models\Game  $game
125
     * @return \Illuminate\Http\RedirectResponse
126
     */
127
    public function destroy(Game $game)
128
    {
129
        $game->delete();
130
        return redirect()->route('admin.games.index')
131
            ->with('success', __('games.delete_success_msg'));
132
    }
133
}
134