Passed
Push — master ( c29de4...7571e0 )
by Paul
04:24
created
plugin/Application.php 1 patch
Spacing   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -40,13 +40,13 @@  discard block
 block discarded – undo
40 40
     public function __construct()
41 41
     {
42 42
         static::$instance = $this;
43
-        $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php');
44
-        $plugin = get_file_data($this->file, [
43
+        $this->file = realpath( trailingslashit( dirname( __DIR__ ) ).static::ID.'.php' );
44
+        $plugin = get_file_data( $this->file, [
45 45
             'languages' => 'Domain Path',
46 46
             'name' => 'Plugin Name',
47 47
             'version' => 'Version',
48
-        ], 'plugin');
49
-        array_walk($plugin, function ($value, $key) {
48
+        ], 'plugin' );
49
+        array_walk( $plugin, function( $value, $key ) {
50 50
             $this->$key = $value;
51 51
         });
52 52
     }
@@ -57,17 +57,17 @@  discard block
 block discarded – undo
57 57
     public function activate()
58 58
     {
59 59
         $this->scheduleCronJob();
60
-        add_option(static::PREFIX.'activated', true);
60
+        add_option( static::PREFIX.'activated', true );
61 61
     }
62 62
 
63 63
     /**
64 64
      * @param string $view
65 65
      * @return string
66 66
      */
67
-    public function build($view, array $data = [])
67
+    public function build( $view, array $data = [] )
68 68
     {
69 69
         ob_start();
70
-        $this->render($view, $data);
70
+        $this->render( $view, $data );
71 71
         return ob_get_clean();
72 72
     }
73 73
 
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
      * @param string $capability
76 76
      * @return bool
77 77
      */
78
-    public function can($capability)
78
+    public function can( $capability )
79 79
     {
80
-        return $this->make(Role::class)->can($capability);
80
+        return $this->make( Role::class )->can( $capability );
81 81
     }
82 82
 
83 83
     /**
@@ -86,35 +86,35 @@  discard block
 block discarded – undo
86 86
     public function catchFatalError()
87 87
     {
88 88
         $error = error_get_last();
89
-        if (E_ERROR !== Arr::get($error, 'type') 
90
-            || !Str::contains(Arr::get($error, 'message'), $this->path())) {
89
+        if( E_ERROR !== Arr::get( $error, 'type' ) 
90
+            || !Str::contains( Arr::get( $error, 'message' ), $this->path() ) ) {
91 91
             return;
92 92
         }
93
-        glsr_log()->error($error['message']);
93
+        glsr_log()->error( $error['message'] );
94 94
     }
95 95
 
96 96
     /**
97 97
      * @param string $name
98 98
      * @return array
99 99
      */
100
-    public function config($name)
100
+    public function config( $name )
101 101
     {
102
-        $configFile = $this->path('config/'.$name.'.php');
103
-        $config = file_exists($configFile)
102
+        $configFile = $this->path( 'config/'.$name.'.php' );
103
+        $config = file_exists( $configFile )
104 104
             ? include $configFile
105 105
             : [];
106
-        return apply_filters('site-reviews/config/'.$name, $config);
106
+        return apply_filters( 'site-reviews/config/'.$name, $config );
107 107
     }
108 108
 
109 109
     /**
110 110
      * @param string $property
111 111
      * @return string
112 112
      */
113
-    public function constant($property, $className = 'static')
113
+    public function constant( $property, $className = 'static' )
114 114
     {
115 115
         $constant = $className.'::'.$property;
116
-        return defined($constant)
117
-            ? apply_filters('site-reviews/const/'.$property, constant($constant))
116
+        return defined( $constant )
117
+            ? apply_filters( 'site-reviews/const/'.$property, constant( $constant ) )
118 118
             : '';
119 119
     }
120 120
 
@@ -130,17 +130,17 @@  discard block
 block discarded – undo
130 130
      * @param string $view
131 131
      * @return void|string
132 132
      */
133
-    public function file($view)
133
+    public function file( $view )
134 134
     {
135
-        $view.= '.php';
135
+        $view .= '.php';
136 136
         $filePaths = [];
137
-        if (Str::startsWith('templates/', $view)) {
138
-            $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view));
137
+        if( Str::startsWith( 'templates/', $view ) ) {
138
+            $filePaths[] = $this->themePath( Str::removePrefix( 'templates/', $view ) );
139 139
         }
140
-        $filePaths[] = $this->path($view);
141
-        $filePaths[] = $this->path('views/'.$view);
142
-        foreach ($filePaths as $file) {
143
-            if (!file_exists($file)) {
140
+        $filePaths[] = $this->path( $view );
141
+        $filePaths[] = $this->path( 'views/'.$view );
142
+        foreach( $filePaths as $file ) {
143
+            if( !file_exists( $file ) ) {
144 144
                 continue;
145 145
             }
146 146
             return $file;
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function getDefaults()
154 154
     {
155
-        if (empty($this->defaults)) {
156
-            $this->defaults = $this->make(DefaultsManager::class)->get();
155
+        if( empty($this->defaults) ) {
156
+            $this->defaults = $this->make( DefaultsManager::class )->get();
157 157
         }
158
-        return apply_filters('site-reviews/get/defaults', $this->defaults);
158
+        return apply_filters( 'site-reviews/get/defaults', $this->defaults );
159 159
     }
160 160
 
161 161
     /**
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      * @param string $tab
164 164
      * @return string
165 165
      */
166
-    public function getPermission($page = '', $tab = 'index')
166
+    public function getPermission( $page = '', $tab = 'index' )
167 167
     {
168 168
         $fallback = 'edit_posts';
169 169
         $permissions = [
@@ -184,11 +184,11 @@  discard block
 block discarded – undo
184 184
                 'system-info' => 'edit_others_posts',
185 185
             ]
186 186
         ];
187
-        $permission = Arr::get($permissions, $page, $fallback);
188
-        if (is_array($permission)) {
189
-            $permission = Arr::get($permission, $tab, $fallback);
187
+        $permission = Arr::get( $permissions, $page, $fallback );
188
+        if( is_array( $permission ) ) {
189
+            $permission = Arr::get( $permission, $tab, $fallback );
190 190
         }
191
-        return empty($permission) || !is_string($permission)
191
+        return empty($permission) || !is_string( $permission )
192 192
             ? $fallback
193 193
             : $permission;
194 194
     }
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
      * @param string $tab
199 199
      * @return bool
200 200
      */
201
-    public function hasPermission($page = '', $tab = 'index')
201
+    public function hasPermission( $page = '', $tab = 'index' )
202 202
     {
203 203
         $isAdmin = $this->isAdmin();
204
-        return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab)));
204
+        return !$isAdmin || ($isAdmin && $this->can( $this->getPermission( $page, $tab ) ));
205 205
     }
206 206
 
207 207
     /**
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
      */
210 210
     public function init()
211 211
     {
212
-        $this->make(Actions::class)->run();
213
-        $this->make(Filters::class)->run();
212
+        $this->make( Actions::class )->run();
213
+        $this->make( Filters::class )->run();
214 214
     }
215 215
 
216 216
     /**
@@ -225,31 +225,31 @@  discard block
 block discarded – undo
225 225
      * @param string $file
226 226
      * @return string
227 227
      */
228
-    public function path($file = '', $realpath = true)
228
+    public function path( $file = '', $realpath = true )
229 229
     {
230
-        $path = plugin_dir_path($this->file);
231
-        if (!$realpath) {
232
-            $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file));
230
+        $path = plugin_dir_path( $this->file );
231
+        if( !$realpath ) {
232
+            $path = trailingslashit( WP_PLUGIN_DIR ).basename( dirname( $this->file ) );
233 233
         }
234
-        $path = trailingslashit($path).ltrim(trim($file), '/');
235
-        return apply_filters('site-reviews/path', $path, $file);
234
+        $path = trailingslashit( $path ).ltrim( trim( $file ), '/' );
235
+        return apply_filters( 'site-reviews/path', $path, $file );
236 236
     }
237 237
 
238 238
     /**
239 239
      * @param object $addon
240 240
      * @return void
241 241
      */
242
-    public function register($addon)
242
+    public function register( $addon )
243 243
     {
244 244
         try {
245
-            $reflection = new \ReflectionClass($addon);
246
-            if ($id = $reflection->getConstant('ID')) {
245
+            $reflection = new \ReflectionClass( $addon );
246
+            if( $id = $reflection->getConstant( 'ID' ) ) {
247 247
                 $this->addons[] = $id;
248
-                $this->bind($id, $addon);
248
+                $this->bind( $id, $addon );
249 249
                 $addon->init();
250 250
             }
251
-        } catch(\ReflectionException $e) {
252
-            glsr_log()->error('Attempted to register an invalid addon.');
251
+        } catch( \ReflectionException $e ) {
252
+            glsr_log()->error( 'Attempted to register an invalid addon.' );
253 253
         }
254 254
     }
255 255
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      */
259 259
     public function registerAddons()
260 260
     {
261
-        do_action('site-reviews/addon/register', $this);
261
+        do_action( 'site-reviews/addon/register', $this );
262 262
     }
263 263
 
264 264
     /**
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
      */
267 267
     public function registerLanguages()
268 268
     {
269
-        load_plugin_textdomain(static::ID, false,
270
-            trailingslashit(plugin_basename($this->path()).'/'.$this->languages)
269
+        load_plugin_textdomain( static::ID, false,
270
+            trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages )
271 271
         );
272 272
     }
273 273
 
@@ -276,26 +276,26 @@  discard block
 block discarded – undo
276 276
      */
277 277
     public function registerReviewTypes()
278 278
     {
279
-        $types = apply_filters('site-reviews/addon/types', []);
280
-        $this->reviewTypes = wp_parse_args($types, [
281
-            'local' => __('Local', 'site-reviews'),
282
-        ]);
279
+        $types = apply_filters( 'site-reviews/addon/types', [] );
280
+        $this->reviewTypes = wp_parse_args( $types, [
281
+            'local' => __( 'Local', 'site-reviews' ),
282
+        ] );
283 283
     }
284 284
 
285 285
     /**
286 286
      * @param string $view
287 287
      * @return void
288 288
      */
289
-    public function render($view, array $data = [])
289
+    public function render( $view, array $data = [] )
290 290
     {
291
-        $view = apply_filters('site-reviews/render/view', $view, $data);
292
-        $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data);
293
-        if (!file_exists($file)) {
294
-            glsr_log()->error('File not found: '.$file);
291
+        $view = apply_filters( 'site-reviews/render/view', $view, $data );
292
+        $file = apply_filters( 'site-reviews/views/file', $this->file( $view ), $view, $data );
293
+        if( !file_exists( $file ) ) {
294
+            glsr_log()->error( 'File not found: '.$file );
295 295
             return;
296 296
         }
297
-        $data = apply_filters('site-reviews/views/data', $data, $view);
298
-        extract($data);
297
+        $data = apply_filters( 'site-reviews/views/data', $data, $view );
298
+        extract( $data );
299 299
         include $file;
300 300
     }
301 301
 
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
      */
305 305
     public function scheduleCronJob()
306 306
     {
307
-        if (false === wp_next_scheduled(static::CRON_EVENT)) {
308
-            wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT);
307
+        if( false === wp_next_scheduled( static::CRON_EVENT ) ) {
308
+            wp_schedule_event( time(), 'twicedaily', static::CRON_EVENT );
309 309
         }
310 310
     }
311 311
 
@@ -314,9 +314,9 @@  discard block
 block discarded – undo
314 314
      */
315 315
     public function setDefaults()
316 316
     {
317
-        if (get_option(static::PREFIX.'activated')) {
318
-            $this->make(DefaultsManager::class)->set();
319
-            delete_option(static::PREFIX.'activated');
317
+        if( get_option( static::PREFIX.'activated' ) ) {
318
+            $this->make( DefaultsManager::class )->set();
319
+            delete_option( static::PREFIX.'activated' );
320 320
         }
321 321
     }
322 322
 
@@ -324,9 +324,9 @@  discard block
 block discarded – undo
324 324
      * @param string $file
325 325
      * @return string
326 326
      */
327
-    public function themePath($file = '')
327
+    public function themePath( $file = '' )
328 328
     {
329
-        return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/');
329
+        return get_stylesheet_directory().'/'.static::ID.'/'.ltrim( trim( $file ), '/' );
330 330
     }
331 331
 
332 332
     /**
@@ -334,36 +334,36 @@  discard block
 block discarded – undo
334 334
      */
335 335
     public function unscheduleCronJob()
336 336
     {
337
-        wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT);
337
+        wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT ) ), static::CRON_EVENT );
338 338
     }
