Completed
Branch master (a9a295)
by litefeel
01:36
created
lib/client/base.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 	 * @param string $endpoint API endpoint.
38 38
 	 * @param array  $body Request body.
39 39
 	 *
40
-	 * @return stdClass|WP_Error
40
+	 * @return stdClass
41 41
 	 */
42 42
 	protected function call( $method, $endpoint, $body = array() ) {
43 43
 		if ( is_wp_error( $error = $this->can_call() ) ) {
Please login to merge, or discard this patch.
Spacing   +25 added lines, -26 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 			return $error;
45 45
 		}
46 46
 
@@ -51,24 +51,23 @@  discard block
 block discarded – undo
51 51
 			),
52 52
 		);
53 53
 
54
-		if ( 'GET' !== $method ) {
55
-			$args['body'] = function_exists( 'wp_json_encode' ) ?
56
-				wp_json_encode( $body ) :
57
-				json_encode( $body );
54
+		if ('GET' !== $method) {
55
+			$args['body'] = function_exists('wp_json_encode') ?
56
+				wp_json_encode($body) : json_encode($body);
58 57
 		}
59 58
 
60 59
 		$tmpbody = isset($args['body']) ? $args['body'] : '';
61 60
 		error_log("writing-on-github-call $method $endpoint $tmpbody");
62 61
 
63
-		$response = wp_remote_request( $endpoint, $args );
64
-		$status   = wp_remote_retrieve_header( $response, 'status' );
65
-		$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));
66 65
 
