GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 1b89ee...33d1e4 )
by Brad
06:45 queued 03:33
created

FS_Admin_Notices   A

Complexity

Total Complexity 29

Size/Duplication

Total Lines 285
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 285
rs 10
c 0
b 0
f 0
wmc 29
lcom 2
cbo 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 7 2
B __construct() 0 24 2
B add() 0 24 2
A remove_sticky() 0 13 3
A has_sticky() 0 9 2
A add_sticky() 0 15 2
B clear_all_sticky() 0 16 8
A add_all() 0 3 1
A get_site_notices() 0 12 3
A should_use_network_notices() 0 18 4
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 10.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
    /**
3
     * @package     Freemius
4
     * @copyright   Copyright (c) 2015, Freemius, Inc.
5
     * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
6
     * @since       2.0.0
7
     */
8
9
    if ( ! defined( 'ABSPATH' ) ) {
10
        exit;
11
    }
12
13
    /**
14
     * WP Admin notices manager both for site level and network level.
15
     *
16
     * Class FS_Admin_Notices
17
     */
18
    class FS_Admin_Notices {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
19
        /**
20
         * @since 1.2.2
21
         *
22
         * @var string
23
         */
24
        protected $_module_unique_affix;
25
        /**
26
         * @var string
27
         */
28
        protected $_id;
29
        /**
30
         * @var string
31
         */
32
        protected $_title;
33
        /**
34
         * @var FS_Admin_Notice_Manager
35
         */
36
        protected $_notices;
37
        /**
38
         * @var FS_Admin_Notice_Manager
39
         */
40
        protected $_network_notices;
41
        /**
42
         * @var int The ID of the blog that is associated with the current site level options.
43
         */
44
        private $_blog_id = 0;
45
        /**
46
         * @var bool
47
         */
48
        private $_is_multisite;
49
        /**
50
         * @var FS_Admin_Notices[]
51
         */
52
        private static $_instances = array();
53
54
        /**
55
         * @param string $id
56
         * @param string $title
57
         * @param string $module_unique_affix
58
         *
59
         * @return FS_Admin_Notices
60
         */
61
        static function instance( $id, $title = '', $module_unique_affix = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
62
            if ( ! isset( self::$_instances[ $id ] ) ) {
63
                self::$_instances[ $id ] = new FS_Admin_Notices( $id, $title, $module_unique_affix );
64
            }
65
66
            return self::$_instances[ $id ];
67
        }
68
69
        protected function __construct( $id, $title = '', $module_unique_affix = '' ) {
70
            $this->_id                  = $id;
71
            $this->_title               = $title;
72
            $this->_module_unique_affix = $module_unique_affix;
73
            $this->_is_multisite        = is_multisite();
74
75
            if ( $this->_is_multisite ) {
76
                $this->_blog_id = get_current_blog_id();
77
78
                $this->_network_notices = FS_Admin_Notice_Manager::instance(
79
                    $id,
80
                    $title,
81
                    $module_unique_affix,
82
                    true
83
                );
84
            }
85
86
            $this->_notices = FS_Admin_Notice_Manager::instance(
87
                $id,
88
                $title,
89
                $module_unique_affix,
90
                $this->_blog_id
91
            );
92
        }
93
94
        /**
95
         * Add admin message to admin messages queue, and hook to admin_notices / all_admin_notices if not yet hooked.
96
         *
97
         * @author Vova Feldman (@svovaf)
98
         * @since  1.0.4
99
         *
100
         * @param string   $message
101
         * @param string   $title
102
         * @param string   $type
103
         * @param bool     $is_sticky
104
         * @param string   $id Message ID
105
         * @param bool     $store_if_sticky
106
         * @param int|null $network_level_or_blog_id
107
         *
108
         * @uses   add_action()
109
         */
110
        function add(
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
111
            $message,
112
            $title = '',
113
            $type = 'success',
114
            $is_sticky = false,
115
            $id = '',
116
            $store_if_sticky = true,
117
            $network_level_or_blog_id = null
118
        ) {
119
            if ( $this->should_use_network_notices( $id, $network_level_or_blog_id ) ) {
120
                $notices = $this->_network_notices;
121
            } else {
122
                $notices = $this->get_site_notices( $network_level_or_blog_id );
123
            }
124
125
            $notices->add(
126
                $message,
127
                $title,
128
                $type,
129
                $is_sticky,
130
                $id,
131
                $store_if_sticky
132
            );
133
        }
134
135
        /**
136
         * @author Vova Feldman (@svovaf)
137
         * @since  1.0.7
138
         *
139
         * @param string|string[] $ids
140
         * @param int|null        $network_level_or_blog_id
141
         */
142
        function remove_sticky( $ids, $network_level_or_blog_id = null ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
143
            if ( ! is_array( $ids ) ) {
144
                $ids = array( $ids );
145
            }
146
147
            if ( $this->should_use_network_notices( $ids[0], $network_level_or_blog_id ) ) {
148
                $notices = $this->_network_notices;
149
            } else {
150
                $notices = $this->get_site_notices( $network_level_or_blog_id );
151
            }
152
153
            return $notices->remove_sticky( $ids );
154
        }
155
156
        /**
157
         * Check if sticky message exists by id.
158
         *
159
         * @author Vova Feldman (@svovaf)
160
         * @since  1.0.9
161
         *
162
         * @param string   $id
163
         * @param int|null $network_level_or_blog_id
164
         *
165
         * @return bool
166
         */
167
        function has_sticky( $id, $network_level_or_blog_id = null ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
168
            if ( $this->should_use_network_notices( $id, $network_level_or_blog_id ) ) {
169
                $notices = $this->_network_notices;
170
            } else {
171
                $notices = $this->get_site_notices( $network_level_or_blog_id );
172
            }
173
174
            return $notices->has_sticky( $id );
175
        }
176
177
        /**
178
         * Adds sticky admin notification.
179
         *
180
         * @author Vova Feldman (@svovaf)
181
         * @since  1.0.7
182
         *
183
         * @param string   $message
184
         * @param string   $id Message ID
185
         * @param string   $title
186
         * @param string   $type
187
         * @param int|null $network_level_or_blog_id
188
         */
189
        function add_sticky(
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
190
            $message,
191
            $id,
192
            $title = '',
193
            $type = 'success',
194
            $network_level_or_blog_id = null
195
        ) {
196
            if ( $this->should_use_network_notices( $id, $network_level_or_blog_id ) ) {
197
                $notices = $this->_network_notices;
198
            } else {
199
                $notices = $this->get_site_notices( $network_level_or_blog_id );
200
            }
201
202
            $notices->add_sticky( $message, $id, $title, $type );
203
        }
204
205
        /**
206
         * Clear all sticky messages.
207
         *
208
         * @author Vova Feldman (@svovaf)
209
         * @since  2.0.0
210
         *
211
         * @param int|null $network_level_or_blog_id
212
         */
213
        function clear_all_sticky( $network_level_or_blog_id = null ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
214
            if ( ! $this->_is_multisite ||
215
                 false === $network_level_or_blog_id ||
216
                 0 == $network_level_or_blog_id ||
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $network_level_or_blog_id of type integer|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
217
                 is_null( $network_level_or_blog_id )
218
            ) {
219
                $notices = $this->get_site_notices( $network_level_or_blog_id );
220
                $notices->clear_all_sticky();
221
            }
222
223
            if ( $this->_is_multisite &&
224
                 ( true === $network_level_or_blog_id || is_null( $network_level_or_blog_id ) )
225
            ) {
226
                $this->_network_notices->clear_all_sticky();
227
            }
228
        }
229
230
        /**
231
         * Add admin message to all admin messages queue, and hook to all_admin_notices if not yet hooked.
232
         *
233
         * @author Vova Feldman (@svovaf)
234
         * @since  1.0.4
235
         *
236
         * @param string $message
237
         * @param string $title
238
         * @param string $type
239
         * @param bool   $is_sticky
240
         * @param string $id Message ID
241
         */
242
        function add_all( $message, $title = '', $type = 'success', $is_sticky = false, $id = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
243
            $this->add( $message, $title, $type, $is_sticky, true, $id );
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$id is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
244
        }
245
246
        #--------------------------------------------------------------------------------
247
        #region Helper Methods
248
        #--------------------------------------------------------------------------------
249
250
        /**
251
         * @author Vova Feldman (@svovaf)
252
         * @since  2.0.0
253
         *
254
         * @param int $blog_id
255
         *
256
         * @return FS_Admin_Notice_Manager
257
         */
258
        private function get_site_notices( $blog_id = 0 ) {
259
            if ( 0 == $blog_id || $blog_id == $this->_blog_id ) {
260
                return $this->_notices;
261
            }
262
263
            return FS_Admin_Notice_Manager::instance(
264
                $this->_id,
265
                $this->_title,
266
                $this->_module_unique_affix,
267
                $blog_id
0 ignored issues
show
Documentation introduced by
$blog_id is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
268
            );
269
        }
270
271
        /**
272
         * Check if the network notices should be used.
273
         *
274
         * @author Vova Feldman (@svovaf)
275
         * @since  2.0.0
276
         *
277
         * @param string        $id
278
         * @param null|bool|int $network_level_or_blog_id When an integer, use the given blog storage. When `true` use the multisite notices (if there's a network). When `false`, use the current context blog notices. When `null`, the decision which notices manager to use (MS vs. Current S) will be handled internally and determined based on the $id and the context admin (blog admin vs. network level admin).
279
         *
280
         * @return bool
281
         */
282
        private function should_use_network_notices( $id = '', $network_level_or_blog_id = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
283
            if ( ! $this->_is_multisite ) {
284
                // Not a multisite environment.
285
                return false;
286
            }
287
288
            if ( is_numeric( $network_level_or_blog_id ) ) {
289
                // Explicitly asked to use a specified blog storage.
290
                return false;
291
            }
292
293
            if ( is_bool( $network_level_or_blog_id ) ) {
294
                // Explicitly specified whether should use the network or blog level storage.
295
                return $network_level_or_blog_id;
296
            }
297
298
            return fs_is_network_admin();
299
        }
300
301
        #endregion
302
    }