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

Util   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 51
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 4 1
A getValidHooks() 0 4 1
A getHooks() 0 4 1
A getActionType() 0 4 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\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