Passed
Push — main ( 72ff1c...f45cd4 )
by Paul
05:18
created

Hooks::removeAction()   B

Complexity

Conditions 8
Paths 7

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 25
ccs 0
cts 18
cp 0
rs 8.4444
c 1
b 0
f 0
cc 8
nc 7
nop 2
crap 72
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\WooRewards;
4
5
use GeminiLabs\SiteReviews\Compatibility;
6
use GeminiLabs\SiteReviews\Contracts\HooksContract;
7
8
class Hooks implements HooksContract
9
{
10
    /**
11
     * @var Controller
12
     */
13
    public $controller;
14
15
    public function __construct()
16
    {
17
        glsr()->singleton(Controller::class);
18
        $this->controller = glsr(Controller::class);
19
    }
20
21
    public function run(): void
22
    {
23
        if (!class_exists('\LWS_WooRewards') || !class_exists('\LWS\WOOREWARDS\Core\Trace')) {
24
            return;
25
        }
26
        add_action('lws_woorewards_abstracts_event_installed', function () {
27
            glsr(Compatibility::class)->removeHook('comment_post', 'trigger', '\LWS\WOOREWARDS\Events\ProductReview');
28
            glsr(Compatibility::class)->removeHook('comment_unapproved_to_approved', 'delayedApproval', '\LWS\WOOREWARDS\Events\ProductReview');
29
            glsr(Compatibility::class)->removeHook('wp_insert_comment', 'review', '\LWS\WOOREWARDS\Events\ProductReview');
30
            if ($this->controller->event) {
31
                add_action('site-reviews/review/approved', [$this->controller, 'onApprovedReview'], 20);
32
                add_action('site-reviews/review/created', [$this->controller, 'onCreatedReview'], 20);
33
            }
34
        });
35
    }
36
}
37