Completed
Push — master ( a1632d...ba3869 )
by Konstantinos
06:19
created

PublicAPIController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 57.83 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
lcom 1
cbo 6
dl 48
loc 83
rs 10
c 1
b 0
f 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
B playerListAction() 24 24 2
B teamListAction() 24 24 2
A serverListAction() 0 22 2
A getLogChannel() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
use Symfony\Component\HttpFoundation\JsonResponse;
4
5
class PublicAPIController extends JSONController
6
{
7 View Code Duplication
    public function playerListAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
    {
9
        /** @var Player[] $players */
10
        $players = $this->getQueryBuilder('Player')
11
            ->getModels($fast = true);
12
13
        $response = array(
14
            'players' => array(),
15
            'success' => true,
16
            'version' => 0
17
        );
18
19
        foreach ($players as $player) {
20
            $response['players'][] = array(
21
                'id' => $player->getId(),
22
                'alias' => $player->getAlias(),
23
                'username' => $player->getUsername(),
24
                'team' => $player->getTeam()->getId(),
25
                'url' => $player->getPermaLink('show', $absolute = true)
26
            );
27
        }
28
29
        return new JsonResponse($response);
30
    }
31
32 View Code Duplication
    public function teamListAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        /** @var Team[] $teams */
35
        $teams = $this->getQueryBuilder('Team')
36
            ->getModels($fast = true);
37
38
        $response = array(
39
            'teams' => array(),
40
            'success' => true,
41
            'version' => 0
42
        );
43
44
        foreach ($teams as $team) {
45
            $response['teams'][] = array(
46
                'id' => $team->getId(),
47
                'alias' => $team->getAlias(),
48
                'name' => $team->getName(),
49
                'url' => $team->getPermaLink('show', $absolute = true),
50
                'status' => $team->getStatus()
51
            );
52
        }
53
54
        return new JsonResponse($response);
55
    }
56
57
    public function serverListAction()
58
    {
59
        /** @var Server[] $servers */
60
        $servers = $this->getQueryBuilder('Server')
61
            ->getModels($fast = true);
62
63
        $response = array(
64
            'servers' => array(),
65
            'success' => true,
66
            'version' => 0
67
        );
68
69
        foreach ($servers as $server) {
70
            $response['servers'][] = array(
71
                'id' => $server->getId(),
72
                'name' => $server->getName(),
73
                'address' => $server->getAddress(),
74
            );
75
        }
76
77
        return new JsonResponse($response);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    protected static function getLogChannel()
84
    {
85
        return 'api';
86
    }
87
}
88