339 339
 
340 340
     /**
341 341
      * @param string $path
342 342
      * @return string
343 343
      */
344
-    public function url($path = '')
344
+    public function url( $path = '' )
345 345
     {
346
-        $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/'));
347
-        return apply_filters('site-reviews/url', $url, $path);
346
+        $url = esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' ) );
347
+        return apply_filters( 'site-reviews/url', $url, $path );
348 348
     }
349 349
 
350 350
     /**
351 351
      * @param string $versionLevel
352 352
      * @return string
353 353
      */
354
-    public function version($versionLevel = '')
354
+    public function version( $versionLevel = '' )
355 355
     {
356 356
         $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i';
357
-        preg_match($pattern, $this->version, $matches);
358
-        switch ($versionLevel) {
357
+        preg_match( $pattern, $this->version, $matches );
358
+        switch( $versionLevel ) {
359 359
             case 'major':
360
-                $version = Arr::get($matches, 1);
360
+                $version = Arr::get( $matches, 1 );
361 361
                 break;
362 362
             case 'minor':
363
-                $version = Arr::get($matches, 1).Arr::get($matches, 2);
363
+                $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 );
364 364
                 break;
365 365
             case 'patch':
366
-                $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3);
366
+                $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ).Arr::get( $matches, 3 );
367 367
                 break;
368 368
         }
369 369
         return empty($version)
Please login to merge, or discard this patch.