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

Enabler::operatingSystemIsNotWindows()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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