Test Failed
Push — develop ( db5b9c...b55dd4 )
by Paul
17:52
created

Hooks   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
eloc 31
c 1
b 0
f 0
dl 0
loc 59
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A version() 0 5 2
A supportedVersion() 0 3 1
A hasPluginsLoaded() 0 3 1
A onPluginsLoaded() 0 26 3
A isInstalled() 0 8 6
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 hasPluginsLoaded(): bool
10
    {
11
        return true;
12
    }
13
14
    /**
15
     * @action plugins_loaded:0
16
     */
17
    public function onPluginsLoaded(): void
18
    {
19
        if (!$this->isInstalled()) {
20
            return;
21
        }
22
        if (!$this->isVersionSupported()) {
23
            $this->notify('Breakdance');
24
            return;
25
        }
26
        $this->hook(Controller::class, [
27
            ['registerElements', 'breakdance_loaded', 5],
28
            // Unfortunately we can't perform this action yet because Breakdance
29
            // does not support AJAX searching in multiselect controls.
30
            // ['registerRoutes', 'breakdance_loaded'],
31
            ['searchAssignedPosts', 'breakdance_ajax_breakdance_get_posts', 1],
32
            ['searchAssignedPosts', 'wp_ajax_breakdance_get_posts', 1],
33
            ['searchAssignedPosts', 'wp_ajax_nopriv_breakdance_get_posts', 1],
34
            ['searchAssignedTerms', 'breakdance_ajax_breakdance_get_posts', 1],
35
            ['searchAssignedTerms', 'wp_ajax_breakdance_get_posts', 1],
36
            ['searchAssignedTerms', 'wp_ajax_nopriv_breakdance_get_posts', 1],
37
            ['searchAssignedUsers', 'breakdance_ajax_breakdance_get_posts', 1],
38
            ['searchAssignedUsers', 'wp_ajax_breakdance_get_posts', 1],
39
            ['searchAssignedUsers', 'wp_ajax_nopriv_breakdance_get_posts', 1],
40
            ['searchPostId', 'breakdance_ajax_breakdance_get_posts', 1],
41
            ['searchPostId', 'wp_ajax_breakdance_get_posts', 1],
42
            ['searchPostId', 'wp_ajax_nopriv_breakdance_get_posts', 1],
43
        ]);
44
    }
45
46
    protected function isInstalled(): bool
47
    {
48
        return class_exists('Breakdance\Elements\Element')
49
            && function_exists('Breakdance\AJAX\get_nonce_for_ajax_requests')
50
            && function_exists('Breakdance\AJAX\get_nonce_key_for_ajax_requests')
51
            && function_exists('Breakdance\AJAX\register_handler')
52
            && function_exists('Breakdance\Elements\registerCategory')
53
            && function_exists('Breakdance\Permissions\hasMinimumPermission');
54
    }
55
56
    protected function supportedVersion(): string
57
    {
58
        return '2.2.0';
59
    }
60
61
    protected function version(): string
62
    {
63
        return defined('__BREAKDANCE_VERSION')
64
            ? (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...
65
            : '';
66
    }
67
}
68