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

WarmUpCacheCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
}