Passed
Push — master ( a15adc...3eeabd )
by SignpostMarv
05:36
created

FastRouteCacheCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 24 3
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 4
    public function execute(InputInterface $input, OutputInterface $output) : int
22
    {
23 4
        $cacheFilename = static::tempnamCheck(static::tempnam(), $output);
24
25 4
        if ( ! is_string($cacheFilename)) {
0 ignored issues
show
introduced by
The condition is_string($cacheFilename) is always true.
Loading history...
26 2
            return 1;
27
        }
28
29 2
        unlink($cacheFilename);
30
31 2
        $cacheFilename .= '.cache';
32
33
        /**
34
        * @var string[] $sources
35
        */
36 2
        $sources = $input->getArgument('sources');
37
38 2
        Compiler::ObtainDispatcher(['cacheFile' => $cacheFilename], ...$sources);
39
40 2
        $output->write(file_get_contents($cacheFilename) ?: 'false');
41
42 2
        unlink($cacheFilename);
43
44 2
        return 0;
45
    }
46
47 4
    protected function configure() : void
48
    {
49 4
        $this->setDescription(
50 4
            'Update the cache used by the daft framework router'
51 4
        )->addArgument(
52 4
            'sources',
53 4
            InputArgument::REQUIRED | InputArgument::IS_ARRAY,
54 4
            'class names for sources'
55
        );
56 4
    }
57
}
58