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