Completed
Pull Request — development (#560)
by Thomas
06:46
created

ApiGeocacheController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 3
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getReportsAction() 0 18 3
1
<?php
2
3
namespace AppBundle\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
11
class ApiGeocacheController extends Controller
12
{
13
14
    /**
15
     * @Route("/api/geocache/getReports")
16
     * @param Request $request
0 ignored issues
show
introduced by
Request => \Symfony\Component\HttpFoundation\Request
Loading history...
17
     * @return \Symfony\Component\HttpFoundation\Response
18
     */
19
    public function getReportsAction(Request $request)
20
    {
21
        if ($this->container->getParameter('api_secret') === 'ThisTokenIsNotSoSecretChangeIt') {
22
            return new JsonResponse(['please change your api_secret to a secure one!']);
23
        }
24
25
        if ($request->get('key') !== $this->container->getParameter('api_secret')) {
26
            return new JsonResponse([]);
27
        }
28
29
        /** @var Reports $reports */
0 ignored issues
show
introduced by
Reports => \Oc\GeoCache\Reports
Loading history...
30
        $reports = $this->container->get('oc.geo_cache.reports');
31
        $geoCachesArray = explode('|', $request->get('geocaches'));
32
33
        $geoCaches = $reports->getReportStatus($geoCachesArray);
34
35
        return new JsonResponse($geoCaches);
36
    }
37
}
38