Test Failed
Push — master ( 6db55f...0b650e )
by Chris
21:02
created

LinkManager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 17
c 1
b 0
f 0
dl 0
loc 38
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A enabledTags() 0 3 1
A doInitAction() 0 10 3
A hook() 0 3 1
A links() 0 9 1
1
<?php
2
3
namespace Leonidas\Framework\Site\Module;
4
5
use Leonidas\Framework\Module\Abstracts\Module;
6
use Leonidas\Hooks\TargetsInitHook;
7
8
class LinkManager extends Module
9
{
10
    use TargetsInitHook;
11
12
    public function hook(): void
13
    {
14
        $this->targetInitHook();
15
    }
16
17
    protected function doInitAction(): void
18
    {
19
        $enabled = $this->enabledTags();
20
21
        foreach ($this->links() as $tag => $args) {
22
            if (!in_array($tag, $enabled)) {
23
                $callback = $args[0];
24
                $priority = $args[1] ?? HOOK_DEFAULT_PRIORITY;
25
26
                remove_action('wp_head', $callback, $priority);
27
            }
28
        }
29
    }
30
31
    protected function links(): array
32
    {
33
        return [
34
            'adjacent_posts' => ['adjacent_posts_rel_link_wp_head'],
35
            'canonical' => ['rel_canonical'],
36
            'generator' => ['wp_generator'],
37
            'rsd' => ['rsd_link'],
38
            'shortlink' => ['wp_shortlink_wp_head'],
39
            'wlwmanifest' => ['wlwmanifest_link'],
40
        ];
41
    }
42
43
    protected function enabledTags(): array
44
    {
45
        return $this->getConfig('view.links', []);
46
    }
47
}
48