Conditions | 11 |
Paths | 12 |
Total Lines | 33 |
Code Lines | 22 |
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 |
||
9 | public static function get_access_token( $user_id = false ) { |
||
10 | if ( $user_id ) { |
||
11 | if ( !$tokens = Jetpack_Options::get_option( 'user_tokens' ) ) { |
||
12 | return false; |
||
13 | } |
||
14 | if ( $user_id === JETPACK_MASTER_USER ) { |
||
15 | if ( !$user_id = Jetpack_Options::get_option( 'master_user' ) ) { |
||
16 | return false; |
||
17 | } |
||
18 | } |
||
19 | if ( !isset( $tokens[$user_id] ) || !$token = $tokens[$user_id] ) { |
||
20 | return false; |
||
21 | } |
||
22 | $token_chunks = explode( '.', $token ); |
||
23 | if ( empty( $token_chunks[1] ) || empty( $token_chunks[2] ) ) { |
||
24 | return false; |
||
25 | } |
||
26 | if ( $user_id != $token_chunks[2] ) { |
||
27 | return false; |
||
28 | } |
||
29 | $token = "{$token_chunks[0]}.{$token_chunks[1]}"; |
||
30 | } else { |
||
31 | $token = Jetpack_Options::get_option( 'blog_token' ); |
||
32 | if ( empty( $token ) ) { |
||
33 | return false; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | return (object) array( |
||
38 | 'secret' => $token, |
||
39 | 'external_user_id' => (int) $user_id, |
||
40 | ); |
||
41 | } |
||
42 | |||
123 |