Passed
Push — develop ( 469876...830617 )
by
unknown
55s queued 11s
created

ChartController::indexAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
8
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9
use VideoGamesRecords\CoreBundle\Entity\Chart;
10
use VideoGamesRecords\CoreBundle\Tools\Score;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpFoundation\JsonResponse;
13
14
/**
15
 * Class ChartController
16
 */
17
class ChartController extends Controller
18
{
19
20
21
    /**
22
     * @Route("/{id}/{slug}", requirements={"id": "[1-9]\d*"}, name="vgr_chart_index")
23
     * @Method("GET")
24
     * @Cache(smaxage="10")
25
     *
26
     * @param int $id
27
     * @param string $slug
28
     */
29
    public function indexAction($id, $slug)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

29
    public function indexAction(/** @scrutinizer ignore-unused */ $id, $slug)

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

Loading history...
Unused Code introduced by
The parameter $slug is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

29
    public function indexAction($id, /** @scrutinizer ignore-unused */ $slug)

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

Loading history...
30
    {
31
        //@todo redirect to front
32
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
33
    }
34
35
36
    /**
37
     * @param Chart    $chart
38
     * @param Request $request
39
     * @return mixed
40
     */
41
    public function playerRanking(Chart $chart, Request $request)
42
    {
43
        $maxRank = $request->query->get('maxRank', 20);
44
        $idPlayer = $request->query->get('idPlayer', null);
0 ignored issues
show
Unused Code introduced by
The assignment to $idPlayer is dead and can be removed.
Loading history...
45
        $ranking = $this->getDoctrine()
46
            ->getRepository('VideoGamesRecordsCoreBundle:PlayerChart')
47
            ->getRanking($chart, null, $maxRank);
48
49
50
        for ($i=0; $i<=count($ranking)-1; $i++) {
51
            foreach ($chart->getLibs() as $lib) {
52
                $key = $lib->getIdLibChart();
53
                // format value
54
                $ranking[$i]['values'][] = Score::formatScore(
55
                    $ranking[$i]["value_$key"],
56
                    $lib->getType()->getMask()
57
                );
58
            }
59
        }
60
        return $ranking;
61
    }
62
}
63