Completed
Push — master ( 95a54c...7178fa )
by Samuel
10:58
created

SoftwareInstallTask   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 45
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
getVersionCommand() 0 1 ?
getInstallCommand() 0 1 ?
A __construct() 0 5 1
A run() 0 10 2
1
<?php
2
3
namespace Dock\Installer;
4
5
use Dock\IO\ProcessRunner;
6
use Dock\IO\UserInteraction;
7
use SRIO\ChainOfResponsibility\NamedChainProcessInterface;
8
9
abstract class SoftwareInstallTask extends InstallerTask implements NamedChainProcessInterface
10
{
11
    /**
12
     * @var ProcessRunner
13
     */
14
    protected $processRunner;
15
    /**
16
     * @var UserInteraction
17
     */
18
    protected $userInteraction;
19
20
    /**
21
     * @param UserInteraction        $userInteraction
22
     * @param \Dock\IO\ProcessRunner $processRunner
23
     */
24
    public function __construct(UserInteraction $userInteraction, ProcessRunner $processRunner)
25
    {
26
        $this->userInteraction = $userInteraction;
27
        $this->processRunner = $processRunner;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function run()
34
    {
35
        if ($this->processRunner->run($this->getVersionCommand(), false)->isSuccessful()) {
36
            $this->userInteraction->write(sprintf('"%s" is already installed', $this->getName()));
37
        } else {
38
            $this->userInteraction->write(sprintf('Installing "%s"', $this->getName()));
39
            $this->processRunner->run($this->getInstallCommand());
40
            $this->userInteraction->write(sprintf('"%s" successfully installed', $this->getName()));
41
        }
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    abstract protected function getVersionCommand();
48
49
    /**
50
     * @return string
51
     */
52
    abstract protected function getInstallCommand();
53
}
54