Passed
Push — master ( b34030...56c38f )
by Sebastian
03:50
created

Cli::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 4
crap 2
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace sebastianfeldmann\CaptainHook\Runner\Action;
11
12
use sebastianfeldmann\CaptainHook\Config;
13
use sebastianfeldmann\CaptainHook\Console\IO;
14
use sebastianfeldmann\CaptainHook\Exception;
15
use sebastianfeldmann\CaptainHook\Git\Repository;
16
use sebastianfeldmann\CaptainHook\Hook\Action;
17
use Symfony\Component\Process\Process;
18
19
/**
20
 * Class Cli
21
 *
22
 * @package CaptainHook
23
 * @author  Sebastian Feldmann <[email protected]>
24
 * @link    https://github.com/sebastianfeldmann/captainhook
25
 * @since   Class available since Release 0.9.0
26
 */
27
class Cli implements Action
28
{
29
    /**
30
     * Execute the configured action.
31
     *
32
     * @param  \sebastianfeldmann\CaptainHook\Config         $config
33
     * @param  \sebastianfeldmann\CaptainHook\Console\IO     $io
34
     * @param  \sebastianfeldmann\CaptainHook\Git\Repository $repository
35
     * @param  \sebastianfeldmann\CaptainHook\Config\Action  $action
36
     * @throws \sebastianfeldmann\CaptainHook\Exception\ActionExecution
37
     */
38 3
    public function execute(Config $config, IO $io, Repository $repository, Config\Action $action)
39
    {
40 3
        $process = new Process($action->getAction());
41 3
        $process->run();
42
43 3
        if (!$process->isSuccessful()) {
44 1
            throw new Exception\ActionExecution($process->getOutput() . PHP_EOL . $process->getErrorOutput());
45
        }
46
47 2
        $io->write($process->getOutput());
48 2
    }
49
}
50