Passed
Push — master ( 5b49ac...957a79 )
by SignpostMarv
02:45
created

FastRouteCacheCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 2
dl 0
loc 19
ccs 0
cts 10
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
* @author SignpostMarv
4
*/
5
declare(strict_types=1);
6
7
namespace SignpostMarv\DaftFramework\Symfony\Console\Command;
8
9
use SignpostMarv\DaftRouter\Router\Compiler;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class FastRouteCacheCommand extends Command
15
{
16
    /**
17
    * @var string
18
    */
19
    protected static $defaultName = 'daft-framework:router:update-cache';
20
21
    public function execute(InputInterface $input, OutputInterface $output) : int
22
    {
23
        $cacheFilename = tempnam(sys_get_temp_dir(), static::class);
24
        unlink($cacheFilename);
25
26
        $cacheFilename .= '.cache';
27
28
        Compiler::ObtainDispatcher(
29
            [
30
                'cacheFile' => $cacheFilename,
31
            ],
32
            ...$input->getArgument('sources')
33
        );
34
35
        $output->write(file_get_contents($cacheFilename));
36
37
        unlink($cacheFilename);
38
39
        return 0;
40
    }
41
42
    protected function configure() : void
43
    {
44
        $this->setDescription(
45
            'Update the cache used by the daft framework router'
46
        )->addArgument(
47
            'sources',
48
            InputArgument::REQUIRED | InputArgument::IS_ARRAY,
49
            'class names for sources'
50
        );
51
    }
52
}
53