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