| Conditions | 15 |
| Paths | 8 |
| Total Lines | 69 |
| 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 |
||
| 70 | public function wp_rest_authenticate( $user ) { |
||
| 71 | if ( ! empty( $user ) ) { |
||
| 72 | // Another authentication method is in effect. |
||
| 73 | return $user; |
||
| 74 | } |
||
| 75 | |||
| 76 | Utils::init_default_constants(); |
||
| 77 | |||
| 78 | if ( ! isset( $_GET['_for'] ) || 'jetpack' !== $_GET['_for'] ) { |
||
| 79 | // Nothing to do for this authentication method. |
||
| 80 | return null; |
||
| 81 | } |
||
| 82 | |||
| 83 | if ( ! isset( $_GET['token'] ) && ! isset( $_GET['signature'] ) ) { |
||
| 84 | // Nothing to do for this authentication method. |
||
| 85 | return null; |
||
| 86 | } |
||
| 87 | |||
| 88 | if ( ! isset( $_SERVER['REQUEST_METHOD'] ) ) { |
||
| 89 | $this->rest_authentication_status = new \WP_Error( |
||
|
|
|||
| 90 | 'rest_invalid_request', |
||
| 91 | __( 'The request method is missing.', 'jetpack' ), |
||
| 92 | array( 'status' => 400 ) |
||
| 93 | ); |
||
| 94 | return null; |
||
| 95 | } |
||
| 96 | |||
| 97 | // Only support specific request parameters that have been tested and |
||
| 98 | // are known to work with signature verification. A different method |
||
| 99 | // can be passed to the WP REST API via the '?_method=' parameter if |
||
| 100 | // needed. |
||
| 101 | if ( 'GET' !== $_SERVER['REQUEST_METHOD'] && 'POST' !== $_SERVER['REQUEST_METHOD'] ) { |
||
| 102 | $this->rest_authentication_status = new \WP_Error( |
||
| 103 | 'rest_invalid_request', |
||
| 104 | __( 'This request method is not supported.', 'jetpack' ), |
||
| 105 | array( 'status' => 400 ) |
||
| 106 | ); |
||
| 107 | return null; |
||
| 108 | } |
||
| 109 | if ( 'POST' !== $_SERVER['REQUEST_METHOD'] && ! empty( file_get_contents( 'php://input' ) ) ) { |
||
| 110 | $this->rest_authentication_status = new \WP_Error( |
||
| 111 | 'rest_invalid_request', |
||
| 112 | __( 'This request method does not support body parameters.', 'jetpack' ), |
||
| 113 | array( 'status' => 400 ) |
||
| 114 | ); |
||
| 115 | return null; |
||
| 116 | } |
||
| 117 | |||
| 118 | $verified = $this->connection_manager->verify_xml_rpc_signature(); |
||
| 119 | |||
| 120 | if ( |
||
| 121 | $verified && |
||
| 122 | isset( $verified['type'] ) && |
||
| 123 | 'user' === $verified['type'] && |
||
| 124 | ! empty( $verified['user_id'] ) |
||
| 125 | ) { |
||
| 126 | // Authentication successful. |
||
| 127 | $this->rest_authentication_status = true; |
||
| 128 | return $verified['user_id']; |
||
| 129 | } |
||
| 130 | |||
| 131 | // Something else went wrong. Probably a signature error. |
||
| 132 | $this->rest_authentication_status = new \WP_Error( |
||
| 133 | 'rest_invalid_signature', |
||
| 134 | __( 'The request is not signed correctly.', 'jetpack' ), |
||
| 135 | array( 'status' => 400 ) |
||
| 136 | ); |
||
| 137 | return null; |
||
| 138 | } |
||
| 139 | |||
| 161 |
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..