Test Failed
Push — develop ( 65d39e...93bfc8 )
by Paul
09:43
created

glsr_store_deprecated_hook()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 20
rs 9.7998
cc 3
nc 3
nop 4
1
<?php
2
3
defined('ABSPATH') || exit;
4
5
/*
6
 * Provide support for the deprecated {{ assigned_to }} tag
7
 * @param string $template
8
 * @return string
9
 * @since 5.0
10
 */
11
add_filter('site-reviews/build/template/review', function ($template) {
12
    return str_replace('{{ assigned_to }}', '{{ assigned_links }}', $template);
13
});
14
/*
15
 * Fix the {{ review_id }} tag in the review template which now only returns the ID
16
 * @param string $template
17
 * @return string
18
 * @since 5.3
19
 */
20
add_filter('site-reviews/build/template/review', function ($template) {
21
    return str_replace('id="{{ review_id }}"', 'id="review-{{ review_id }}"', $template);
22
});
23
24
add_action('plugins_loaded', function () {
25
    if (!glsr()->filterBool('support/deprecated/v7', true)) {
26
        return;
27
    }
28
    add_filter('site-reviews/review-form/fields/all', function ($fields, $args) {
29
        return apply_filters_deprecated('site-reviews/review-form/fields/normalized',
30
            [$fields, $args],
31
            '7.0',
32
            'site-reviews/review-form/fields/all'
33
        );
34
    }, 10, 2);
35
});
36
37
add_action('plugins_loaded', function () {
38
    if (!glsr()->filterBool('support/deprecated/v6', true)) {
39
        return;
40
    }
41
    add_filter('site-reviews/rest-api/reviews/schema/properties', function ($properties) {
42
        return apply_filters_deprecated('site-reviews/rest-api/reviews/properties',
43
            [$properties],
44
            '6.5.0',
45
            'site-reviews/rest-api/reviews/schema/properties'
46
        );
47
    }, 9);
48
    add_filter('site-reviews/rest-api/summary/schema/properties', function ($properties) {
49
        return apply_filters_deprecated('site-reviews/rest-api/summary/properties',
50
            [$properties],
51
            '6.5.0',
52
            'site-reviews/rest-api/summary/schema/properties'
53
        );
54
    }, 9);
55
    add_action('site-reviews/review/updated', function ($review, $data) {
56
        return do_action_deprecated('site-reviews/review/saved',
0 ignored issues
show
Bug introduced by
Are you sure the usage of do_action_deprecated('si...eviews/review/updated') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
57
            [$review, $data],
58
            '6.7.0',
59
            'site-reviews/review/updated'
60
        );
61
    }, 10, 2);
62
    add_filter('site-reviews/slack/notification', function ($notification) {
63
        return apply_filters_deprecated('site-reviews/slack/compose',
64
            [$notification],
65
            '6.9.0',
66
            'site-reviews/slack/notification'
67
        );
68
    });
69
});
70
71
add_action('plugins_loaded', function () {
72
    if (!glsr()->filterBool('support/deprecated/v5', true)) {
73
        return;
74
    }
75
    add_filter('site-reviews/config/forms/review-form', function ($config) {
76
        return apply_filters_deprecated('site-reviews/config/forms/submission-form',
77
            [$config],
78
            '5.0',
79
            'site-reviews/config/forms/review-form'
80
        );
81
    }, 9);
82
    add_filter('site-reviews/rendered/template/reviews', function ($html) {
83
        return apply_filters_deprecated('site-reviews/reviews/reviews-wrapper',
84
            [$html],
85
            '5.0',
86
            '',
87
            'Please use a custom "reviews.php" template instead.'
88
        );
89
    });
90
    add_filter('site-reviews/review-form/order', function ($order) {
91
        return apply_filters_deprecated('site-reviews/submission-form/order',
92
            [$order],
93
            '5.0',
94
            'site-reviews/review-form/order'
95
        );
96
    }, 9);
97
    add_filter('site-reviews/defaults/review-table-filters', function ($defaults) {
98
        return apply_filters_deprecated('site-reviews/review-table/filter',
99
            [$defaults],
100
            '5.11.0',
101
            'site-reviews/defaults/review-table-filters'
102
        );
103
    });
104
    add_action('site-reviews/review/responded', function ($review, $response) {
105
        return do_action_deprecated('site-reviews/review/response',
0 ignored issues
show
Bug introduced by
Are you sure the usage of do_action_deprecated('si...nted on the FAQ page.') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
106
            [$review, $response],
107
            '5.11.0',
108
            'site-reviews/review/responded',
109
            'This hook is documented on the FAQ page.'
110
        );
111
    }, 9, 2);
112
});
113
114
function glsr_calculate_ratings()
115
{
116
    _deprecated_function('glsr_calculate_ratings', '5.0');
117
}
118
119
function glsr_get_rating($args = [])
120
{
121
    _deprecated_function('glsr_get_rating', '5.0', 'glsr_get_ratings');
122
    return new GeminiLabs\SiteReviews\Arguments($args);
123
}
124
125
function glsr_store_deprecated_hook($hook, $replacement, $version, $message)
126
{
127
    if (!str_starts_with($hook, glsr()->id)) {
128
        return;
129
    }
130
    if (empty($replacement)) {
131
        $notice = sprintf(
132
            'Hook %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
133
            $hook,
134
            $version
135
        );
136
    } else {
137
        $notice = sprintf(
138
            'Hook %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
139
            $hook,
140
            $version,
141
            $replacement
142
        );
143
    }
144
    glsr()->append('deprecated', trim($notice.' '.$message));
145
}
146
add_action('deprecated_hook_run', 'glsr_store_deprecated_hook', 10, 4);
147
148
function glsr_store_deprecated_function($fn, $replacement, $version)
149
{
150
    if (!str_starts_with($fn, glsr()->prefix)) {
151
        return;
152
    }
153
    if (empty($replacement)) {
154
        $notice = sprintf(
155
            'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
156
            $fn,
157
            $version
158
        );
159
    } else {
160
        $notice = sprintf(
161
            'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
162
            $fn,
163
            $version,
164
            $replacement
165
        );
166
    }
167
    glsr()->append('deprecated', $notice);
168
}
169
add_action('deprecated_function_run', 'glsr_store_deprecated_function', 10, 3);
170
171
function glsr_log_deprecated_notices()
172
{
173
    $notices = glsr()->retrieveAs('array', 'deprecated', []);
174
    $notices = array_keys(array_flip(array_filter($notices)));
175
    natsort($notices);
176
    array_walk($notices, fn ($notice) => glsr_log()->notice($notice));
177
}
178
add_action('admin_footer', 'glsr_log_deprecated_notices');
179
add_action('wp_footer', 'glsr_log_deprecated_notices');
180