| Conditions | 16 |
| Paths | 8 |
| Total Lines | 78 |
| 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 |
||
| 78 | public function wp_rest_authenticate( $user ) { |
||
| 79 | if ( $this->doing_determine_current_user_filter || ! empty( $user ) ) { |
||
| 80 | // Another authentication method is in effect. |
||
| 81 | return $user; |
||
| 82 | } |
||
| 83 | |||
| 84 | $this->initialize_determine_current_user_filter(); |
||
| 85 | |||
| 86 | add_filter( |
||
| 87 | 'jetpack_constant_default_value', |
||
| 88 | __NAMESPACE__ . '\Utils::jetpack_api_constant_filter', |
||
| 89 | 10, |
||
| 90 | 2 |
||
| 91 | ); |
||
| 92 | |||
| 93 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
||
| 94 | if ( ! isset( $_GET['_for'] ) || 'jetpack' !== $_GET['_for'] ) { |
||
| 95 | // Nothing to do for this authentication method. |
||
| 96 | return $this->return_determine_current_user_filter(); |
||
| 97 | } |
||
| 98 | |||
| 99 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
||
| 100 | if ( ! isset( $_GET['token'] ) && ! isset( $_GET['signature'] ) ) { |
||
| 101 | // Nothing to do for this authentication method. |
||
| 102 | return $this->return_determine_current_user_filter(); |
||
| 103 | } |
||
| 104 | |||
| 105 | if ( ! isset( $_SERVER['REQUEST_METHOD'] ) ) { |
||
| 106 | $this->rest_authentication_status = new \WP_Error( |
||
|
|
|||
| 107 | 'rest_invalid_request', |
||
| 108 | __( 'The request method is missing.', 'jetpack' ), |
||
| 109 | array( 'status' => 400 ) |
||
| 110 | ); |
||
| 111 | return $this->return_determine_current_user_filter(); |
||
| 112 | } |
||
| 113 | |||
| 114 | // Only support specific request parameters that have been tested and |
||
| 115 | // are known to work with signature verification. A different method |
||
| 116 | // can be passed to the WP REST API via the '?_method=' parameter if |
||
| 117 | // needed. |
||
| 118 | if ( 'GET' !== $_SERVER['REQUEST_METHOD'] && 'POST' !== $_SERVER['REQUEST_METHOD'] ) { |
||
| 119 | $this->rest_authentication_status = new \WP_Error( |
||
| 120 | 'rest_invalid_request', |
||
| 121 | __( 'This request method is not supported.', 'jetpack' ), |
||
| 122 | array( 'status' => 400 ) |
||
| 123 | ); |
||
| 124 | return $this->return_determine_current_user_filter(); |
||
| 125 | } |
||
| 126 | if ( 'POST' !== $_SERVER['REQUEST_METHOD'] && ! empty( file_get_contents( 'php://input' ) ) ) { |
||
| 127 | $this->rest_authentication_status = new \WP_Error( |
||
| 128 | 'rest_invalid_request', |
||
| 129 | __( 'This request method does not support body parameters.', 'jetpack' ), |
||
| 130 | array( 'status' => 400 ) |
||
| 131 | ); |
||
| 132 | return $this->return_determine_current_user_filter(); |
||
| 133 | } |
||
| 134 | |||
| 135 | $verified = $this->connection_manager->verify_xml_rpc_signature(); |
||
| 136 | |||
| 137 | if ( |
||
| 138 | $verified && |
||
| 139 | isset( $verified['type'] ) && |
||
| 140 | 'user' === $verified['type'] && |
||
| 141 | ! empty( $verified['user_id'] ) |
||
| 142 | ) { |
||
| 143 | // Authentication successful. |
||
| 144 | $this->rest_authentication_status = true; |
||
| 145 | return $this->return_determine_current_user_filter( $verified['user_id'] ); |
||
| 146 | } |
||
| 147 | |||
| 148 | // Something else went wrong. Probably a signature error. |
||
| 149 | $this->rest_authentication_status = new \WP_Error( |
||
| 150 | 'rest_invalid_signature', |
||
| 151 | __( 'The request is not signed correctly.', 'jetpack' ), |
||
| 152 | array( 'status' => 400 ) |
||
| 153 | ); |
||
| 154 | return $this->return_determine_current_user_filter(); |
||
| 155 | } |
||
| 156 | |||
| 202 |
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..