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

Util::isValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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