FastRouteCacheCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
eloc 20
c 8
b 0
f 0
dl 0
loc 47
ccs 18
cts 18
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 26 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
	const INT_RETURN_OK = 0;
17
18
	const INT_RETURN_FAIL = 1;
19
20
	/**
21
	* @var string
22
	*/
23
	protected static $defaultName = 'daft-framework:router:update-cache';
24
25 2
	public function execute(InputInterface $input, OutputInterface $output) : int
26
	{
27 2
		$cacheFilename = static::tempnamCheck($output);
28
29 2
		if ( ! is_string($cacheFilename)) {
30 1
			return self::INT_RETURN_FAIL;
31
		}
32
33 1
		unlink($cacheFilename);
34
35 1
		$cacheFilename .= '.cache';
36
37
		/**
38
		* @var string[]
39
		*
40
		* @psalm-var array<int, class-string<\SignpostMarv\DaftRouter\DaftSource>>
41
		*/
42 1
		$sources = $input->getArgument('sources');
43
44 1
		Compiler::ObtainDispatcher(['cacheFile' => $cacheFilename], ...$sources);
45
46 1
		$output->write(file_get_contents($cacheFilename) ?: 'false');
47
48 1
		unlink($cacheFilename);
49
50 1
		return self::INT_RETURN_OK;
51
	}
52
53 2
	protected function configure() : void
54
	{
55 2
		$this->setDescription(
56 2
			'Update the cache used by the daft framework router'
57 2
		)->addArgument(
58 2
			'sources',
59 2
			InputArgument::REQUIRED | InputArgument::IS_ARRAY,
60 2
			'class names for sources'
61
		);
62 2
	}
63
}
64