|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
4
|
|
|
|
|
5
|
|
|
class PublicAPIController extends JSONController |
|
6
|
|
|
{ |
|
7
|
|
View Code Duplication |
public function playerListAction() |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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
|
|
|
|
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.