Passed
Push — master ( f510e9...9822a2 )
by Paul
10:29
created

AbstractHooks   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 19
dl 0
loc 39
ccs 0
cts 17
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hook() 0 11 4
A __construct() 0 7 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Hooks;
4
5
use GeminiLabs\SiteReviews\Helpers\Str;
6
7
abstract class AbstractHooks
8
{
9
    protected $basename;
10
    protected $id;
11
    protected $prefix;
12
    protected $taxonomy;
13
    protected $type;
14
15
    public function __construct()
16
    {
17
        $this->basename = plugin_basename(glsr()->file);
18
        $this->id = glsr()->id;
19
        $this->prefix = glsr()->prefix;
20
        $this->taxonomy = glsr()->taxonomy;
21
        $this->type = glsr()->post_type;
22
    }
23
24
    /**
25
     * @param string $classname
26
     * @return void
27
     */
28
    public function hook($classname, array $hooks)
29
    {
30
        $controller = glsr($classname);
31
        foreach ($hooks as $hook) {
32
            if (2 > count($hook)) {
33
                continue;
34
            }
35
            $func = Str::startsWith('filter', $hook[0]) ? 'add_filter' : 'add_action';
36
            $hook = array_pad($hook, 3, 10); // priority
37
            $hook = array_pad($hook, 4, 1); // allowed args
38
            call_user_func($func, $hook[1], [$controller, $hook[0]], (int) $hook[2], (int) $hook[3]);
39
        }
40
    }
41
42
    /**
43
     * @return void
44
     */
45
    abstract public function run();
46
}
47