Passed
Push — develop ( e8f487...e4693f )
by
unknown
01:12 queued 10s
created

PlayerChartController::submit()   F

Complexity

Conditions 13
Paths 469

Size

Total Lines 121
Code Lines 80

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 80
nc 469
nop 1
dl 0
loc 121
rs 2.9863
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use VideoGamesRecords\CoreBundle\Entity\PlayerChart;
8
use Symfony\Component\HttpFoundation\Request;
9
use VideoGamesRecords\CoreBundle\Tools\Score;
10
use Symfony\Component\HttpFoundation\JsonResponse;
11
use VideoGamesRecords\CoreBundle\Entity\PlayerChartLib;
12
use Doctrine\DBAL\DBALException;
13
14
/**
15
 * Class PlayerChartController
16
 */
17
class PlayerChartController extends Controller
18
{
19
20
    /**
21
     * @param Request $request
22
     * @return mixed
23
     */
24
    public function getOne(Request $request)
25
    {
26
        $idPlayer = $request->query->get('idPlayer', 0);
27
        $idChart = $request->query->get('idChart', 0);
28
29
        $playerChart = $this->getDoctrine()->getRepository('VideoGamesRecordsCoreBundle:PlayerChart')->getFromUnique($idPlayer, $idChart);
30
        if ($playerChart === null) {
31
            $playerChart = new PlayerChart();
32
            $chart = $this->getDoctrine()->getRepository('VideoGamesRecordsCoreBundle:Chart')->find($idChart);
33
            $player = $this->getDoctrine()->getRepository('VideoGamesRecordsCoreBundle:Player')->find($idPlayer);
34
            $playerChart->setIdPlayerChart(-1);
35
            $playerChart->setChart($chart);
36
            $playerChart->setPlayer($player);
37
            foreach ($chart->getLibs() as $lib) {
38
                $playerChartLib = new PlayerChartLib();
39
                $playerChartLib->setId(-1);
40
                $playerChartLib->setLibChart($lib);
41
                $playerChart->addLib($playerChartLib);
42
            }
43
        }
44
        return $playerChart;
45
    }
46
}
47