Passed
Push — main ( cebfe5...3df9c7 )
by Sebastian
04:33
created

Debug::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 10
c 0
b 0
f 0
nc 1
nop 4
dl 0
loc 14
ccs 11
cts 11
cp 1
crap 1
rs 9.9332
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Hook;
13
14
use CaptainHook\App\Config;
15
use CaptainHook\App\Console\IO;
16
use CaptainHook\App\Exception\ActionFailed;
17
use SebastianFeldmann\Git\Repository;
18
19
/**
20
 * Debug hook to test hook triggering
21
 *
22
 * @package CaptainHook
23
 * @author  Sebastian Feldmann <[email protected]>
24
 * @link    https://github.com/captainhookphp/captainhook
25
 * @since   Class available since Release 4.0.4
26
 */
27
abstract class Debug implements Action
28
{
29
    /**
30
     * Executes the action
31
     *
32
     * @param  \CaptainHook\App\Config           $config
33
     * @param  \CaptainHook\App\Console\IO       $io
34
     * @param  \SebastianFeldmann\Git\Repository $repository
35
     * @param  \CaptainHook\App\Config\Action    $action
36
     * @return void
37
     * @throws \Exception
38
     */
39
    abstract public function execute(Config $config, IO $io, Repository $repository, Config\Action $action): void;
40
41
    /**
42
     * Generate some debug output
43
     *
44
     * @param \CaptainHook\App\Console\IO       $io
45
     * @param \SebastianFeldmann\Git\Repository $repository
46
     * @return void
47
     * @throws \CaptainHook\App\Exception\ActionFailed
48
     */
49 2
    protected function debugOutput(IO $io, Repository $repository): void
50
    {
51 2
        $originalHookArguments = $io->getArguments();
52 2
        $currentGitTag         = $repository->getInfoOperator()->getCurrentTag();
53
54 2
        $io->write(['', '']);
55 2
        $io->write('<info>Executing Dummy action</info>');
56 2
        $io->write($this->getArgumentOutput($originalHookArguments));
57 2
        $io->write('  Current git-tag: <comment>' . $currentGitTag . '</comment>');
58 2
        $io->write('  StandardInput: ' . PHP_EOL . '    ' . implode(PHP_EOL . '    ', $io->getStandardInput()));
59
    }
60
61
    /**
62
     * Format output to display original hook arguments
63
     *
64
     * @param  array<string> $args
65
     * @return string
66
     */
67 2
    protected function getArgumentOutput(array $args): string
68
    {
69 2
        $out = '  Original arguments:' . PHP_EOL;
70 2
        foreach ($args as $name => $value) {
71 2
            $out .= '    ' . $name . ' => <comment>' . $value . '</comment>' . PHP_EOL;
72
        }
73 2
        return trim($out);
74
    }
75
}
76