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 — master ( 737b79...d4ff54 )
by Brad
02:47
created

FS_GDPR_Manager::update_option()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
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 13 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.1.0
7
     */
8
9
    if ( ! defined( 'ABSPATH' ) ) {
10
        exit;
11
    }
12
13
    class FS_GDPR_Manager {
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
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...
14
        /**
15
         * @var FS_Option_Manager
16
         */
17
        private $_storage;
18
        /**
19
         * @var array {
20
         * @type bool $required           Are GDPR rules apply on the current context admin.
21
         * @type bool $show_opt_in_notice Should the marketing and offers opt-in message be shown to the admin or not. If not set, defaults to `true`.
22
         * @type int  $notice_shown_at    Last time the special GDPR opt-in message was shown to the current admin.
23
         * }
24
         */
25
        private $_data;
26
        /**
27
         * @var int
28
         */
29
        private $_wp_user_id;
30
        /**
31
         * @var string
32
         */
33
        private $_option_name;
34
        /**
35
         * @var FS_Admin_Notices
36
         */
37
        private $_notices;
38
39
        #--------------------------------------------------------------------------------
40
        #region Singleton
41
        #--------------------------------------------------------------------------------
42
43
        /**
44
         * @var FS_GDPR_Manager
45
         */
46
        private static $_instance;
47
48
        /**
49
         * @return FS_GDPR_Manager
50
         */
51
        public static function instance() {
52
            if ( ! isset( self::$_instance ) ) {
53
                self::$_instance = new self();
54
            }
55
56
            return self::$_instance;
57
        }
58
59
        #endregion
60
61
        private function __construct() {
62
            $this->_storage     = FS_Option_Manager::get_manager( WP_FS__GDPR_OPTION_NAME, true, true );
63
            $this->_wp_user_id  = Freemius::get_current_wp_user_id();
64
            $this->_option_name = "u{$this->_wp_user_id}";
65
            $this->_data        = $this->_storage->get_option( $this->_option_name, array() );
66
            $this->_notices     = FS_Admin_Notices::instance( 'all_admins', '', '', true );
67
68
            if ( ! is_array( $this->_data ) ) {
69
                $this->_data = array();
70
            }
71
        }
72
73
        /**
74
         * Update a GDPR option for the current admin and store it.
75
         *
76
         * @author Vova Feldman (@svovaf)
77
         * @since  2.1.0
78
         *
79
         * @param string $name
80
         * @param mixed  $value
81
         */
82
        private function update_option( $name, $value ) {
83
            $this->_data[ $name ] = $value;
84
85
            $this->_storage->set_option( $this->_option_name, $this->_data, true );
86
        }
87
88
        /**
89
         * @author Leo Fajardo (@leorw)
90
         * @since  2.1.0
91
         *
92
         * @return bool|null
93
         */
94
        public function is_required() {
95
            return isset( $this->_data['required'] ) ?
96
                $this->_data['required'] :
97
                null;
98
        }
99
100
        /**
101
         * @author Leo Fajardo (@leorw)
102
         * @since  2.1.0
103
         *
104
         * @param bool $is_required
105
         */
106
        public function store_is_required( $is_required ) {
107
            $this->update_option( 'required', $is_required );
108
        }
109
110
        /**
111
         * Checks if the GDPR opt-in sticky notice is currently shown.
112
         *
113
         * @author Vova Feldman (@svovaf)
114
         * @since  2.1.0
115
         *
116
         * @return bool
117
         */
118
        public function is_opt_in_notice_shown() {
119
            return $this->_notices->has_sticky( "gdpr_optin_actions_{$this->_wp_user_id}", true );
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer|null.

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...
120
        }
121
122
        /**
123
         * Remove the GDPR opt-in sticky notice.
124
         *
125
         * @author Vova Feldman (@svovaf)
126
         * @since  2.1.0
127
         */
128
        public function remove_opt_in_notice() {
129
            $this->_notices->remove_sticky( "gdpr_optin_actions_{$this->_wp_user_id}", true );
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer|null.

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...
130
131
            $this->disable_opt_in_notice();
132
        }
133
134
        /**
135
         * Prevents the opt-in message from being added/shown.
136
         *
137
         * @author Leo Fajardo (@leorw)
138
         * @since  2.1.0
139
         */
140
        public function disable_opt_in_notice() {
141
            $this->update_option( 'show_opt_in_notice', false );
142
        }
143
144
        /**
145
         * Checks if a GDPR opt-in message needs to be shown to the current admin.
146
         *
147
         * @author Vova Feldman (@svovaf)
148
         * @since  2.1.0
149
         *
150
         * @return bool
151
         */
152
        public function should_show_opt_in_notice() {
153
            return (
154
                ! isset( $this->_data['show_opt_in_notice'] ) ||
155
                true === $this->_data['show_opt_in_notice']
156
            );
157
        }
158
159
        /**
160
         * Get the last time the GDPR opt-in notice was shown.
161
         *
162
         * @author Vova Feldman (@svovaf)
163
         * @since  2.1.0
164
         *
165
         * @return false|int
166
         */
167
        public function last_time_notice_was_shown() {
168
            return isset( $this->_data['notice_shown_at'] ) ?
169
                $this->_data['notice_shown_at'] :
170
                false;
171
        }
172
173
        /**
174
         * Update the timestamp of the last time the GDPR opt-in message was shown to now.
175
         *
176
         * @author Vova Feldman (@svovaf)
177
         * @since  2.1.0
178
         */
179
        public function notice_was_just_shown() {
180
            $this->update_option( 'notice_shown_at', WP_FS__SCRIPT_START_TIME );
181
        }
182
183
        /**
184
         * @param string      $message
185
         * @param string|null $plugin_title
186
         *
187
         * @author Vova Feldman (@svovaf)
188
         * @since  2.1.0
189
         */
190
        public function add_opt_in_sticky_notice( $message, $plugin_title = null ) {
191
            $this->_notices->add_sticky(
192
                $message,
193
                "gdpr_optin_actions_{$this->_wp_user_id}",
194
                '',
195
                'promotion',
196
                true,
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer|null.

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...
197
                $this->_wp_user_id,
198
                $plugin_title,
199
                true
200
            );
201
        }
202
    }