Completed
Push — master ( 202f3c...15bdf1 )
by Tom
09:14 queued 04:46
created

Enabler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 37
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A functionExists() 0 4 1
A operatingSystemIsNotWindows() 0 4 1
A assert() 0 10 2
1
<?php
2
/*
3
 * @author Tom Klingenberg <https://github.com/ktomk>
4
 */
5
6
namespace N98\Util\Console;
7
8
use N98\Util\OperatingSystem;
9
use RuntimeException;
10
use Symfony\Component\Console\Command\Command;
11
12
/**
13
 * Class Enabler
14
 *
15
 * Utility class to check console command requirements to be "enabled".
16
 *
17
 * @see N98\Magento\Command\Database\DumpCommand::execute()
18
 *
19
 * @package N98\Util\Console
20
 */
21
class Enabler
22
{
23
    /**
24
     * @var Command
25
     */
26
    private $command;
27
28
    public function __construct(Command $command)
29
    {
30
        $this->command = $command;
31
    }
32
33
    public function functionExists($name)
34
    {
35
        $this->assert(function_exists($name), sprintf('function "%s" is not available', $name));
36
    }
37
38
    public function operatingSystemIsNotWindows()
39
    {
40
        $this->assert(!OperatingSystem::isWindows(), "operating system is windows");
41
    }
42
43
    /**
44
     * @param $condition
45
     * @param $message
46
     */
47
    private function assert($condition, $message)
48
    {
49
        if ($condition) {
50
            return;
51
        }
52
53
        throw new RuntimeException(
54
            sprintf('Command %s is not available because %s.', $this->command->getName(), $message)
55
        );
56
    }
57
}
58