Passed
Push — master ( 9898de...7e761f )
by litefeel
07:06
created
lib/controller.php 1 patch
Spacing   +73 added lines, -73 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,54 +34,54 @@  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 65
         $error = $payload->should_import();
66
-        if ( is_wp_error( $error ) ) {
66
+        if (is_wp_error($error)) {
67 67
             /* @var WP_Error $error */
68
-            return $this->app->response()->error( $error );
68
+            return $this->app->response()->error($error);
69 69
         }
70 70
 
71 71
         $this->app->semaphore()->lock();
72
-        remove_action( 'save_post', array( $this, 'export_post' ) );
73
-        remove_action( 'delete_post', array( $this, 'delete_post' ) );
72
+        remove_action('save_post', array($this, 'export_post'));
73
+        remove_action('delete_post', array($this, 'delete_post'));
74 74
 
75
-        $result = $this->app->import()->payload( $payload );
75
+        $result = $this->app->import()->payload($payload);
76 76
 
77 77
         $this->app->semaphore()->unlock();
78 78
 
79
-        if ( is_wp_error( $result ) ) {
79
+        if (is_wp_error($result)) {
80 80
             /* @var WP_Error $result */
81
-            return $this->app->response()->error( $result );
81
+            return $this->app->response()->error($result);
82 82
         }
83 83
 
84
-        return $this->app->response()->success( $result );
84
+        return $this->app->response()->success($result);
85 85
     }
86 86
 
87 87
     /**
@@ -90,36 +90,36 @@  discard block
 block discarded – undo
90 90
      * @param  boolean $force
91 91
      * @return boolean
92 92
      */
93
-    public function import_master( $user_id = 0, $force = false ) {
94
-        if ( ! $this->app->semaphore()->is_open() ) {
95
-            return $this->app->response()->error( new WP_Error(
93
+    public function import_master($user_id = 0, $force = false) {
94
+        if ( ! $this->app->semaphore()->is_open()) {
95
+            return $this->app->response()->error(new WP_Error(
96 96
                 'semaphore_locked',
97
-                sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::import_master()' )
98
-            ) );
97
+                sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::import_master()')
98
+            ));
99 99
         }
100 100
 
101 101
         $this->app->semaphore()->lock();
102
-        remove_action( 'save_post', array( $this, 'export_post' ) );
103
-        remove_action( 'save_post', array( $this, 'delete_post' ) );
102
+        remove_action('save_post', array($this, 'export_post'));
103
+        remove_action('save_post', array($this, 'delete_post'));
104 104
 
105
-        if ( $user_id ) {
106
-            wp_set_current_user( $user_id );
105
+        if ($user_id) {
106
+            wp_set_current_user($user_id);
107 107
         }
108 108
 
109
-        $result = $this->app->import()->master( $force );
109
+        $result = $this->app->import()->master($force);
110 110
 
111 111
         $this->app->semaphore()->unlock();
112 112
 
113
-        if ( is_wp_error( $result ) ) {
113
+        if (is_wp_error($result)) {
114 114
             /* @var WP_Error $result */
115
-            update_option( '_wogh_import_error', $result->get_error_message() );
115
+            update_option('_wogh_import_error', $result->get_error_message());
116 116
 
117
-            return $this->app->response()->error( $result );
117
+            return $this->app->response()->error($result);
118 118
         }
119 119
 
120
-        update_option( '_wogh_import_complete', 'yes' );
120
+        update_option('_wogh_import_complete', 'yes');
121 121
 
122
-        return $this->app->response()->success( $result );
122
+        return $this->app->response()->success($result);
123 123
     }
124 124
 
125 125
     /**
@@ -129,34 +129,34 @@  discard block
 block discarded – undo
129 129
      * @param  boolean    $force
130 130
      * @return boolean
131 131
      */
132
-    public function export_all( $user_id = 0, $force = false ) {
133
-        if ( ! $this->app->semaphore()->is_open() ) {
134
-            return $this->app->response()->error( new WP_Error(
132
+    public function export_all($user_id = 0, $force = false) {
133
+        if ( ! $this->app->semaphore()->is_open()) {
134
+            return $this->app->response()->error(new WP_Error(
135 135
                 'semaphore_locked',
136
-                sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_all()' )
137
-            ) );
136
+                sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_all()')
137
+            ));
138 138
         }
139 139
 
140 140
         $this->app->semaphore()->lock();
141 141
 
142
-        if ( $user_id ) {
143
-            wp_set_current_user( $user_id );
142
+        if ($user_id) {
143
+            wp_set_current_user($user_id);
144 144
         }
145 145
 
146 146
         $result = $this->app->export()->full($force);
147 147
         $this->app->semaphore()->unlock();
148 148
 
149 149
         // Maybe move option updating out of this class/upgrade message display?
150
-        if ( is_wp_error( $result ) ) {
150
+        if (is_wp_error($result)) {
151 151
             /* @var WP_Error $result */
152
-            update_option( '_wogh_export_error', $result->get_error_message() );
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,28 +169,28 @@  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 ) ) {
188
+        if (is_wp_error($result)) {
189 189
             /* @var WP_Error $result */
190
-            return $this->app->response()->error( $result );
190
+            return $this->app->response()->error($result);
191 191
         }
192 192
 
193
-        return $this->app->response()->success( $result );
193
+        return $this->app->response()->success($result);
194 194
     }
195 195
 
196 196
     /**
@@ -202,28 +202,28 @@  discard block
 block discarded – undo
202 202
      *
203 203
      * @return boolean
204 204
      */
205
-    public function delete_post( $post_id ) {
206
-        if ( wp_is_post_revision( $post_id ) ) {
205
+    public function delete_post($post_id) {
206
+        if (wp_is_post_revision($post_id)) {
207 207
             return;
208 208
         }
209 209
 
210
-        if ( ! $this->app->semaphore()->is_open() ) {
211
-            return $this->app->response()->error( new WP_Error(
210
+        if ( ! $this->app->semaphore()->is_open()) {
211
+            return $this->app->response()->error(new WP_Error(
212 212
                 'semaphore_locked',
213
-                sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::delete_post()' )
214
-            ) );
213
+                sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::delete_post()')
214
+            ));
215 215
         }
216 216
 
217 217
         $this->app->semaphore()->lock();
218
-        $result = $this->app->export()->delete( $post_id );
218
+        $result = $this->app->export()->delete($post_id);
219 219
         $this->app->semaphore()->unlock();
220 220
 
221
-        if ( is_wp_error( $result ) ) {
221
+        if (is_wp_error($result)) {
222 222
             /* @var WP_Error $result */
223
-            return $this->app->response()->error( $result );
223
+            return $this->app->response()->error($result);
224 224
         }
225 225
 
226
-        return $this->app->response()->success( $result );
226
+        return $this->app->response()->success($result);
227 227
     }
228 228
 
229 229
     /**
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
      * than just returning data.
233 233
      */
234 234
     protected function set_ajax() {
235
-        if ( ! defined( 'WOGH_AJAX' ) ) {
236
-            define( 'WOGH_AJAX', true );
235
+        if ( ! defined('WOGH_AJAX')) {
236
+            define('WOGH_AJAX', true);
237 237
         }
238 238
     }
239 239
 }
Please login to merge, or discard this patch.
lib/payload.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
      * @param Writing_On_GitHub $app      Application container.
30 30
      * @param string                $raw_data Raw request data.
31 31
      */
32
-    public function __construct( Writing_On_GitHub $app, $raw_data ) {
32
+    public function __construct(Writing_On_GitHub $app, $raw_data) {
33 33
         $this->app  = $app;
34
-        $this->data = json_decode( $raw_data );
34
+        $this->data = json_decode($raw_data);
35 35
     }
36 36
 
37 37
     /**
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function should_import() {
43 43
         // @todo how do we get this without importing the whole api object just for this?
44
-        if ( strtolower( $this->data->repository->full_name ) !== strtolower( $this->app->api()->fetch()->repository() ) ) {
44
+        if (strtolower($this->data->repository->full_name) !== strtolower($this->app->api()->fetch()->repository())) {
45 45
             return new WP_Error(
46 46
                 'incorrect_repository',
47
-                sprintf( 'Incorrect repository, %s -> %s .',
47
+                sprintf('Incorrect repository, %s -> %s .',
48 48
                     $this->data->repository->full_name,
49 49
                     $this->app->api()->fetch()->repository()
50 50
                 )
@@ -52,15 +52,15 @@  discard block
 block discarded – undo
52 52
         }
53 53
 
54 54
         // The last term in the ref is the payload_branch name.
55
-        $refs   = explode( '/', $this->data->ref );
56
-        $payload_branch = array_pop( $refs );
55
+        $refs   = explode('/', $this->data->ref);
56
+        $payload_branch = array_pop($refs);
57 57
 
58 58
         $branch = $this->app->api()->fetch()->branch();
59 59
 
60
-        if ( $branch !== $payload_branch ) {
60
+        if ($branch !== $payload_branch) {
61 61
             return new WP_Error(
62 62
                 'incorrect_branch',
63
-                sprintf( 'Incorrect branch, %s -> %s .',
63
+                sprintf('Incorrect branch, %s -> %s .',
64 64
                     $payload_branch,
65 65
                     $branch
66 66
                 )
@@ -68,20 +68,20 @@  discard block
 block discarded – undo
68 68
         }
69 69
 
70 70
         // We add a tag to commits we push out, so we shouldn't pull them in again.
71
-        $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' );
71
+        $tag = apply_filters('wogh_commit_msg_tag', 'wogh');
72 72
 
73
-        if ( ! $tag ) {
74
-            throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) );
73
+        if ( ! $tag) {
74
+            throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github'));
75 75
         }
76 76
 
77
-        if ( $tag === substr( $this->message(), -1 * strlen( $tag ) ) ) {
77
+        if ($tag === substr($this->message(), -1 * strlen($tag))) {
78 78
             return new WP_Error(
79 79
                 'skip_import',
80 80
                 'Skip import on auto export post.'
81 81
             );
82 82
         }
83 83
 
84
-        if ( ! $this->get_commit_id() ) {
84
+        if ( ! $this->get_commit_id()) {
85 85
             return new WP_Error(
86 86
                 'invalid_payload',
87 87
                 "[Missing Commit ID] won't be imported."
Please login to merge, or discard this patch.