Passed
Branch develop (6d6783)
by BENARD
03:42
created

PlayerController::getPositions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 33
nc 1
nop 1
dl 0
loc 35
rs 9.392
c 0
b 0
f 0
1
<?php
2
3
namespace VideoGamesRecords\DwhBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6
use Symfony\Component\HttpFoundation\Request;
7
use VideoGamesRecords\DwhBundle\Repository\PlayerRepository;
8
9
/**
10
 * Class PlayerController
11
 */
12
class PlayerController extends AbstractController
13
{
14
    private PlayerRepository $playerRepository;
15
16
    public function __construct(PlayerRepository $playerRepository)
17
    {
18
        $this->playerRepository = $playerRepository;
19
    }
20
21
22
    /**
23
     * @param Request $request
24
     * @return array
25
     */
26
    public function getPositions(Request $request): array
27
    {
28
        $idPlayer = $request->query->get('idPlayer', null);
29
        $object = $this->playerRepository->findOneBy(array('id' => $idPlayer), array('date' => 'DESC'));
30
        return array(
31
            $object->getChartRank1(),
32
            $object->getChartRank2(),
33
            $object->getChartRank3(),
34
            $object->getChartRank(4),
35
            $object->getChartRank(5),
36
            $object->getChartRank(6),
37
            $object->getChartRank(7),
38
            $object->getChartRank(8),
39
            $object->getChartRank(9),
40
            $object->getChartRank(10),
41
            $object->getChartRank(11),
42
            $object->getChartRank(12),
43
            $object->getChartRank(13),
44
            $object->getChartRank(14),
45
            $object->getChartRank(15),
46
            $object->getChartRank(16),
47
            $object->getChartRank(17),
48
            $object->getChartRank(18),
49
            $object->getChartRank(19),
50
            $object->getChartRank(20),
51
            $object->getChartRank(21),
52
            $object->getChartRank(22),
53
            $object->getChartRank(23),
54
            $object->getChartRank(24),
55
            $object->getChartRank(25),
56
            $object->getChartRank(26),
57
            $object->getChartRank(27),
58
            $object->getChartRank(28),
59
            $object->getChartRank(29),
60
            $object->getChartRank(30),
61
        );
62
    }
63
64
    /**
65
     * @param Request $request
66
     * @return array
67
     */
68
    public function getMedalsByTime(Request $request): array
69
    {
70
         $idPlayer = $request->query->get('idPlayer', null);
71
         $list = $this->playerRepository->findBy(array('id' => $idPlayer), array('date' => 'ASC'));
72
73
         $return = [
74
             'rank0' => [],
75
             'rank1' => [],
76
             'rank2' => [],
77
             'rank3' => [],
78
             'date' => [],
79
         ];
80
         foreach ($list as $object) {
81
            $return['rank0'][] = $object->getChartRank0();
82
            $return['rank1'][] = $object->getChartRank1();
83
            $return['rank2'][] = $object->getChartRank2();
84
            $return['rank3'][] = $object->getChartRank3();
85
            $return['date'][] = $object->getDate();
86
         }
87
         return $return;
88
    }
89
}
90