Passed
Push — master ( 2cb2b7...f763a2 )
by SignpostMarv
02:22
created

FastRouteCacheCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 1
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 2
    public function configure() : void
22
    {
23 2
        $this->setDescription(
24 2
            'Update the cache used by the daft framework router'
25 2
        )->addArgument(
26 2
            'sources',
27 2
            InputArgument::REQUIRED | InputArgument::IS_ARRAY,
28 2
            'class names for sources'
29
        );
30 2
    }
31
32 2
    public function execute(InputInterface $input, OutputInterface $output) : int
33
    {
34 2
        $cacheFilename = tempnam(sys_get_temp_dir(), static::class);
35 2
        unlink($cacheFilename);
36
37 2
        $cacheFilename .= '.cache';
38
39 2
        Compiler::ObtainDispatcher(
40
            [
41 2
                'cacheFile' => $cacheFilename,
42
            ],
43 2
            ...$input->getArgument('sources')
44
        );
45
46 2
        $output->write(file_get_contents($cacheFilename));
47
48 2
        unlink($cacheFilename);
49
50 2
        return 0;
51
    }
52
}
53