Passed
Push — master ( 38d253...7e6548 )
by Dāvis
03:34
created

ScriptController::generateAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Script\Controller;
4
5
use Predis\Client;
6
use Symfony\Bundle\FrameworkBundle\Console\Application;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\Console\Input\ArrayInput;
9
use Symfony\Component\HttpFoundation\JsonResponse;
10
use Sludio\HelperBundle\Translatable\Repository\TranslatableRepository as Sludio;
11
12
class ScriptController extends Controller
13
{
14
    public function redisAction()
15
    {
16
        $clients = [];
17
        foreach ($this->container->getServiceIds() as $id) {
1 ignored issue
show
Bug introduced by
The method getServiceIds() does not exist on Symfony\Component\Depend...tion\ContainerInterface. It seems like you code against a sub-type of Symfony\Component\Depend...tion\ContainerInterface such as Symfony\Component\DependencyInjection\Container or Symfony\Component\Depend...ection\ContainerBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        foreach ($this->container->/** @scrutinizer ignore-call */ getServiceIds() as $id) {
Loading history...
18 View Code Duplication
            if (substr($id, 0, 9) === 'snc_redis' && $this->container->get($id) instanceof Client) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
                $clients[] = $id;
20
            }
21
        }
22
23
        foreach ($clients as $snc) {
24
            $this->container->get($snc)->flushdb();
25
        }
26
27
        return new JsonResponse(['success' => 1], 200, [
28
            'Cache-Control' => 'no-cache',
29
        ]);
30
    }
31
32
    public function cacheAction()
33
    {
34
        global $kernel;
35
36
        if ('AppCache' === get_class($kernel)) {
37
            $kernel = $kernel->getKernel();
38
        }
39
40
        $commands = [
41
            'clear',
42
            'warmup',
43
        ];
44
        foreach ($commands as $command) {
45
            $application = new Application($kernel);
46
            $application->setAutoExit(false);
47
            $input = new ArrayInput([
48
                'command' => 'cache:'.$command,
49
                '--env' => $kernel->getEnvironment(),
50
            ]);
51
            $application->run($input);
52
        }
53
54
        return new JsonResponse(['success' => 1], 200, [
55
            'Cache-Control' => 'no-cache',
56
        ]);
57
    }
58
59
    public function lexikAction()
60
    {
61
        global $kernel;
62
63
        if ('AppCache' === get_class($kernel)) {
64
            $kernel = $kernel->getKernel();
65
        }
66
67
        $application = new Application($kernel);
68
        $application->setAutoExit(false);
69
70
        $input = new ArrayInput([
71
            'command' => 'sludio:lexik:clear',
72
        ]);
73
        $application->run($input);
74
75
        return new JsonResponse(['success' => 1], 200, [
76
            'Cache-Control' => 'no-cache',
77
        ]);
78
    }
79
80
    public function generateAction()
81
    {
82
        Sludio::getAllTranslations();
83
84
        return new JsonResponse(['success' => 1], 200, [
85
            'Cache-Control' => 'no-cache',
86
        ]);
87
    }
88
}
89