Completed
Push — master ( aa9657...bb9832 )
by Sebastian
05:21
created

Cli   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 23
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 11 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\Hook\Action;
16
use SebastianFeldmann\Cli\Processor\ProcOpen as Processor;
17
use SebastianFeldmann\Git\Repository;
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\Git\Repository             $repository
35
     * @param  \SebastianFeldmann\CaptainHook\Config\Action  $action
36
     * @throws \Exception
37
     */
38 3
    public function execute(Config $config, IO $io, Repository $repository, Config\Action $action)
39
    {
40 3
        $processor = new Processor();
41 3
        $result    = $processor->run($action->getAction());
42
43 3
        if (!$result->isSuccessful()) {
44 1
            throw Exception\ActionFailed::withMessage($result->getStdOut() . PHP_EOL . $result->getStdErr());
45
        }
46
47 2
        $io->write($result->getStdOut());
48 2
    }
49
}
50