CommandExists::getMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Bencagri\Artisan\Deployer\Requirement;
5
6
use Bencagri\Artisan\Deployer\Task\Task;
7
8
class CommandExists extends AbstractRequirement
9
{
10
    private $commandName;
11
12
    public function __construct(array $servers, string $commandName)
13
    {
14
        parent::__construct($servers);
15
        $this->commandName = $commandName;
16
    }
17
18
    public function getMessage() : string
19
    {
20
        return sprintf('<ok>[OK]</> <command>%s</> command exists', $this->commandName);
21
    }
22
23
    public function getChecker() : Task
24
    {
25
        $shellCommand = sprintf('%s %s', $this->isWindows() ? 'where' : 'which', $this->commandName);
26
27
        return new Task($this->getServers(), $shellCommand);
28
    }
29
30
    private function isWindows() : bool
31
    {
32
        return '\\' === DIRECTORY_SEPARATOR;
33
    }
34
}
35