Registerable   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 2
eloc 6
c 5
b 1
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A registerHook() 0 9 2
1
<?php
2
3
/**
4
 * Trait used for often registering things around Wordpress.
5
 *
6
 * PHP version 7.4
7
 *
8
 * @category Traits
9
 * @package  Chaospelt\Kernel\Traits
10
 *
11
 * @author  Stf Kolev <[email protected]>
12
 * @license BSD-3-Clause https://opensource.org/licenses/BSD-3-Clause
13
 *
14
 * @link https://github.com/stfkolev/chaospelt
15
 */
16
17
namespace Chaospelt\Kernel\Traits;
18
19
use Chaospelt\Kernel\Concerns\Fluent;
20
use ReflectionClass;
21
22
/**
23
 * Trait used for often registering things around Wordpress.
24
 *
25
 * @category Traits
26
 * @package  Chaospelt\Kernel\Traits
27
 *
28
 * @author  Stf Kolev <[email protected]>
29
 * @license BSD-3-Clause https://opensource.org/licenses/BSD-3-Clause
30
 *
31
 * @link https://github.com/stfkolev/chaospelt
32
 */
33
trait Registerable
34
{
35
    /**
36
     * Used to register Wordpress hooks.
37
     *
38
     * @param string $hook  Used to specify the name of the hook
39
     * @param string $type  Used to specify the type of the hook
40
     * @param mixed  $class Class that should be used for the closure
41
     *
42
     * @return void
43
     */
44
    public function registerHook($hook, $type, $class)
45
    {
46
        $reflectedConcern = new \ReflectionClass($class);
47
48
        if ($reflectedConcern->implementsInterface(Fluent::class)) {
49
            $fluentReflection = new ReflectionClass(Fluent::class);
50
            $firstMethod = reset($fluentReflection->getMethods());
51
            
52
            ("add_$type")($hook, [$class, $firstMethod->name]);
53
        }
54
    }
55
}
56