Conditions | 19 |
Paths | 22 |
Total Lines | 98 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
88 | public function wp_rest_authenticate( $user ) { |
||
89 | if ( $this->doing_determine_current_user_filter ) { |
||
90 | return $user; |
||
91 | } |
||
92 | |||
93 | $this->doing_determine_current_user_filter = true; |
||
94 | |||
95 | try { |
||
96 | if ( ! empty( $user ) ) { |
||
97 | // Another authentication method is in effect. |
||
98 | return $user; |
||
99 | } |
||
100 | |||
101 | add_filter( |
||
102 | 'jetpack_constant_default_value', |
||
103 | __NAMESPACE__ . '\Utils::jetpack_api_constant_filter', |
||
104 | 10, |
||
105 | 2 |
||
106 | ); |
||
107 | |||
108 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
||
109 | if ( ! isset( $_GET['_for'] ) || 'jetpack' !== $_GET['_for'] ) { |
||
110 | // Nothing to do for this authentication method. |
||
111 | return null; |
||
112 | } |
||
113 | |||
114 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
||
115 | if ( ! isset( $_GET['token'] ) && ! isset( $_GET['signature'] ) ) { |
||
116 | // Nothing to do for this authentication method. |
||
117 | return null; |
||
118 | } |
||
119 | |||
120 | if ( ! isset( $_SERVER['REQUEST_METHOD'] ) ) { |
||
121 | $this->rest_authentication_status = new \WP_Error( |
||
|
|||
122 | 'rest_invalid_request', |
||
123 | __( 'The request method is missing.', 'jetpack' ), |
||
124 | array( 'status' => 400 ) |
||
125 | ); |
||
126 | return null; |
||
127 | } |
||
128 | |||
129 | // Only support specific request parameters that have been tested and |
||
130 | // are known to work with signature verification. A different method |
||
131 | // can be passed to the WP REST API via the '?_method=' parameter if |
||
132 | // needed. |
||
133 | if ( 'GET' !== $_SERVER['REQUEST_METHOD'] && 'POST' !== $_SERVER['REQUEST_METHOD'] ) { |
||
134 | $this->rest_authentication_status = new \WP_Error( |
||
135 | 'rest_invalid_request', |
||
136 | __( 'This request method is not supported.', 'jetpack' ), |
||
137 | array( 'status' => 400 ) |
||
138 | ); |
||
139 | return null; |
||
140 | } |
||
141 | if ( 'POST' !== $_SERVER['REQUEST_METHOD'] && ! empty( file_get_contents( 'php://input' ) ) ) { |
||
142 | $this->rest_authentication_status = new \WP_Error( |
||
143 | 'rest_invalid_request', |
||
144 | __( 'This request method does not support body parameters.', 'jetpack' ), |
||
145 | array( 'status' => 400 ) |
||
146 | ); |
||
147 | return null; |
||
148 | } |
||
149 | |||
150 | $verified = $this->connection_manager->verify_xml_rpc_signature(); |
||
151 | |||
152 | if ( |
||
153 | $verified && |
||
154 | isset( $verified['type'] ) && |
||
155 | 'blog' === $verified['type'] |
||
156 | ) { |
||
157 | // Site-level authentication successful. |
||
158 | $this->rest_authentication_status = true; |
||
159 | $this->rest_authentication_type = 'blog'; |
||
160 | return null; |
||
161 | } |
||
162 | |||
163 | if ( |
||
164 | $verified && |
||
165 | isset( $verified['type'] ) && |
||
166 | 'user' === $verified['type'] && |
||
167 | ! empty( $verified['user_id'] ) |
||
168 | ) { |
||
169 | // User-level authentication successful. |
||
170 | $this->rest_authentication_status = true; |
||
171 | $this->rest_authentication_type = 'user'; |
||
172 | return $verified['user_id']; |
||
173 | } |
||
174 | |||
175 | // Something else went wrong. Probably a signature error. |
||
176 | $this->rest_authentication_status = new \WP_Error( |
||
177 | 'rest_invalid_signature', |
||
178 | __( 'The request is not signed correctly.', 'jetpack' ), |
||
179 | array( 'status' => 400 ) |
||
180 | ); |
||
181 | return null; |
||
182 | } finally { |
||
183 | $this->doing_determine_current_user_filter = false; |
||
184 | } |
||
185 | } |
||
186 | |||
221 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..