@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @param Writing_On_GitHub $app Application container. |
| 28 | 28 | */ |
| 29 | - public function __construct( Writing_On_GitHub $app ) { |
|
| 29 | + public function __construct(Writing_On_GitHub $app) { |
|
| 30 | 30 | $this->app = $app; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @return stdClass|WP_Error |
| 41 | 41 | */ |
| 42 | - protected function call( $method, $endpoint, $body = array() ) { |
|
| 43 | - if ( is_wp_error( $error = $this->can_call() ) ) { |
|
| 42 | + protected function call($method, $endpoint, $body = array()) { |
|
| 43 | + if (is_wp_error($error = $this->can_call())) { |
|
| 44 | 44 | /* @var WP_Error $error */ |
| 45 | 45 | return $error; |
| 46 | 46 | } |
@@ -52,25 +52,25 @@ discard block |
||
| 52 | 52 | ), |
| 53 | 53 | ); |
| 54 | 54 | |
| 55 | - if ( 'GET' !== $method ) { |
|
| 56 | - $args['body'] = json_encode( $body ); |
|
| 55 | + if ('GET' !== $method) { |
|
| 56 | + $args['body'] = json_encode($body); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // $tmpbody = isset( $args['body'] ) ? $args['body'] : ''; |
| 60 | 60 | // error_log( "writing-on-github-call $method $endpoint $tmpbody" ); |
| 61 | 61 | |
| 62 | - $response = wp_remote_request( $endpoint, $args ); |
|
| 63 | - $status = wp_remote_retrieve_header( $response, 'status' ); |
|
| 64 | - $body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
| 62 | + $response = wp_remote_request($endpoint, $args); |
|
| 63 | + $status = wp_remote_retrieve_header($response, 'status'); |
|
| 64 | + $body = json_decode(wp_remote_retrieve_body($response)); |
|
| 65 | 65 | |
| 66 | - if ( '2' !== substr( $status, 0, 1 ) && '3' !== substr( $status, 0, 1 ) ) { |
|
| 66 | + if ('2' !== substr($status, 0, 1) && '3' !== substr($status, 0, 1)) { |
|
| 67 | 67 | return new WP_Error( |
| 68 | - strtolower( str_replace( ' ', '_', $status ) ), |
|
| 68 | + strtolower(str_replace(' ', '_', $status)), |
|
| 69 | 69 | sprintf( |
| 70 | - __( 'Method %s to endpoint %s failed with error: %s', 'writing-on-github' ), |
|
| 70 | + __('Method %s to endpoint %s failed with error: %s', 'writing-on-github'), |
|
| 71 | 71 | $method, |
| 72 | 72 | $endpoint, |
| 73 | - ( $body && $body->message ) ? $body->message : 'Unknown error' |
|
| 73 | + ($body && $body->message) ? $body->message : 'Unknown error' |
|
| 74 | 74 | ) |
| 75 | 75 | ); |
| 76 | 76 | } |
@@ -84,28 +84,28 @@ discard block |
||
| 84 | 84 | * @return true|WP_Error |
| 85 | 85 | */ |
| 86 | 86 | protected function can_call() { |
| 87 | - if ( ! $this->oauth_token() ) { |
|
| 87 | + if ( ! $this->oauth_token()) { |
|
| 88 | 88 | return new WP_Error( |
| 89 | 89 | 'missing_token', |
| 90 | - __( 'Writing On GitHub needs an auth token. Please update your settings.', 'writing-on-github' ) |
|
| 90 | + __('Writing On GitHub needs an auth token. Please update your settings.', 'writing-on-github') |
|
| 91 | 91 | ); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | $repo = $this->repository(); |
| 95 | 95 | |
| 96 | - if ( ! $repo ) { |
|
| 96 | + if ( ! $repo) { |
|
| 97 | 97 | return new WP_Error( |
| 98 | 98 | 'missing_repository', |
| 99 | - __( 'Writing On GitHub needs a repository. Please update your settings.', 'writing-on-github' ) |
|
| 99 | + __('Writing On GitHub needs a repository. Please update your settings.', 'writing-on-github') |
|
| 100 | 100 | ); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $parts = explode( '/', $repo ); |
|
| 103 | + $parts = explode('/', $repo); |
|
| 104 | 104 | |
| 105 | - if ( 2 !== count( $parts ) ) { |
|
| 105 | + if (2 !== count($parts)) { |
|
| 106 | 106 | return new WP_Error( |
| 107 | 107 | 'malformed_repository', |
| 108 | - __( 'Writing On GitHub needs a properly formed repository. Please update your settings.', 'writing-on-github' ) |
|
| 108 | + __('Writing On GitHub needs a properly formed repository. Please update your settings.', 'writing-on-github') |
|
| 109 | 109 | ); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @return string |
| 119 | 119 | */ |
| 120 | 120 | public function repository() { |
| 121 | - return (string) get_option( self::REPO_OPTION_KEY ); |
|
| 121 | + return (string) get_option(self::REPO_OPTION_KEY); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -127,18 +127,18 @@ discard block |
||
| 127 | 127 | * @return string |
| 128 | 128 | */ |
| 129 | 129 | public function oauth_token() { |
| 130 | - return (string) get_option( self::TOKEN_OPTION_KEY ); |
|
| 130 | + return (string) get_option(self::TOKEN_OPTION_KEY); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | 134 | * Returns the GitHub host to sync with (for GitHub Enterprise support) |
| 135 | 135 | */ |
| 136 | 136 | public function api_base() { |
| 137 | - return get_option( self::HOST_OPTION_KEY ); |
|
| 137 | + return get_option(self::HOST_OPTION_KEY); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | public function branch() { |
| 141 | - $branch = get_option( self::BRANCH_OPTION_KEY ); |
|
| 141 | + $branch = get_option(self::BRANCH_OPTION_KEY); |
|
| 142 | 142 | return $branch ? $branch : 'master'; |
| 143 | 143 | } |
| 144 | 144 | |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * Returns String the relative API call path |
| 201 | 201 | */ |
| 202 | - public function content_endpoint( $path = false ) { |
|
| 202 | + public function content_endpoint($path = false) { |
|
| 203 | 203 | $url = $this->api_base() . '/repos/'; |
| 204 | 204 | $url = $url . $this->repository() . '/contents'; |
| 205 | 205 | |
| 206 | - if ( ! empty($path) ) { |
|
| 206 | + if ( ! empty($path)) { |
|
| 207 | 207 | $url .= '/' . $path; |
| 208 | 208 | } |
| 209 | 209 | |