Passed
Push — master ( 7bee4d...457c92 )
by Sebastian
01:54
created

Util::getHookCommand()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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 CaptainHook\App\Hook;
11
12
use CaptainHook\App\Hooks;
13
use RuntimeException;
14
15
/**
16
 * Class Util
17
 *
18
 * @package CaptainHook
19
 * @author  Sebastian Feldmann <[email protected]>
20
 * @link    https://github.com/captainhookphp/captainhook
21
 * @since   Class available since Release 0.9.0
22
 */
23
abstract class Util
24
{
25
    /**
26
     * Checks if a hook name is valid
27
     *
28
     * @param  string $hook
29
     * @return bool
30
     */
31 42
    public static function isValid(string $hook) : bool
32
    {
33 42
        return isset(Hooks::getValidHooks()[$hook]);
34
    }
35
36
    /**
37
     * Returns list of valid hooks
38
     *
39
     * @return array
40
     */
41 37
    public static function getValidHooks() : array
42
    {
43 37
        return Hooks::getValidHooks();
44
    }
45
46
    /**
47
     * Returns hooks command class
48
     *
49
     * @param  string $hook
50
     * @return string
51
     */
52 15
    public static function getHookCommand(string $hook) : string
53
    {
54 15
        if (!self::isValid($hook)) {
55 3
            throw new RuntimeException(sprintf('Hook \'%s\' is not supported', $hook));
56
        }
57 12
        return Hooks::getValidHooks()[$hook];
58
    }
59
60
    /**
61
     * Get a list of all supported hooks
62
     *
63
     * @return array
64
     */
65 4
    public static function getHooks() : array
66
    {
67 4
        return array_keys(Hooks::getValidHooks());
68
    }
69
}
70