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

GeoCacheController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getReportsAction() 0 19 3
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