Completed
Push — master ( 176b02...5ca4f8 )
by Sebastian
02:13
created

Debug::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
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 CaptainHook\App\Hook;
11
12
use CaptainHook\App\Config;
13
use CaptainHook\App\Console\IO;
14
use CaptainHook\App\Exception\ActionFailed;
15
use SebastianFeldmann\Git\Repository;
16
17
/**
18
 * Debug hook to test hook triggering
19
 *
20
 * @package CaptainHook
21
 * @author  Sebastian Feldmann <[email protected]>
22
 * @link    https://github.com/captainhookphp/captainhook
23
 * @since   Class available since Release 4.0.4
24
 */
25
class Debug implements Action
26
{
27
    /**
28
     * Executes the action
29
     *
30
     * @param  \CaptainHook\App\Config           $config
31
     * @param  \CaptainHook\App\Console\IO       $io
32
     * @param  \SebastianFeldmann\Git\Repository $repository
33
     * @param  \CaptainHook\App\Config\Action    $action
34
     * @return void
35
     * @throws \Exception
36
     */
37 1
    public function execute(Config $config, IO $io, Repository $repository, Config\Action $action) : void
38
    {
39 1
        $originalHookArguments = $io->getArguments();
40 1
        $currentGitTag         = $repository->getInfoOperator()->getCurrentTag();
41
42 1
        $io->write('<info>Executing Dummy action</info>');
43 1
        $io->write($this->getArgumentOutput($originalHookArguments));
44 1
        $io->write('  Current git-tag: <comment>' . $currentGitTag . '</comment>');
45
46 1
        throw ActionFailed::withMessage(
47
            'The \'Debug\' action is only for debugging purposes, ' .
48 1
            'please remove the \'Debug\' action from your config'
49
        );
50
    }
51
52
    /**
53
     * Format output to display original hook arguments
54
     *
55
     * @param  array $args
56
     * @return string
57
     */
58 1
    protected function getArgumentOutput(array $args) : string
59
    {
60 1
        $out = '  Original arguments:' . PHP_EOL;
61 1
        foreach ($args as $name => $value) {
62 1
            $out .= '    ' . $name . ' => <comment>' . $value . '</comment>' . PHP_EOL;
63
        }
64 1
        return $out;
65
    }
66
}
67