Test Failed
Push — master ( 8056b0...16429a )
by Paweł
02:11
created

WarmUpCacheCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 16
rs 9.9
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\Serializer;
9
use pjpawel\LightApi\Container\ContainerLoader;
10
use pjpawel\LightApi\Kernel;
11
use pjpawel\LightApi\Route\Router;
12
use ReflectionClass;
13
14
class WarmUpCacheCommand extends KernelAwareCommand
15
{
16
17
    /**
18
     * @inheritDoc
19
     */
20
    public function execute(InputInterface $input, OutputInterface $output): int
21
    {
22
        $reflectionClass = new ReflectionClass(Kernel::class);
23
        /** @var Serializer $serializer */
24
        $serializer = $reflectionClass->getProperty('serializer')->getValue($this->kernel);
25
        $serializerClass = new ReflectionClass($serializer);
26
        if (rmdir($serializerClass->getProperty('serializedDir')->getValue($serializer))) {
27
            throw new \Exception('Cannot remove dir: ' .
28
                $serializerClass->getProperty('serializedDir')->getValue($serializer));
29
        }
30
        $serializer->makeSerialization([
31
            ContainerLoader::class => $reflectionClass->getProperty('containerLoader')->getValue($this->kernel),
32
            Router::class => $reflectionClass->getProperty('router')->getValue($this->kernel),
33
            CommandsLoader::class => $reflectionClass->getProperty('commandLoader')->getValue($this->kernel)
34
        ]);
35
        return self::SUCCESS;
36
    }
37
}