Test Failed
Push — develop ( 76157d...9702e2 )
by Paul
08:08
created

Hooks   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 15
eloc 27
c 3
b 0
f 2
dl 0
loc 55
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A version() 0 5 2
A supportedVersion() 0 3 1
A levelPluginsLoaded() 0 3 1
A onPluginsLoaded() 0 17 3
B isInstalled() 0 10 8
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Breakdance;
4
5
use GeminiLabs\SiteReviews\Integrations\IntegrationHooks;
6
7
class Hooks extends IntegrationHooks
8
{
9
    public function levelPluginsLoaded(): ?int
10
    {
11
        return 5;
12
    }
13
14
    /**
15
     * The "breakdance_loaded" hook is triggered on plugins_loaded:10
16
     * so we need to load hooks earlier than that.
17
     * 
18
     * @action plugins_loaded:5
19
     */
20
    public function onPluginsLoaded(): void
21
    {
22
        if (!$this->isInstalled()) {
23
            return;
24
        }
25
        if (!$this->isVersionSupported()) {
26
            $this->notify('Breakdance');
27
            return;
28
        }
29
        $this->hook(Controller::class, [
30
            ['interceptGetPostsQuery', 'breakdance_ajax_breakdance_get_posts', 1],
31
            ['interceptGetPostsQuery', 'wp_ajax_breakdance_get_posts', 1],
32
            ['interceptGetPostsQuery', 'wp_ajax_nopriv_breakdance_get_posts', 1],
33
            ['printInlineStyles', 'unofficial_i_am_kevin_geary_master_of_all_things_css_and_html'],
34
            ['registerDesignControls', 'init'],
35
            ['registerElements', 'breakdance_loaded', 5], // run early
36
            ['registerRoutes', 'breakdance_loaded', 5], // run early
37
        ]);
38
    }
39
40
    protected function isInstalled(): bool
41
    {
42
        return class_exists('Breakdance\Elements\Element')
43
            && function_exists('Breakdance\AJAX\get_nonce_for_ajax_requests')
44
            && function_exists('Breakdance\AJAX\get_nonce_key_for_ajax_requests')
45
            && function_exists('Breakdance\AJAX\register_handler')
46
            && function_exists('Breakdance\Elements\c')
47
            && function_exists('Breakdance\Elements\PresetSections\getPresetSection')
48
            && function_exists('Breakdance\Elements\registerCategory')
49
            && function_exists('Breakdance\Permissions\hasMinimumPermission');
50
    }
51
52
    protected function supportedVersion(): string
53
    {
54
        return '2.2.0';
55
    }
56
57
    protected function version(): string
58
    {
59
        return defined('__BREAKDANCE_VERSION')
60
            ? (string) \__BREAKDANCE_VERSION
0 ignored issues
show
Bug introduced by
The constant __BREAKDANCE_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
61
            : '';
62
    }
63
}
64