Passed
Push — master ( f27ff6...85ae0d )
by Paweł
01:57
created

WarmUpCacheCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 13 1
A __construct() 0 3 1
1
<?php
2
3
namespace pjpawel\LightApi\Command\Internal;
4
5
use pjpawel\LightApi\Command\CommandsLoader;
6
use pjpawel\LightApi\Command\Input\InputInterface;
7
use pjpawel\LightApi\Command\Output\OutputInterface;
8
use pjpawel\LightApi\Component\FilesManager;
9
use pjpawel\LightApi\Component\Serializer;
10
use pjpawel\LightApi\Container\ContainerLoader;
11
use pjpawel\LightApi\Kernel;
12
use pjpawel\LightApi\Route\Router;
13
use ReflectionClass;
14
15
class WarmUpCacheCommand extends KernelAwareCommand
16
{
17
18
    private FilesManager $filesManager;
19
20
    public function __construct()
21
    {
22
        $this->filesManager = new FilesManager();
23
    }
24
25
    /**
26
     * @inheritDoc
27
     */
28
    public function execute(InputInterface $input, OutputInterface $output): int
29
    {
30
        $reflectionClass = new ReflectionClass(Kernel::class);
31
        /** @var Serializer $serializer */
32
        $serializer = $reflectionClass->getProperty('serializer')->getValue($this->kernel);
33
        $serializerClass = new ReflectionClass($serializer);
34
        $this->filesManager->removeDirRecursive($serializerClass->getProperty('serializedDir')->getValue($serializer));
35
        $serializer->makeSerialization([
36
            ContainerLoader::class => $reflectionClass->getProperty('containerLoader')->getValue($this->kernel),
37
            Router::class => $reflectionClass->getProperty('router')->getValue($this->kernel),
38
            CommandsLoader::class => $reflectionClass->getProperty('commandLoader')->getValue($this->kernel)
39
        ]);
40
        return self::SUCCESS;
41
    }
42
}