Passed
Pull Request — development (#671)
by Nick
06:47
created

GeoCacheController::getReportsAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Oc\GeoCache\Controller;
4
5
use Oc\GeoCache\Reports;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
12
/**
13
 * Class GeoCacheController
14
 *
15
 * @package Oc\GeoCache\Controller
16
 */
17
class GeoCacheController extends Controller
18
{
19
20
    /**
21
     * @param Request $request
22
     *
23
     * @return Response
24
     *
25
     * @Route("/api/geocache/getReports")
26
     */
27
    public function getReportsAction(Request $request)
28
    {
29
        //TODO: may 'api_secret' be 'secret'?
30
        if ($this->container->getParameter('api_secret') === 'ThisTokenIsNotSoSecretChangeIt') {
31
            return new JsonResponse(['please change your api_secret to a secure one!']);
32
        }
33
34
        if ($request->get('key') !== $this->container->getParameter('api_secret')) {
35
            return new JsonResponse([]);
36
        }
37
38
        /** @var Reports $reports */
39
        $reports = $this->container->get('oc.geo_cache.reports');
40
        $geoCachesArray = explode('|', $request->get('geocaches'));
41
42
        $geoCaches = $reports->getReportStatus($geoCachesArray);
43
44
        return new JsonResponse($geoCaches);
45
    }
46
}
47