Completed
Pull Request — master (#26)
by Christopher
07:26
created

GroupController::getGroup()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 21
nc 1
nop 3
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace TechWilk\Rota\Controller;
4
5
use DateTime;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use TechWilk\Rota\EventQuery;
9
use TechWilk\Rota\GroupQuery;
10
11
class GroupController extends BaseController
12
{
13
    public function getGroup(ServerRequestInterface $request, ResponseInterface $response, $args)
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
        $this->logger->info("Fetch group GET '/group/".$args['id']."'");
16
        $events = EventQuery::create()
17
            ->useEventPersonQuery()
18
                ->useUserRoleQuery()
19
                    ->useRoleQuery()
20
                        ->filterByGroupId($args['id'])
21
                    ->endUse()
22
                ->endUse()
23
            ->endUse()
24
            ->filterByDate(['min' => new DateTime()])
25
            ->filterByRemoved(false)
26
            ->orderByDate('asc')
27
            ->distinct()
28
            ->find();
29
30
        $group = GroupQuery::create()
31
                ->useRoleQuery()
32
                ->endUse()
33
                ->distinct()
34
                ->findPk($args['id']);
35
36
        return $this->view->render($response, 'group.twig', ['events' => $events, 'group' => $group]);
37
    }
38
39
    public function getGroupRoles(ServerRequestInterface $request, ResponseInterface $response, $args)
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...
40
    {
41
        $this->logger->info("Fetch group roles GET '/group/".$args['id']."/roles'");
42
        $events = EventQuery::create()
0 ignored issues
show
Unused Code introduced by
$events is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43
            ->useEventPersonQuery()
44
                ->useUserRoleQuery()
45
                    ->useRoleQuery()
46
                        ->filterByGroupId($args['id'])
47
                    ->endUse()
48
                ->endUse()
49
            ->endUse()
50
            ->filterByDate(['min' => new DateTime()])
51
            ->filterByRemoved(false)
52
            ->orderByDate('asc')
53
            ->distinct()
54
            ->find();
55
56
        $group = GroupQuery::create()
0 ignored issues
show
Unused Code introduced by
$group is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
                ->useRoleQuery()
58
                ->endUse()
59
                ->distinct()
60
                ->findPk($args['id']);
61
62
        // temporary redirect
63
        return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('home').'old/roles.php');
64
65
        return $this->view->render($response, 'group-roles.twig', ['events' => $events, 'group' => $group]);
0 ignored issues
show
Unused Code introduced by
return $this->view->rend...s, 'group' => $group)); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
66
    }
67
}
68