BanController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 10.71%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 7
dl 0
loc 57
ccs 3
cts 28
cp 0.1071
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createAction() 0 6 1
A showAction() 0 4 1
A editAction() 0 4 1
A deleteAction() 0 4 1
A unbanAction() 0 17 3
A listAction() 0 14 1
1
<?php
2
3
use Symfony\Component\HttpFoundation\RedirectResponse;
4
use Symfony\Component\HttpFoundation\Request;
5
6
class BanController extends CRUDController
7
{
8
    public function showAction(Ban $ban)
9
    {
10
        return array("ban" => $ban);
11
    }
12
13
    public function listAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
14
    {
15
        $currentPage = $this->getCurrentPage();
16
17
        $qb = $this->getQueryBuilder()
18
            ->sortBy('updated')->reverse()
19
            ->limit(16)->fromPage($currentPage);
20
21
        return array(
22
            'bans'        => $qb->getModels(),
23
            'currentPage' => $currentPage,
24
            'totalPages'  => $qb->countPages()
25
        );
26
    }
27
28 1
    public function createAction(Player $me, Player $player = null)
29
    {
30 1
        $this->data->set('player', $player);
31
32 1
        return $this->create($me);
33
    }
34
35
    public function editAction(Player $me, Ban $ban)
36
    {
37
        return $this->edit($ban, $me, "ban");
38
    }
39
40
    public function deleteAction(Player $me, Ban $ban)
41
    {
42
        return $this->delete($ban, $me);
43
    }
44
45
    public function unbanAction(Player $me, Ban $ban)
46
    {
47
        if (!$this->canEdit($me, $ban)) {
48
            throw new ForbiddenException("You are not allowed to unban a player.");
49
        } elseif ($ban->isExpired()) {
50
            throw new ForbiddenException("Sorry, this ban has already expired.");
51
        }
52
53
        $victim = $ban->getVictim();
54
55
        return $this->showConfirmationForm(function () use ($ban) {
56
            $ban->expire();
57
58
            return new RedirectResponse($ban->getUrl());
59
        }, "Are you sure you want to unban <strong>{$victim->getEscapedUsername()}</strong>?",
60
            "{$victim->getUsername()}'s ban has been deactivated successfully", "Unban");
61
    }
62
}
63