Completed
Pull Request — 1.x (#35)
by
unknown
18:26
created

AbstractCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 4
c 3
b 1
f 0
lcom 0
cbo 2
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCacheTool() 0 4 1
A ensureExtensionLoaded() 0 6 2
A setContainer() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of CacheTool.
5
 *
6
 * (c) Samuel Gordalina <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CacheTool\Command;
13
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17
18
abstract class AbstractCommand extends Command implements ContainerAwareInterface
19
{
20
    /**
21
     * @var ContainerInterface
22
     */
23
    protected $container;
24
25
    /**
26
     * @return CacheTool
27
     */
28
    protected function getCacheTool()
29
    {
30
        return $this->container->get('cachetool');
31
    }
32
33
    /**
34
     * @param  string $extension
35
     */
36
    protected function ensureExtensionLoaded($extension)
37
    {
38
        if (!$this->getCacheTool()->extension_loaded($extension)) {
39
            throw new \Exception("Extension `{$extension}` is not loaded");
40
        }
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function setContainer(ContainerInterface $container = null)
47
    {
48
        $this->container = $container;
49
    }
50
}
51