Passed
Push — develop ( 9523f4...6fbaf9 )
by Nikita
07:23
created

ServersController::updateSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Gameap\Http\Controllers;
4
5
use Gameap\Http\Requests\ServerVarsRequest;
6
use Gameap\Models\Server;
7
use Gameap\Repositories\ServerRepository;
8
use Illuminate\Support\Facades\Auth;
9
10
class ServersController extends AuthController
11
{
12
    /**
13
     * The ServerRepository instance.
14
     *
15
     * @var \Gameap\Repositories\ServerRepository
16
     */
17
    protected $repository;
18
19
    /**
20
     * Create a new ServersController instance.
21
     *
22
     * @param ServerRepository $repository
23
     */
24 27
    public function __construct(ServerRepository $repository)
25
    {
26 27
        parent::__construct();
27
28 27
        $this->repository = $repository;
29 27
    }
30
31
    /**
32
     * Display a listing of the resource.
33
     *
34
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
35
     */
36
    public function index()
37
    {
38
        return view('servers.list',[
39
            'servers' => $this->repository->getServersForAuth()
40
        ]);
41
    }
42
43
    /**
44
     * Display the specified resource.
45
     *
46
     * @param  \Gameap\Models\Server  $server
47
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
48
49
     * @throws \Illuminate\Auth\Access\AuthorizationException
50
     */
51 6
    public function show(Server $server)
52
    {
53 6
        $this->authorize('server-control', $server);
54
55 3
        return ($server->installed === $server::INSTALLED && $server->enabled && !$server->blocked) ?
56 1
            view('servers.view', compact('server'))
57 3
            : view('servers.not_active', compact('server'));
58
    }
59
60
    /**
61
     * @param Server $server
62
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
63
     *
64
     * @throws \Illuminate\Auth\Access\AuthorizationException
65
     */
66 15
    public function filemanager(Server $server)
67
    {
68 15
        $this->authorize('server-control', $server);
69 6
        $this->authorize('server-files', $server);
70
71 3
        return view('servers.filemanager', compact('server'));
72
    }
73
74
    /**
75
     * @param Server $server
76
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
77
     *
78
     * @throws \Illuminate\Auth\Access\AuthorizationException
79
     */
80 6
    public function settings(Server $server)
81
    {
82 6
        $this->authorize('server-settings', $server);
83
84 3
        return view('servers.settings', compact('server'));
85
    }
86
87
    /**
88
     * @param ServerVarsRequest $request
89
     * @param Server $server
90
     * @return \Illuminate\Http\RedirectResponse
91
     *
92
     * @throws \Illuminate\Auth\Access\AuthorizationException
93
     */
94
    public function updateSettings(ServerVarsRequest $request, Server $server)
95
    {
96
        $this->authorize('server-control', $server);
97
        $this->authorize('server-settings', $server);
98
99
        $this->repository->updateVars($server, $request);
100
101
        return redirect()->route('servers.settings', ['server' => $server->id])
102
            ->with('success', __('servers.update_success_msg'));
103
    }
104
}