67
-		if ( '2' !== substr( $status, 0, 1 ) && '3' !== substr( $status, 0, 1 ) ) {
66
+		if ('2' !== substr($status, 0, 1) && '3' !== substr($status, 0, 1)) {
68 67
 			return new WP_Error(
69
-				strtolower( str_replace( ' ', '_', $status ) ),
68
+				strtolower(str_replace(' ', '_', $status)),
70 69
 				sprintf(
71
-					__( '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'),
72 71
 					$method,
73 72
 					$endpoint,
74 73
 					$body && $body->message ? $body->message : 'Unknown error'
@@ -85,28 +84,28 @@  discard block
 block discarded – undo
85 84
 	 * @return true|WP_Error
86 85
 	 */
87 86
 	protected function can_call() {
88
-		if ( ! $this->oauth_token() ) {
87
+		if ( ! $this->oauth_token()) {
89 88
 			return new WP_Error(
90 89
 				'missing_token',
91
-				__( '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')
92 91
 			);
93 92
 		}
94 93
 
95 94
 		$repo = $this->repository();
96 95
 
97
-		if ( ! $repo ) {
96
+		if ( ! $repo) {
98 97
 			return new WP_Error(
99 98
 				'missing_repository',
100
-				__( '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')
101 100
 			);
102 101
 		}
103 102
 
104
-		$parts = explode( '/', $repo );
103
+		$parts = explode('/', $repo);
105 104
 
106
-		if ( 2 !== count( $parts ) ) {
105
+		if (2 !== count($parts)) {
107 106
 			return new WP_Error(
108 107
 				'malformed_repository',
109
-				__( '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')
110 109
 			);
111 110
 		}
112 111
 
@@ -119,7 +118,7 @@  discard block
 block discarded – undo
119 118
 	 * @return string
120 119
 	 */
121 120
 	public function repository() {
122
-		return (string) get_option( self::REPO_OPTION_KEY );
121
+		return (string) get_option(self::REPO_OPTION_KEY);
123 122
 	}
124 123
 
125 124
 	/**
@@ -128,18 +127,18 @@  discard block
 block discarded – undo
128 127
 	 * @return string
129 128
 	 */
130 129
 	public function oauth_token() {
131
-		return (string) get_option( self::TOKEN_OPTION_KEY );
130
+		return (string) get_option(self::TOKEN_OPTION_KEY);
132 131
 	}
133 132
 
134 133
 	/**
135 134
 	 * Returns the GitHub host to sync with (for GitHub Enterprise support)
136 135
 	 */
137 136
 	public function api_base() {
138
-		return get_option( self::HOST_OPTION_KEY );
137
+		return get_option(self::HOST_OPTION_KEY);
139 138
 	}
140 139
 
141 140
 	public function branch() {
142
-		$branch = get_option( self::BRANCH_OPTION_KEY );
141
+		$branch = get_option(self::BRANCH_OPTION_KEY);
143 142
 		return $branch ? $branch : 'master';
144 143
 	}
145 144
 
@@ -200,11 +199,11 @@  discard block
 block discarded – undo
200 199
 	 *
201 200
 	 * Returns String the relative API call path
202 201
 	 */
203
-	public function content_endpoint( $path = false ) {
202
+	public function content_endpoint($path = false) {
204 203
 		$url = $this->api_base() . '/repos/';
205 204
 		$url = $url . $this->repository() . '/contents';
206 205
 
207
-		if ( ! empty($path) ) {
206
+		if ( ! empty($path)) {
208 207
 			$url .= '/' . $path;
209 208
 		}
210 209
 
Please login to merge, or discard this patch.
lib/client/persist.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -31,6 +31,7 @@
 block discarded – undo
31 31
 	/**
32 32
 	 * Delete the file.
33 33
 	 *
34
+	 * @param string $message
34 35
 	 * @return array
35 36
 	 */
36 37
 	public function delete_file( $path, $sha, $message ) {
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
 	 */
17 17
 	protected function export_user() {
18 18
 		$user_id = get_current_user_id();
19
-		$user = get_userdata( $user_id );
19
+		$user = get_userdata($user_id);
20 20
 
21
-		if ( $user ) {
21
+		if ($user) {
22 22
 			return array(
23 23
 				'name'  => $user->display_name,
24 24
 				'email' => $user->user_email,
@@ -33,17 +33,17 @@  discard block
 block discarded – undo
33 33
 	 *
34 34
 	 * @return array
35 35
 	 */
36
-	public function delete_file( $path, $sha, $message ) {
36
+	public function delete_file($path, $sha, $message) {
37 37
 		$body = new stdClass();
38 38
 		$body->message = $message;
39 39
 		$body->sha = $sha;
40 40
 		$body->branch = $this->branch();
41 41
 
42
-		if ( $author = $this->export_user() ) {
42
+		if ($author = $this->export_user()) {
43 43
 			$body->author = $author;
44 44
 		}
45 45
 
46
-		return $this->call( 'DELETE', $this->content_endpoint( $path ), $body );
46
+		return $this->call('DELETE', $this->content_endpoint($path), $body);
47 47
 	}
48 48
 
49 49
 	/**
@@ -51,17 +51,17 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @return array
53 53
 	 */
54
-	public function create_file( $blob, $message ) {
54
+	public function create_file($blob, $message) {
55 55
 		$body = $blob->to_body();
56 56
 		$body->message = $message;
57 57
 		$body->branch = $this->branch();
58 58
 		unset($body->sha);
59 59
 
60
-		if ( $author = $this->export_user() ) {
60
+		if ($author = $this->export_user()) {
61 61
 			$body->author = $author;
62 62
 		}
63 63
 
64
-		return $this->call( 'PUT', $this->content_endpoint( $blob->path() ), $body );
64
+		return $this->call('PUT', $this->content_endpoint($blob->path()), $body);
65 65
 	}
66 66
 
67 67
 	/**
@@ -69,15 +69,15 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return array
71 71
 	 */
72
-	public function update_file( $blob, $message ) {
72
+	public function update_file($blob, $message) {
73 73
 		$body = $blob->to_body();
74 74
 		$body->message = $message;
75 75
 		$body->branch = $this->branch();
76 76
 
77
-		if ( $author = $this->export_user() ) {
77
+		if ($author = $this->export_user()) {
78 78
 			$body->author = $author;
79 79
 		}
80 80
 
81
-		return $this->call( 'PUT', $this->content_endpoint( $blob->path() ), $body );
81
+		return $this->call('PUT', $this->content_endpoint($blob->path()), $body);
82 82
 	}
83 83
 }
Please login to merge, or discard this patch.
lib/controller.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 *
168 168
 	 * @param int $post_id Post ID.
169 169
 	 *
170
-	 * @return boolean
170
+	 * @return null|boolean
171 171
 	 */
172 172
 	public function export_post( $post_id ) {
173 173
 		if ( wp_is_post_revision( $post_id ) ) {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @param int $post_id Post ID.
201 201
 	 *
202
-	 * @return boolean
202
+	 * @return null|boolean
203 203
 	 */
204 204
 	public function delete_post( $post_id ) {
205 205
 		if ( wp_is_post_revision( $post_id ) ) {
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param Writing_On_GitHub $app Applicatio container.
23 23
 	 */
24
-	public function __construct( Writing_On_GitHub $app ) {
24
+	public function __construct(Writing_On_GitHub $app) {
25 25
 		$this->app = $app;
26 26
 	}
27 27
 
@@ -34,57 +34,57 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	public function pull_posts() {
36 36
 		$this->set_ajax();
37
-		if ( ! $this->app->semaphore()->is_open() ) {
38
-			return $this->app->response()->error( new WP_Error(
37
+		if ( ! $this->app->semaphore()->is_open()) {
38
+			return $this->app->response()->error(new WP_Error(
39 39
 				'semaphore_locked',
40
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::pull_posts()' )
41
-			) );
40
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::pull_posts()')
41
+			));
42 42
 		}
43 43
 
44
-		if ( ! $this->app->request()->is_secret_valid() ) {
45
-			return $this->app->response()->error( new WP_Error(
44
+		if ( ! $this->app->request()->is_secret_valid()) {
45
+			return $this->app->response()->error(new WP_Error(
46 46
 				'invalid_headers',
47
-				__( 'Failed to validate secret.', 'writing-on-github' )
48
-			) );
47
+				__('Failed to validate secret.', 'writing-on-github')
48
+			));
49 49
 		}
50 50
 
51 51
 		// ping
52
-		if ( $this->app->request()->is_ping() ) {
53
-			return $this->app->response()->success( __( 'Wordpress is ready.', 'writing-on-github' ) );
52
+		if ($this->app->request()->is_ping()) {
53
+			return $this->app->response()->success(__('Wordpress is ready.', 'writing-on-github'));
54 54
 		}
55 55
 
56 56
 		// push
57
-		if ( ! $this->app->request()->is_push() ) {
58
-			return $this->app->response()->error( new WP_Error(
57
+		if ( ! $this->app->request()->is_push()) {
58
+			return $this->app->response()->error(new WP_Error(
59 59
 				'invalid_headers',
60
-				__( 'Failed to validate webhook event.', 'writing-on-github' )
61
-			) );
60
+				__('Failed to validate webhook event.', 'writing-on-github')
61
+			));
62 62
 		}
63 63
 		$payload = $this->app->request()->payload();
64 64
 
65
-		if ( ! $payload->should_import() ) {
66
-			return $this->app->response()->error( new WP_Error(
65
+		if ( ! $payload->should_import()) {
66
+			return $this->app->response()->error(new WP_Error(
67 67
 				'invalid_payload',
68 68
 				sprintf(
69
-					__( "%s won't be imported.", 'writing-on-github' ),
70
-					strtolower( $payload->get_commit_id() ) ? : '[Missing Commit ID]'
69
+					__("%s won't be imported.", 'writing-on-github'),
70
+					strtolower($payload->get_commit_id()) ?: '[Missing Commit ID]'
71 71
 				)
72
-			) );
72
+			));
73 73
 		}
74 74
 
75 75
 		$this->app->semaphore()->lock();
76
-		remove_action( 'save_post', array( $this, 'export_post' ) );
77
-		remove_action( 'delete_post', array( $this, 'delete_post' ) );
76
+		remove_action('save_post', array($this, 'export_post'));
77
+		remove_action('delete_post', array($this, 'delete_post'));
78 78
 
79
-		$result = $this->app->import()->payload( $payload );
79
+		$result = $this->app->import()->payload($payload);
80 80
 
81 81
 		$this->app->semaphore()->unlock();
82 82
 
83
-		if ( is_wp_error( $result ) ) {
84
-			return $this->app->response()->error( $result );
83
+		if (is_wp_error($result)) {
84
+			return $this->app->response()->error($result);
85 85
 		}
86 86
 
87
-		return $this->app->response()->success( $result );
87
+		return $this->app->response()->success($result);
88 88
 	}
89 89
 
90 90
 	/**
@@ -92,35 +92,35 @@  discard block
 block discarded – undo
92 92
 	 *
93 93
 	 * @return boolean
94 94
 	 */
95
-	public function import_master( $user_id ) {
96
-		if ( ! $this->app->semaphore()->is_open() ) {
97
-			return $this->app->response()->error( new WP_Error(
95
+	public function import_master($user_id) {
96
+		if ( ! $this->app->semaphore()->is_open()) {
97
+			return $this->app->response()->error(new WP_Error(
98 98
 				'semaphore_locked',
99
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::import_master()' )
100
-			) );
99
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::import_master()')
100
+			));
101 101
 		}
102 102
 
103 103
 		$this->app->semaphore()->lock();
104
-		remove_action( 'save_post', array( $this, 'export_post' ) );
105
-		remove_action( 'save_post', array( $this, 'delete_post' ) );
104
+		remove_action('save_post', array($this, 'export_post'));
105
+		remove_action('save_post', array($this, 'delete_post'));
106 106
 
107
-		if ( $user_id ) {
108
-			wp_set_current_user( $user_id );
107
+		if ($user_id) {
108
+			wp_set_current_user($user_id);
109 109
 		}
110 110
 
111 111
 		$result = $this->app->import()->master();
112 112
 
113 113
 		$this->app->semaphore()->unlock();
114 114
 
115
-		if ( is_wp_error( $result ) ) {
116
-			update_option( '_wogh_import_error', $result->get_error_message() );
115
+		if (is_wp_error($result)) {
116
+			update_option('_wogh_import_error', $result->get_error_message());
117 117
 
118
-			return $this->app->response()->error( $result );
118
+			return $this->app->response()->error($result);
119 119
 		}
120 120
 
121
-		update_option( '_wogh_import_complete', 'yes' );
121
+		update_option('_wogh_import_complete', 'yes');
122 122
 
123
-		return $this->app->response()->success( $result );
123
+		return $this->app->response()->success($result);
124 124
 	}
125 125
 
126 126
 	/**
@@ -130,33 +130,33 @@  discard block
 block discarded – undo
130 130
      * @param  boolean    $force
131 131
      * @return boolean
132 132
      */
133
-	public function export_all( $user_id, $force = false ) {
134
-		if ( ! $this->app->semaphore()->is_open() ) {
135
-			return $this->app->response()->error( new WP_Error(
133
+	public function export_all($user_id, $force = false) {
134
+		if ( ! $this->app->semaphore()->is_open()) {
135
+			return $this->app->response()->error(new WP_Error(
136 136
 				'semaphore_locked',
137
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_all()' )
138
-			) );
137
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_all()')
138
+			));
139 139
 		}
140 140
 
141 141
 		$this->app->semaphore()->lock();
142 142
 
143
-		if ( $user_id ) {
144
-			wp_set_current_user( $user_id );
143
+		if ($user_id) {
144
+			wp_set_current_user($user_id);
145 145
 		}
146 146
 
147 147
 		$result = $this->app->export()->full($force);
148 148
 		$this->app->semaphore()->unlock();
149 149
 
150 150
 		// Maybe move option updating out of this class/upgrade message display?
151
-		if ( is_wp_error( $result ) ) {
152
-			update_option( '_wogh_export_error', $result->get_error_message() );
151
+		if (is_wp_error($result)) {
152
+			update_option('_wogh_export_error', $result->get_error_message());
153 153
 
154
-			return $this->app->response()->error( $result );
154
+			return $this->app->response()->error($result);
155 155
 		} else {
156
-			update_option( '_wogh_export_complete', 'yes' );
157
-			update_option( '_wogh_fully_exported', 'yes' );
156
+			update_option('_wogh_export_complete', 'yes');
157
+			update_option('_wogh_fully_exported', 'yes');
158 158
 
159
-			return $this->app->response()->success( $result );
159
+			return $this->app->response()->success($result);
160 160
 		}
161 161
 	}
162 162
 
@@ -169,27 +169,27 @@  discard block
 block discarded – undo
169 169
 	 *
170 170
 	 * @return boolean
171 171
 	 */
172
-	public function export_post( $post_id ) {
173
-		if ( wp_is_post_revision( $post_id ) ) {
172
+	public function export_post($post_id) {
173
+		if (wp_is_post_revision($post_id)) {
174 174
 			return;
175 175
 		}
176 176
 
177
-		if ( ! $this->app->semaphore()->is_open() ) {
178
-			return $this->app->response()->error( new WP_Error(
177
+		if ( ! $this->app->semaphore()->is_open()) {
178
+			return $this->app->response()->error(new WP_Error(
179 179
 				'semaphore_locked',
180
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_post()' )
181
-			) );
180
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_post()')
181
+			));
182 182
 		}
183 183
 
184 184
 		$this->app->semaphore()->lock();
185
-		$result = $this->app->export()->update( $post_id );
185
+		$result = $this->app->export()->update($post_id);
186 186
 		$this->app->semaphore()->unlock();
187 187
 
188
-		if ( is_wp_error( $result ) ) {
189
-			return $this->app->response()->error( $result );
188
+		if (is_wp_error($result)) {
189
+			return $this->app->response()->error($result);
190 190
 		}
191 191
 
192
-		return $this->app->response()->success( $result );
192
+		return $this->app->response()->success($result);
193 193
 	}
194 194
 
195 195
 	/**
@@ -201,27 +201,27 @@  discard block
 block discarded – undo
201 201
 	 *
202 202
 	 * @return boolean
203 203
 	 */
204
-	public function delete_post( $post_id ) {
205
-		if ( wp_is_post_revision( $post_id ) ) {
204
+	public function delete_post($post_id) {
205
+		if (wp_is_post_revision($post_id)) {
206 206
 			return;
207 207
 		}
208 208
 
209
-		if ( ! $this->app->semaphore()->is_open() ) {
210
-			return $this->app->response()->error( new WP_Error(
209
+		if ( ! $this->app->semaphore()->is_open()) {
210
+			return $this->app->response()->error(new WP_Error(
211 211
 				'semaphore_locked',
212
-				sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::delete_post()' )
213
-			) );
212
+				sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::delete_post()')
213
+			));
214 214
 		}
215 215
 
216 216
 		$this->app->semaphore()->lock();
217
-		$result = $this->app->export()->delete( $post_id );
217
+		$result = $this->app->export()->delete($post_id);
218 218
 		$this->app->semaphore()->unlock();
219 219
 
220
-		if ( is_wp_error( $result ) ) {
221
-			return $this->app->response()->error( $result );
220
+		if (is_wp_error($result)) {
221
+			return $this->app->response()->error($result);
222 222
 		}
223 223
 
224
-		return $this->app->response()->success( $result );
224
+		return $this->app->response()->success($result);
225 225
 	}
226 226
 
227 227
 	/**
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
 	 * than just returning data.
231 231
 	 */
232 232
 	protected function set_ajax() {
233
-		if ( ! defined( 'WOGH_AJAX' ) ) {
234
-			define( 'WOGH_AJAX', true );
233
+		if ( ! defined('WOGH_AJAX')) {
234
+			define('WOGH_AJAX', true);
235 235
 		}
236 236
 	}
237 237
 }
Please login to merge, or discard this patch.
lib/database.php 2 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -108,7 +108,6 @@  discard block
 block discarded – undo
108 108
 	 * and associates their author as well as their latest
109 109
 	 *
110 110
 	 * @param Writing_On_GitHub_Post[] $posts Array of Posts to save.
111
-	 * @param string                       $email Author email.
112 111
 	 *
113 112
 	 * @return string|WP_Error
114 113
 	 */
@@ -178,6 +177,9 @@  discard block
 block discarded – undo
178 177
 		return __( 'Successfully saved posts.', 'writing-on-github' );
179 178
 	}
180 179
 
180
+	/**
181
+	 * @param Writing_On_GitHub_Post $post
182
+	 */
181 183
 	protected function post_args( $post ) {
182 184
 		$args = $post->get_args();
183 185
 		$meta = $post->get_meta();
Please login to merge, or discard this patch.
Spacing   +122 added lines, -123 removed lines patch added patch discarded remove patch
@@ -21,21 +21,21 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @var array
23 23
 	 */
24
-	protected $whitelisted_post_types = array( 'post', 'page' );
24
+	protected $whitelisted_post_types = array('post', 'page');
25 25
 
26 26
 	/**
27 27
 	 * Currently whitelisted post statuses.
28 28
 	 *
29 29
 	 * @var array
30 30
 	 */
31
-	protected $whitelisted_post_statuses = array( 'publish' );
31
+	protected $whitelisted_post_statuses = array('publish');
32 32
 
33 33
 	/**
34 34
 	 * Instantiates a new Database object.
35 35
 	 *
36 36
 	 * @param Writing_On_GitHub $app Application container.
37 37
 	 */
38
-	public function __construct( Writing_On_GitHub $app ) {
38
+	public function __construct(Writing_On_GitHub $app) {
39 39
 		$this->app = $app;
40 40
 	}
41 41
 
@@ -45,32 +45,32 @@  discard block
 block discarded – undo
45 45
      * @param  bool $force
46 46
      * @return Writing_On_GitHub_Post[]|WP_Error
47 47
      */
48
-	public function fetch_all_supported( $force = false ) {
49
-		$args  = array(
48
+	public function fetch_all_supported($force = false) {
49
+		$args = array(
50 50
 			'post_type'   => $this->get_whitelisted_post_types(),
51 51
 			'post_status' => $this->get_whitelisted_post_statuses(),
52 52
 			'nopaging'    => true,
53 53
 			'fields'      => 'ids',
54 54
 		);
55 55
 
56
-		$query = new WP_Query( apply_filters( 'wogh_pre_fetch_all_supported', $args ) );
56
+		$query = new WP_Query(apply_filters('wogh_pre_fetch_all_supported', $args));
57 57
 
58 58
 		$post_ids = $query->get_posts();
59 59
 
60
-		if ( ! $post_ids ) {
60
+		if ( ! $post_ids) {
61 61
 			return new WP_Error(
62 62
 				'no_results',
63
-				__( 'Querying for supported posts returned no results.', 'writing-on-github' )
63
+				__('Querying for supported posts returned no results.', 'writing-on-github')
64 64
 			);
65 65
 		}
66 66
 
67 67
 		$results = array();
68
-		foreach ( $post_ids as $post_id ) {
68
+		foreach ($post_ids as $post_id) {
69 69
 			// Do not export posts that have already been exported
70
-			if ( $force || ! get_post_meta( $post_id, '_wogh_sha', true ) ||
71
-				 ! get_post_meta( $post_id, '_wogh_github_path', true) ) {
70
+			if ($force || ! get_post_meta($post_id, '_wogh_sha', true) ||
71
+				 ! get_post_meta($post_id, '_wogh_github_path', true)) {
72 72
 
73
-				$results[] = new Writing_On_GitHub_Post( $post_id, $this->app->api() );
73
+				$results[] = new Writing_On_GitHub_Post($post_id, $this->app->api());
74 74
 			}
75 75
 		}
76 76
 
@@ -84,10 +84,10 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @return WP_Error|Writing_On_GitHub_Post
86 86
 	 */
87
-	public function fetch_by_id( $post_id ) {
88
-		$post = new Writing_On_GitHub_Post( $post_id, $this->app->api() );
87
+	public function fetch_by_id($post_id) {
88
+		$post = new Writing_On_GitHub_Post($post_id, $this->app->api());
89 89
 
90
-		if ( ! $this->is_post_supported( $post ) ) {
90
+		if ( ! $this->is_post_supported($post)) {
91 91
 			return new WP_Error(
92 92
 				'unsupported_post',
93 93
 				sprintf(
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 *
113 113
 	 * @return string|WP_Error
114 114
 	 */
115
-	public function save_posts( array $posts ) {
115
+	public function save_posts(array $posts) {
116 116
 
117 117
 		/**
118 118
 		 * Whether an error has occurred.
@@ -121,20 +121,19 @@  discard block
 block discarded – undo
121 121
 		 */
122 122
 		$error = false;
123 123
 
124
-		foreach ( $posts as $post ) {
125
-			$args = apply_filters( 'wogh_pre_import_args', $this->post_args( $post ), $post );
124
+		foreach ($posts as $post) {
125
+			$args = apply_filters('wogh_pre_import_args', $this->post_args($post), $post);
126 126
 
127 127
 			remove_filter('content_save_pre', 'wp_filter_post_kses');
128 128
 			$post_id = $post->is_new() ?
129
-				wp_insert_post( $args, true ) :
130
-				wp_update_post( $args, true );
129
+				wp_insert_post($args, true) : wp_update_post($args, true);
131 130
 			add_filter('content_save_pre', 'wp_filter_post_kses');
132 131
 
133
-			if ( is_wp_error( $post_id ) ) {
134
-				if ( ! $error ) {
132
+			if (is_wp_error($post_id)) {
133
+				if ( ! $error) {
135 134
 					$error = $post_id;
136 135
 				} else {
137
-					$error->add( $post_id->get_error_code(), $post_id->get_error_message() );
136
+					$error->add($post_id->get_error_code(), $post_id->get_error_message());
138 137
 				}
139 138
 
140 139
 				// Abort saving if updating the post fails.
@@ -143,42 +142,42 @@  discard block
 block discarded – undo
143 142
 
144 143
 			// $this->set_revision_author( $post_id, $user_id );
145 144
 
146
-			if ( $post->is_new() ) {
145
+			if ($post->is_new()) {
147 146
 				$author = false;
148 147
 				$meta = $post->get_meta();
149
-				if ( ! empty( $meta ) && ! empty( $meta['author'] ) ) {
148
+				if ( ! empty($meta) && ! empty($meta['author'])) {
150 149
 					$author = $meta['author'];
151 150
 				}
152
-				$user    = $this->fetch_commit_user( $author );
153
-				$user_id = ! is_wp_error( $user ) ? $user->ID : 0;
154
-				$this->set_post_author( $post_id, $user_id );
151
+				$user    = $this->fetch_commit_user($author);
152
+				$user_id = ! is_wp_error($user) ? $user->ID : 0;
153
+				$this->set_post_author($post_id, $user_id);
155 154
 			}
156 155
 
157
-			$post->set_post( get_post( $post_id ) );
156
+			$post->set_post(get_post($post_id));
158 157
 
159
-			$meta = apply_filters( 'wogh_pre_import_meta', $post->get_meta(), $post );
158
+			$meta = apply_filters('wogh_pre_import_meta', $post->get_meta(), $post);
160 159
 
161
-			unset( $meta['tags'] );
162
-			unset( $meta['categories'] );
163
-			unset( $meta['author'] );
164
-			unset( $meta['post_date'] );
165
-			unset( $meta['post_excerpt'] );
166
-			unset( $meta['permalink'] );
167
-			unset( $meta['link'] );
160
+			unset($meta['tags']);
161
+			unset($meta['categories']);
162
+			unset($meta['author']);
163
+			unset($meta['post_date']);
164
+			unset($meta['post_excerpt']);
165
+			unset($meta['permalink']);
166
+			unset($meta['link']);
168 167
 
169
-			foreach ( $meta as $key => $value ) {
170
-				update_post_meta( $post_id, $key, $value );
168
+			foreach ($meta as $key => $value) {
169
+				update_post_meta($post_id, $key, $value);
171 170
 			}
172 171
 		}
173 172
 
174
-		if ( $error ) {
173
+		if ($error) {
175 174
 			return $error;
176 175
 		}
177 176
 
178
-		return __( 'Successfully saved posts.', 'writing-on-github' );
177
+		return __('Successfully saved posts.', 'writing-on-github');
179 178
 	}
180 179
 
181
-	protected function post_args( $post ) {
180
+	protected function post_args($post) {
182 181
 		$args = $post->get_args();
183 182
 		$meta = $post->get_meta();
184 183
 
@@ -186,14 +185,14 @@  discard block
 block discarded – undo
186 185
 		$args['post_content'] = addslashes($args['post_content']);
187 186
 
188 187
 		// update tags
189
-		if ( isset( $meta['tags'] ) && $meta['tags'] ) {
188
+		if (isset($meta['tags']) && $meta['tags']) {
190 189
 		    $args['tags_input'] = $meta['tags'];
191 190
 		}
192 191
 
193 192
 		// update categories
194
-		if ( isset( $meta['categories'] ) && $meta['categories'] ) {
193
+		if (isset($meta['categories']) && $meta['categories']) {
195 194
 		    $categories = $meta['categories'];
196
-		    if (!is_array($categories)) {
195
+		    if ( ! is_array($categories)) {
197 196
 		        $categories = array($categories);
198 197
 		    }
199 198
 		    $terms = get_terms(array(
@@ -209,7 +208,7 @@  discard block
 block discarded – undo
209 208
 		    }
210 209
 
211 210
 		    $ids = array();
212
-		    if (!empty($terms)) {
211
+		    if ( ! empty($terms)) {
213 212
 		        foreach ($terms as $id => $name) {
214 213
 		            $ids[] = $id;
215 214
 		            unset($map[$name]);
@@ -217,7 +216,7 @@  discard block
 block discarded – undo
217 216
 		    }
218 217
 
219 218
 		    // create new terms
220
-		    if (!empty($map)) {
219
+		    if ( ! empty($map)) {
221 220
 		        foreach ($map as $name => $value) {
222 221
 		            $term = wp_insert_term($name, 'category', array('parent' => 0));
223 222
 		            // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
@@ -238,77 +237,77 @@  discard block
 block discarded – undo
238 237
 	 *
239 238
 	 * @return string|WP_Error
240 239
 	 */
241
-	public function delete_post_by_path( $path ) {
242
-		$query = new WP_Query( array(
240
+	public function delete_post_by_path($path) {
241
+		$query = new WP_Query(array(
243 242
 			'meta_key'       => '_wogh_github_path',
244 243
 			'meta_value'     => $path,
245 244
 			'meta_compare'   => '=',
246 245
 			'posts_per_page' => 1,
247 246
 			'fields'         => 'ids',
248
-		) );
247
+		));
249 248
 
250 249
 		$post_id = $query->get_posts();
251
-		$post_id = array_pop( $post_id );
250
+		$post_id = array_pop($post_id);
252 251
 
253
-		if ( ! $post_id ) {
254
-			$parts     = explode( '/', $path );
255
-			$filename  = array_pop( $parts );
256
-			$directory = $parts ? array_shift( $parts ) : '';
252
+		if ( ! $post_id) {
253
+			$parts     = explode('/', $path);
254
+			$filename  = array_pop($parts);
255
+			$directory = $parts ? array_shift($parts) : '';
257 256
 
258
-			if ( false !== strpos( $directory, 'post' ) ) {
259
-				preg_match( '/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/', $filename, $matches );
257
+			if (false !== strpos($directory, 'post')) {
258
+				preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/', $filename, $matches);
260 259
 				$title = $matches[4];
261 260
 
262
-				$query = new WP_Query( array(
261
+				$query = new WP_Query(array(
263 262
 					'name'     => $title,
264 263
 					'posts_per_page' => 1,
265 264
 					'post_type' => $this->get_whitelisted_post_types(),
266 265
 					'fields'         => 'ids',
267
-				) );
266
+				));
268 267
 
269 268
 				$post_id = $query->get_posts();
270
-				$post_id = array_pop( $post_id );
269
+				$post_id = array_pop($post_id);
271 270
 			}
272 271
 
273
-			if ( ! $post_id ) {
274
-				preg_match( '/(.*)\.md/', $filename, $matches );
272
+			if ( ! $post_id) {
273
+				preg_match('/(.*)\.md/', $filename, $matches);
275 274
 				$title = $matches[1];
276 275
 
277
-				$query = new WP_Query( array(
276
+				$query = new WP_Query(array(
278 277
 					'name'     => $title,
279 278
 					'posts_per_page' => 1,
280 279
 					'post_type' => $this->get_whitelisted_post_types(),
281 280
 					'fields'         => 'ids',
282
-				) );
281
+				));
283 282
 
284 283
 				$post_id = $query->get_posts();
285
-				$post_id = array_pop( $post_id );
284
+				$post_id = array_pop($post_id);
286 285
 			}
287 286
 		}
288 287
 
289
-		if ( ! $post_id ) {
288
+		if ( ! $post_id) {
290 289
 			return new WP_Error(
291 290
 				'path_not_found',
292 291
 				sprintf(
293
-					__( 'Post not found for path %s.', 'writing-on-github' ),
292
+					__('Post not found for path %s.', 'writing-on-github'),
294 293
 					$path
295 294
 				)
296 295
 			);
297 296
 		}
298 297
 
299
-		$result = wp_delete_post( $post_id );
298
+		$result = wp_delete_post($post_id);
300 299
 
301 300
 		// If deleting fails...
302
-		if ( false === $result ) {
303
-			$post = get_post( $post_id );
301
+		if (false === $result) {
302
+			$post = get_post($post_id);
304 303
 
305 304
 			// ...and the post both exists and isn't in the trash...
306
-			if ( $post && 'trash' !== $post->post_status ) {
305
+			if ($post && 'trash' !== $post->post_status) {
307 306
 				// ... then something went wrong.
308 307
 				return new WP_Error(
309 308
 					'db_error',
310 309
 					sprintf(
311
-						__( 'Failed to delete post ID %d.', 'writing-on-github' ),
310
+						__('Failed to delete post ID %d.', 'writing-on-github'),
312 311
 						$post_id
313 312
 					)
314 313
 				);
@@ -316,25 +315,25 @@  discard block
 block discarded – undo
316 315
 		}
317 316
 
318 317
 		return sprintf(
319
-			__( 'Successfully deleted post ID %d.', 'writing-on-github' ),
318
+			__('Successfully deleted post ID %d.', 'writing-on-github'),
320 319
 			$post_id
321 320
 		);
322 321
 	}
323 322
 
324
-	public function delete_post( $post_id ) {
325
-		$result = wp_delete_post( $post_id );
323
+	public function delete_post($post_id) {
324
+		$result = wp_delete_post($post_id);
326 325
 
327 326
 		// If deleting fails...
328
-		if ( false === $result ) {
329
-			$post = get_post( $post_id );
327
+		if (false === $result) {
328
+			$post = get_post($post_id);
330 329
 
331 330
 			// ...and the post both exists and isn't in the trash...
332
-			if ( $post && 'trash' !== $post->post_status ) {
331
+			if ($post && 'trash' !== $post->post_status) {
333 332
 				// ... then something went wrong.
334 333
 				return new WP_Error(
335 334
 					'db_error',
336 335
 					sprintf(
337
-						__( 'Failed to delete post ID %d.', 'writing-on-github' ),
336
+						__('Failed to delete post ID %d.', 'writing-on-github'),
338 337
 						$post_id
339 338
 					)
340 339
 				);
@@ -342,7 +341,7 @@  discard block
 block discarded – undo
342 341
 		}
343 342
 
344 343
 		return sprintf(
345
-			__( 'Successfully deleted post ID %d.', 'writing-on-github' ),
344
+			__('Successfully deleted post ID %d.', 'writing-on-github'),
346 345
 			$post_id
347 346
 		);
348 347
 	}
@@ -353,7 +352,7 @@  discard block
 block discarded – undo
353 352
 	 * @return array
354 353
 	 */
355 354
 	protected function get_whitelisted_post_types() {
356
-		return apply_filters( 'wogh_whitelisted_post_types', $this->whitelisted_post_types );
355
+		return apply_filters('wogh_whitelisted_post_types', $this->whitelisted_post_types);
357 356
 	}
358 357
 
359 358
 	/**
@@ -362,7 +361,7 @@  discard block
 block discarded – undo
362 361
 	 * @return array
363 362
 	 */
364 363
 	protected function get_whitelisted_post_statuses() {
365
-		return apply_filters( 'wogh_whitelisted_post_statuses', $this->whitelisted_post_statuses );
364
+		return apply_filters('wogh_whitelisted_post_statuses', $this->whitelisted_post_statuses);
366 365
 	}
367 366
 
368 367
 	/**
@@ -372,12 +371,12 @@  discard block
 block discarded – undo
372 371
 	 *
373 372
 	 * @return string Whitelist formatted for query
374 373
 	 */
375
-	protected function format_for_query( $whitelist ) {
376
-		foreach ( $whitelist as $key => $value ) {
377
-			$whitelist[ $key ] = "'$value'";
374
+	protected function format_for_query($whitelist) {
375
+		foreach ($whitelist as $key => $value) {
376
+			$whitelist[$key] = "'$value'";
378 377
 		}
379 378
 
380
-		return implode( ', ', $whitelist );
379
+		return implode(', ', $whitelist);
381 380
 	}
382 381
 
383 382
 	/**
@@ -388,25 +387,25 @@  discard block
 block discarded – undo
388 387
 	 *
389 388
 	 * @return boolean                          True if supported, false if not.
390 389
 	 */
391
-	protected function is_post_supported( Writing_On_GitHub_Post $post ) {
392
-		if ( wp_is_post_revision( $post->id ) ) {
390
+	protected function is_post_supported(Writing_On_GitHub_Post $post) {
391
+		if (wp_is_post_revision($post->id)) {
393 392
 			return false;
394 393
 		}
395 394
 
396 395
 		// We need to allow trashed posts to be queried, but they are not whitelisted for export.
397
-		if ( ! in_array( $post->status(), $this->get_whitelisted_post_statuses() ) && 'trash' !== $post->status() ) {
396
+		if ( ! in_array($post->status(), $this->get_whitelisted_post_statuses()) && 'trash' !== $post->status()) {
398 397
 			return false;
399 398
 		}
400 399
 
401
-		if ( ! in_array( $post->type(), $this->get_whitelisted_post_types() ) ) {
400
+		if ( ! in_array($post->type(), $this->get_whitelisted_post_types())) {
402 401
 			return false;
403 402
 		}
404 403
 
405
-		if ( $post->has_password() ) {
404
+		if ($post->has_password()) {
406 405
 			return false;
407 406
 		}
408 407
 
409
-		return apply_filters( 'wogh_is_post_supported', true, $post );
408
+		return apply_filters('wogh_is_post_supported', true, $post);
410 409
 	}
411 410
 
412 411
 	/**
@@ -419,35 +418,35 @@  discard block
 block discarded – undo
419 418
 	 *
420 419
 	 * @return WP_Error|WP_User
421 420
 	 */
422
-	protected function fetch_commit_user( $display_name ) {
421
+	protected function fetch_commit_user($display_name) {
423 422
 		// If we can't find a user and a default hasn't been set,
424 423
 		// we're just going to set the revision author to 0.
425 424
 		$user = false;
426 425
 
427
-		if ( ! empty( $display_name ) ) {
428
-			$search_string = esc_attr( $display_name );
429
-			$query = new WP_User_Query( array(
426
+		if ( ! empty($display_name)) {
427
+			$search_string = esc_attr($display_name);
428
+			$query = new WP_User_Query(array(
430 429
 			    'search'         => "{$search_string}",
431 430
 			    'search_columns' => array(
432 431
 			        'display_name',
433 432
 			        'user_nicename',
434 433
 			        'user_login',
435 434
 			    )
436
-			) );
435
+			));
437 436
 			$users = $query->get_results();
438 437
 			$user = empty($users) ? false : $users[0];
439 438
 		}
440 439
 
441
-		if ( ! $user ) {
440
+		if ( ! $user) {
442 441
 			// Use the default user.
443
-			$user = get_user_by( 'id', (int) get_option( 'wogh_default_user' ) );
442
+			$user = get_user_by('id', (int) get_option('wogh_default_user'));
444 443
 		}
445 444
 
446
-		if ( ! $user ) {
445
+		if ( ! $user) {
447 446
 			return new WP_Error(
448 447
 				'user_not_found',
449 448
 				sprintf(
450
-					__( 'Commit user not found for email %s', 'writing-on-github' ),
449
+					__('Commit user not found for email %s', 'writing-on-github'),
451 450
 					$email
452 451
 				)
453 452
 			);
@@ -465,28 +464,28 @@  discard block
 block discarded – undo
465 464
 	 *
466 465
 	 * @return string|WP_Error
467 466
 	 */
468
-	protected function set_revision_author( $post_id, $user_id ) {
469
-		$revision = wp_get_post_revisions( $post_id );
467
+	protected function set_revision_author($post_id, $user_id) {
468
+		$revision = wp_get_post_revisions($post_id);
470 469
 
471
-		if ( ! $revision ) {
472
-			$new_revision = wp_save_post_revision( $post_id );
470
+		if ( ! $revision) {
471
+			$new_revision = wp_save_post_revision($post_id);
473 472
 
474
-			if ( ! $new_revision || is_wp_error( $new_revision ) ) {
475
-				return new WP_Error( 'db_error', 'There was a problem saving a new revision.' );
473
+			if ( ! $new_revision || is_wp_error($new_revision)) {
474
+				return new WP_Error('db_error', 'There was a problem saving a new revision.');
476 475
 			}
477 476
 
478 477
 			// `wp_save_post_revision` returns the ID, whereas `get_post_revision` returns the whole object
479 478
 			// in order to be consistent, let's make sure we have the whole object before continuing.
480
-			$revision = get_post( $new_revision );
479
+			$revision = get_post($new_revision);
481 480
 
482
-			if ( ! $revision ) {
483
-				return new WP_Error( 'db_error', 'There was a problem retrieving the newly recreated revision.' );
481
+			if ( ! $revision) {
482
+				return new WP_Error('db_error', 'There was a problem retrieving the newly recreated revision.');
484 483
 			}
485 484
 		} else {
486
-			$revision = array_shift( $revision );
485
+			$revision = array_shift($revision);
487 486
 		}
488 487
 
489
-		return $this->set_post_author( $revision->ID, $user_id );
488
+		return $this->set_post_author($revision->ID, $user_id);
490 489
 	}
491 490
 
492 491
 	/**
@@ -499,7 +498,7 @@  discard block
 block discarded – undo
499 498
 	 *
500 499
 	 * @return string|WP_Error
501 500
 	 */
502
-	protected function set_post_author( $post_id, $user_id ) {
501
+	protected function set_post_author($post_id, $user_id) {
503 502
 		global $wpdb;
504 503
 
505 504
 		$result = $wpdb->update(
@@ -510,25 +509,25 @@  discard block
 block discarded – undo
510 509
 			array(
511 510
 				'ID' => (int) $post_id,
512 511
 			),
513
-			array( '%d' ),
514
-			array( '%d' )
512
+			array('%d'),
513
+			array('%d')
515 514
 		);
516 515
 
517
-		if ( false === $result ) {
518
-			return new WP_Error( 'db_error', $wpdb->last_error );
516
+		if (false === $result) {
517
+			return new WP_Error('db_error', $wpdb->last_error);
519 518
 		}
520 519
 
521
-		if ( 0 === $result ) {
520
+		if (0 === $result) {
522 521
 			return sprintf(
523
-				__( 'No change for post ID %d.', 'writing-on-github' ),
522
+				__('No change for post ID %d.', 'writing-on-github'),
524 523
 				$post_id
525 524
 			);
526 525
 		}
527 526
 
528
-		clean_post_cache( $post_id );
527
+		clean_post_cache($post_id);
529 528
 
530 529
 		return sprintf(
531
-			__( 'Successfully updated post ID %d.', 'writing-on-github' ),
530
+			__('Successfully updated post ID %d.', 'writing-on-github'),
532 531
 			$post_id
533 532
 		);
534 533
 	}
@@ -541,7 +540,7 @@  discard block
 block discarded – undo
541 540
 	 *
542 541
 	 * @return bool|int
543 542
 	 */
544
-	public function set_post_sha( $post, $sha ) {
545
-		return update_post_meta( $post->id, '_wogh_sha', $sha );
543
+	public function set_post_sha($post, $sha) {
544
+		return update_post_meta($post->id, '_wogh_sha', $sha);
546 545
 	}
547 546
 }
Please login to merge, or discard this patch.
lib/export.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -142,6 +142,10 @@
 block discarded – undo
142 142
 		return true;
143 143
 	}
144 144
 
145
+	/**
146
+	 * @param Writing_On_GitHub_Post $post
147
+	 * @param Writing_On_GitHub_Persist_Client $persist
148
+	 */
145 149
 	protected function new_post( $post, $persist ) {
146 150
 		$github_path = $post->github_path();
147 151
 		$old_github_path = $post->old_github_path();
Please login to merge, or discard this patch.
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param Writing_On_GitHub $app Application container.
24 24
 	 */
25
-	public function __construct( Writing_On_GitHub $app ) {
25
+	public function __construct(Writing_On_GitHub $app) {
26 26
 		$this->app = $app;
27 27
 	}
28 28
 
@@ -32,31 +32,31 @@  discard block
 block discarded – undo
32 32
      * @param  bool    $force_all
33 33
      * @return string|WP_Error
34 34
      */
35
-	public function full( $force_all = false ) {
35
+	public function full($force_all = false) {
36 36
 		$posts = $this->app->database()->fetch_all_supported($force_all);
37 37
 
38
-		if ( is_wp_error( $posts ) ) {
38
+		if (is_wp_error($posts)) {
39 39
 			return $posts;
40 40
 		}
41 41
 
42 42
         $error = false;
43 43
 
44
-        foreach ( $posts as $post ) {
45
-            $result = $this->update( $post->id() );
46
-            if ( is_wp_error( $result ) ) {
47
-                if ( $error ) {
48
-                    $error->add( $result->get_error_code(), $result->get_error_message() );
44
+        foreach ($posts as $post) {
45
+            $result = $this->update($post->id());
46
+            if (is_wp_error($result)) {
47
+                if ($error) {
48
+                    $error->add($result->get_error_code(), $result->get_error_message());
49 49
                 } else {
50 50
                     $error = $result;
51 51
                 }
52 52
             }
53 53
         }
54 54
 
55
-        if ( is_wp_error( $error ) ) {
55
+        if (is_wp_error($error)) {
56 56
             return $error;
57 57
         }
58 58
 
59
-        return __( 'Export to GitHub completed successfully.', 'writing-on-github' );
59
+        return __('Export to GitHub completed successfully.', 'writing-on-github');
60 60
 	}
61 61
 
62 62
 
@@ -65,10 +65,10 @@  discard block
 block discarded – undo
65 65
 	 * @param  int  $post_id
66 66
 	 * @return boolean
67 67
 	 */
68
-	protected function github_path( $post_id ) {
69
-		$github_path = get_post_meta( $post_id, '_wogh_github_path', true );
68
+	protected function github_path($post_id) {
69
+		$github_path = get_post_meta($post_id, '_wogh_github_path', true);
70 70
 
71
-		if ( $github_path && $this->app->api()->fetch()->exists( $github_path ) ) {
71
+		if ($github_path && $this->app->api()->fetch()->exists($github_path)) {
72 72
 			return $github_path;
73 73
 		}
74 74
 
@@ -82,29 +82,29 @@  discard block
 block discarded – undo
82 82
 	 *
83 83
 	 * @return string|WP_Error
84 84
 	 */
85
-	public function update( $post_id ) {
86
-		$post = $this->app->database()->fetch_by_id( $post_id );
85
+	public function update($post_id) {
86
+		$post = $this->app->database()->fetch_by_id($post_id);
87 87
 
88
-		if ( is_wp_error( $post ) ) {
88
+		if (is_wp_error($post)) {
89 89
 			return $post;
90 90
 		}
91 91
 
92
-		if ( 'trash' === $post->status() ) {
93
-			return $this->delete( $post_id );
92
+		if ('trash' === $post->status()) {
93
+			return $this->delete($post_id);
94 94
 		}
95 95
 
96
-		if ( $old_github_path = $this->github_path( $post->id() ) ) {
96
+		if ($old_github_path = $this->github_path($post->id())) {
97 97
 			error_log("old_github_path: $old_github_path");
98 98
 			$post->set_old_github_path($old_github_path);
99 99
 		}
100 100
 
101
-		$result = $this->new_posts( array( $post ) );
101
+		$result = $this->new_posts(array($post));
102 102
 
103
-		if ( is_wp_error( $result ) ) {
103
+		if (is_wp_error($result)) {
104 104
 			return $result;
105 105
 		}
106 106
 
107
-		return __( 'Export to GitHub completed successfully.', 'writing-on-github' );
107
+		return __('Export to GitHub completed successfully.', 'writing-on-github');
108 108
 	}
109 109
 
110 110
 	/**
@@ -114,16 +114,16 @@  discard block
 block discarded – undo
114 114
 	 *
115 115
 	 * @return string|WP_Error
116 116
 	 */
117
-	public function new_posts( array $posts ) {
117
+	public function new_posts(array $posts) {
118 118
 		$error = false;
119 119
 
120 120
 		$persist = $this->app->api()->persist();
121 121
 
122
-		foreach ( $posts as $post ) {
123
-			$result = $this->new_post( $post, $persist );
124
-			if ( is_wp_error( $result ) ) {
125
-				if ( $error ) {
126
-					$error->add( $result->get_error_code(), $result->get_error_message() );
122
+		foreach ($posts as $post) {
123
+			$result = $this->new_post($post, $persist);
124
+			if (is_wp_error($result)) {
125
+				if ($error) {
126
+					$error->add($result->get_error_code(), $result->get_error_message());
127 127
 				} else {
128 128
 					$error = $result;
129 129
 				}
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 		// $result = $this->app->api()->persist()->commit( $master );
136 136
 
137
-		if ( is_wp_error( $error ) ) {
137
+		if (is_wp_error($error)) {
138 138
 			return $error;
139 139
 		}
140 140
 
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
 		return true;
143 143
 	}
144 144
 
145
-	protected function new_post( $post, $persist ) {
145
+	protected function new_post($post, $persist) {
146 146
 		$github_path = $post->github_path();
147 147
 		$old_github_path = $post->old_github_path();
148 148
 		$blob = $post->to_blob();
149 149
 		$result = false;
150 150
 
151
-		if ( $old_github_path && $old_github_path != $github_path ) {
151
+		if ($old_github_path && $old_github_path != $github_path) {
152 152
 			// rename
153 153
 			$message = apply_filters(
154 154
 				'wogh_commit_msg_move_post',
@@ -156,20 +156,20 @@  discard block
 block discarded – undo
156 156
 					'Move %s to %s via WordPress at %s (%s)',
157 157
 					$old_github_path, $github_path,
158 158
 					site_url(),
159
-					get_bloginfo( 'name' )
159
+					get_bloginfo('name')
160 160
 				)
161 161
 			) . $this->get_commit_msg_tag();
162 162
 
163
-			$result = $persist->delete_file( $post->old_github_path(), $blob->sha(), $message );
164
-			if ( is_wp_error( $result ) ) {
163
+			$result = $persist->delete_file($post->old_github_path(), $blob->sha(), $message);
164
+			if (is_wp_error($result)) {
165 165
 				return $result;
166 166
 			}
167 167
 
168
-			$result = $persist->create_file( $blob, $message );
169
-			if ( is_wp_error( $result ) ) {
168
+			$result = $persist->create_file($blob, $message);
169
+			if (is_wp_error($result)) {
170 170
 				return $result;
171 171
 			}
172
-		} elseif ( ! $old_github_path ) {
172
+		} elseif ( ! $old_github_path) {
173 173
 			// create new
174 174
 			$message = apply_filters(
175 175
 				'wogh_commit_msg_new_post',
@@ -177,14 +177,14 @@  discard block
 block discarded – undo
177 177
 					'Create new post %s from WordPress at %s (%s)',
178 178
 					$github_path,
179 179
 					site_url(),
180
-					get_bloginfo( 'name' )
180
+					get_bloginfo('name')
181 181
 				)
182 182
 			) . $this->get_commit_msg_tag();
183
-			$result = $persist->create_file( $blob, $message );
184
-			if ( is_wp_error( $result ) ) {
183
+			$result = $persist->create_file($blob, $message);
184
+			if (is_wp_error($result)) {
185 185
 				return $result;
186 186
 			}
187
-		} elseif ( $old_github_path && $old_github_path == $github_path ) {
187
+		} elseif ($old_github_path && $old_github_path == $github_path) {
188 188
 			// update
189 189
 			$message = apply_filters(
190 190
 				'wogh_commit_msg_update_post',
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
 					'Update post %s from WordPress at %s (%s)',
193 193
 					$github_path,
194 194
 					site_url(),
195
-					get_bloginfo( 'name' )
195
+					get_bloginfo('name')
196 196
 				)
197 197
 			) . $this->get_commit_msg_tag();
198
-			$result = $persist->update_file( $blob, $message );
199
-			if ( is_wp_error( $result ) ) {
198
+			$result = $persist->update_file($blob, $message);
199
+			if (is_wp_error($result)) {
200 200
 				return $result;
201 201
 			}
202 202
 		}
@@ -215,14 +215,14 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @return string|WP_Error
217 217
 	 */
218
-	public function delete( $post_id ) {
219
-		$post = $this->app->database()->fetch_by_id( $post_id );
218
+	public function delete($post_id) {
219
+		$post = $this->app->database()->fetch_by_id($post_id);
220 220
 
221
-		if ( is_wp_error( $post ) ) {
221
+		if (is_wp_error($post)) {
222 222
 			return $post;
223 223
 		}
224 224
 
225
-		$github_path = get_post_meta( $post_id, '_wogh_github_path', true );
225
+		$github_path = get_post_meta($post_id, '_wogh_github_path', true);
226 226
 
227 227
 		$message = apply_filters(
228 228
 			'wogh_commit_msg_delete',
@@ -230,18 +230,18 @@  discard block
 block discarded – undo
230 230
 				'Deleting %s via WordPress at %s (%s)',
231 231
 				$github_path,
232 232
 				site_url(),
233
-				get_bloginfo( 'name' )
233
+				get_bloginfo('name')
234 234
 			),
235 235
 			$post
236 236
 		) . $this->get_commit_msg_tag();
237 237
 
238
-		$result = $this->app->api()->persist()->delete_file( $github_path, $post->sha(), $message );
238
+		$result = $this->app->api()->persist()->delete_file($github_path, $post->sha(), $message);
239 239
 
240
-		if ( is_wp_error( $result ) ) {
240
+		if (is_wp_error($result)) {
241 241
 			return $result;
242 242
 		}
243 243
 
244
-		return __( 'Export to GitHub completed successfully.', 'writing-on-github' );
244
+		return __('Export to GitHub completed successfully.', 'writing-on-github');
245 245
 	}
246 246
 
247 247
 
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 	 *
253 253
 	 * @return bool
254 254
 	 */
255
-	public function set_user( $user_id ) {
256
-		return update_option( self::EXPORT_USER_OPTION, (int) $user_id );
255
+	public function set_user($user_id) {
256
+		return update_option(self::EXPORT_USER_OPTION, (int) $user_id);
257 257
 	}
258 258
 
259 259
 	/**
@@ -262,10 +262,10 @@  discard block
 block discarded – undo
262 262
 	 * @return string
263 263
 	 */
264 264
 	protected function get_commit_msg_tag() {
265
-		$tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' );
265
+		$tag = apply_filters('wogh_commit_msg_tag', 'wogh');
266 266
 
267
-		if ( ! $tag ) {
268
-			throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) );
267
+		if ( ! $tag) {
268
+			throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github'));
269 269
 		}
270 270
 
271 271
 		return ' - ' . $tag;
Please login to merge, or discard this patch.
lib/import.php 2 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -140,6 +140,9 @@  discard block
 block discarded – undo
140 140
 		return __( 'Payload processed', 'writing-on-github' );
141 141
 	}
142 142
 
143
+	/**
144
+	 * @param boolean $delete_ids
145
+	 */
143 146
 	protected function compare( $files, &$delete_ids ) {
144 147
 		if ( is_wp_error( $files ) ) {
145 148
 			return $files;
@@ -217,7 +220,6 @@  discard block
 block discarded – undo
217 220
 	/**
218 221
 	 * Checks whether the provided blob should be imported.
219 222
 	 *
220
-	 * @param Writing_On_GitHub_Blob $blob Blob to validate.
221 223
 	 *
222 224
 	 * @return bool
223 225
 	 */
Please login to merge, or discard this patch.
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param Writing_On_GitHub $app Application container.
24 24
 	 */
25
-	public function __construct( Writing_On_GitHub $app ) {
25
+	public function __construct(Writing_On_GitHub $app) {
26 26
 		$this->app = $app;
27 27
 	}
28 28
 
@@ -70,21 +70,21 @@  discard block
 block discarded – undo
70 70
 	// 	return __( 'Payload processed', 'writing-on-github' );
71 71
 	// }
72 72
 
73
-	public function payload( Writing_On_GitHub_Payload $payload ) {
73
+	public function payload(Writing_On_GitHub_Payload $payload) {
74 74
 
75
-		$result = $this->app->api()->fetch()->compare( $payload->get_before_commit_id() );
75
+		$result = $this->app->api()->fetch()->compare($payload->get_before_commit_id());
76 76
 
77
-		if ( is_wp_error( $result ) ) {
77
+		if (is_wp_error($result)) {
78 78
 			return $result;
79 79
 		}
80 80
 
81
-		$result = $this->import_files( $result );
81
+		$result = $this->import_files($result);
82 82
 
83
-		if ( is_wp_error( $result ) ) {
83
+		if (is_wp_error($result)) {
84 84
 			return $files;
85 85
 		}
86 86
 
87
-		return __( 'Payload processed', 'writing-on-github' );
87
+		return __('Payload processed', 'writing-on-github');
88 88
 	}
89 89
 
90 90
 	/**
@@ -92,23 +92,23 @@  discard block
 block discarded – undo
92 92
 	 * @param  array $files [Writing_On_GitHub_File_Info]
93 93
 	 * @return string|WP_ERROR
94 94
 	 */
95
-	protected function import_files( $files ) {
95
+	protected function import_files($files) {
96 96
 
97
-		$error 		= false;
97
+		$error = false;
98 98
 		$delete_ids = false;
99 99
 
100
-		$result = $this->compare( $files, $delete_ids );
100
+		$result = $this->compare($files, $delete_ids);
101 101
 
102
-		if ( is_wp_error( $result ) ) {
102
+		if (is_wp_error($result)) {
103 103
 			return $result;
104 104
 		}
105 105
 
106
-		if ( $delete_ids ) {
106
+		if ($delete_ids) {
107 107
 			foreach ($delete_ids as $id) {
108
-				$result = $this->app->database()->delete_post( $id );
109
-				if ( is_wp_error( $result ) ) {
110
-					if ( $error ) {
111
-						$error->add( $result->get_error_code(), $result->get_error_message() );
108
+				$result = $this->app->database()->delete_post($id);
109
+				if (is_wp_error($result)) {
110
+					if ($error) {
111
+						$error->add($result->get_error_code(), $result->get_error_message());
112 112
 					} else {
113 113
 						$error = $result;
114 114
 					}
@@ -127,21 +127,21 @@  discard block
 block discarded – undo
127 127
 	public function master() {
128 128
 		$result = $this->app->api()->fetch()->tree_recursive();
129 129
 
130
-		if ( is_wp_error( $result ) ) {
130
+		if (is_wp_error($result)) {
131 131
 			return $result;
132 132
 		}
133 133
 
134
-		$result = $this->import_files( $result );
134
+		$result = $this->import_files($result);
135 135
 
136
-		if ( is_wp_error( $result ) ) {
136
+		if (is_wp_error($result)) {
137 137
 			return $result;
138 138
 		}
139 139
 
140
-		return __( 'Payload processed', 'writing-on-github' );
140
+		return __('Payload processed', 'writing-on-github');
141 141
 	}
142 142
 
143
-	protected function compare( $files, &$delete_ids ) {
144
-		if ( is_wp_error( $files ) ) {
143
+	protected function compare($files, &$delete_ids) {
144
+		if (is_wp_error($files)) {
145 145
 			return $files;
146 146
 		}
147 147
 
@@ -150,44 +150,44 @@  discard block
 block discarded – undo
150 150
 
151 151
 		$idsmap = array();
152 152
 
153
-		foreach ( $files as $file ) {
154
-			if ( ! $this->importable_file( $file ) ) {
153
+		foreach ($files as $file) {
154
+			if ( ! $this->importable_file($file)) {
155 155
 				continue;
156 156
 			}
157 157
 
158 158
 			$blob = $this->app->api()->fetch()->blob($file);
159 159
 			// network error ?
160
-			if ( is_wp_error($blob) ) {
160
+			if (is_wp_error($blob)) {
161 161
 				continue;
162 162
 			}
163 163
 
164 164
 
165
-			if ( $this->importable_raw_file($blob) ) {
165
+			if ($this->importable_raw_file($blob)) {
166 166
 				$this->import_raw_file($blob, $file->status == 'removed');
167 167
 				continue;
168 168
 			}
169 169
 
170
-			if ( ! $this->importable_blob($blob) ) {
170
+			if ( ! $this->importable_blob($blob)) {
171 171
 				continue;
172 172
 			}
173 173
 
174
-			$post = $this->blob_to_post( $blob );
174
+			$post = $this->blob_to_post($blob);
175 175
 
176
-			if ( $file->status == 'removed' ) {
177
-				if ( $blob->id() ) {
176
+			if ($file->status == 'removed') {
177
+				if ($blob->id()) {
178 178
 					$idsmap[$blob->id()] = true;
179 179
 				}
180
-			} elseif ( $post != false ) {
180
+			} elseif ($post != false) {
181 181
 				$posts[] = $post;
182
-				if ( $post->is_new() ) {
182
+				if ($post->is_new()) {
183 183
 					$new[] = $post;
184 184
 				}
185 185
 			}
186 186
 		}
187 187
 
188 188
 		foreach ($posts as $post) {
189
-			if ( $post->id() && isset( $idsmap[$post->id()] ) ) {
190
-				unset( $idsmap[$post->id()] );
189
+			if ($post->id() && isset($idsmap[$post->id()])) {
190
+				unset($idsmap[$post->id()]);
191 191
 			}
192 192
 		}
193 193
 		$delete_ids = array();
@@ -197,16 +197,16 @@  discard block
 block discarded – undo
197 197
 
198 198
 		// $this->app->database()->save_posts( $posts, $commit->author_email() );
199 199
 
200
-		$result = $this->app->database()->save_posts( $posts );
200
+		$result = $this->app->database()->save_posts($posts);
201 201
 
202
-		if ( is_wp_error( $result ) ) {
202
+		if (is_wp_error($result)) {
203 203
 			return $result;
204 204
 		}
205 205
 
206
-		if ( $new ) {
207
-			$result = $this->app->export()->new_posts( $new );
206
+		if ($new) {
207
+			$result = $this->app->export()->new_posts($new);
208 208
 
209
-			if ( is_wp_error( $result ) ) {
209
+			if (is_wp_error($result)) {
210 210
 				return $result;
211 211
 			}
212 212
 		}
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
 	 *
222 222
 	 * @return bool
223 223
 	 */
224
-	protected function importable_file( Writing_On_GitHub_File_Info $file ) {
224
+	protected function importable_file(Writing_On_GitHub_File_Info $file) {
225 225
 
226 226
 		// only _pages and _posts
227
-		if ( strncasecmp($file->path, '_pages/', strlen('_pages/') ) != 0 &&
228
-			 strncasecmp($file->path, '_posts/', strlen('_posts/') ) != 0 &&
229
-			 strncasecmp($file->path, 'images/', strlen('images/') ) != 0 ) {
227
+		if (strncasecmp($file->path, '_pages/', strlen('_pages/')) != 0 &&
228
+			 strncasecmp($file->path, '_posts/', strlen('_posts/')) != 0 &&
229
+			 strncasecmp($file->path, 'images/', strlen('images/')) != 0) {
230 230
 			return false;
231 231
 		}
232 232
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 *
246 246
 	 * @return bool
247 247
 	 */
248
-	protected function importable_blob( Writing_On_GitHub_Blob $blob ) {
248
+	protected function importable_blob(Writing_On_GitHub_Blob $blob) {
249 249
 		// global $wpdb;
250 250
 
251 251
 		// // Skip the repo's readme.
@@ -258,20 +258,20 @@  discard block
 block discarded – undo
258 258
 		// 	return false;
259 259
 		// }
260 260
 
261
-		if ( ! $blob->has_frontmatter() ) {
261
+		if ( ! $blob->has_frontmatter()) {
262 262
 			return false;
263 263
 		}
264 264
 
265 265
 		return true;
266 266
 	}
267 267
 
268
-	protected function importable_raw_file( Writing_On_GitHub_Blob $blob ) {
269
-		if ( $blob->has_frontmatter() ) {
268
+	protected function importable_raw_file(Writing_On_GitHub_Blob $blob) {
269
+		if ($blob->has_frontmatter()) {
270 270
 			return false;
271 271
 		}
272 272
 
273 273
 		// only images
274
-		if ( strncasecmp($blob->path(), 'images/', strlen('images/') ) != 0) {
274
+		if (strncasecmp($blob->path(), 'images/', strlen('images/')) != 0) {
275 275
 			return false;
276 276
 		}
277 277
 
@@ -283,16 +283,16 @@  discard block
 block discarded – undo
283 283
 	 * @param  Writing_On_GitHub_Blob $blob
284 284
 	 * @param  bool                   $is_remove
285 285
 	 */
286
-	protected function import_raw_file( Writing_On_GitHub_Blob $blob, $is_remove ) {
286
+	protected function import_raw_file(Writing_On_GitHub_Blob $blob, $is_remove) {
287 287
 		$arr = wp_upload_dir();
288 288
 		$path = $arr['basedir'] . '/writing-on-github/' . $blob->path();
289
-		if ( $is_remove ) {
290
-			if ( file_exists($path) ) {
289
+		if ($is_remove) {
290
+			if (file_exists($path)) {
291 291
 				unlink($path);
292 292
 			}
293 293
 		} else {
294 294
 			$dirname = dirname($path);
295
-			if ( ! file_exists($dirname) ) {
295
+			if ( ! file_exists($dirname)) {
296 296
 				wp_mkdir_p($dirname);
297 297
 			}
298 298
 
@@ -307,57 +307,57 @@  discard block
 block discarded – undo
307 307
 	 *
308 308
 	 * @return Writing_On_GitHub_Post
309 309
 	 */
310
-	protected function blob_to_post( Writing_On_GitHub_Blob $blob ) {
311
-		$args = array( 'post_content' => $blob->content_import() );
310
+	protected function blob_to_post(Writing_On_GitHub_Blob $blob) {
311
+		$args = array('post_content' => $blob->content_import());
312 312
 		$meta = $blob->meta();
313 313
 
314 314
 		$id = false;
315 315
 
316
-		if ( $meta ) {
317
-			if ( array_key_exists( 'layout', $meta ) ) {
316
+		if ($meta) {
317
+			if (array_key_exists('layout', $meta)) {
318 318
 				$args['post_type'] = $meta['layout'];
319
-				unset( $meta['layout'] );
319
+				unset($meta['layout']);
320 320
 			}
321 321
 
322
-			if ( array_key_exists( 'published', $meta ) ) {
322
+			if (array_key_exists('published', $meta)) {
323 323
 				$args['post_status'] = true === $meta['published'] ? 'publish' : 'draft';
324
-				unset( $meta['published'] );
324
+				unset($meta['published']);
325 325
 			}
326 326
 
327
-			if ( array_key_exists( 'post_title', $meta ) ) {
327
+			if (array_key_exists('post_title', $meta)) {
328 328
 				$args['post_title'] = $meta['post_title'];
329
-				unset( $meta['post_title'] );
329
+				unset($meta['post_title']);
330 330
 			}
331 331
 
332
-			if ( array_key_exists( 'post_name', $meta ) ) {
332
+			if (array_key_exists('post_name', $meta)) {
333 333
 				$args['post_name'] = $meta['post_name'];
334
-				unset( $meta['post_name'] );
334
+				unset($meta['post_name']);
335 335
 			}
336 336
 
337
-			if ( array_key_exists( 'ID', $meta ) ) {
337
+			if (array_key_exists('ID', $meta)) {
338 338
 				$id = $args['ID'] = $meta['ID'];
339 339
 				$blob->set_id($id);
340
-				unset( $meta['ID'] );
340
+				unset($meta['ID']);
341 341
 			}
342 342
 		}
343 343
 
344 344
 		$meta['_wogh_sha'] = $blob->sha();
345 345
 
346
-		if ( $id ) {
347
-			$old_sha = get_post_meta( $id, '_wogh_sha', true );
348
-			$old_github_path = get_post_meta( $id, '_wogh_github_path', true );
346
+		if ($id) {
347
+			$old_sha = get_post_meta($id, '_wogh_sha', true);
348
+			$old_github_path = get_post_meta($id, '_wogh_github_path', true);
349 349
 
350 350
 			// dont save post when has same sha
351
-			if ( $old_sha  && $old_sha == $meta['_wogh_sha'] &&
352
-				 $old_github_path && $old_github_path == $blob->path() ) {
351
+			if ($old_sha && $old_sha == $meta['_wogh_sha'] &&
352
+				 $old_github_path && $old_github_path == $blob->path()) {
353 353
 				return false;
354 354
 			}
355 355
 		}
356 356
 
357
-		$post = new Writing_On_GitHub_Post( $args, $this->app->api() );
358
-		$post->set_old_github_path( $blob->path() );
359
-		$post->set_meta( $meta );
360
-		$blob->set_id( $post->id() );
357
+		$post = new Writing_On_GitHub_Post($args, $this->app->api());
358
+		$post->set_old_github_path($blob->path());
359
+		$post->set_meta($meta);
360
+		$blob->set_id($post->id());
361 361
 
362 362
 		return $post;
363 363
 	}
Please login to merge, or discard this patch.
lib/request.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
 	/**
42 42
 	 * Validates the header's secret.
43 43
 	 *
44
-	 * @return true|WP_Error
44
+	 * @return boolean
45 45
 	 */
46 46
 	public function is_secret_valid() {
47 47
 		$headers = $this->headers();
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param Writing_On_GitHub $app Application container.
36 36
 	 */
37
-	public function __construct( Writing_On_GitHub $app ) {
37
+	public function __construct(Writing_On_GitHub $app) {
38 38
 		$this->app = $app;
39 39
 	}
40 40
 
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 		$this->raw_data = $this->read_raw_data();
50 50
 
51 51
 		// Validate request secret.
52
-		$hash = hash_hmac( 'sha1', $this->raw_data, $this->secret() );
53
-		if ( 'sha1=' . $hash !== $headers['X-Hub-Signature'] ) {
52
+		$hash = hash_hmac('sha1', $this->raw_data, $this->secret());
53
+		if ('sha1=' . $hash !== $headers['X-Hub-Signature']) {
54 54
 			return false;
55 55
 		}
56 56
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 * @return Writing_On_GitHub_Payload
91 91
 	 */
92 92
 	public function payload() {
93
-		return new Writing_On_GitHub_Payload( $this->app, $this->raw_data );
93
+		return new Writing_On_GitHub_Payload($this->app, $this->raw_data);
94 94
 	}
95 95
 
96 96
 	/**
@@ -101,11 +101,11 @@  discard block
 block discarded – undo
101 101
 	 * @return array
102 102
 	 */
103 103
 	protected function headers() {
104
-		if ( $this->headers ) {
104
+		if ($this->headers) {
105 105
 			return $this->headers;
106 106
 		}
107 107
 
108
-		if ( function_exists( 'getallheaders' ) ) {
108
+		if (function_exists('getallheaders')) {
109 109
 
110 110
 			$this->headers = getallheaders();
111 111
 			return $this->headers;
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 		 * @see http://www.php.net/manual/en/function.getallheaders.php
116 116
 		 */
117 117
 		$this->headers = array();
118
-		foreach ( $_SERVER as $name => $value ) {
119
-			if ( 'HTTP_' === substr( $name, 0, 5 ) ) {
120
-				$this->headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
118
+		foreach ($_SERVER as $name => $value) {
119
+			if ('HTTP_' === substr($name, 0, 5)) {
120
+				$this->headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
121 121
 			}
122 122
 		}
123 123
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @return string
131 131
 	 */
132 132
 	protected function read_raw_data() {
133
-		return file_get_contents( 'php://input' );
133
+		return file_get_contents('php://input');
134 134
 	}
135 135
 
136 136
 	/**
@@ -139,6 +139,6 @@  discard block
 block discarded – undo
139 139
 	 * @return string
140 140
 	 */
141 141
 	protected function secret() {
142
-		return get_option( 'wogh_secret' );
142
+		return get_option('wogh_secret');
143 143
 	}
144 144
 }
Please login to merge, or discard this patch.
Spyc.php 2 patches
Doc Comments   +77 added lines, -1 removed lines patch added patch discarded remove patch
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
      * Creates a literal block for dumping
362 362
      * @access private
363 363
      * @return string
364
-     * @param $value
364
+     * @param string $value
365 365
      * @param $indent int The value of the indent
366 366
      */
367 367
   private function _doLiteralBlock($value,$indent) {
@@ -430,6 +430,9 @@  discard block
 block discarded – undo
430 430
     return in_array($value, $words, true);
431 431
   }
432 432
 
433
+  /**
434
+   * @param string $value
435
+   */
433 436
   private function isTranslationWord($value) {
434 437
     return (
435 438
       self::isTrueWord($value)  ||
@@ -471,11 +474,17 @@  discard block
 block discarded – undo
471 474
 
472 475
 // LOADING FUNCTIONS
473 476
 
477
+  /**
478
+   * @param string $input
479
+   */
474 480
   private function __load($input) {
475 481
     $Source = $this->loadFromSource($input);
476 482
     return $this->loadWithSource($Source);
477 483
   }
478 484
 
485
+  /**
486
+   * @param string $input
487
+   */
479 488
   private function __loadString($input) {
480 489
     $Source = $this->loadFromString($input);
481 490
     return $this->loadWithSource($Source);
@@ -692,6 +701,7 @@  discard block
 block discarded – undo
692 701
   /**
693 702
      * Used in inlines to check for more inlines or quoted strings
694 703
      * @access private
704
+     * @param string $inline
695 705
      * @return array
696 706
      */
697 707
   private function _inlineEscape($inline) {
@@ -822,12 +832,18 @@  discard block
 block discarded – undo
822 832
     return $explode;
823 833
   }
824 834
 
835
+  /**
836
+   * @param integer $lineIndent
837
+   */
825 838
   private function literalBlockContinues ($line, $lineIndent) {
826 839
     if (!trim($line)) return true;
827 840
     if (strlen($line) - strlen(ltrim($line)) > $lineIndent) return true;
828 841
     return false;
829 842
   }
830 843
 
844
+  /**
845
+   * @param boolean $alias
846
+   */
831 847
   private function referenceContentsByAlias ($alias) {
832 848
     do {
833 849
       if (!isset($this->SavedGroups[$alias])) { echo "Bad group name: $alias."; break; }
@@ -926,6 +942,9 @@  discard block
 block discarded – undo
926 942
 
927 943
   }
928 944
 
945
+  /**
946
+   * @param string $line
947
+   */
929 948
   private static function startsLiteralBlock ($line) {
930 949
     $lastChar = substr (trim($line), -1);
931 950
     if ($lastChar != '>' && $lastChar != '|') return false;
@@ -935,6 +954,9 @@  discard block
 block discarded – undo
935 954
     return $lastChar;
936 955
   }
937 956
 
957
+  /**
958
+   * @param string $line
959
+   */
938 960
   private static function greedilyNeedNextLine($line) {
939 961
     $line = trim ($line);
940 962
     if (!strlen($line)) return false;
@@ -944,6 +966,10 @@  discard block
 block discarded – undo
944 966
     return false;
945 967
   }
946 968
 
969
+  /**
970
+   * @param string $literalBlock
971
+   * @param string $literalBlockStyle
972
+   */
947 973
   private function addLiteralLine ($literalBlock, $line, $literalBlockStyle, $indent = -1) {
948 974
     $line = self::stripIndent($line, $indent);
949 975
     if ($literalBlockStyle !== '|') {
@@ -963,6 +989,9 @@  discard block
 block discarded – undo
963 989
     return $literalBlock . $line;
964 990
   }
965 991
 
992
+   /**
993
+    * @param string $literalBlock
994
+    */
966 995
    function revertLiteralPlaceHolder ($lineArray, $literalBlock) {
967 996
      foreach ($lineArray as $k => $_) {
968 997
       if (is_array($_))
@@ -978,6 +1007,9 @@  discard block
 block discarded – undo
978 1007
     return substr ($line, $indent);
979 1008
   }
980 1009
 
1010
+  /**
1011
+   * @param integer $indent
1012
+   */
981 1013
   private function getParentPathByIndent ($indent) {
982 1014
     if ($indent == 0) return array();
983 1015
     $linePath = $this->path;
@@ -1003,6 +1035,9 @@  discard block
 block discarded – undo
1003 1035
   }
1004 1036
 
1005 1037
 
1038
+  /**
1039
+   * @param string $line
1040
+   */
1006 1041
   private static function isComment ($line) {
1007 1042
     if (!$line) return false;
1008 1043
     if ($line[0] == '#') return true;
@@ -1010,6 +1045,9 @@  discard block
 block discarded – undo
1010 1045
     return false;
1011 1046
   }
1012 1047
 
1048
+  /**
1049
+   * @param string $line
1050
+   */
1013 1051
   private static function isEmpty ($line) {
1014 1052
     return (trim ($line) === '');
1015 1053
   }
@@ -1035,6 +1073,9 @@  discard block
 block discarded – undo
1035 1073
   }
1036 1074
 
1037 1075
 
1076
+  /**
1077
+   * @param string $value
1078
+   */
1038 1079
   private static function unquote ($value) {
1039 1080
     if (!$value) return $value;
1040 1081
     if (!is_string($value)) return $value;
@@ -1043,10 +1084,16 @@  discard block
 block discarded – undo
1043 1084
     return $value;
1044 1085
   }
1045 1086
 
1087
+  /**
1088
+   * @param string $line
1089
+   */
1046 1090
   private function startsMappedSequence ($line) {
1047 1091
     return (substr($line, 0, 2) == '- ' && substr ($line, -1, 1) == ':');
1048 1092
   }
1049 1093
 
1094
+  /**
1095
+   * @param string $line
1096
+   */
1050 1097
   private function returnMappedSequence ($line) {
1051 1098
     $array = array();
1052 1099
     $key         = self::unquote(trim(substr($line,1,-1)));
@@ -1063,6 +1110,9 @@  discard block
 block discarded – undo
1063 1110
     }
1064 1111
   }
1065 1112
 
1113
+  /**
1114
+   * @param string $line
1115
+   */
1066 1116
   private function returnMappedValue ($line) {
1067 1117
     $this->checkKeysInValue($line);
1068 1118
     $array = array();
@@ -1071,18 +1121,30 @@  discard block
 block discarded – undo
1071 1121
     return $array;
1072 1122
   }
1073 1123
 
1124
+  /**
1125
+   * @param string $line
1126
+   */
1074 1127
   private function startsMappedValue ($line) {
1075 1128
     return (substr ($line, -1, 1) == ':');
1076 1129
   }
1077 1130
 
1131
+  /**
1132
+   * @param string $line
1133
+   */
1078 1134
   private function isPlainArray ($line) {
1079 1135
     return ($line[0] == '[' && substr ($line, -1, 1) == ']');
1080 1136
   }
1081 1137
 
1138
+  /**
1139
+   * @param string $line
1140
+   */
1082 1141
   private function returnPlainArray ($line) {
1083 1142
     return $this->_toType($line);
1084 1143
   }
1085 1144
 
1145
+  /**
1146
+   * @param string $line
1147
+   */
1086 1148
   private function returnKeyValuePair ($line) {
1087 1149
     $array = array();
1088 1150
     $key = '';
@@ -1111,6 +1173,9 @@  discard block
 block discarded – undo
1111 1173
   }
1112 1174
 
1113 1175
 
1176
+  /**
1177
+   * @param string $line
1178
+   */
1114 1179
   private function returnArrayElement ($line) {
1115 1180
      if (strlen($line) <= 1) return array(array()); // Weird %)
1116 1181
      $array = array();
@@ -1124,6 +1189,9 @@  discard block
 block discarded – undo
1124 1189
   }
1125 1190
 
1126 1191
 
1192
+  /**
1193
+   * @param string $line
1194
+   */
1127 1195
   private function nodeContainsGroup ($line) {
1128 1196
     $symbolsForReference = 'A-z0-9_\-';
1129 1197
     if (strpos($line, '&') === false && strpos($line, '*') === false) return false; // Please die fast ;-)
@@ -1136,12 +1204,20 @@  discard block
 block discarded – undo
1136 1204
 
1137 1205
   }
1138 1206
 
1207
+  /**
1208
+   * @param string $line
1209
+   * @param string $group
1210
+   */
1139 1211
   private function addGroup ($line, $group) {
1140 1212
     if ($group[0] == '&') $this->_containsGroupAnchor = substr ($group, 1);
1141 1213
     if ($group[0] == '*') $this->_containsGroupAlias = substr ($group, 1);
1142 1214
     //print_r ($this->path);
1143 1215
   }
1144 1216
 
1217
+  /**
1218
+   * @param string $line
1219
+   * @param string $group
1220
+   */
1145 1221
   private function stripGroup ($line, $group) {
1146 1222
     $line = trim(str_replace($group, '', $line));
1147 1223
     return $line;
Please login to merge, or discard this patch.
Spacing   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -10,40 +10,40 @@  discard block
 block discarded – undo
10 10
    * @package Spyc
11 11
    */
12 12
 
13
-if (!function_exists('spyc_load')) {
13
+if ( ! function_exists('spyc_load')) {
14 14
   /**
15 15
    * Parses YAML to array.
16 16
    * @param string $string YAML string.
17 17
    * @return array
18 18
    */
19
-  function spyc_load ($string) {
19
+  function spyc_load($string) {
20 20
     return Spyc::YAMLLoadString($string);
21 21
   }
22 22
 }
23 23
 
24
-if (!function_exists('spyc_load_file')) {
24
+if ( ! function_exists('spyc_load_file')) {
25 25
   /**
26 26
    * Parses YAML to array.
27 27
    * @param string $file Path to YAML file.
28 28
    * @return array
29 29
    */
30
-  function spyc_load_file ($file) {
30
+  function spyc_load_file($file) {
31 31
     return Spyc::YAMLLoad($file);
32 32
   }
33 33
 }
34 34
 
35
-if (!function_exists('spyc_dump')) {
35
+if ( ! function_exists('spyc_dump')) {
36 36
   /**
37 37
    * Dumps array to YAML.
38 38
    * @param array $data Array.
39 39
    * @return string
40 40
    */
41
-  function spyc_dump ($data) {
41
+  function spyc_dump($data) {
42 42
     return Spyc::YAMLDump($data, false, false, true);
43 43
   }
44 44
 }
45 45
 
46
-if (!class_exists('Spyc')) {
46
+if ( ! class_exists('Spyc')) {
47 47
 
48 48
 /**
49 49
    * The Simple PHP YAML Class.
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
  * @param string $input
121 121
  * @return array
122 122
  */
123
-  public function load ($input) {
123
+  public function load($input) {
124 124
     return $this->__loadString($input);
125 125
   }
126 126
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
  * @param string $file
130 130
  * @return array
131 131
  */
132
-  public function loadFile ($file) {
132
+  public function loadFile($file) {
133 133
     return $this->__load($file);
134 134
   }
135 135
 
@@ -224,18 +224,18 @@  discard block
 block discarded – undo
224 224
      * @param int $indent Pass in false to use the default, which is 2
225 225
      * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
226 226
      */
227
-  public function dump($array,$indent = false,$wordwrap = false, $no_opening_dashes = false) {
227
+  public function dump($array, $indent = false, $wordwrap = false, $no_opening_dashes = false) {
228 228
     // Dumps to some very clean YAML.  We'll have to add some more features
229 229
     // and options soon.  And better support for folding.
230 230
 
231 231
     // New features and options.
232
-    if ($indent === false or !is_numeric($indent)) {
232
+    if ($indent === false or ! is_numeric($indent)) {
233 233
       $this->_dumpIndent = 2;
234 234
     } else {
235 235
       $this->_dumpIndent = $indent;
236 236
     }
237 237
 
238
-    if ($wordwrap === false or !is_numeric($wordwrap)) {
238
+    if ($wordwrap === false or ! is_numeric($wordwrap)) {
239 239
       $this->_dumpWordWrap = 40;
240 240
     } else {
241 241
       $this->_dumpWordWrap = $wordwrap;
@@ -243,15 +243,15 @@  discard block
 block discarded – undo
243 243
 
244 244
     // New YAML document
245 245
     $string = "";
246
-    if (!$no_opening_dashes) $string = "---\n";
246
+    if ( ! $no_opening_dashes) $string = "---\n";
247 247
 
248 248
     // Start at the base of the array and move through it.
249 249
     if ($array) {
250
-      $array = (array)$array;
250
+      $array = (array) $array;
251 251
       $previous_key = -1;
252 252
       foreach ($array as $key => $value) {
253
-        if (!isset($first_key)) $first_key = $key;
254
-        $string .= $this->_yamlize($key,$value,0,$previous_key, $first_key, $array);
253
+        if ( ! isset($first_key)) $first_key = $key;
254
+        $string .= $this->_yamlize($key, $value, 0, $previous_key, $first_key, $array);
255 255
         $previous_key = $key;
256 256
       }
257 257
     }
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
      * @param $value The value of the item
267 267
      * @param $indent The indent of the current node
268 268
      */
269
-  private function _yamlize($key,$value,$indent, $previous_key = -1, $first_key = 0, $source_array = null) {
270
-    if(is_object($value)) $value = (array)$value;
269
+  private function _yamlize($key, $value, $indent, $previous_key = -1, $first_key = 0, $source_array = null) {
270
+    if (is_object($value)) $value = (array) $value;
271 271
     if (is_array($value)) {
272 272
       if (empty ($value))
273 273
         return $this->_dumpNode($key, array(), $indent, $previous_key, $first_key, $source_array);
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
       // Add the indent
278 278
       $indent += $this->_dumpIndent;
279 279
       // Yamlize the array
280
-      $string .= $this->_yamlizeArray($value,$indent);
281
-    } elseif (!is_array($value)) {
280
+      $string .= $this->_yamlizeArray($value, $indent);
281
+    } elseif ( ! is_array($value)) {
282 282
       // It doesn't have children.  Yip.
283 283
       $string = $this->_dumpNode($key, $value, $indent, $previous_key, $first_key, $source_array);
284 284
     }
@@ -292,12 +292,12 @@  discard block
 block discarded – undo
292 292
      * @param $array The array you want to convert
293 293
      * @param $indent The indent of the current level
294 294
      */
295
-  private function _yamlizeArray($array,$indent) {
295
+  private function _yamlizeArray($array, $indent) {
296 296
     if (is_array($array)) {
297 297
       $string = '';
298 298
       $previous_key = -1;
299 299
       foreach ($array as $key => $value) {
300
-        if (!isset($first_key)) $first_key = $key;
300
+        if ( ! isset($first_key)) $first_key = $key;
301 301
         $string .= $this->_yamlize($key, $value, $indent, $previous_key, $first_key, $array);
302 302
         $previous_key = $key;
303 303
       }
@@ -317,14 +317,14 @@  discard block
 block discarded – undo
317 317
      */
318 318
   private function _dumpNode($key, $value, $indent, $previous_key = -1, $first_key = 0, $source_array = null) {
319 319
     // do some folding here, for blocks
320
-    if (is_string ($value) && ((strpos($value,"\n") !== false || strpos($value,": ") !== false || strpos($value,"- ") !== false ||
321
-      strpos($value,"*") !== false || strpos($value,"#") !== false || strpos($value,"<") !== false || strpos($value,">") !== false || strpos ($value, '%') !== false || strpos ($value, '  ') !== false ||
322
-      strpos($value,"[") !== false || strpos($value,"]") !== false || strpos($value,"{") !== false || strpos($value,"}") !== false) || strpos($value,"&") !== false || strpos($value, "'") !== false || strpos($value, "!") === 0 ||
323
-      substr ($value, -1, 1) == ':')
320
+    if (is_string($value) && ((strpos($value, "\n") !== false || strpos($value, ": ") !== false || strpos($value, "- ") !== false ||
321
+      strpos($value, "*") !== false || strpos($value, "#") !== false || strpos($value, "<") !== false || strpos($value, ">") !== false || strpos($value, '%') !== false || strpos($value, '  ') !== false ||
322
+      strpos($value, "[") !== false || strpos($value, "]") !== false || strpos($value, "{") !== false || strpos($value, "}") !== false) || strpos($value, "&") !== false || strpos($value, "'") !== false || strpos($value, "!") === 0 ||
323
+      substr($value, -1, 1) == ':')
324 324
     ) {
325
-      $value = $this->_doLiteralBlock($value,$indent);
325
+      $value = $this->_doLiteralBlock($value, $indent);
326 326
     } else {
327
-      $value  = $this->_doFolding($value,$indent);
327
+      $value = $this->_doFolding($value, $indent);
328 328
     }
329 329
 
330 330
     if ($value === array()) $value = '[ ]';
@@ -332,8 +332,8 @@  discard block
 block discarded – undo
332 332
     if (self::isTranslationWord($value)) {
333 333
       $value = $this->_doLiteralBlock($value, $indent);
334 334
     }
335
-    if (trim ($value) != $value)
336
-       $value = $this->_doLiteralBlock($value,$indent);
335
+    if (trim($value) != $value)
336
+       $value = $this->_doLiteralBlock($value, $indent);
337 337
 
338 338
     if (is_bool($value)) {
339 339
        $value = $value ? "true" : "false";
@@ -342,17 +342,17 @@  discard block
 block discarded – undo
342 342
     if ($value === null) $value = 'null';
343 343
     if ($value === "'" . self::REMPTY . "'") $value = null;
344 344
 
345
-    $spaces = str_repeat(' ',$indent);
345
+    $spaces = str_repeat(' ', $indent);
346 346
 
347 347
     //if (is_int($key) && $key - 1 == $previous_key && $first_key===0) {
348
-    if (is_array ($source_array) && array_keys($source_array) === range(0, count($source_array) - 1)) {
348
+    if (is_array($source_array) && array_keys($source_array) === range(0, count($source_array) - 1)) {
349 349
       // It's a sequence
350
-      $string = $spaces.'- '.$value."\n";
350
+      $string = $spaces . '- ' . $value . "\n";
351 351
     } else {
352 352
       // if ($first_key===0)  throw new Exception('Keys are all screwy.  The first one was zero, now it\'s "'. $key .'"');
353 353
       // It's mapped
354 354
       if (strpos($key, ":") !== false || strpos($key, "#") !== false) { $key = '"' . $key . '"'; }
355
-      $string = rtrim ($spaces.$key.': '.$value)."\n";
355
+      $string = rtrim($spaces . $key . ': ' . $value) . "\n";
356 356
     }
357 357
     return $string;
358 358
   }
@@ -364,25 +364,25 @@  discard block
 block discarded – undo
364 364
      * @param $value
365 365
      * @param $indent int The value of the indent
366 366
      */
367
-  private function _doLiteralBlock($value,$indent) {
367
+  private function _doLiteralBlock($value, $indent) {
368 368
     if ($value === "\n") return '\n';
369 369
     if (strpos($value, "\n") === false && strpos($value, "'") === false) {
370
-      return sprintf ("'%s'", $value);
370
+      return sprintf("'%s'", $value);
371 371
     }
372 372
     if (strpos($value, "\n") === false && strpos($value, '"') === false) {
373
-      return sprintf ('"%s"', $value);
373
+      return sprintf('"%s"', $value);
374 374
     }
375
-    $exploded = explode("\n",$value);
375
+    $exploded = explode("\n", $value);
376 376
     $newValue = '|';
377 377
     if (isset($exploded[0]) && ($exploded[0] == "|" || $exploded[0] == "|-" || $exploded[0] == ">")) {
378 378
         $newValue = $exploded[0];
379 379
         unset($exploded[0]);
380 380
     }
381 381
     $indent += $this->_dumpIndent;
382
-    $spaces   = str_repeat(' ',$indent);
382
+    $spaces = str_repeat(' ', $indent);
383 383
     foreach ($exploded as $line) {
384 384
       $line = trim($line);
385
-      if (strpos($line, '"') === 0 && strrpos($line, '"') == (strlen($line)-1) || strpos($line, "'") === 0 && strrpos($line, "'") == (strlen($line)-1)) {
385
+      if (strpos($line, '"') === 0 && strrpos($line, '"') == (strlen($line) - 1) || strpos($line, "'") === 0 && strrpos($line, "'") == (strlen($line) - 1)) {
386 386
         $line = substr($line, 1, -1);
387 387
       }
388 388
       $newValue .= "\n" . $spaces . ($line);
@@ -396,16 +396,16 @@  discard block
 block discarded – undo
396 396
      * @return string
397 397
      * @param $value The string you wish to fold
398 398
      */
399
-  private function _doFolding($value,$indent) {
399
+  private function _doFolding($value, $indent) {
400 400
     // Don't do anything if wordwrap is set to 0
401 401
 
402
-    if ($this->_dumpWordWrap !== 0 && is_string ($value) && strlen($value) > $this->_dumpWordWrap) {
402
+    if ($this->_dumpWordWrap !== 0 && is_string($value) && strlen($value) > $this->_dumpWordWrap) {
403 403
       $indent += $this->_dumpIndent;
404
-      $indent = str_repeat(' ',$indent);
405
-      $wrapped = wordwrap($value,$this->_dumpWordWrap,"\n$indent");
406
-      $value   = ">\n".$indent.$wrapped;
404
+      $indent = str_repeat(' ', $indent);
405
+      $wrapped = wordwrap($value, $this->_dumpWordWrap, "\n$indent");
406
+      $value   = ">\n" . $indent . $wrapped;
407 407
     } else {
408
-      if ($this->setting_dump_force_quotes && is_string ($value) && $value !== self::REMPTY)
408
+      if ($this->setting_dump_force_quotes && is_string($value) && $value !== self::REMPTY)
409 409
         $value = '"' . $value . '"';
410 410
       if (is_numeric($value) && is_string($value))
411 411
         $value = '"' . $value . '"';
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 
433 433
   private function isTranslationWord($value) {
434 434
     return (
435
-      self::isTrueWord($value)  ||
435
+      self::isTrueWord($value) ||
436 436
       self::isFalseWord($value) ||
437 437
       self::isNullWord($value)
438 438
     );
@@ -483,8 +483,8 @@  discard block
 block discarded – undo
483 483
 
484 484
   private function loadWithSource($Source) {
485 485
     if (empty ($Source)) return array();
486
-    if ($this->setting_use_syck_is_possible && function_exists ('syck_load')) {
487
-      $array = syck_load (implode ("\n", $Source));
486
+    if ($this->setting_use_syck_is_possible && function_exists('syck_load')) {
487
+      $array = syck_load(implode("\n", $Source));
488 488
       return is_array($array) ? $array : array();
489 489
     }
490 490
 
@@ -504,10 +504,10 @@  discard block
 block discarded – undo
504 504
 
505 505
       $literalBlockStyle = self::startsLiteralBlock($line);
506 506
       if ($literalBlockStyle) {
507
-        $line = rtrim ($line, $literalBlockStyle . " \n");
507
+        $line = rtrim($line, $literalBlockStyle . " \n");
508 508
         $literalBlock = '';
509
-        $line .= ' '.$this->LiteralPlaceHolder;
510
-        $literal_block_indent = strlen($Source[$i+1]) - strlen(ltrim($Source[$i+1]));
509
+        $line .= ' ' . $this->LiteralPlaceHolder;
510
+        $literal_block_indent = strlen($Source[$i + 1]) - strlen(ltrim($Source[$i + 1]));
511 511
         while (++$i < $cnt && $this->literalBlockContinues($Source[$i], $this->indent)) {
512 512
           $literalBlock = $this->addLiteralLine($literalBlock, $Source[$i], $literalBlockStyle, $literal_block_indent);
513 513
         }
@@ -515,19 +515,19 @@  discard block
 block discarded – undo
515 515
       }
516 516
 
517 517
       // Strip out comments
518
-      if (strpos ($line, '#')) {
519
-          $line = preg_replace('/\s*#([^"\']+)$/','',$line);
518
+      if (strpos($line, '#')) {
519
+          $line = preg_replace('/\s*#([^"\']+)$/', '', $line);
520 520
       }
521 521
 
522 522
       while (++$i < $cnt && self::greedilyNeedNextLine($line)) {
523
-        $line = rtrim ($line, " \n\t\r") . ' ' . ltrim ($Source[$i], " \t");
523
+        $line = rtrim($line, " \n\t\r") . ' ' . ltrim($Source[$i], " \t");
524 524
       }
525 525
       $i--;
526 526
 
527 527
       $lineArray = $this->_parseLine($line);
528 528
 
529 529
       if ($literalBlockStyle)
530
-        $lineArray = $this->revertLiteralPlaceHolder ($lineArray, $literalBlock);
530
+        $lineArray = $this->revertLiteralPlaceHolder($lineArray, $literalBlock);
531 531
 
532 532
       $this->addArray($lineArray, $this->indent);
533 533
 
@@ -540,17 +540,17 @@  discard block
 block discarded – undo
540 540
     return $this->result;
541 541
   }
542 542
 
543
-  private function loadFromSource ($input) {
544
-    if (!empty($input) && strpos($input, "\n") === false && file_exists($input))
543
+  private function loadFromSource($input) {
544
+    if ( ! empty($input) && strpos($input, "\n") === false && file_exists($input))
545 545
       $input = file_get_contents($input);
546 546
 
547 547
     return $this->loadFromString($input);
548 548
   }
549 549
 
550
-  private function loadFromString ($input) {
551
-    $lines = explode("\n",$input);
550
+  private function loadFromString($input) {
551
+    $lines = explode("\n", $input);
552 552
     foreach ($lines as $k => $_) {
553
-      $lines[$k] = rtrim ($_, "\r");
553
+      $lines[$k] = rtrim($_, "\r");
554 554
     }
555 555
     return $lines;
556 556
   }
@@ -562,16 +562,16 @@  discard block
 block discarded – undo
562 562
      * @param string $line A line from the YAML file
563 563
      */
564 564
   private function _parseLine($line) {
565
-    if (!$line) return array();
565
+    if ( ! $line) return array();
566 566
     $line = trim($line);
567
-    if (!$line) return array();
567
+    if ( ! $line) return array();
568 568
 
569 569
     $array = array();
570 570
 
571 571
     $group = $this->nodeContainsGroup($line);
572 572
     if ($group) {
573 573
       $this->addGroup($line, $group);
574
-      $line = $this->stripGroup ($line, $group);
574
+      $line = $this->stripGroup($line, $group);
575 575
     }
576 576
 
577 577
     if ($this->startsMappedSequence($line))
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
 
605 605
     $is_quoted = false;
606 606
     do {
607
-      if (!$value) break;
607
+      if ( ! $value) break;
608 608
       if ($first_character != '"' && $first_character != "'") break;
609 609
       if ($last_character != '"' && $last_character != "'") break;
610 610
       $is_quoted = true;
@@ -613,37 +613,37 @@  discard block
 block discarded – undo
613 613
     if ($is_quoted) {
614 614
       $value = str_replace('\n', "\n", $value);
615 615
       if ($first_character == "'")
616
-        return strtr(substr ($value, 1, -1), array ('\'\'' => '\'', '\\\''=> '\''));
617
-      return strtr(substr ($value, 1, -1), array ('\\"' => '"', '\\\''=> '\''));
616
+        return strtr(substr($value, 1, -1), array('\'\'' => '\'', '\\\''=> '\''));
617
+      return strtr(substr($value, 1, -1), array('\\"' => '"', '\\\''=> '\''));
618 618
     }
619 619
 
620
-    if (strpos($value, ' #') !== false && !$is_quoted)
621
-      $value = preg_replace('/\s+#(.+)$/','',$value);
620
+    if (strpos($value, ' #') !== false && ! $is_quoted)
621
+      $value = preg_replace('/\s+#(.+)$/', '', $value);
622 622
 
623 623
     if ($first_character == '[' && $last_character == ']') {
624 624
       // Take out strings sequences and mappings
625
-      $innerValue = trim(substr ($value, 1, -1));
625
+      $innerValue = trim(substr($value, 1, -1));
626 626
       if ($innerValue === '') return array();
627 627
       $explode = $this->_inlineEscape($innerValue);
628 628
       // Propagate value array
629
-      $value  = array();
629
+      $value = array();
630 630
       foreach ($explode as $v) {
631 631
         $value[] = $this->_toType($v);
632 632
       }
633 633
       return $value;
634 634
     }
635 635
 
636
-    if (strpos($value,': ')!==false && $first_character != '{') {
637
-      $array = explode(': ',$value);
636
+    if (strpos($value, ': ') !== false && $first_character != '{') {
637
+      $array = explode(': ', $value);
638 638
       $key   = trim($array[0]);
639 639
       array_shift($array);
640
-      $value = trim(implode(': ',$array));
640
+      $value = trim(implode(': ', $array));
641 641
       $value = $this->_toType($value);
642 642
       return array($key => $value);
643 643
     }
644 644
 
645 645
     if ($first_character == '{' && $last_character == '}') {
646
-      $innerValue = trim(substr ($value, 1, -1));
646
+      $innerValue = trim(substr($value, 1, -1));
647 647
       if ($innerValue === '') return array();
648 648
       // Inline Mapping
649 649
       // Take out strings sequences and mappings
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
       foreach ($explode as $v) {
654 654
         $SubArr = $this->_toType($v);
655 655
         if (empty($SubArr)) continue;
656
-        if (is_array ($SubArr)) {
656
+        if (is_array($SubArr)) {
657 657
           $array[key($SubArr)] = $SubArr[key($SubArr)]; continue;
658 658
         }
659 659
         $array[] = $SubArr;
@@ -665,8 +665,8 @@  discard block
 block discarded – undo
665 665
       return null;
666 666
     }
667 667
 
668
-    if ( is_numeric($value) && preg_match ('/^(-|)[1-9]+[0-9]*$/', $value) ){
669
-      $intvalue = (int)$value;
668
+    if (is_numeric($value) && preg_match('/^(-|)[1-9]+[0-9]*$/', $value)) {
669
+      $intvalue = (int) $value;
670 670
       if ($intvalue != PHP_INT_MAX && $intvalue != ~PHP_INT_MAX)
671 671
         $value = $intvalue;
672 672
       return $value;
@@ -681,8 +681,8 @@  discard block
 block discarded – undo
681 681
 
682 682
     if (is_numeric($value)) {
683 683
       if ($value === '0') return 0;
684
-      if (rtrim ($value, 0) === $value)
685
-        $value = (float)$value;
684
+      if (rtrim($value, 0) === $value)
685
+        $value = (float) $value;
686 686
       return $value;
687 687
     }
688 688
 
@@ -707,17 +707,17 @@  discard block
 block discarded – undo
707 707
 
708 708
     // Check for empty strings
709 709
     $regex = '/("")|(\'\')/';
710
-    if (preg_match_all($regex,$inline,$strings)) {
710
+    if (preg_match_all($regex, $inline, $strings)) {
711 711
       $saved_empties = $strings[0];
712
-      $inline  = preg_replace($regex,'YAMLEmpty',$inline);
712
+      $inline = preg_replace($regex, 'YAMLEmpty', $inline);
713 713
     }
714 714
     unset($regex);
715 715
 
716 716
     // Check for strings
717 717
     $regex = '/(?:(")|(?:\'))((?(1)[^"]+|[^\']+))(?(1)"|\')/';
718
-    if (preg_match_all($regex,$inline,$strings)) {
718
+    if (preg_match_all($regex, $inline, $strings)) {
719 719
       $saved_strings = $strings[0];
720
-      $inline  = preg_replace($regex,'YAMLString',$inline);
720
+      $inline = preg_replace($regex, 'YAMLString', $inline);
721 721
     }
722 722
     unset($regex);
723 723
 
@@ -727,33 +727,33 @@  discard block
 block discarded – undo
727 727
     do {
728 728
 
729 729
     // Check for sequences
730
-    while (preg_match('/\[([^{}\[\]]+)\]/U',$inline,$matchseqs)) {
730
+    while (preg_match('/\[([^{}\[\]]+)\]/U', $inline, $matchseqs)) {
731 731
       $seqs[] = $matchseqs[0];
732 732
       $inline = preg_replace('/\[([^{}\[\]]+)\]/U', ('YAMLSeq' . (count($seqs) - 1) . 's'), $inline, 1);
733 733
     }
734 734
 
735 735
     // Check for mappings
736
-    while (preg_match('/{([^\[\]{}]+)}/U',$inline,$matchmaps)) {
736
+    while (preg_match('/{([^\[\]{}]+)}/U', $inline, $matchmaps)) {
737 737
       $maps[] = $matchmaps[0];
738 738
       $inline = preg_replace('/{([^\[\]{}]+)}/U', ('YAMLMap' . (count($maps) - 1) . 's'), $inline, 1);
739 739
     }
740 740
 
741 741
     if ($i++ >= 10) break;
742 742
 
743
-    } while (strpos ($inline, '[') !== false || strpos ($inline, '{') !== false);
743
+    } while (strpos($inline, '[') !== false || strpos($inline, '{') !== false);
744 744
 
745
-    $explode = explode(',',$inline);
745
+    $explode = explode(',', $inline);
746 746
     $explode = array_map('trim', $explode);
747 747
     $stringi = 0; $i = 0;
748 748
 
749 749
     while (1) {
750 750
 
751 751
     // Re-add the sequences
752
-    if (!empty($seqs)) {
752
+    if ( ! empty($seqs)) {
753 753
       foreach ($explode as $key => $value) {
754
-        if (strpos($value,'YAMLSeq') !== false) {
754
+        if (strpos($value, 'YAMLSeq') !== false) {
755 755
           foreach ($seqs as $seqk => $seq) {
756
-            $explode[$key] = str_replace(('YAMLSeq'.$seqk.'s'),$seq,$value);
756
+            $explode[$key] = str_replace(('YAMLSeq' . $seqk . 's'), $seq, $value);
757 757
             $value = $explode[$key];
758 758
           }
759 759
         }
@@ -761,11 +761,11 @@  discard block
 block discarded – undo
761 761
     }
762 762
 
763 763
     // Re-add the mappings
764
-    if (!empty($maps)) {
764
+    if ( ! empty($maps)) {
765 765
       foreach ($explode as $key => $value) {
766
-        if (strpos($value,'YAMLMap') !== false) {
766
+        if (strpos($value, 'YAMLMap') !== false) {
767 767
           foreach ($maps as $mapk => $map) {
768
-            $explode[$key] = str_replace(('YAMLMap'.$mapk.'s'), $map, $value);
768
+            $explode[$key] = str_replace(('YAMLMap' . $mapk . 's'), $map, $value);
769 769
             $value = $explode[$key];
770 770
           }
771 771
         }
@@ -774,10 +774,10 @@  discard block
 block discarded – undo
774 774
 
775 775
 
776 776
     // Re-add the strings
777
-    if (!empty($saved_strings)) {
777
+    if ( ! empty($saved_strings)) {
778 778
       foreach ($explode as $key => $value) {
779
-        while (strpos($value,'YAMLString') !== false) {
780
-          $explode[$key] = preg_replace('/YAMLString/',$saved_strings[$stringi],$value, 1);
779
+        while (strpos($value, 'YAMLString') !== false) {
780
+          $explode[$key] = preg_replace('/YAMLString/', $saved_strings[$stringi], $value, 1);
781 781
           unset($saved_strings[$stringi]);
782 782
           ++$stringi;
783 783
           $value = $explode[$key];
@@ -787,9 +787,9 @@  discard block
 block discarded – undo
787 787
 
788 788
 
789 789
     // Re-add the empties
790
-    if (!empty($saved_empties)) {
790
+    if ( ! empty($saved_empties)) {
791 791
       foreach ($explode as $key => $value) {
792
-        while (strpos($value,'YAMLEmpty') !== false) {
792
+        while (strpos($value, 'YAMLEmpty') !== false) {
793 793
           $explode[$key] = preg_replace('/YAMLEmpty/', '', $value, 1);
794 794
           $value = $explode[$key];
795 795
         }
@@ -798,16 +798,16 @@  discard block
 block discarded – undo
798 798
 
799 799
     $finished = true;
800 800
     foreach ($explode as $key => $value) {
801
-      if (strpos($value,'YAMLSeq') !== false) {
801
+      if (strpos($value, 'YAMLSeq') !== false) {
802 802
         $finished = false; break;
803 803
       }
804
-      if (strpos($value,'YAMLMap') !== false) {
804
+      if (strpos($value, 'YAMLMap') !== false) {
805 805
         $finished = false; break;
806 806
       }
807
-      if (strpos($value,'YAMLString') !== false) {
807
+      if (strpos($value, 'YAMLString') !== false) {
808 808
         $finished = false; break;
809 809
       }
810
-      if (strpos($value,'YAMLEmpty') !== false) {
810
+      if (strpos($value, 'YAMLEmpty') !== false) {
811 811
         $finished = false; break;
812 812
       }
813 813
     }
@@ -822,15 +822,15 @@  discard block
 block discarded – undo
822 822
     return $explode;
823 823
   }
824 824
 
825
-  private function literalBlockContinues ($line, $lineIndent) {
826
-    if (!trim($line)) return true;
825
+  private function literalBlockContinues($line, $lineIndent) {
826
+    if ( ! trim($line)) return true;
827 827
     if (strlen($line) - strlen(ltrim($line)) > $lineIndent) return true;
828 828
     return false;
829 829
   }
830 830
 
831
-  private function referenceContentsByAlias ($alias) {
831
+  private function referenceContentsByAlias($alias) {
832 832
     do {
833
-      if (!isset($this->SavedGroups[$alias])) { echo "Bad group name: $alias."; break; }
833
+      if ( ! isset($this->SavedGroups[$alias])) { echo "Bad group name: $alias."; break; }
834 834
       $groupPath = $this->SavedGroups[$alias];
835 835
       $value = $this->result;
836 836
       foreach ($groupPath as $k) {
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
     return $value;
841 841
   }
842 842
 
843
-  private function addArrayInline ($array, $indent) {
843
+  private function addArrayInline($array, $indent) {
844 844
       $CommonGroupPath = $this->path;
845 845
       if (empty ($array)) return false;
846 846
 
@@ -851,22 +851,22 @@  discard block
 block discarded – undo
851 851
       return true;
852 852
   }
853 853
 
854
-  private function addArray ($incoming_data, $incoming_indent) {
854
+  private function addArray($incoming_data, $incoming_indent) {
855 855
 
856 856
    // print_r ($incoming_data);
857 857
 
858
-    if (count ($incoming_data) > 1)
859
-      return $this->addArrayInline ($incoming_data, $incoming_indent);
858
+    if (count($incoming_data) > 1)
859
+      return $this->addArrayInline($incoming_data, $incoming_indent);
860 860
 
861
-    $key = key ($incoming_data);
861
+    $key = key($incoming_data);
862 862
     $value = isset($incoming_data[$key]) ? $incoming_data[$key] : null;
863 863
     if ($key === '__!YAMLZero') $key = '0';
864 864
 
865
-    if ($incoming_indent == 0 && !$this->_containsGroupAlias && !$this->_containsGroupAnchor) { // Shortcut for root-level values.
865
+    if ($incoming_indent == 0 && ! $this->_containsGroupAlias && ! $this->_containsGroupAnchor) { // Shortcut for root-level values.
866 866
       if ($key || $key === '' || $key === '0') {
867 867
         $this->result[$key] = $value;
868 868
       } else {
869
-        $this->result[] = $value; end ($this->result); $key = key ($this->result);
869
+        $this->result[] = $value; end($this->result); $key = key($this->result);
870 870
       }
871 871
       $this->path[$incoming_indent] = $key;
872 872
       return;
@@ -889,25 +889,25 @@  discard block
 block discarded – undo
889 889
 
890 890
     // Adding string or numeric key to the innermost level or $this->arr.
891 891
     if (is_string($key) && $key == '<<') {
892
-      if (!is_array ($_arr)) { $_arr = array (); }
892
+      if ( ! is_array($_arr)) { $_arr = array(); }
893 893
 
894
-      $_arr = array_merge ($_arr, $value);
894
+      $_arr = array_merge($_arr, $value);
895 895
     } else if ($key || $key === '' || $key === '0') {
896
-      if (!is_array ($_arr))
897
-        $_arr = array ($key=>$value);
896
+      if ( ! is_array($_arr))
897
+        $_arr = array($key=>$value);
898 898
       else
899 899
         $_arr[$key] = $value;
900 900
     } else {
901
-      if (!is_array ($_arr)) { $_arr = array ($value); $key = 0; }
902
-      else { $_arr[] = $value; end ($_arr); $key = key ($_arr); }
901
+      if ( ! is_array($_arr)) { $_arr = array($value); $key = 0; }
902
+      else { $_arr[] = $value; end($_arr); $key = key($_arr); }
903 903
     }
904 904
 
905 905
     $reverse_path = array_reverse($this->path);
906
-    $reverse_history = array_reverse ($history);
906
+    $reverse_history = array_reverse($history);
907 907
     $reverse_history[0] = $_arr;
908 908
     $cnt = count($reverse_history) - 1;
909 909
     for ($i = 0; $i < $cnt; $i++) {
910
-      $reverse_history[$i+1][$reverse_path[$i]] = $reverse_history[$i];
910
+      $reverse_history[$i + 1][$reverse_path[$i]] = $reverse_history[$i];
911 911
     }
912 912
     $this->result = $reverse_history[$cnt];
913 913
 
@@ -915,9 +915,9 @@  discard block
 block discarded – undo
915 915
 
916 916
     if ($this->_containsGroupAnchor) {
917 917
       $this->SavedGroups[$this->_containsGroupAnchor] = $this->path;
918
-      if (is_array ($value)) {
919
-        $k = key ($value);
920
-        if (!is_int ($k)) {
918
+      if (is_array($value)) {
919
+        $k = key($value);
920
+        if ( ! is_int($k)) {
921 921
           $this->SavedGroups[$this->_containsGroupAnchor][$incoming_indent + 2] = $k;
922 922
         }
923 923
       }
@@ -926,70 +926,70 @@  discard block
 block discarded – undo
926 926
 
927 927
   }
928 928
 
929
-  private static function startsLiteralBlock ($line) {
930
-    $lastChar = substr (trim($line), -1);
929
+  private static function startsLiteralBlock($line) {
930
+    $lastChar = substr(trim($line), -1);
931 931
     if ($lastChar != '>' && $lastChar != '|') return false;
932 932
     if ($lastChar == '|') return $lastChar;
933 933
     // HTML tags should not be counted as literal blocks.
934
-    if (preg_match ('#<.*?>$#', $line)) return false;
934
+    if (preg_match('#<.*?>$#', $line)) return false;
935 935
     return $lastChar;
936 936
   }
937 937
 
938 938
   private static function greedilyNeedNextLine($line) {
939
-    $line = trim ($line);
940
-    if (!strlen($line)) return false;
941
-    if (substr ($line, -1, 1) == ']') return false;
939
+    $line = trim($line);
940
+    if ( ! strlen($line)) return false;
941
+    if (substr($line, -1, 1) == ']') return false;
942 942
     if ($line[0] == '[') return true;
943
-    if (preg_match ('#^[^:]+?:\s*\[#', $line)) return true;
943
+    if (preg_match('#^[^:]+?:\s*\[#', $line)) return true;
944 944
     return false;
945 945
   }
946 946
 
947
-  private function addLiteralLine ($literalBlock, $line, $literalBlockStyle, $indent = -1) {
947
+  private function addLiteralLine($literalBlock, $line, $literalBlockStyle, $indent = -1) {
948 948
     $line = self::stripIndent($line, $indent);
949 949
     if ($literalBlockStyle !== '|') {
950 950
         $line = self::stripIndent($line);
951 951
     }
952
-    $line = rtrim ($line, "\r\n\t ") . "\n";
952
+    $line = rtrim($line, "\r\n\t ") . "\n";
953 953
     if ($literalBlockStyle == '|') {
954 954
       return $literalBlock . $line;
955 955
     }
956 956
     if (strlen($line) == 0)
957 957
       return rtrim($literalBlock, ' ') . "\n";
958 958
     if ($line == "\n" && $literalBlockStyle == '>') {
959
-      return rtrim ($literalBlock, " \t") . "\n";
959
+      return rtrim($literalBlock, " \t") . "\n";
960 960
     }
961 961
     if ($line != "\n")
962
-      $line = trim ($line, "\r\n ") . " ";
962
+      $line = trim($line, "\r\n ") . " ";
963 963
     return $literalBlock . $line;
964 964
   }
965 965
 
966
-   function revertLiteralPlaceHolder ($lineArray, $literalBlock) {
966
+   function revertLiteralPlaceHolder($lineArray, $literalBlock) {
967 967
      foreach ($lineArray as $k => $_) {
968 968
       if (is_array($_))
969
-        $lineArray[$k] = $this->revertLiteralPlaceHolder ($_, $literalBlock);
970
-      else if (substr($_, -1 * strlen ($this->LiteralPlaceHolder)) == $this->LiteralPlaceHolder)
971
-	       $lineArray[$k] = rtrim ($literalBlock, " \r\n");
969
+        $lineArray[$k] = $this->revertLiteralPlaceHolder($_, $literalBlock);
970
+      else if (substr($_, -1 * strlen($this->LiteralPlaceHolder)) == $this->LiteralPlaceHolder)
971
+	       $lineArray[$k] = rtrim($literalBlock, " \r\n");
972 972
      }
973 973
      return $lineArray;
974 974
    }
975 975
 
976
-  private static function stripIndent ($line, $indent = -1) {
976
+  private static function stripIndent($line, $indent = -1) {
977 977
     if ($indent == -1) $indent = strlen($line) - strlen(ltrim($line));
978
-    return substr ($line, $indent);
978
+    return substr($line, $indent);
979 979
   }
980 980
 
981
-  private function getParentPathByIndent ($indent) {
981
+  private function getParentPathByIndent($indent) {
982 982
     if ($indent == 0) return array();
983 983
     $linePath = $this->path;
984 984
     do {
985 985
       end($linePath); $lastIndentInParentPath = key($linePath);
986
-      if ($indent <= $lastIndentInParentPath) array_pop ($linePath);
986
+      if ($indent <= $lastIndentInParentPath) array_pop($linePath);
987 987
     } while ($indent <= $lastIndentInParentPath);
988 988
     return $linePath;
989 989
   }
990 990
 
991 991
 
992
-  private function clearBiggerPathValues ($indent) {
992
+  private function clearBiggerPathValues($indent) {
993 993
 
994 994
 
995 995
     if ($indent == 0) $this->path = array();
@@ -1003,94 +1003,94 @@  discard block
 block discarded – undo
1003 1003
   }
1004 1004
 
1005 1005
 
1006
-  private static function isComment ($line) {
1007
-    if (!$line) return false;
1006
+  private static function isComment($line) {
1007
+    if ( ! $line) return false;
1008 1008
     if ($line[0] == '#') return true;
1009 1009
     if (trim($line, " \r\n\t") == '---') return true;
1010 1010
     return false;
1011 1011
   }
1012 1012
 
1013
-  private static function isEmpty ($line) {
1014
-    return (trim ($line) === '');
1013
+  private static function isEmpty($line) {
1014
+    return (trim($line) === '');
1015 1015
   }
1016 1016
 
1017 1017
 
1018
-  private function isArrayElement ($line) {
1019
-    if (!$line || !is_scalar($line)) return false;
1018
+  private function isArrayElement($line) {
1019
+    if ( ! $line || ! is_scalar($line)) return false;
1020 1020
     if (substr($line, 0, 2) != '- ') return false;
1021
-    if (strlen ($line) > 3)
1022
-      if (substr($line,0,3) == '---') return false;
1021
+    if (strlen($line) > 3)
1022
+      if (substr($line, 0, 3) == '---') return false;
1023 1023
 
1024 1024
     return true;
1025 1025
   }
1026 1026
 
1027
-  private function isHashElement ($line) {
1027
+  private function isHashElement($line) {
1028 1028
     return strpos($line, ':');
1029 1029
   }
1030 1030
 
1031
-  private function isLiteral ($line) {
1031
+  private function isLiteral($line) {
1032 1032
     if ($this->isArrayElement($line)) return false;
1033 1033
     if ($this->isHashElement($line)) return false;
1034 1034
     return true;
1035 1035
   }
1036 1036
 
1037 1037
 
1038
-  private static function unquote ($value) {
1039
-    if (!$value) return $value;
1040
-    if (!is_string($value)) return $value;
1041
-    if ($value[0] == '\'') return trim ($value, '\'');
1042
-    if ($value[0] == '"') return trim ($value, '"');
1038
+  private static function unquote($value) {
1039
+    if ( ! $value) return $value;
1040
+    if ( ! is_string($value)) return $value;
1041
+    if ($value[0] == '\'') return trim($value, '\'');
1042
+    if ($value[0] == '"') return trim($value, '"');
1043 1043
     return $value;
1044 1044
   }
1045 1045
 
1046
-  private function startsMappedSequence ($line) {
1047
-    return (substr($line, 0, 2) == '- ' && substr ($line, -1, 1) == ':');
1046
+  private function startsMappedSequence($line) {
1047
+    return (substr($line, 0, 2) == '- ' && substr($line, -1, 1) == ':');
1048 1048
   }
1049 1049
 
1050
-  private function returnMappedSequence ($line) {
1050
+  private function returnMappedSequence($line) {
1051 1051
     $array = array();
1052
-    $key         = self::unquote(trim(substr($line,1,-1)));
1052
+    $key         = self::unquote(trim(substr($line, 1, -1)));
1053 1053
     $array[$key] = array();
1054
-    $this->delayedPath = array(strpos ($line, $key) + $this->indent => $key);
1054
+    $this->delayedPath = array(strpos($line, $key) + $this->indent => $key);
1055 1055
     return array($array);
1056 1056
   }
1057 1057
 
1058 1058
   private function checkKeysInValue($value) {
1059 1059
     if (strchr('[{"\'', $value[0]) === false) {
1060 1060
       if (strchr($value, ': ') !== false) {
1061
-          throw new Exception('Too many keys: '.$value);
1061
+          throw new Exception('Too many keys: ' . $value);
1062 1062
       }
1063 1063
     }
1064 1064
   }
1065 1065
 
1066
-  private function returnMappedValue ($line) {
1066
+  private function returnMappedValue($line) {
1067 1067
     $this->checkKeysInValue($line);
1068 1068
     $array = array();
1069
-    $key         = self::unquote (trim(substr($line,0,-1)));
1069
+    $key         = self::unquote(trim(substr($line, 0, -1)));
1070 1070
     $array[$key] = '';
1071 1071
     return $array;
1072 1072
   }
1073 1073
 
1074
-  private function startsMappedValue ($line) {
1075
-    return (substr ($line, -1, 1) == ':');
1074
+  private function startsMappedValue($line) {
1075
+    return (substr($line, -1, 1) == ':');
1076 1076
   }
1077 1077
 
1078
-  private function isPlainArray ($line) {
1079
-    return ($line[0] == '[' && substr ($line, -1, 1) == ']');
1078
+  private function isPlainArray($line) {
1079
+    return ($line[0] == '[' && substr($line, -1, 1) == ']');
1080 1080
   }
1081 1081
 
1082
-  private function returnPlainArray ($line) {
1082
+  private function returnPlainArray($line) {
1083 1083
     return $this->_toType($line);
1084 1084
   }
1085 1085
 
1086
-  private function returnKeyValuePair ($line) {
1086
+  private function returnKeyValuePair($line) {
1087 1087
     $array = array();
1088 1088
     $key = '';
1089
-    if (strpos ($line, ': ')) {
1089
+    if (strpos($line, ': ')) {
1090 1090
       // It's a key/value pair most likely
1091 1091
       // If the key is in double quotes pull it out
1092
-      if (($line[0] == '"' || $line[0] == "'") && preg_match('/^(["\'](.*)["\'](\s)*:)/',$line,$matches)) {
1093
-        $value = trim(str_replace($matches[1],'',$line));
1092
+      if (($line[0] == '"' || $line[0] == "'") && preg_match('/^(["\'](.*)["\'](\s)*:)/', $line, $matches)) {
1093
+        $value = trim(str_replace($matches[1], '', $line));
1094 1094
         $key   = $matches[2];
1095 1095
       } else {
1096 1096
         // Do some guesswork as to the key and the value
@@ -1104,17 +1104,17 @@  discard block
 block discarded – undo
1104 1104
       if ($key === '0') $key = '__!YAMLZero';
1105 1105
       $array[$key] = $value;
1106 1106
     } else {
1107
-      $array = array ($line);
1107
+      $array = array($line);
1108 1108
     }
1109 1109
     return $array;
1110 1110
 
1111 1111
   }
1112 1112
 
1113 1113
 
1114
-  private function returnArrayElement ($line) {
1114
+  private function returnArrayElement($line) {
1115 1115
      if (strlen($line) <= 1) return array(array()); // Weird %)
1116 1116
      $array = array();
1117
-     $value   = trim(substr($line,1));
1117
+     $value   = trim(substr($line, 1));
1118 1118
      $value   = $this->_toType($value);
1119 1119
      if ($this->isArrayElement($value)) {
1120 1120
        $value = $this->returnArrayElement($value);
@@ -1124,25 +1124,25 @@  discard block
 block discarded – undo
1124 1124
   }
1125 1125
 
1126 1126
 
1127
-  private function nodeContainsGroup ($line) {
1127
+  private function nodeContainsGroup($line) {
1128 1128
     $symbolsForReference = 'A-z0-9_\-';
1129 1129
     if (strpos($line, '&') === false && strpos($line, '*') === false) return false; // Please die fast ;-)
1130
-    if ($line[0] == '&' && preg_match('/^(&['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1];
1131
-    if ($line[0] == '*' && preg_match('/^(\*['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1];
1132
-    if (preg_match('/(&['.$symbolsForReference.']+)$/', $line, $matches)) return $matches[1];
1133
-    if (preg_match('/(\*['.$symbolsForReference.']+$)/', $line, $matches)) return $matches[1];
1134
-    if (preg_match ('#^\s*<<\s*:\s*(\*[^\s]+).*$#', $line, $matches)) return $matches[1];
1130
+    if ($line[0] == '&' && preg_match('/^(&[' . $symbolsForReference . ']+)/', $line, $matches)) return $matches[1];
1131
+    if ($line[0] == '*' && preg_match('/^(\*[' . $symbolsForReference . ']+)/', $line, $matches)) return $matches[1];
1132
+    if (preg_match('/(&[' . $symbolsForReference . ']+)$/', $line, $matches)) return $matches[1];
1133
+    if (preg_match('/(\*[' . $symbolsForReference . ']+$)/', $line, $matches)) return $matches[1];
1134
+    if (preg_match('#^\s*<<\s*:\s*(\*[^\s]+).*$#', $line, $matches)) return $matches[1];
1135 1135
     return false;
1136 1136
 
1137 1137
   }
1138 1138
 
1139
-  private function addGroup ($line, $group) {
1140
-    if ($group[0] == '&') $this->_containsGroupAnchor = substr ($group, 1);
1141
-    if ($group[0] == '*') $this->_containsGroupAlias = substr ($group, 1);
1139
+  private function addGroup($line, $group) {
1140
+    if ($group[0] == '&') $this->_containsGroupAnchor = substr($group, 1);
1141
+    if ($group[0] == '*') $this->_containsGroupAlias = substr($group, 1);
1142 1142
     //print_r ($this->path);
1143 1143
   }
1144 1144
 
1145
-  private function stripGroup ($line, $group) {
1145
+  private function stripGroup($line, $group) {
1146 1146
     $line = trim(str_replace($group, '', $line));
1147 1147
     return $line;
1148 1148
   }
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 do {
1156 1156
   if (PHP_SAPI != 'cli') break;
1157 1157
   if (empty ($_SERVER['argc']) || $_SERVER['argc'] < 2) break;
1158
-  if (empty ($_SERVER['PHP_SELF']) || FALSE === strpos ($_SERVER['PHP_SELF'], 'Spyc.php') ) break;
1158
+  if (empty ($_SERVER['PHP_SELF']) || FALSE === strpos($_SERVER['PHP_SELF'], 'Spyc.php')) break;
1159 1159
   $file = $argv[1];
1160
-  echo json_encode (spyc_load_file ($file));
1160
+  echo json_encode(spyc_load_file($file));
1161 1161
 } while (0);
Please login to merge, or discard this patch.
writing-on-github.php 1 patch
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 
13 13
 // If the functions have already been autoloaded, don't reload.
14 14
 // This fixes function duplication during unit testing.
15
-if ( defined( 'WRITING_ON_GITHUB_TEST' ) && WRITING_ON_GITHUB_TEST ) {
16
-	$path = dirname( __FILE__ ) . '/vendor/autoload_52.php';
15
+if (defined('WRITING_ON_GITHUB_TEST') && WRITING_ON_GITHUB_TEST) {
16
+	$path = dirname(__FILE__) . '/vendor/autoload_52.php';
17 17
 	include_once $path;
18 18
 }
19 19
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 // require_once(dirname(__FILE__) . '/views/options.php');
42 42
 // require_once(dirname(__FILE__) . '/views/user-setting-field.php');
43 43
 
44
-add_action( 'plugins_loaded', array( new Writing_On_GitHub, 'boot' ) );
44
+add_action('plugins_loaded', array(new Writing_On_GitHub, 'boot'));
45 45
 
46 46
 class Writing_On_GitHub {
47 47
 
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
 	public function __construct() {
139 139
 		self::$instance = $this;
140 140
 
141
-		if ( is_admin() ) {
141
+		if (is_admin()) {
142 142
 			$this->admin = new Writing_On_GitHub_Admin;
143 143
 		}
144 144
 
145
-		$this->controller = new Writing_On_GitHub_Controller( $this );
145
+		$this->controller = new Writing_On_GitHub_Controller($this);
146 146
 
147
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
148
-			WP_CLI::add_command( 'wogh', $this->cli() );
147
+		if (defined('WP_CLI') && WP_CLI) {
148
+			WP_CLI::add_command('wogh', $this->cli());
149 149
 		}
150 150
 	}
151 151
 
@@ -153,30 +153,30 @@  discard block
 block discarded – undo
153 153
 	 * Attaches the plugin's hooks into WordPress.
154 154
 	 */
155 155
 	public function boot() {
156
-		register_activation_hook( __FILE__, array( $this, 'activate' ) );
157
-		add_action( 'admin_notices', array( $this, 'activation_notice' ) );
156
+		register_activation_hook(__FILE__, array($this, 'activate'));
157
+		add_action('admin_notices', array($this, 'activation_notice'));
158 158
 
159
-		add_action( 'init', array( $this, 'l10n' ) );
159
+		add_action('init', array($this, 'l10n'));
160 160
 
161 161
 		// Controller actions.
162
-		add_action( 'save_post', array( $this->controller, 'export_post' ) );
163
-		add_action( 'delete_post', array( $this->controller, 'delete_post' ) );
164
-		add_action( 'wp_ajax_nopriv_wogh_push_request', array( $this->controller, 'pull_posts' ) );
165
-        add_action( 'wogh_export', array( $this->controller, 'export_all' ), 10, 2 );
166
-		add_action( 'wogh_import', array( $this->controller, 'import_master' ), 10, 1 );
167
-		add_filter( 'get_edit_post_link', array( $this, 'edit_post_link' ), 10, 3 );
162
+		add_action('save_post', array($this->controller, 'export_post'));
163
+		add_action('delete_post', array($this->controller, 'delete_post'));
164
+		add_action('wp_ajax_nopriv_wogh_push_request', array($this->controller, 'pull_posts'));
165
+        add_action('wogh_export', array($this->controller, 'export_all'), 10, 2);
166
+		add_action('wogh_import', array($this->controller, 'import_master'), 10, 1);
167
+		add_filter('get_edit_post_link', array($this, 'edit_post_link'), 10, 3);
168 168
 
169 169
 		// add_filter( 'wogh_post_meta', array( $this, 'ignore_post_meta' ), 10, 1 );
170 170
 		// add_filter( 'wogh_pre_import_meta', array( $this, 'ignore_post_meta' ), 10, 1 );
171
-		add_filter( 'the_content', array( $this, 'the_content' ) );
171
+		add_filter('the_content', array($this, 'the_content'));
172 172
 
173
-		do_action( 'wogh_boot', $this );
173
+		do_action('wogh_boot', $this);
174 174
 	}
175 175
 
176 176
 	public function edit_post_link($link, $postID, $context) {
177
-		if ( ! wp_is_post_revision( $postID ) ) {
178
-			$post = new Writing_On_GitHub_Post( $postID, Writing_On_GitHub::$instance->api() );
179
-			if ( $post->is_on_github() ) {
177
+		if ( ! wp_is_post_revision($postID)) {
178
+			$post = new Writing_On_GitHub_Post($postID, Writing_On_GitHub::$instance->api());
179
+			if ($post->is_on_github()) {
180 180
 				return $post->github_edit_url();
181 181
 			}
182 182
 		}
@@ -235,29 +235,29 @@  discard block
 block discarded – undo
235 235
 	 * Init i18n files
236 236
 	 */
237 237
 	public function l10n() {
238
-		load_plugin_textdomain( self::$text_domain );
238
+		load_plugin_textdomain(self::$text_domain);
239 239
 	}
240 240
 
241 241
 	/**
242 242
 	 * Sets and kicks off the export cronjob
243 243
 	 */
244
-	public function start_export( $force = false ) {
245
-		$this->start_cron( 'export', $force );
244
+	public function start_export($force = false) {
245
+		$this->start_cron('export', $force);
246 246
 	}
247 247
 
248 248
 	/**
249 249
 	 * Sets and kicks off the import cronjob
250 250
 	 */
251 251
 	public function start_import() {
252
-		$this->start_cron( 'import' );
252
+		$this->start_cron('import');
253 253
 	}
254 254
 
255 255
 	/**
256 256
 	 * Enables the admin notice on initial activation
257 257
 	 */
258 258
 	public function activate() {
259
-		if ( 'yes' !== get_option( '_wogh_fully_exported' ) ) {
260
-			set_transient( '_wogh_activated', 'yes' );
259
+		if ('yes' !== get_option('_wogh_fully_exported')) {
260
+			set_transient('_wogh_activated', 'yes');
261 261
 		}
262 262
 	}
263 263
 
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
 	 * Displays the activation admin notice
266 266
 	 */
267 267
 	public function activation_notice() {
268
-		if ( ! get_transient( '_wogh_activated' ) ) {
268
+		if ( ! get_transient('_wogh_activated')) {
269 269
 			return;
270 270
 		}
271 271
 
272
-		delete_transient( '_wogh_activated' );
272
+		delete_transient('_wogh_activated');
273 273
 
274 274
 		?><div class="updated">
275 275
 			<p>
276 276
 				<?php
277 277
 					printf(
278
-						__( 'To set up your site to sync with GitHub, update your <a href="%s">settings</a> and click "Export to GitHub."', 'writing-on-github' ),
279
-						admin_url( 'options-general.php?page=' . static::$text_domain)
278
+						__('To set up your site to sync with GitHub, update your <a href="%s">settings</a> and click "Export to GitHub."', 'writing-on-github'),
279
+						admin_url('options-general.php?page=' . static::$text_domain)
280 280
 					);
281 281
 				?>
282 282
 			</p>
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 	 * @return Writing_On_GitHub_CLI
299 299
 	 */
300 300
 	public function cli() {
301
-		if ( ! $this->cli ) {
301
+		if ( ! $this->cli) {
302 302
 			$this->cli = new Writing_On_GitHub_CLI;
303 303
 		}
304 304
 
@@ -311,8 +311,8 @@  discard block
 block discarded – undo
311 311
 	 * @return Writing_On_GitHub_Request
312 312
 	 */
313 313
 	public function request() {
314
-		if ( ! $this->request ) {
315
-			$this->request = new Writing_On_GitHub_Request( $this );
314
+		if ( ! $this->request) {
315
+			$this->request = new Writing_On_GitHub_Request($this);
316 316
 		}
317 317
 
318 318
 		return $this->request;
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
 	 * @return Writing_On_GitHub_Response
325 325
 	 */
326 326
 	public function response() {
327
-		if ( ! $this->response ) {
328
-			$this->response = new Writing_On_GitHub_Response( $this );
327
+		if ( ! $this->response) {
328
+			$this->response = new Writing_On_GitHub_Response($this);
329 329
 		}
330 330
 
331 331
 		return $this->response;
@@ -337,8 +337,8 @@  discard block
 block discarded – undo
337 337
 	 * @return Writing_On_GitHub_Api
338 338
 	 */
339 339
 	public function api() {
340
-		if ( ! $this->api ) {
341
-			$this->api = new Writing_On_GitHub_Api( $this );
340
+		if ( ! $this->api) {
341
+			$this->api = new Writing_On_GitHub_Api($this);
342 342
 		}
343 343
 
344 344
 		return $this->api;
@@ -350,8 +350,8 @@  discard block
 block discarded – undo
350 350
 	 * @return Writing_On_GitHub_Import
351 351
 	 */
352 352
 	public function import() {
353
-		if ( ! $this->import ) {
354
-			$this->import = new Writing_On_GitHub_Import( $this );
353
+		if ( ! $this->import) {
354
+			$this->import = new Writing_On_GitHub_Import($this);
355 355
 		}
356 356
 
357 357
 		return $this->import;
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
 	 * @return Writing_On_GitHub_Export
364 364
 	 */
365 365
 	public function export() {
366
-		if ( ! $this->export ) {
367
-			$this->export = new Writing_On_GitHub_Export( $this );
366
+		if ( ! $this->export) {
367
+			$this->export = new Writing_On_GitHub_Export($this);
368 368
 		}
369 369
 
370 370
 		return $this->export;
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 	 * @return Writing_On_GitHub_Semaphore
377 377
 	 */
378 378
 	public function semaphore() {
379
-		if ( ! $this->semaphore ) {
379
+		if ( ! $this->semaphore) {
380 380
 			$this->semaphore = new Writing_On_GitHub_Semaphore;
381 381
 		}
382 382
 
@@ -389,8 +389,8 @@  discard block
 block discarded – undo
389 389
 	 * @return Writing_On_GitHub_Database
390 390
 	 */
391 391
 	public function database() {
392
-		if ( ! $this->database ) {
393
-			$this->database = new Writing_On_GitHub_Database( $this );
392
+		if ( ! $this->database) {
393
+			$this->database = new Writing_On_GitHub_Database($this);
394 394
 		}
395 395
 
396 396
 		return $this->database;
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 	 * @return Writing_On_GitHub_Cache
403 403
 	 */
404 404
 	public function cache() {
405
-		if ( ! $this->cache ) {
405
+		if ( ! $this->cache) {
406 406
 			$this->cache = new Writing_On_GitHub_Cache;
407 407
 		}
408 408
 
@@ -417,18 +417,18 @@  discard block
 block discarded – undo
417 417
 	 * @param mixed $msg
418 418
 	 * @param string $write
419 419
 	 */
420
-	public static function write_log( $msg, $write = 'line' ) {
421
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
422
-			if ( is_array( $msg ) || is_object( $msg ) ) {
423
-				WP_CLI::print_value( $msg );
420
+	public static function write_log($msg, $write = 'line') {
421
+		if (defined('WP_CLI') && WP_CLI) {
422
+			if (is_array($msg) || is_object($msg)) {
423
+				WP_CLI::print_value($msg);
424 424
 			} else {
425
-				WP_CLI::$write( $msg );
425
+				WP_CLI::$write($msg);
426 426
 			}
427
-		} elseif ( true === WP_DEBUG ) {
428
-			if ( is_array( $msg ) || is_object( $msg ) ) {
429
-				error_log( print_r( $msg, true ) );
427
+		} elseif (true === WP_DEBUG) {
428
+			if (is_array($msg) || is_object($msg)) {
429
+				error_log(print_r($msg, true));
430 430
 			} else {
431
-				error_log( $msg );
431
+				error_log($msg);
432 432
 			}
433 433
 		}
434 434
 	}
@@ -439,10 +439,10 @@  discard block
 block discarded – undo
439 439
      * @param bool   $force
440 440
      * @param string $type
441 441
      */
442
-	protected function start_cron( $type, $force = false ) {
443
-		update_option( '_wogh_' . $type . '_started', 'yes' );
442
+	protected function start_cron($type, $force = false) {
443
+		update_option('_wogh_' . $type . '_started', 'yes');
444 444
 		$user_id = get_current_user_id();
445
-		wp_schedule_single_event( time(), 'wogh_' . $type . '', array( $user_id, $force ) );
445
+		wp_schedule_single_event(time(), 'wogh_' . $type . '', array($user_id, $force));
446 446
 		spawn_cron();
447 447
 	}
448 448
 }
Please login to merge, or discard this patch.