AdminController::clearStatsCache()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 2
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controller\Admin;
4
5
use App\Repository\ImageRepository;
6
use App\Repository\WanderRepository;
7
use App\Service\StatsService;
8
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\Routing\Annotation\Route;
12
use Symfony\Contracts\Cache\TagAwareCacheInterface;
13
use Symfony\UX\Chartjs\Builder\ChartBuilderInterface;
14
use Symfony\UX\Chartjs\Model\Chart;
15
16
/**
17
 * @Route("/admin", name="admin_")
18
 */
19
class AdminController extends AbstractController
20
{
21
    /**
22
     * @Route("/", name="index")
23
     */
24
    public function index(
25
        StatsService $statsService
26
    ): Response {
27
        $wanderStats = $statsService->getWanderStats();
28
        $imageStats = $statsService->getImageStats();
29
        $imageLocationStats = $statsService->getImageLocationStats();
30
31
        return $this->render('admin/index.html.twig', [
32
            'imageStats' => $imageStats,
33
            'wanderStats' => $wanderStats,
34
            'imageLocationStats' => $imageLocationStats
35
        ]);
36
    }
37
38
    /**
39
     * @Route("/clearStatsCache", name="clear_stats_cache")
40
     */
41
    public function clearStatsCache(Request $request, TagAwareCacheInterface $cache): Response
42
    {
43
        if ($this->isCsrfTokenValid('admin_clear_stats_cache', (string) $request->request->get('_token'))) {
44
            $cache->invalidateTags(['stats']);
45
            $this->addFlash(
46
                'notice',
47
                'Stats Cache Cleared.'
48
            );
49
        } else {
50
            $this->addFlash(
51
                'error',
52
                'Stats not cleared. Invalid Csrf token.'
53
            );
54
        }
55
        return $this->redirectToRoute('admin_index');
56
    }
57
}