Completed
Push — master ( ee0aed...da9ac8 )
by Michael
03:02
created

ClearCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 77
ccs 0
cts 32
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 23 2
A getDescription() 0 4 1
A getTitle() 0 4 1
1
<?php
2
3
namespace Stats\Commands\Cache;
4
5
use Doctrine\Common\Cache\Cache;
6
use Doctrine\Common\Cache\FlushableCache;
7
use Joomla\Controller\AbstractController;
8
use Stats\CommandInterface;
9
10
/**
11
 * CLI command for clearing the application cache
12
 *
13
 * @method         \Stats\CliApplication  getApplication()  Get the application object.
14
 * @property-read  \Stats\CliApplication  $app              Application object
15
 *
16
 * @since          1.0
17
 */
18
class ClearCommand extends AbstractController implements CommandInterface
19
{
20
	/**
21
	 * The cache handler.
22
	 *
23
	 * @var    Cache
24
	 * @since  1.0
25
	 */
26
	private $cache;
27
28
	/**
29
	 * Constructor.
30
	 *
31
	 * @param   Cache  $cache  The cache handler
32
	 *
33
	 * @since   1.0
34
	 */
35
	public function __construct(Cache $cache)
36
	{
37
		$this->cache = $cache;
38
	}
39
40
	/**
41
	 * Execute the controller.
42
	 *
43
	 * @return  boolean
44
	 *
45
	 * @since   1.0
46
	 */
47
	public function execute()
48
	{
49
		$this->getApplication()->outputTitle('Cache: Clear');
50
51
		if ($this->cache instanceof FlushableCache)
52
		{
53
			$this->cache->flushAll();
54
55
			$this->getApplication()->out('<info>The application cache has been cleared.</info>');
56
		}
57
		else
58
		{
59
			$this->getApplication()->out(
60
				sprintf(
61
					'<comment>This command only supports clearing the cache with %1$s instances that implement the %2$s interface.</comment>',
62
					Cache::class,
63
					FlushableCache::class
64
				)
65
			);
66
		}
67
68
		return true;
69
	}
70
71
	/**
72
	 * Get the command's description
73
	 *
74
	 * @return  string
75
	 *
76
	 * @since   1.0
77
	 */
78
	public function getDescription()
79
	{
80
		return 'Clear the application cache.';
81
	}
82
83
	/**
84
	 * Get the command's title
85
	 *
86
	 * @return  string
87
	 *
88
	 * @since   1.0
89
	 */
90
	public function getTitle()
91
	{
92
		return 'Clear Cache';
93
	}
94
}
95