Completed
Pull Request — development (#560)
by Thomas
07:00
created

ApiGeocacheController::getReportsAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 18
rs 9.4285
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