Completed
Push — master ( fb5c6c...3561cd )
by Tom
04:39
created

Enabler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 45
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
 * this file is part of magerun
4
 *
5
 * @author Tom Klingenberg <https://github.com/ktomk>
6
 */
7
8
namespace N98\Util\Console;
9
10
use N98\Util\OperatingSystem;
11
use RuntimeException;
12
use Symfony\Component\Console\Command\Command;
13
14
/**
15
 * Class Enabler
16
 *
17
 * Utility class to check console command requirements to be "enabled".
18
 *
19
 * @see \N98\Magento\Command\Database\DumpCommand::execute()
20
 *
21
 * @package N98\Util\Console
22
 */
23
class Enabler
24
{
25
    /**
26
     * @var Command
27
     */
28
    private $command;
29
30
    public function __construct(Command $command)
31
    {
32
        $this->command = $command;
33
    }
34
35
    /**
36
     * @param $name
37
     *
38
     * @return void
39
     */
40
    public function functionExists($name)
41
    {
42
        $this->assert(function_exists($name), sprintf('function "%s" is not available', $name));
43
    }
44
45
    /**
46
     * @return void
47
     */
48
    public function operatingSystemIsNotWindows()
49
    {
50
        $this->assert(!OperatingSystem::isWindows(), "operating system is windows");
51
    }
52
53
    /**
54
     * @param $condition
55
     * @param $message
56
     */
57
    private function assert($condition, $message)
58
    {
59
        if ($condition) {
60
            return;
61
        }
62
63
        throw new RuntimeException(
64
            sprintf('Command %s is not available because %s.', $this->command->getName(), $message)
65
        );
66
    }
67
}
68