Passed
Push — master ( b34030...56c38f )
by Sebastian
03:50
created

HookHandler::setHook()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 3
eloc 5
nc 2
nop 1
crap 3
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\Runner;
11
12
use sebastianfeldmann\CaptainHook\Exception;
13
use sebastianfeldmann\CaptainHook\Hook\Util as HookUtil;
14
use sebastianfeldmann\CaptainHook\Runner;
15
16
/**
17
 * Class HookHandler
18
 *
19
 * @package CaptainHook
20
 * @author  Sebastian Feldmann <[email protected]>
21
 * @link    https://github.com/sebastianfeldmann/captainhook
22
 * @since   Class available since Release 0.9.0
23
 */
24
abstract class HookHandler extends Runner
25
{
26
    /**
27
     * Hook that should be handled
28
     *
29
     * @var string
30
     */
31
    protected $hookToHandle;
32
33
    /**
34
     * Hook setter.
35
     *
36
     * @param  string $hook
37
     * @return \sebastianfeldmann\CaptainHook\Runner\HookHandler
38
     * @throws \sebastianfeldmann\CaptainHook\Exception\InvalidHookName
39
     */
40 10
    public function setHook($hook)
41
    {
42 10
        if (null !== $hook && !HookUtil::isValid($hook)) {
43 2
            throw new Exception\InvalidHookName('Invalid hook name \'' . $hook . '\'');
44
        }
45 8
        $this->hookToHandle = $hook;
46 8
        return $this;
47
    }
48
}
49