Passed
Push — master ( 04b043...334ee0 )
by Paul
04:11
created
plugin/Modules/Html/Template.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -11,15 +11,15 @@  discard block
 block discarded – undo
11 11
      * @param string $templatePath
12 12
      * @return void|string
13 13
      */
14
-    public function build($templatePath, array $data = [])
14
+    public function build( $templatePath, array $data = [] )
15 15
     {
16
-        $data = $this->normalize($data);
17
-        $path = Str::removePrefix('templates/', $templatePath);
18
-        $template = glsr()->build($templatePath, $data);
19
-        $template = apply_filters('site-reviews/build/template/'.$path, $template, $data);
20
-        $template = $this->interpolate($template, $data, $path);
21
-        $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data);
22
-        $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data);
16
+        $data = $this->normalize( $data );
17
+        $path = Str::removePrefix( 'templates/', $templatePath );
18
+        $template = glsr()->build( $templatePath, $data );
19
+        $template = apply_filters( 'site-reviews/build/template/'.$path, $template, $data );
20
+        $template = $this->interpolate( $template, $data, $path );
21
+        $template = apply_filters( 'site-reviews/rendered/template', $template, $templatePath, $data );
22
+        $template = apply_filters( 'site-reviews/rendered/template/'.$path, $template, $data );
23 23
         return $template;
24 24
     }
25 25
 
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
      * @param string $templatePath
30 30
      * @return string
31 31
      */
32
-    public function interpolate($template, array $data = [], $templatePath)
32
+    public function interpolate( $template, array $data = [], $templatePath )
33 33
     {
34
-        $context = $this->normalizeContext(Arr::get($data, 'context', []));
35
-        $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data);
36
-        return $this->interpolateContext($template, $context);
34
+        $context = $this->normalizeContext( Arr::get( $data, 'context', [] ) );
35
+        $context = apply_filters( 'site-reviews/interpolate/'.$templatePath, $context, $template, $data );
36
+        return $this->interpolateContext( $template, $context );
37 37
     }
38 38
 
39 39
     /**
@@ -41,35 +41,35 @@  discard block
 block discarded – undo
41 41
      * @param string $text
42 42
      * @return string
43 43
      */
44
-    public function interpolateContext($text, array $context = [])
44
+    public function interpolateContext( $text, array $context = [] )
45 45
     {
46
-        foreach ($context as $key => $value) {
46
+        foreach( $context as $key => $value ) {
47 47
             $text = strtr(
48 48
                 $text,
49
-                array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value)
49
+                array_fill_keys( ['{'.$key.'}', '{{ '.$key.' }}'], $value )
50 50
             );
51 51
         }
52
-        return trim($text);
52
+        return trim( $text );
53 53
     }
54 54
 
55 55
     /**
56 56
      * @param string $templatePath
57 57
      * @return void|string
58 58
      */
59
-    public function render($templatePath, array $data = [])
59
+    public function render( $templatePath, array $data = [] )
60 60
     {
61
-        echo $this->build($templatePath, $data);
61
+        echo $this->build( $templatePath, $data );
62 62
     }
63 63
 
64 64
     /**
65 65
      * @return array
66 66
      */
67
-    protected function normalize(array $data)
67
+    protected function normalize( array $data )
68 68
     {
69 69
         $arrayKeys = ['context', 'globals'];
70
-        $data = wp_parse_args($data, array_fill_keys($arrayKeys, []));
71
-        foreach ($arrayKeys as $key) {
72
-            if (is_array($data[$key])) {
70
+        $data = wp_parse_args( $data, array_fill_keys( $arrayKeys, [] ) );
71
+        foreach( $arrayKeys as $key ) {
72
+            if( is_array( $data[$key] ) ) {
73 73
                 continue;
74 74
             }
75 75
             $data[$key] = [];
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
     /**
81 81
      * @return array
82 82
      */
83
-    protected function normalizeContext(array $context)
83
+    protected function normalizeContext( array $context )
84 84
     {
85
-        $context = array_filter($context, function ($value) {
86
-            return !is_array($value) && !is_object($value);
85
+        $context = array_filter( $context, function( $value ) {
86
+            return !is_array( $value ) && !is_object( $value );
87 87
         });
88
-        return array_map(function ($value) {
89
-            return (string) $value;
90
-        }, $context);
88
+        return array_map( function( $value ) {
89
+            return (string)$value;
90
+        }, $context );
91 91
     }
92 92
 }
Please login to merge, or discard this patch.
plugin/Helpers/Arr.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -7,10 +7,10 @@  discard block
 block discarded – undo
7 7
     /**
8 8
      * @return bool
9 9
      */
10
-    public static function compareArrays(array $arr1, array $arr2)
10
+    public static function compareArrays( array $arr1, array $arr2 )
11 11
     {
12
-        sort($arr1);
13
-        sort($arr2);
12
+        sort( $arr1 );
13
+        sort( $arr2 );
14 14
         return $arr1 == $arr2;
15 15
     }
16 16
 
@@ -18,21 +18,21 @@  discard block
 block discarded – undo
18 18
      * @param mixed $array
19 19
      * @return array
20 20
      */
21
-    public static function consolidateArray($array)
21
+    public static function consolidateArray( $array )
22 22
     {
23
-        return is_array($array) || is_object($array)
24
-            ? (array) $array
23
+        return is_array( $array ) || is_object( $array )
24
+            ? (array)$array
25 25
             : [];
26 26
     }
27 27
 
28 28
     /**
29 29
      * @return array
30 30
      */
31
-    public static function convertDotNotationArray(array $array)
31
+    public static function convertDotNotationArray( array $array )
32 32
     {
33 33
         $results = [];
34
-        foreach ($array as $path => $value) {
35
-            $results = static::set($results, $path, $value);
34
+        foreach( $array as $path => $value ) {
35
+            $results = static::set( $results, $path, $value );
36 36
         }
37 37
         return $results;
38 38
     }
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
      * @param mixed $callback
43 43
      * @return array
44 44
      */
45
-    public static function convertStringToArray($string, $callback = null)
45
+    public static function convertStringToArray( $string, $callback = null )
46 46
     {
47
-        $array = array_map('trim', explode(',', $string));
47
+        $array = array_map( 'trim', explode( ',', $string ) );
48 48
         return $callback
49
-            ? array_filter($array, $callback)
50
-            : array_filter($array);
49
+            ? array_filter( $array, $callback )
50
+            : array_filter( $array );
51 51
     }
52 52
 
53 53
     /**
@@ -55,17 +55,17 @@  discard block
 block discarded – undo
55 55
      * @param string $prefix
56 56
      * @return array
57 57
      */
58
-    public static function flattenArray(array $array, $flattenValue = false, $prefix = '')
58
+    public static function flattenArray( array $array, $flattenValue = false, $prefix = '' )
59 59
     {
60 60
         $result = [];
61
-        foreach ($array as $key => $value) {
62
-            $newKey = ltrim($prefix.'.'.$key, '.');
63
-            if (static::isIndexedFlatArray($value)) {
64
-                if ($flattenValue) {
65
-                    $value = '['.implode(', ', $value).']';
61
+        foreach( $array as $key => $value ) {
62
+            $newKey = ltrim( $prefix.'.'.$key, '.' );
63
+            if( static::isIndexedFlatArray( $value ) ) {
64
+                if( $flattenValue ) {
65
+                    $value = '['.implode( ', ', $value ).']';
66 66
                 }
67
-            } elseif (is_array($value)) {
68
-                $result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey));
67
+            } elseif( is_array( $value ) ) {
68
+                $result = array_merge( $result, static::flattenArray( $value, $flattenValue, $newKey ) );
69 69
                 continue;
70 70
             }
71 71
             $result[$newKey] = $value;
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
      * @param mixed $fallback
81 81
      * @return mixed
82 82
      */
83
-    public static function get($data, $path = '', $fallback = '')
83
+    public static function get( $data, $path = '', $fallback = '' )
84 84
     {
85
-        $data = static::consolidateArray($data);
86
-        $keys = explode('.', $path);
87
-        foreach ($keys as $key) {
88
-            if (!isset($data[$key])) {
85
+        $data = static::consolidateArray( $data );
86
+        $keys = explode( '.', $path );
87
+        foreach( $keys as $key ) {
88
+            if( !isset($data[$key]) ) {
89 89
                 return $fallback;
90 90
             }
91 91
             $data = $data[$key];
@@ -97,18 +97,18 @@  discard block
 block discarded – undo
97 97
      * @param string $key
98 98
      * @return array
99 99
      */
100
-    public static function insertAfter($key, array $array, array $insert)
100
+    public static function insertAfter( $key, array $array, array $insert )
101 101
     {
102
-        return static::insertInArray($array, $insert, $key, 'after');
102
+        return static::insertInArray( $array, $insert, $key, 'after' );
103 103
     }
104 104
 
105 105
     /**
106 106
      * @param string $key
107 107
      * @return array
108 108
      */
109
-    public static function insertBefore($key, array $array, array $insert)
109
+    public static function insertBefore( $key, array $array, array $insert )
110 110
     {
111
-        return static::insertInArray($array, $insert, $key, 'before');
111
+        return static::insertInArray( $array, $insert, $key, 'before' );
112 112
     }
113 113
 
114 114
     /**
@@ -116,47 +116,47 @@  discard block
 block discarded – undo
116 116
      * @param string $position
117 117
      * @return array
118 118
      */
119
-    public static function insertInArray(array $array, array $insert, $key, $position = 'before')
119
+    public static function insertInArray( array $array, array $insert, $key, $position = 'before' )
120 120
     {
121
-        $keyPosition = intval(array_search($key, array_keys($array)));
122
-        if ('after' == $position) {
121
+        $keyPosition = intval( array_search( $key, array_keys( $array ) ) );
122
+        if( 'after' == $position ) {
123 123
             ++$keyPosition;
124 124
         }
125
-        if (false !== $keyPosition) {
126
-            $result = array_slice($array, 0, $keyPosition);
127
-            $result = array_merge($result, $insert);
128
-            return array_merge($result, array_slice($array, $keyPosition));
125
+        if( false !== $keyPosition ) {
126
+            $result = array_slice( $array, 0, $keyPosition );
127
+            $result = array_merge( $result, $insert );
128
+            return array_merge( $result, array_slice( $array, $keyPosition ) );
129 129
         }
130
-        return array_merge($array, $insert);
130
+        return array_merge( $array, $insert );
131 131
     }
132 132
 
133 133
     /**
134 134
      * @param mixed $array
135 135
      * @return bool
136 136
      */
137
-    public static function isIndexedFlatArray($array)
137
+    public static function isIndexedFlatArray( $array )
138 138
     {
139
-        if (!is_array($array) || array_filter($array, 'is_array')) {
139
+        if( !is_array( $array ) || array_filter( $array, 'is_array' ) ) {
140 140
             return false;
141 141
         }
142
-        return wp_is_numeric_array($array);
142
+        return wp_is_numeric_array( $array );
143 143
     }
144 144
 
145 145
     /**
146 146
      * @param bool $prefixed
147 147
      * @return array
148 148
      */
149
-    public static function prefixArrayKeys(array $values, $prefixed = true)
149
+    public static function prefixArrayKeys( array $values, $prefixed = true )
150 150
     {
151 151
         $trim = '_';
152 152
         $prefix = $prefixed
153 153
             ? $trim
154 154
             : '';
155 155
         $prefixed = [];
156
-        foreach ($values as $key => $value) {
157
-            $key = trim($key);
158
-            if (0 === strpos($key, $trim)) {
159
-                $key = substr($key, strlen($trim));
156
+        foreach( $values as $key => $value ) {
157
+            $key = trim( $key );
158
+            if( 0 === strpos( $key, $trim ) ) {
159
+                $key = substr( $key, strlen( $trim ) );
160 160
             }
161 161
             $prefixed[$prefix.$key] = $value;
162 162
         }
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
     /**
167 167
      * @return array
168 168
      */
169
-    public static function removeEmptyArrayValues(array $array)
169
+    public static function removeEmptyArrayValues( array $array )
170 170
     {
171 171
         $result = [];
172
-        foreach ($array as $key => $value) {
173
-            if (!$value) {
172
+        foreach( $array as $key => $value ) {
173
+            if( !$value ) {
174 174
                 continue;
175 175
             }
176
-            $result[$key] = is_array($value)
177
-                ? static::removeEmptyArrayValues($value)
176
+            $result[$key] = is_array( $value )
177
+                ? static::removeEmptyArrayValues( $value )
178 178
                 : $value;
179 179
         }
180 180
         return $result;
@@ -187,14 +187,14 @@  discard block
 block discarded – undo
187 187
      * @param mixed $value
188 188
      * @return array
189 189
      */
190
-    public static function set(array $data, $path, $value)
190
+    public static function set( array $data, $path, $value )
191 191
     {
192
-        $token = strtok($path, '.');
192
+        $token = strtok( $path, '.' );
193 193
         $ref = &$data;
194
-        while (false !== $token) {
195
-            $ref = static::consolidateArray($ref);
194
+        while( false !== $token ) {
195
+            $ref = static::consolidateArray( $ref );
196 196
             $ref = &$ref[$token];
197
-            $token = strtok('.');
197
+            $token = strtok( '.' );
198 198
         }
199 199
         $ref = $value;
200 200
         return $data;
@@ -203,16 +203,16 @@  discard block
 block discarded – undo
203 203
     /**
204 204
      * @return array
205 205
      */
206
-    public static function unique(array $values)
206
+    public static function unique( array $values )
207 207
     {
208
-        return array_filter(array_unique($values));
208
+        return array_filter( array_unique( $values ) );
209 209
     }
210 210
 
211 211
     /**
212 212
      * @return array
213 213
      */
214
-    public static function unprefixArrayKeys(array $values)
214
+    public static function unprefixArrayKeys( array $values )
215 215
     {
216
-        return static::prefixArrayKeys($values, false);
216
+        return static::prefixArrayKeys( $values, false );
217 217
     }
218 218
 }
Please login to merge, or discard this patch.
views/pages/tools/general.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,42 +1,42 @@  discard block
 block discarded – undo
1
-<?php defined('WPINC') || die; ?>
1
+<?php defined( 'WPINC' ) || die; ?>
2 2
 
3
-<?php if (glsr()->hasPermission('settings')) : ?>
3
+<?php if( glsr()->hasPermission( 'settings' ) ) : ?>
4 4
 <div class="glsr-card card">
5 5
     <h3>Export Settings</h3>
6 6
     <p>Export the Site Reviews settings for this site to a <code>*.json</code> file. This allows you to easily import the plugin settings into another site.</p>
7
-    <p>To export your Site Reviews' reviews and categories, please use the WordPress <a href="<?= admin_url('export.php'); ?>">Export</a> tool.</p>
7
+    <p>To export your Site Reviews' reviews and categories, please use the WordPress <a href="<?= admin_url( 'export.php' ); ?>">Export</a> tool.</p>
8 8
     <form method="post">
9 9
         <input type="hidden" name="{{ id }}[_action]" value="export-settings">
10
-        <?php wp_nonce_field('export-settings'); ?>
11
-        <?php submit_button(__('Export Settings', 'site-reviews'), 'secondary'); ?>
10
+        <?php wp_nonce_field( 'export-settings' ); ?>
11
+        <?php submit_button( __( 'Export Settings', 'site-reviews' ), 'secondary' ); ?>
12 12
     </form>
13 13
 </div>
14 14
 <?php endif; ?>
15 15
 
16
-<?php if (glsr()->hasPermission('settings')) : ?>
16
+<?php if( glsr()->hasPermission( 'settings' ) ) : ?>
17 17
 <div class="glsr-card card">
18 18
     <h3>Import Settings</h3>
19 19
     <p>Import the Site Reviews settings from a <code>*.json</code> file. This file can be obtained by exporting the settings on another site using the export tool below.</p>
20
-    <p>To import your Site Reviews' reviews and categories from another website, please use the WordPress <a href="<?= admin_url('import.php'); ?>">Import</a> tool.</p>
20
+    <p>To import your Site Reviews' reviews and categories from another website, please use the WordPress <a href="<?= admin_url( 'import.php' ); ?>">Import</a> tool.</p>
21 21
     <form method="post" enctype="multipart/form-data">
22 22
         <input type="file" name="import-file">
23 23
         <input type="hidden" name="{{ id }}[_action]" value="import-settings">
24
-        <?php wp_nonce_field('import-settings'); ?>
25
-        <?php submit_button(__('Import Settings', 'site-reviews'), 'secondary'); ?>
24
+        <?php wp_nonce_field( 'import-settings' ); ?>
25
+        <?php submit_button( __( 'Import Settings', 'site-reviews' ), 'secondary' ); ?>
26 26
     </form>
27 27
 </div>
28 28
 <?php endif; ?>
29 29
 
30
-<?php if (glsr()->hasPermission('settings')) : ?>
30
+<?php if( glsr()->hasPermission( 'settings' ) ) : ?>
31 31
 <div class="glsr-card card">
32 32
     <h3>Migrate Plugin</h3>
33 33
     <p>Run this tool if your reviews stopped working correctly after upgrading the plugin to the latest version (i.e. read-only reviews, zero-star ratings, missing role capabilities, etc.).</p>
34 34
     <form method="post">
35 35
         <input type="hidden" name="{{ id }}[_action]" value="migrate-reviews">
36
-        <?php wp_nonce_field('migrate-reviews'); ?>
36
+        <?php wp_nonce_field( 'migrate-reviews' ); ?>
37 37
         <p class="submit">
38 38
             <button type="submit" class="glsr-button button" name="migrate-reviews" id="migrate-reviews">
39
-                <span data-loading="<?= __('Migrating Reviews, please wait...', 'site-reviews'); ?>"><?= __('Run Migration', 'site-reviews'); ?></span>
39
+                <span data-loading="<?= __( 'Migrating Reviews, please wait...', 'site-reviews' ); ?>"><?= __( 'Run Migration', 'site-reviews' ); ?></span>
40 40
             </button>
41 41
         </p>
42 42
     </form>
@@ -49,26 +49,26 @@  discard block
 block discarded – undo
49 49
     <p>If you suspect that the rating counts are incorrect (perhaps you have cloned a page that had reviews assigned to it, or edited/deleted reviews directly from your database), you can recalculate them here.</p>
50 50
     <form method="post">
51 51
         <input type="hidden" name="{{ id }}[_action]" value="count-reviews">
52
-        <?php wp_nonce_field('count-reviews'); ?>
52
+        <?php wp_nonce_field( 'count-reviews' ); ?>
53 53
         <p class="submit">
54 54
             <button type="submit" class="glsr-button button" name="count-reviews" id="count-reviews">
55
-                <span data-loading="<?= __('Recalculating Counts, please wait...', 'site-reviews'); ?>"><?= __('Recalculate Counts', 'site-reviews'); ?></span>
55
+                <span data-loading="<?= __( 'Recalculating Counts, please wait...', 'site-reviews' ); ?>"><?= __( 'Recalculate Counts', 'site-reviews' ); ?></span>
56 56
             </button>
57 57
         </p>
58 58
     </form>
59 59
 </div>
60 60
 
61
-<?php if (glsr()->hasPermission('settings')) : ?>
61
+<?php if( glsr()->hasPermission( 'settings' ) ) : ?>
62 62
 <div class="glsr-card card">
63 63
     <h3>Reset Permissions</h3>
64 64
     <p>Site Reviews provides custom post_type capabilities that mirror the capabilities of your posts by default. For example, if a user role has permission to edit others posts, then that role will also have permission to edit other users reviews.</p>
65 65
     <p>If you have changed the capabilities of your user roles and you suspect that Site Reviews is not working correctly due to your changes, you may use this tool to reset the Site Reviews capabilities for your user roles.</p>
66 66
     <form method="post">
67 67
         <input type="hidden" name="{{ id }}[_action]" value="reset-permissions">
68
-        <?php wp_nonce_field('reset-permissions'); ?>
68
+        <?php wp_nonce_field( 'reset-permissions' ); ?>
69 69
         <p class="submit">
70 70
             <button type="submit" class="glsr-button button" name="reset-permissions" id="reset-permissions">
71
-                <span data-loading="<?= __('Resetting Permissions, please wait...', 'site-reviews'); ?>"><?= __('Reset Permissions', 'site-reviews'); ?></span>
71
+                <span data-loading="<?= __( 'Resetting Permissions, please wait...', 'site-reviews' ); ?>"><?= __( 'Reset Permissions', 'site-reviews' ); ?></span>
72 72
             </button>
73 73
         </p>
74 74
     </form>
Please login to merge, or discard this patch.
views/partials/styles/divi/submit-button.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1
-<?php defined('WPINC') || die; ?>
1
+<?php defined( 'WPINC' ) || die; ?>
2 2
 
3 3
 <div class="et_contact_bottom_container">
4 4
     <button type="submit" class="glsr-button et_pb_contact_submit et_pb_button">
Please login to merge, or discard this patch.
plugin/Handlers/EnqueuePublicAssets.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      */
27 27
     public function enqueueAssets()
28 28
     {
29
-        if (apply_filters('site-reviews/assets/css', true)) {
29
+        if( apply_filters( 'site-reviews/assets/css', true ) ) {
30 30
             wp_enqueue_style(
31 31
                 Application::ID,
32 32
                 $this->getStylesheet(),
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
                 glsr()->version
35 35
             );
36 36
         }
37
-        if (apply_filters('site-reviews/assets/js', true)) {
38
-            $dependencies = apply_filters('site-reviews/assets/polyfill', true)
37
+        if( apply_filters( 'site-reviews/assets/js', true ) ) {
38
+            $dependencies = apply_filters( 'site-reviews/assets/polyfill', true )
39 39
                 ? [Application::ID.'/polyfill']
40 40
                 : [];
41
-            $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies);
41
+            $dependencies = apply_filters( 'site-reviews/enqueue/public/dependencies', $dependencies );
42 42
             wp_enqueue_script(
43 43
                 Application::ID,
44
-                glsr()->url('assets/scripts/'.Application::ID.'.js'),
44
+                glsr()->url( 'assets/scripts/'.Application::ID.'.js' ),
45 45
                 $dependencies,
46 46
                 glsr()->version,
47 47
                 true
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function enqueuePolyfillService()
56 56
     {
57
-        if (!apply_filters('site-reviews/assets/polyfill', true)) {
57
+        if( !apply_filters( 'site-reviews/assets/polyfill', true ) ) {
58 58
             return;
59 59
         }
60
-        wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([
60
+        wp_enqueue_script( Application::ID.'/polyfill', add_query_arg( [
61 61
             'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver',
62 62
             'flags' => 'gated',
63
-        ], 'https://polyfill.io/v3/polyfill.min.js'));
63
+        ], 'https://polyfill.io/v3/polyfill.min.js' ) );
64 64
     }
65 65
 
66 66
     /**
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
         // wpforms-recaptcha
72 72
         // google-recaptcha
73 73
         // nf-google-recaptcha
74
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
74
+        if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) {
75 75
             return;
76 76
         }
77
-        $language = apply_filters('site-reviews/recaptcha/language', get_locale());
78
-        wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([
77
+        $language = apply_filters( 'site-reviews/recaptcha/language', get_locale() );
78
+        wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg( [
79 79
             'hl' => $language,
80 80
             'render' => 'explicit',
81
-        ], 'https://www.google.com/recaptcha/api.js'));
81
+        ], 'https://www.google.com/recaptcha/api.js' ) );
82 82
     }
83 83
 
84 84
     /**
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
         $variables = [
90 90
             'action' => Application::PREFIX.'action',
91 91
             'ajaxpagination' => $this->getFixedSelectorsForPagination(),
92
-            'ajaxurl' => admin_url('admin-ajax.php'),
92
+            'ajaxurl' => admin_url( 'admin-ajax.php' ),
93 93
             'nameprefix' => Application::ID,
94
-            'urlparameter' => glsr(OptionManager::class)->getBool('settings.reviews.pagination.url_parameter'),
95
-            'validationconfig' => glsr(Style::class)->validation,
96
-            'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(),
94
+            'urlparameter' => glsr( OptionManager::class )->getBool( 'settings.reviews.pagination.url_parameter' ),
95
+            'validationconfig' => glsr( Style::class )->validation,
96
+            'validationstrings' => glsr( ValidationStringsDefaults::class )->defaults(),
97 97
         ];
98
-        $variables = apply_filters('site-reviews/enqueue/public/localize', $variables);
99
-        wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before');
98
+        $variables = apply_filters( 'site-reviews/enqueue/public/localize', $variables );
99
+        wp_add_inline_script( Application::ID, $this->buildInlineScript( $variables ), 'before' );
100 100
     }
101 101
 
102 102
     /**
@@ -104,35 +104,35 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public function inlineStyles()
106 106
     {
107
-        $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css');
108
-        if (!apply_filters('site-reviews/assets/css', true)) {
107
+        $inlineStylesheetPath = glsr()->path( 'assets/styles/inline-styles.css' );
108
+        if( !apply_filters( 'site-reviews/assets/css', true ) ) {
109 109
             return;
110 110
         }
111
-        if (!file_exists($inlineStylesheetPath)) {
112
-            glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath);
111
+        if( !file_exists( $inlineStylesheetPath ) ) {
112
+            glsr_log()->error( 'Inline stylesheet is missing: '.$inlineStylesheetPath );
113 113
             return;
114 114
         }
115
-        $inlineStylesheetValues = glsr()->config('inline-styles');
115
+        $inlineStylesheetValues = glsr()->config( 'inline-styles' );
116 116
         $stylesheet = str_replace(
117
-            array_keys($inlineStylesheetValues),
118
-            array_values($inlineStylesheetValues),
119
-            file_get_contents($inlineStylesheetPath)
117
+            array_keys( $inlineStylesheetValues ),
118
+            array_values( $inlineStylesheetValues ),
119
+            file_get_contents( $inlineStylesheetPath )
120 120
         );
121
-        wp_add_inline_style(Application::ID, $stylesheet);
121
+        wp_add_inline_style( Application::ID, $stylesheet );
122 122
     }
123 123
 
124 124
     /**
125 125
      * @return string
126 126
      */
127
-    protected function buildInlineScript(array $variables)
127
+    protected function buildInlineScript( array $variables )
128 128
     {
129 129
         $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});';
130
-        foreach ($variables as $key => $value) {
131
-            $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
130
+        foreach( $variables as $key => $value ) {
131
+            $script .= sprintf( 'GLSR.%s=%s;', $key, json_encode( $value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) );
132 132
         }
133 133
         $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys
134
-        $optimizedScript = preg_replace($pattern, '$1$2', $script);
135
-        return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables);
134
+        $optimizedScript = preg_replace( $pattern, '$1$2', $script );
135
+        return apply_filters( 'site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables );
136 136
     }
137 137
 
138 138
     /**
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
     protected function getFixedSelectorsForPagination()
142 142
     {
143 143
         $selectors = ['#wpadminbar', '.site-navigation-fixed'];
144
-        return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors);
144
+        return apply_filters( 'site-reviews/enqueue/public/localize/ajax-pagination', $selectors );
145 145
     }
146 146
 
147 147
     /**
@@ -149,9 +149,9 @@  discard block
 block discarded – undo
149 149
      */
150 150
     protected function getStylesheet()
151 151
     {
152
-        $currentStyle = glsr(Style::class)->style;
153
-        return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css'))
154
-            ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css')
155
-            : glsr()->url('assets/styles/'.Application::ID.'.css');
152
+        $currentStyle = glsr( Style::class )->style;
153
+        return file_exists( glsr()->path( 'assets/styles/custom/'.$currentStyle.'.css' ) )
154
+            ? glsr()->url( 'assets/styles/custom/'.$currentStyle.'.css' )
155
+            : glsr()->url( 'assets/styles/'.Application::ID.'.css' );
156 156
     }
157 157
 }
Please login to merge, or discard this patch.
plugin/Controllers/SettingsController.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -17,18 +17,18 @@  discard block
 block discarded – undo
17 17
      * @return array
18 18
      * @callback register_setting
19 19
      */
20
-    public function callbackRegisterSettings($input)
20
+    public function callbackRegisterSettings( $input )
21 21
     {
22
-        $settings = Arr::consolidateArray($input);
23
-        if (1 === count($settings) && array_key_exists('settings', $settings)) {
24
-            $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input);
25
-            $options = $this->sanitizeGeneral($input, $options);
26
-            $options = $this->sanitizeLicenses($input, $options);
27
-            $options = $this->sanitizeSubmissions($input, $options);
28
-            $options = $this->sanitizeTranslations($input, $options);
29
-            $options = apply_filters('site-reviews/settings/callback', $options, $settings);
30
-            if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') {
31
-                glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews'));
22
+        $settings = Arr::consolidateArray( $input );
23
+        if( 1 === count( $settings ) && array_key_exists( 'settings', $settings ) ) {
24
+            $options = array_replace_recursive( glsr( OptionManager::class )->all(), $input );
25
+            $options = $this->sanitizeGeneral( $input, $options );
26
+            $options = $this->sanitizeLicenses( $input, $options );
27
+            $options = $this->sanitizeSubmissions( $input, $options );
28
+            $options = $this->sanitizeTranslations( $input, $options );
29
+            $options = apply_filters( 'site-reviews/settings/callback', $options, $settings );
30
+            if( filter_input( INPUT_POST, 'option_page' ) == Application::ID.'-settings' ) {
31
+                glsr( Notice::class )->addSuccess( __( 'Settings updated.', 'site-reviews' ) );
32 32
             }
33 33
             return $options;
34 34
         }
@@ -41,80 +41,80 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function registerSettings()
43 43
     {
44
-        register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [
44
+        register_setting( Application::ID.'-settings', OptionManager::databaseKey(), [
45 45
             'sanitize_callback' => [$this, 'callbackRegisterSettings'],
46
-        ]);
46
+        ] );
47 47
     }
48 48
 
49 49
     /**
50 50
      * @return array
51 51
      */
52
-    protected function sanitizeGeneral(array $input, array $options)
52
+    protected function sanitizeGeneral( array $input, array $options )
53 53
     {
54 54
         $key = 'settings.general';
55
-        $inputForm = Arr::get($input, $key);
56
-        if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) {
57
-            $options = Arr::set($options, $key.'.multilingual', '');
55
+        $inputForm = Arr::get( $input, $key );
56
+        if( !$this->hasMultilingualIntegration( Arr::get( $inputForm, 'multilingual' ) ) ) {
57
+            $options = Arr::set( $options, $key.'.multilingual', '' );
58 58
         }
59
-        if ('' == trim(Arr::get($inputForm, 'notification_message'))) {
60
-            $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message');
61
-            $options = Arr::set($options, $key.'.notification_message', $defaultValue);
59
+        if( '' == trim( Arr::get( $inputForm, 'notification_message' ) ) ) {
60
+            $defaultValue = Arr::get( glsr()->defaults, $key.'.notification_message' );
61
+            $options = Arr::set( $options, $key.'.notification_message', $defaultValue );
62 62
         }
63
-        $defaultValue = Arr::get($inputForm, 'notifications', []);
64
-        $options = Arr::set($options, $key.'.notifications', $defaultValue);
63
+        $defaultValue = Arr::get( $inputForm, 'notifications', [] );
64
+        $options = Arr::set( $options, $key.'.notifications', $defaultValue );
65 65
         return $options;
66 66
     }
67 67
 
68 68
     /**
69 69
      * @return array
70 70
      */
71
-    protected function sanitizeLicenses(array $input, array $options)
71
+    protected function sanitizeLicenses( array $input, array $options )
72 72
     {
73 73
         $key = 'settings.licenses';
74
-        $licenses = Arr::consolidateArray(Arr::get($input, $key));
75
-        foreach ($licenses as $slug => &$license) {
76
-            if (empty($license)) {
74
+        $licenses = Arr::consolidateArray( Arr::get( $input, $key ) );
75
+        foreach( $licenses as $slug => &$license ) {
76
+            if( empty($license) ) {
77 77
                 continue;
78 78
             }
79
-            $license = $this->verifyLicense($license, $slug);
79
+            $license = $this->verifyLicense( $license, $slug );
80 80
         }
81
-        $options = Arr::set($options, $key, $licenses);
81
+        $options = Arr::set( $options, $key, $licenses );
82 82
         return $options;
83 83
     }
84 84
 
85 85
     /**
86 86
      * @return array
87 87
      */
88
-    protected function sanitizeSubmissions(array $input, array $options)
88
+    protected function sanitizeSubmissions( array $input, array $options )
89 89
     {
90 90
         $key = 'settings.submissions';
91
-        $inputForm = Arr::get($input, $key);
91
+        $inputForm = Arr::get( $input, $key );
92 92
         $defaultValue = isset($inputForm['required'])
93 93
             ? $inputForm['required']
94 94
             : [];
95
-        $options = Arr::set($options, $key.'.required', $defaultValue);
95
+        $options = Arr::set( $options, $key.'.required', $defaultValue );
96 96
         return $options;
97 97
     }
98 98
 
99 99
     /**
100 100
      * @return array
101 101
      */
102
-    protected function sanitizeTranslations(array $input, array $options)
102
+    protected function sanitizeTranslations( array $input, array $options )
103 103
     {
104 104
         $key = 'settings.strings';
105
-        $inputForm = Arr::consolidateArray(Arr::get($input, $key));
106
-        if (!empty($inputForm)) {
107
-            $options = Arr::set($options, $key, array_values(array_filter($inputForm)));
105
+        $inputForm = Arr::consolidateArray( Arr::get( $input, $key ) );
106
+        if( !empty($inputForm) ) {
107
+            $options = Arr::set( $options, $key, array_values( array_filter( $inputForm ) ) );
108 108
             $allowedTags = [
109 109
                 'a' => ['class' => [], 'href' => [], 'target' => []],
110 110
                 'span' => ['class' => []],
111 111
             ];
112
-            array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) {
113
-                if (isset($string['s2'])) {
114
-                    $string['s2'] = wp_kses($string['s2'], $allowedTags);
112
+            array_walk( $options['settings']['strings'], function( &$string ) use ($allowedTags) {
113
+                if( isset($string['s2']) ) {
114
+                    $string['s2'] = wp_kses( $string['s2'], $allowedTags );
115 115
                 }
116
-                if (isset($string['p2'])) {
117
-                    $string['p2'] = wp_kses($string['p2'], $allowedTags);
116
+                if( isset($string['p2']) ) {
117
+                    $string['p2'] = wp_kses( $string['p2'], $allowedTags );
118 118
                 }
119 119
             });
120 120
         }
@@ -125,24 +125,24 @@  discard block
 block discarded – undo
125 125
      * @param string $integrationSlug
126 126
      * @return bool
127 127
      */
128
-    protected function hasMultilingualIntegration($integrationSlug)
128
+    protected function hasMultilingualIntegration( $integrationSlug )
129 129
     {
130
-        $integration = glsr(Multilingual::class)->getIntegration($integrationSlug);
131
-        if (!$integration) {
130
+        $integration = glsr( Multilingual::class )->getIntegration( $integrationSlug );
131
+        if( !$integration ) {
132 132
             return false;
133 133
         }
134
-        if (!$integration->isActive()) {
135
-            glsr(Notice::class)->addError(sprintf(
136
-                __('Please install/activate the %s plugin to enable integration.', 'site-reviews'),
134
+        if( !$integration->isActive() ) {
135
+            glsr( Notice::class )->addError( sprintf(
136
+                __( 'Please install/activate the %s plugin to enable integration.', 'site-reviews' ),
137 137
                 $integration->pluginName
138
-            ));
138
+            ) );
139 139
             return false;
140
-        } elseif (!$integration->isSupported()) {
141
-            glsr(Notice::class)->addError(sprintf(
142
-                __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'),
140
+        } elseif( !$integration->isSupported() ) {
141
+            glsr( Notice::class )->addError( sprintf(
142
+                __( 'Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews' ),
143 143
                 $integration->pluginName,
144 144
                 $integration->supportedVersion
145
-            ));
145
+            ) );
146 146
             return false;
147 147
         }
148 148
         return true;
@@ -153,21 +153,21 @@  discard block
 block discarded – undo
153 153
      * @param string $slug
154 154
      * @return string
155 155
      */
156
-    protected function verifyLicense($license, $slug)
156
+    protected function verifyLicense( $license, $slug )
157 157
     {
158 158
         try {
159
-            $addon = glsr($slug);
160
-            $updater = new Updater($addon->update_url, $addon->file, [
159
+            $addon = glsr( $slug );
160
+            $updater = new Updater( $addon->update_url, $addon->file, [
161 161
                 'license' => $license,
162 162
                 'testedTo' => $addon->testedTo,
163
-            ]);
164
-            if (!$updater->isLicenseValid()) {
165
-                throw new Exception('Invalid license: '.$license.' ('.$addon->id.')');
163
+            ] );
164
+            if( !$updater->isLicenseValid() ) {
165
+                throw new Exception( 'Invalid license: '.$license.' ('.$addon->id.')' );
166 166
             }
167
-        } catch (Exception $e) {
167
+        } catch( Exception $e ) {
168 168
             $license = '';
169
-            glsr_log()->debug($e->getMessage());
170
-            glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews'));
169
+            glsr_log()->debug( $e->getMessage() );
170
+            glsr( Notice::class )->addError( __( 'A license you entered was invalid.', 'site-reviews' ) );
171 171
         }
172 172
         return $license;
173 173
     }
Please login to merge, or discard this patch.
plugin/Modules/Email.php 1 patch
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -42,15 +42,15 @@  discard block
 block discarded – undo
42 42
     /**
43 43
      * @return Email
44 44
      */
45
-    public function compose(array $email)
45
+    public function compose( array $email )
46 46
     {
47
-        $this->normalize($email);
47
+        $this->normalize( $email );
48 48
         $this->attachments = $this->email['attachments'];
49 49
         $this->headers = $this->buildHeaders();
50 50
         $this->message = $this->buildHtmlMessage();
51 51
         $this->subject = $this->email['subject'];
52 52
         $this->to = $this->email['to'];
53
-        add_action('phpmailer_init', [$this, 'buildPlainTextMessage']);
53
+        add_action( 'phpmailer_init', [$this, 'buildPlainTextMessage'] );
54 54
         return $this;
55 55
     }
56 56
 
@@ -58,11 +58,11 @@  discard block
 block discarded – undo
58 58
      * @param string $format
59 59
      * @return string|null
60 60
      */
61
-    public function read($format = '')
61
+    public function read( $format = '' )
62 62
     {
63
-        if ('plaintext' == $format) {
64
-            $message = $this->stripHtmlTags($this->message);
65
-            return apply_filters('site-reviews/email/message', $message, 'text', $this);
63
+        if( 'plaintext' == $format ) {
64
+            $message = $this->stripHtmlTags( $this->message );
65
+            return apply_filters( 'site-reviews/email/message', $message, 'text', $this );
66 66
         }
67 67
         return $this->message;
68 68
     }
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function send()
74 74
     {
75
-        if (!$this->message || !$this->subject || !$this->to) {
75
+        if( !$this->message || !$this->subject || !$this->to ) {
76 76
             return;
77 77
         }
78
-        add_action('wp_mail_failed', [$this, 'logMailError']);
78
+        add_action( 'wp_mail_failed', [$this, 'logMailError'] );
79 79
         $sent = wp_mail(
80 80
             $this->to,
81 81
             $this->subject,
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
             $this->headers,
84 84
             $this->attachments
85 85
         );
86
-        remove_action('wp_mail_failed', [$this, 'logMailError']);
86
+        remove_action( 'wp_mail_failed', [$this, 'logMailError'] );
87 87
         $this->reset();
88 88
         return $sent;
89 89
     }
@@ -92,16 +92,16 @@  discard block
 block discarded – undo
92 92
      * @return void
93 93
      * @action phpmailer_init
94 94
      */
95
-    public function buildPlainTextMessage(PHPMailer $phpmailer)
95
+    public function buildPlainTextMessage( PHPMailer $phpmailer )
96 96
     {
97
-        if (empty($this->email)) {
97
+        if( empty($this->email) ) {
98 98
             return;
99 99
         }
100
-        if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) {
100
+        if( 'text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody) ) {
101 101
             return;
102 102
         }
103
-        $message = $this->stripHtmlTags($phpmailer->Body);
104
-        $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this);
103
+        $message = $this->stripHtmlTags( $phpmailer->Body );
104
+        $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this );
105 105
     }
106 106
 
107 107
     /**
@@ -112,14 +112,14 @@  discard block
 block discarded – undo
112 112
         $allowed = [
113 113
             'bcc', 'cc', 'from', 'reply-to',
114 114
         ];
115
-        $headers = array_intersect_key($this->email, array_flip($allowed));
116
-        $headers = array_filter($headers);
117
-        foreach ($headers as $key => $value) {
115
+        $headers = array_intersect_key( $this->email, array_flip( $allowed ) );
116
+        $headers = array_filter( $headers );
117
+        foreach( $headers as $key => $value ) {
118 118
             unset($headers[$key]);
119 119
             $headers[] = $key.': '.$value;
120 120
         }
121 121
         $headers[] = 'Content-Type: text/html';
122
-        return apply_filters('site-reviews/email/headers', $headers, $this);
122
+        return apply_filters( 'site-reviews/email/headers', $headers, $this );
123 123
     }
124 124
 
125 125
     /**
@@ -127,54 +127,54 @@  discard block
 block discarded – undo
127 127
      */
128 128
     protected function buildHtmlMessage()
129 129
     {
130
-        $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message'));
131
-        if (!empty($template)) {
132
-            $message = glsr(Template::class)->interpolate(
130
+        $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' ) );
131
+        if( !empty($template) ) {
132
+            $message = glsr( Template::class )->interpolate(
133 133
                 $template, 
134 134
                 ['context' => $this->email['template-tags']], 
135 135
                 $this->email['template']
136 136
             );
137
-        } elseif ($this->email['template']) {
138
-            $message = glsr(Template::class)->build('templates/'.$this->email['template'], [
137
+        } elseif( $this->email['template'] ) {
138
+            $message = glsr( Template::class )->build( 'templates/'.$this->email['template'], [
139 139
                 'context' => $this->email['template-tags'],
140
-            ]);
140
+            ] );
141 141
         }
142
-        if (!isset($message)) {
142
+        if( !isset($message) ) {
143 143
             $message = $this->email['message'];
144 144
         }
145 145
         $message = $this->email['before'].$message.$this->email['after'];
146
-        $message = strip_shortcodes($message);
147
-        $message = wptexturize($message);
148
-        $message = wpautop($message);
149
-        $message = str_replace('&lt;&gt; ', '', $message);
150
-        $message = str_replace(']]>', ']]&gt;', $message);
151
-        $message = glsr(Template::class)->build('partials/email/index', [
146
+        $message = strip_shortcodes( $message );
147
+        $message = wptexturize( $message );
148
+        $message = wpautop( $message );
149
+        $message = str_replace( '&lt;&gt; ', '', $message );
150
+        $message = str_replace( ']]>', ']]&gt;', $message );
151
+        $message = glsr( Template::class )->build( 'partials/email/index', [
152 152
             'context' => ['message' => $message],
153
-        ]);
154
-        return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this);
153
+        ] );
154
+        return apply_filters( 'site-reviews/email/message', stripslashes( $message ), 'html', $this );
155 155
     }
156 156
 
157 157
     /**
158 158
      * @param \WP_Error $error
159 159
      * @return void
160 160
      */
161
-    protected function logMailError($error)
161
+    protected function logMailError( $error )
162 162
     {
163
-        glsr_log()->error('Email was not sent (wp_mail failed)')
164
-            ->debug($this)
165
-            ->debug($error);
163
+        glsr_log()->error( 'Email was not sent (wp_mail failed)' )
164
+            ->debug( $this )
165
+            ->debug( $error );
166 166
     }
167 167
 
168 168
     /**
169 169
      * @return void
170 170
      */
171
-    protected function normalize(array $email = [])
171
+    protected function normalize( array $email = [] )
172 172
     {
173
-        $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email);
174
-        if (empty($email['reply-to'])) {
173
+        $email = shortcode_atts( glsr( EmailDefaults::class )->defaults(), $email );
174
+        if( empty($email['reply-to']) ) {
175 175
             $email['reply-to'] = $email['from'];
176 176
         }
177
-        $this->email = apply_filters('site-reviews/email/compose', $email, $this);
177
+        $this->email = apply_filters( 'site-reviews/email/compose', $email, $this );
178 178
     }
179 179
 
180 180
     /**
@@ -193,21 +193,21 @@  discard block
 block discarded – undo
193 193
     /**
194 194
      * @return string
195 195
      */
196
-    protected function stripHtmlTags($string)
196
+    protected function stripHtmlTags( $string )
197 197
     {
198 198
         // remove invisible elements
199
-        $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string);
199
+        $string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string );
200 200
         // replace certain elements with a line-break
201
-        $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string);
201
+        $string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string );
202 202
         // replace other elements with a space
203
-        $string = preg_replace('@</(td|th)@iu', ' $0', $string);
203
+        $string = preg_replace( '@</(td|th)@iu', ' $0', $string );
204 204
         // add a placeholder for plain-text bullets to list elements
205
-        $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string);
205
+        $string = preg_replace( '@<(li)[^>]*?>@siu', '$0-o-^-o-', $string );
206 206
         // strip all remaining HTML tags
207
-        $string = wp_strip_all_tags($string);
208
-        $string = wp_specialchars_decode($string, ENT_QUOTES);
209
-        $string = preg_replace('/\v(?:[\v\h]+){2,}/u', "\r\n\r\n", $string);
210
-        $string = str_replace('-o-^-o-', ' - ', $string);
211
-        return html_entity_decode($string, ENT_QUOTES, 'UTF-8');
207
+        $string = wp_strip_all_tags( $string );
208
+        $string = wp_specialchars_decode( $string, ENT_QUOTES );
209
+        $string = preg_replace( '/\v(?:[\v\h]+){2,}/u', "\r\n\r\n", $string );
210
+        $string = str_replace( '-o-^-o-', ' - ', $string );
211
+        return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' );
212 212
     }
213 213
 }
Please login to merge, or discard this patch.
plugin/Modules/System.php 1 patch
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
             'setting' => 'Plugin Settings',
43 43
             'reviews' => 'Review Counts',
44 44
         ];
45
-        $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
46
-            $methodName = Helper::buildMethodName('get-'.$key.'-details');
47
-            if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
45
+        $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use ($details) {
46
+            $methodName = Helper::buildMethodName( 'get-'.$key.'-details' );
47
+            if( method_exists( $this, $methodName ) && $systemDetails = $this->$methodName() ) {
48 48
                 return $carry.$this->implode(
49
-                    strtoupper($details[$key]),
50
-                    apply_filters('site-reviews/system/'.$key, $systemDetails)
49
+                    strtoupper( $details[$key] ),
50
+                    apply_filters( 'site-reviews/system/'.$key, $systemDetails )
51 51
                 );
52 52
             }
53 53
             return $carry;
54 54
         });
55
-        return trim($systemInfo);
55
+        return trim( $systemInfo );
56 56
     }
57 57
 
58 58
     /**
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
     public function getActivePluginDetails()
62 62
     {
63 63
         $plugins = get_plugins();
64
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
65
-        $inactive = array_diff_key($plugins, array_flip($activePlugins));
66
-        return $this->normalizePluginList(array_diff_key($plugins, $inactive));
64
+        $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' );
65
+        $inactive = array_diff_key( $plugins, array_flip( $activePlugins ) );
66
+        return $this->normalizePluginList( array_diff_key( $plugins, $inactive ) );
67 67
     }
68 68
 
69 69
     /**
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function getAddonDetails()
73 73
     {
74
-        $details = apply_filters('site-reviews/addon/system-info', []);
75
-        ksort($details);
74
+        $details = apply_filters( 'site-reviews/addon/system-info', [] );
75
+        ksort( $details );
76 76
         return $details;
77 77
     }
78 78
 
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
     public function getBrowserDetails()
83 83
     {
84 84
         $browser = new Browser();
85
-        $name = esc_attr($browser->getName());
86
-        $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
87
-        $version = esc_attr($browser->getVersion());
85
+        $name = esc_attr( $browser->getName() );
86
+        $userAgent = esc_attr( $browser->getUserAgent()->getUserAgentString() );
87
+        $version = esc_attr( $browser->getVersion() );
88 88
         return [
89
-            'Browser Name' => sprintf('%s %s', $name, $version),
89
+            'Browser Name' => sprintf( '%s %s', $name, $version ),
90 90
             'Browser UA' => $userAgent,
91 91
         ];
92 92
     }
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
      */
97 97
     public function getInactivePluginDetails()
98 98
     {
99
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
100
-        $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
99
+        $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' );
100
+        $inactivePlugins = $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ) ) );
101 101
         $multisitePlugins = $this->getMultisitePluginDetails();
102 102
         return empty($multisitePlugins)
103 103
             ? $inactivePlugins
104
-            : array_diff($inactivePlugins, $multisitePlugins);
104
+            : array_diff( $inactivePlugins, $multisitePlugins );
105 105
     }
106 106
 
107 107
     /**
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
      */
110 110
     public function getMuPluginDetails()
111 111
     {
112
-        if (empty($plugins = get_mu_plugins())) {
112
+        if( empty($plugins = get_mu_plugins()) ) {
113 113
             return [];
114 114
         }
115
-        return $this->normalizePluginList($plugins);
115
+        return $this->normalizePluginList( $plugins );
116 116
     }
117 117
 
118 118
     /**
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function getMultisitePluginDetails()
122 122
     {
123
-        $activePlugins = (array) get_site_option('active_sitewide_plugins', []);
124
-        if (!is_multisite() || empty($activePlugins)) {
123
+        $activePlugins = (array)get_site_option( 'active_sitewide_plugins', [] );
124
+        if( !is_multisite() || empty($activePlugins) ) {
125 125
             return [];
126 126
         }
127
-        return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
127
+        return $this->normalizePluginList( array_intersect_key( get_plugins(), $activePlugins ) );
128 128
     }
129 129
 
130 130
     /**
@@ -132,31 +132,31 @@  discard block
 block discarded – undo
132 132
      */
133 133
     public function getPhpDetails()
134 134
     {
135
-        $displayErrors = $this->getINI('display_errors', null)
136
-            ? 'On ('.$this->getINI('display_errors').')'
135
+        $displayErrors = $this->getINI( 'display_errors', null )
136
+            ? 'On ('.$this->getINI( 'display_errors' ).')'
137 137
             : 'N/A';
138
-        $intlSupport = extension_loaded('intl')
139
-            ? phpversion('intl')
138
+        $intlSupport = extension_loaded( 'intl' )
139
+            ? phpversion( 'intl' )
140 140
             : 'false';
141 141
         return [
142
-            'cURL' => var_export(function_exists('curl_init'), true),
143
-            'Default Charset' => $this->getINI('default_charset'),
142
+            'cURL' => var_export( function_exists( 'curl_init' ), true ),
143
+            'Default Charset' => $this->getINI( 'default_charset' ),
144 144
             'Display Errors' => $displayErrors,
145
-            'fsockopen' => var_export(function_exists('fsockopen'), true),
145
+            'fsockopen' => var_export( function_exists( 'fsockopen' ), true ),
146 146
             'Intl' => $intlSupport,
147
-            'IPv6' => var_export(defined('AF_INET6'), true),
148
-            'Max Execution Time' => $this->getINI('max_execution_time'),
149
-            'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'),
150
-            'Max Input Vars' => $this->getINI('max_input_vars'),
151
-            'Memory Limit' => $this->getINI('memory_limit'),
152
-            'Post Max Size' => $this->getINI('post_max_size'),
153
-            'Sendmail Path' => $this->getINI('sendmail_path'),
154
-            'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')),
155
-            'Session Name' => esc_html($this->getINI('session.name')),
156
-            'Session Save Path' => esc_html($this->getINI('session.save_path')),
157
-            'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true),
158
-            'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true),
159
-            'Upload Max Filesize' => $this->getINI('upload_max_filesize'),
147
+            'IPv6' => var_export( defined( 'AF_INET6' ), true ),
148
+            'Max Execution Time' => $this->getINI( 'max_execution_time' ),
149
+            'Max Input Nesting Level' => $this->getINI( 'max_input_nesting_level' ),
150
+            'Max Input Vars' => $this->getINI( 'max_input_vars' ),
151
+            'Memory Limit' => $this->getINI( 'memory_limit' ),
152
+            'Post Max Size' => $this->getINI( 'post_max_size' ),
153
+            'Sendmail Path' => $this->getINI( 'sendmail_path' ),
154
+            'Session Cookie Path' => esc_html( $this->getINI( 'session.cookie_path' ) ),
155
+            'Session Name' => esc_html( $this->getINI( 'session.name' ) ),
156
+            'Session Save Path' => esc_html( $this->getINI( 'session.save_path' ) ),
157
+            'Session Use Cookies' => var_export( wp_validate_boolean( $this->getINI( 'session.use_cookies', false ) ), true ),
158
+            'Session Use Only Cookies' => var_export( wp_validate_boolean( $this->getINI( 'session.use_only_cookies', false ) ), true ),
159
+            'Upload Max Filesize' => $this->getINI( 'upload_max_filesize' ),
160 160
         ];
161 161
     }
162 162
 
@@ -165,19 +165,19 @@  discard block
 block discarded – undo
165 165
      */
166 166
     public function getReviewsDetails()
167 167
     {
168
-        $counts = glsr(CountsManager::class)->getCounts();
169
-        $counts = Arr::flattenArray($counts);
170
-        array_walk($counts, function (&$ratings) use ($counts) {
171
-            if (is_array($ratings)) {
172
-                $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
168
+        $counts = glsr( CountsManager::class )->getCounts();
169
+        $counts = Arr::flattenArray( $counts );
170
+        array_walk( $counts, function( &$ratings ) use ($counts) {
171
+            if( is_array( $ratings ) ) {
172
+                $ratings = array_sum( $ratings ).' ('.implode( ', ', $ratings ).')';
173 173
                 return;
174 174
             }
175 175
             glsr_log()
176
-                ->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
177
-                ->debug($ratings)
178
-                ->debug($counts);
176
+                ->error( '$ratings is not an array, possibly due to incorrectly imported reviews.' )
177
+                ->debug( $ratings )
178
+                ->debug( $counts );
179 179
         });
180
-        ksort($counts);
180
+        ksort( $counts );
181 181
         return $counts;
182 182
     }
183 183
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
             'Host Name' => $this->getHostName(),
192 192
             'MySQL Version' => $wpdb->db_version(),
193 193
             'PHP Version' => PHP_VERSION,
194
-            'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
194
+            'Server Software' => filter_input( INPUT_SERVER, 'SERVER_SOFTWARE' ),
195 195
         ];
196 196
     }
197 197
 
@@ -200,16 +200,16 @@  discard block
 block discarded – undo
200 200
      */
201 201
     public function getSettingDetails()
202 202
     {
203
-        $settings = glsr(OptionManager::class)->get('settings', []);
204
-        $settings = Arr::flattenArray($settings, true);
205
-        $settings = $this->purgeSensitiveData($settings);
206
-        ksort($settings);
203
+        $settings = glsr( OptionManager::class )->get( 'settings', [] );
204
+        $settings = Arr::flattenArray( $settings, true );
205
+        $settings = $this->purgeSensitiveData( $settings );
206
+        ksort( $settings );
207 207
         $details = [];
208
-        foreach ($settings as $key => $value) {
209
-            if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) {
208
+        foreach( $settings as $key => $value ) {
209
+            if( Str::startsWith( 'strings', $key ) && Str::endsWith( 'id', $key ) ) {
210 210
                 continue;
211 211
             }
212
-            $value = htmlspecialchars(trim(preg_replace('/\s\s+/u', '\\n', $value)), ENT_QUOTES, 'UTF-8');
212
+            $value = htmlspecialchars( trim( preg_replace( '/\s\s+/u', '\\n', $value ) ), ENT_QUOTES, 'UTF-8' );
213 213
             $details[$key] = $value;
214 214
         }
215 215
         return $details;
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
     public function getPluginDetails()
222 222
     {
223 223
         return [
224
-            'Console level' => glsr(Console::class)->humanLevel(),
225
-            'Console size' => glsr(Console::class)->humanSize('0'),
226
-            'Last Migration Run' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_migration_run'), 'unknown'),
227
-            'Last Rating Count' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_review_count'), 'unknown'),
224
+            'Console level' => glsr( Console::class )->humanLevel(),
225
+            'Console size' => glsr( Console::class )->humanSize( '0' ),
226
+            'Last Migration Run' => glsr( Date::class )->localized( glsr( OptionManager::class )->get( 'last_migration_run' ), 'unknown' ),
227
+            'Last Rating Count' => glsr( Date::class )->localized( glsr( OptionManager::class )->get( 'last_review_count' ), 'unknown' ),
228 228
             'Version (current)' => glsr()->version,
229
-            'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
229
+            'Version (previous)' => glsr( OptionManager::class )->get( 'version_upgraded_from' ),
230 230
         ];
231 231
     }
232 232
 
@@ -238,23 +238,23 @@  discard block
 block discarded – undo
238 238
         global $wpdb;
239 239
         $theme = wp_get_theme();
240 240
         return [
241
-            'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
242
-            'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
241
+            'Active Theme' => sprintf( '%s v%s', (string)$theme->Name, (string)$theme->Version ),
242
+            'Email Domain' => substr( strrchr( glsr( OptionManager::class )->getWP( 'admin_email' ), '@' ), 1 ),
243 243
             'Home URL' => home_url(),
244 244
             'Language' => get_locale(),
245 245
             'Memory Limit' => WP_MEMORY_LIMIT,
246
-            'Multisite' => var_export(is_multisite(), true),
247
-            'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
248
-            'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
249
-            'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
250
-            'Post Stati' => implode(', ', get_post_stati()),
251
-            'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
252
-            'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
246
+            'Multisite' => var_export( is_multisite(), true ),
247
+            'Page For Posts ID' => glsr( OptionManager::class )->getWP( 'page_for_posts' ),
248
+            'Page On Front ID' => glsr( OptionManager::class )->getWP( 'page_on_front' ),
249
+            'Permalink Structure' => glsr( OptionManager::class )->getWP( 'permalink_structure', 'default' ),
250
+            'Post Stati' => implode( ', ', get_post_stati() ),
251
+            'Remote Post' => glsr( Cache::class )->getRemotePostTest(),
252
+            'Show On Front' => glsr( OptionManager::class )->getWP( 'show_on_front' ),
253 253
             'Site URL' => site_url(),
254
-            'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'),
255
-            'Version' => get_bloginfo('version'),
256
-            'WP Debug' => var_export(defined('WP_DEBUG'), true),
257
-            'WP Max Upload Size' => size_format(wp_max_upload_size()),
254
+            'Timezone' => glsr( OptionManager::class )->getWP( 'timezone_string', $this->getINI( 'date.timezone' ).' (PHP)' ),
255
+            'Version' => get_bloginfo( 'version' ),
256
+            'WP Debug' => var_export( defined( 'WP_DEBUG' ), true ),
257
+            'WP Max Upload Size' => size_format( wp_max_upload_size() ),
258 258
             'WP Memory Limit' => WP_MEMORY_LIMIT,
259 259
         ];
260 260
     }
@@ -284,13 +284,13 @@  discard block
 block discarded – undo
284 284
             'secureserver.net' => 'GoDaddy',
285 285
             'WPE_APIKEY' => 'WP Engine',
286 286
         ];
287
-        foreach ($checks as $key => $value) {
288
-            if (!$this->isWebhostCheckValid($key)) {
287
+        foreach( $checks as $key => $value ) {
288
+            if( !$this->isWebhostCheckValid( $key ) ) {
289 289
                 continue;
290 290
             }
291 291
             return $value;
292 292
         }
293
-        return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
293
+        return implode( ',', array_filter( [DB_HOST, filter_input( INPUT_SERVER, 'SERVER_NAME' )] ) );
294 294
     }
295 295
 
296 296
     /**
@@ -298,16 +298,16 @@  discard block
 block discarded – undo
298 298
      */
299 299
     protected function getHostName()
300 300
     {
301
-        return sprintf('%s (%s)',
301
+        return sprintf( '%s (%s)',
302 302
             $this->detectWebhostProvider(),
303 303
             Helper::getIpAddress()
304 304
         );
305 305
     }
306 306
 
307
-    protected function getINI($name, $disabledValue = 'ini_get() is disabled.')
307
+    protected function getINI( $name, $disabledValue = 'ini_get() is disabled.' )
308 308
     {
309
-        return function_exists('ini_get')
310
-            ? ini_get($name)
309
+        return function_exists( 'ini_get' )
310
+            ? ini_get( $name )
311 311
             : $disabledValue;
312 312
     }
313 313
 
@@ -317,9 +317,9 @@  discard block
 block discarded – undo
317 317
     protected function getWordpressPlugins()
318 318
     {
319 319
         $plugins = get_plugins();
320
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
321
-        $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
322
-        $active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
320
+        $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' );
321
+        $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ) ) );
322
+        $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ) );
323 323
         return $active + $inactive;
324 324
     }
325 325
 
@@ -327,48 +327,48 @@  discard block
 block discarded – undo
327 327
      * @param string $title
328 328
      * @return string
329 329
      */
330
-    protected function implode($title, array $details)
330
+    protected function implode( $title, array $details )
331 331
     {
332 332
         $strings = ['['.$title.']'];
333
-        $padding = max(array_map('strlen', array_keys($details)));
334
-        $padding = max([$padding, static::PAD]);
335
-        foreach ($details as $key => $value) {
336
-            $strings[] = is_string($key)
337
-                ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
333
+        $padding = max( array_map( 'strlen', array_keys( $details ) ) );
334
+        $padding = max( [$padding, static::PAD] );
335
+        foreach( $details as $key => $value ) {
336
+            $strings[] = is_string( $key )
337
+                ? sprintf( '%s : %s', str_pad( $key, $padding, '.' ), $value )
338 338
                 : ' - '.$value;
339 339
         }
340
-        return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
340
+        return implode( PHP_EOL, $strings ).PHP_EOL.PHP_EOL;
341 341
     }
342 342
 
343 343
     /**
344 344
      * @param string $key
345 345
      * @return bool
346 346
      */
347
-    protected function isWebhostCheckValid($key)
347
+    protected function isWebhostCheckValid( $key )
348 348
     {
349
-        return defined($key)
350
-            || filter_input(INPUT_SERVER, $key)
351
-            || Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
352
-            || Str::contains(DB_HOST, $key)
353
-            || Str::contains(php_uname(), $key);
349
+        return defined( $key )
350
+            || filter_input( INPUT_SERVER, $key )
351
+            || Str::contains( filter_input( INPUT_SERVER, 'SERVER_NAME' ), $key )
352
+            || Str::contains( DB_HOST, $key )
353
+            || Str::contains( php_uname(), $key );
354 354
     }
355 355
 
356 356
     /**
357 357
      * @return array
358 358
      */
359
-    protected function normalizePluginList(array $plugins)
359
+    protected function normalizePluginList( array $plugins )
360 360
     {
361
-        $plugins = array_map(function ($plugin) {
362
-            return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version'));
363
-        }, $plugins);
364
-        natcasesort($plugins);
365
-        return array_flip($plugins);
361
+        $plugins = array_map( function( $plugin ) {
362
+            return sprintf( '%s v%s', Arr::get( $plugin, 'Name' ), Arr::get( $plugin, 'Version' ) );
363
+        }, $plugins );
364
+        natcasesort( $plugins );
365
+        return array_flip( $plugins );
366 366
     }
367 367
 
368 368
     /**
369 369
      * @return array
370 370
      */
371
-    protected function purgeSensitiveData(array $settings)
371
+    protected function purgeSensitiveData( array $settings )
372 372
     {
373 373
         $keys = [
374 374
             'general.trustalyze_serial',
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
             'submissions.recaptcha.key',
377 377
             'submissions.recaptcha.secret',
378 378
         ];
379
-        array_walk($settings, function (&$value, $setting) use ($keys) {
380
-            foreach ($keys as $key) {
381
-                if (!Str::startsWith($key, $setting) || empty($value)) {
379
+        array_walk( $settings, function( &$value, $setting ) use ($keys) {
380
+            foreach( $keys as $key ) {
381
+                if( !Str::startsWith( $key, $setting ) || empty($value) ) {
382 382
                     continue;
383 383
                 }
384
-                $value = str_repeat('•', 13);
384
+                $value = str_repeat( '•', 13 );
385 385
                 return;
386 386
             }
387 387
         });
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviews.php 1 patch
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
      * @param Reviews|null $reviews
46 46
      * @return ReviewsHtml
47 47
      */
48
-    public function build(array $args = [], $reviews = null)
48
+    public function build( array $args = [], $reviews = null )
49 49
     {
50
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
-        $this->options = Arr::flattenArray(glsr(OptionManager::class)->all());
50
+        $this->args = glsr( SiteReviewsDefaults::class )->merge( $args );
51
+        $this->options = Arr::flattenArray( glsr( OptionManager::class )->all() );
52 52
         $this->reviews = $reviews instanceof Reviews
53 53
             ? $reviews
54
-            : glsr(ReviewManager::class)->get($this->args);
54
+            : glsr( ReviewManager::class )->get( $this->args );
55 55
         $this->generateSchema();
56 56
         return $this->buildReviews();
57 57
     }
@@ -59,26 +59,26 @@  discard block
 block discarded – undo
59 59
     /**
60 60
      * @return ReviewHtml
61 61
      */
62
-    public function buildReview(Review $review)
62
+    public function buildReview( Review $review )
63 63
     {
64
-        $review = apply_filters('site-reviews/review/build/before', $review);
64
+        $review = apply_filters( 'site-reviews/review/build/before', $review );
65 65
         $this->current = $review;
66 66
         $renderedFields = [];
67
-        foreach ($review as $key => $value) {
68
-            $method = Helper::buildMethodName($key, 'buildOption');
69
-            $field = method_exists($this, $method)
70
-                ? $this->$method($key, $value)
67
+        foreach( $review as $key => $value ) {
68
+            $method = Helper::buildMethodName( $key, 'buildOption' );
69
+            $field = method_exists( $this, $method )
70
+                ? $this->$method( $key, $value )
71 71
                 : false;
72
-            $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
-            if (false === $field) {
72
+            $field = apply_filters( 'site-reviews/review/build/'.$key, $field, $value, $review, $this );
73
+            if( false === $field ) {
74 74
                 continue;
75 75
             }
76 76
             $renderedFields[$key] = $field;
77 77
         }
78
-        $this->wrap($renderedFields, $review);
79
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
78
+        $this->wrap( $renderedFields, $review );
79
+        $renderedFields = apply_filters( 'site-reviews/review/build/after', $renderedFields, $review, $this );
80 80
         $this->current = null;
81
-        return new ReviewHtml($review, (array) $renderedFields);
81
+        return new ReviewHtml( $review, (array)$renderedFields );
82 82
     }
83 83
 
84 84
     /**
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
     public function buildReviews()
88 88
     {
89 89
         $renderedReviews = [];
90
-        foreach ($this->reviews as $index => $review) {
91
-            $renderedReviews[] = $this->buildReview($review);
90
+        foreach( $this->reviews as $index => $review ) {
91
+            $renderedReviews[] = $this->buildReview( $review );
92 92
         }
93
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
93
+        return new ReviewsHtml( $renderedReviews, $this->reviews->max_num_pages, $this->args );
94 94
     }
95 95
 
96 96
     /**
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function generateSchema()
100 100
     {
101
-        if (!wp_validate_boolean($this->args['schema'])) {
101
+        if( !wp_validate_boolean( $this->args['schema'] ) ) {
102 102
             return;
103 103
         }
104
-        glsr(Schema::class)->store(
105
-            glsr(Schema::class)->build($this->args)
104
+        glsr( Schema::class )->store(
105
+            glsr( Schema::class )->build( $this->args )
106 106
         );
107 107
     }
108 108
 
@@ -110,20 +110,20 @@  discard block
 block discarded – undo
110 110
      * @param string $text
111 111
      * @return string
112 112
      */
113
-    public function getExcerpt($text)
113
+    public function getExcerpt( $text )
114 114
     {
115
-        $limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
-        $split = extension_loaded('intl')
117
-            ? $this->getExcerptIntlSplit($text, $limit)
118
-            : $this->getExcerptSplit($text, $limit);
119
-        $hiddenText = substr($text, $split);
120
-        if (!empty($hiddenText)) {
121
-            $showMore = glsr(Builder::class)->span($hiddenText, [
115
+        $limit = intval( $this->getOption( 'settings.reviews.excerpts_length', 55 ) );
116
+        $split = extension_loaded( 'intl' )
117
+            ? $this->getExcerptIntlSplit( $text, $limit )
118
+            : $this->getExcerptSplit( $text, $limit );
119
+        $hiddenText = substr( $text, $split );
120
+        if( !empty($hiddenText) ) {
121
+            $showMore = glsr( Builder::class )->span( $hiddenText, [
122 122
                 'class' => 'glsr-hidden glsr-hidden-text',
123
-                'data-show-less' => __('Show less', 'site-reviews'),
124
-                'data-show-more' => __('Show more', 'site-reviews'),
125
-            ]);
126
-            $text = ltrim(substr($text, 0, $split)).$showMore;
123
+                'data-show-less' => __( 'Show less', 'site-reviews' ),
124
+                'data-show-more' => __( 'Show more', 'site-reviews' ),
125
+            ] );
126
+            $text = ltrim( substr( $text, 0, $split ) ).$showMore;
127 127
         }
128 128
         return $text;
129 129
     }
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
      * @param string $path
134 134
      * @return bool
135 135
      */
136
-    public function isHidden($key, $path = '')
136
+    public function isHidden( $key, $path = '' )
137 137
     {
138 138
         $isOptionEnabled = !empty($path)
139
-            ? $this->isOptionEnabled($path)
139
+            ? $this->isOptionEnabled( $path )
140 140
             : true;
141
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
141
+        return in_array( $key, $this->args['hide'] ) || !$isOptionEnabled;
142 142
     }
143 143
 
144 144
     /**
@@ -146,25 +146,25 @@  discard block
 block discarded – undo
146 146
      * @param string $value
147 147
      * @return bool
148 148
      */
149
-    public function isHiddenOrEmpty($key, $value)
149
+    public function isHiddenOrEmpty( $key, $value )
150 150
     {
151
-        return $this->isHidden($key) || empty($value);
151
+        return $this->isHidden( $key ) || empty($value);
152 152
     }
153 153
 
154 154
     /**
155 155
      * @param string $text
156 156
      * @return string
157 157
      */
158
-    public function normalizeText($text)
158
+    public function normalizeText( $text )
159 159
     {
160
-        $text = wp_kses($text, wp_kses_allowed_html());
161
-        $text = convert_smilies(strip_shortcodes($text));
162
-        $text = str_replace(']]>', ']]&gt;', $text);
163
-        $text = preg_replace('/(\R){2,}/u', '$1', $text);
164
-        if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
-            $text = $this->getExcerpt($text);
160
+        $text = wp_kses( $text, wp_kses_allowed_html() );
161
+        $text = convert_smilies( strip_shortcodes( $text ) );
162
+        $text = str_replace( ']]>', ']]&gt;', $text );
163
+        $text = preg_replace( '/(\R){2,}/u', '$1', $text );
164
+        if( $this->isOptionEnabled( 'settings.reviews.excerpts' ) ) {
165
+            $text = $this->getExcerpt( $text );
166 166
         }
167
-        return wptexturize(nl2br($text));
167
+        return wptexturize( nl2br( $text ) );
168 168
     }
169 169
 
170 170
     /**
@@ -172,19 +172,19 @@  discard block
 block discarded – undo
172 172
      * @param string $value
173 173
      * @return void|string
174 174
      */
175
-    protected function buildOptionAssignedTo($key, $value)
175
+    protected function buildOptionAssignedTo( $key, $value )
176 176
     {
177
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
177
+        if( $this->isHidden( $key, 'settings.reviews.assigned_links' ) ) {
178 178
             return;
179 179
         }
180
-        $post = get_post(glsr(Multilingual::class)->getPostId($value));
181
-        if (empty($post->ID)) {
180
+        $post = get_post( glsr( Multilingual::class )->getPostId( $value ) );
181
+        if( empty($post->ID) ) {
182 182
             return;
183 183
         }
184
-        $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
-            'href' => get_the_permalink($post->ID),
186
-        ]);
187
-        $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
184
+        $permalink = glsr( Builder::class )->a( get_the_title( $post->ID ), [
185
+            'href' => get_the_permalink( $post->ID ),
186
+        ] );
187
+        $assignedTo = sprintf( __( 'Review of %s', 'site-reviews' ), $permalink );
188 188
         return '<span>'.$assignedTo.'</span>';
189 189
     }
190 190
 
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
      * @param string $value
194 194
      * @return void|string
195 195
      */
196
-    protected function buildOptionAuthor($key, $value)
196
+    protected function buildOptionAuthor( $key, $value )
197 197
     {
198
-        if (!$this->isHidden($key)) {
198
+        if( !$this->isHidden( $key ) ) {
199 199
             $name = Str::convertName(
200 200
                 $value,
201
-                glsr_get_option('reviews.name.format'),
202
-                glsr_get_option('reviews.name.initial')
201
+                glsr_get_option( 'reviews.name.format' ),
202
+                glsr_get_option( 'reviews.name.initial' )
203 203
             );
204 204
             return '<span>'.$name.'</span>';
205 205
         }
@@ -210,18 +210,18 @@  discard block
 block discarded – undo
210 210
      * @param string $value
211 211
      * @return void|string
212 212
      */
213
-    protected function buildOptionAvatar($key, $value)
213
+    protected function buildOptionAvatar( $key, $value )
214 214
     {
215
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
215
+        if( $this->isHidden( $key, 'settings.reviews.avatars' ) ) {
216 216
             return;
217 217
         }
218
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
219
-        return glsr(Builder::class)->img([
218
+        $size = $this->getOption( 'settings.reviews.avatars_size', 40 );
219
+        return glsr( Builder::class )->img( [
220 220
             'height' => $size,
221
-            'src' => $this->generateAvatar($value),
222
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
221
+            'src' => $this->generateAvatar( $value ),
222
+            'style' => sprintf( 'width:%1$spx; height:%1$spx;', $size ),
223 223
             'width' => $size,
224
-        ]);
224
+        ] );
225 225
     }
226 226
 
227 227
     /**
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
      * @param string $value
230 230
      * @return void|string
231 231
      */
232
-    protected function buildOptionContent($key, $value)
232
+    protected function buildOptionContent( $key, $value )
233 233
     {
234
-        $text = $this->normalizeText($value);
235
-        if (!$this->isHiddenOrEmpty($key, $text)) {
234
+        $text = $this->normalizeText( $value );
235
+        if( !$this->isHiddenOrEmpty( $key, $text ) ) {
236 236
             return '<p>'.$text.'</p>';
237 237
         }
238 238
     }
@@ -242,19 +242,19 @@  discard block
 block discarded – undo
242 242
      * @param string $value
243 243
      * @return void|string
244 244
      */
245
-    protected function buildOptionDate($key, $value)
245
+    protected function buildOptionDate( $key, $value )
246 246
     {
247
-        if ($this->isHidden($key)) {
247
+        if( $this->isHidden( $key ) ) {
248 248
             return;
249 249
         }
250
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
-        if ('relative' == $dateFormat) {
252
-            $date = glsr(Date::class)->relative($value);
250
+        $dateFormat = $this->getOption( 'settings.reviews.date.format', 'default' );
251
+        if( 'relative' == $dateFormat ) {
252
+            $date = glsr( Date::class )->relative( $value );
253 253
         } else {
254 254
             $format = 'custom' == $dateFormat
255
-                ? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
-                : glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
-            $date = date_i18n($format, strtotime($value));
255
+                ? $this->getOption( 'settings.reviews.date.custom', 'M j, Y' )
256
+                : glsr( OptionManager::class )->getWP( 'date_format', 'F j, Y' );
257
+            $date = date_i18n( $format, strtotime( $value ) );
258 258
         }
259 259
         return '<span>'.$date.'</span>';
260 260
     }
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
      * @param string $value
265 265
      * @return void|string
266 266
      */
267
-    protected function buildOptionRating($key, $value)
267
+    protected function buildOptionRating( $key, $value )
268 268
     {
269
-        if (!$this->isHiddenOrEmpty($key, $value)) {
270
-            return glsr_star_rating($value);
269
+        if( !$this->isHiddenOrEmpty( $key, $value ) ) {
270
+            return glsr_star_rating( $value );
271 271
         }
272 272
     }
273 273
 
@@ -276,16 +276,16 @@  discard block
 block discarded – undo
276 276
      * @param string $value
277 277
      * @return void|string
278 278
      */
279
-    protected function buildOptionResponse($key, $value)
279
+    protected function buildOptionResponse( $key, $value )
280 280
     {
281
-        if ($this->isHiddenOrEmpty($key, $value)) {
281
+        if( $this->isHiddenOrEmpty( $key, $value ) ) {
282 282
             return;
283 283
         }
284
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
-        $text = $this->normalizeText($value);
284
+        $title = sprintf( __( 'Response from %s', 'site-reviews' ), get_bloginfo( 'name' ) );
285
+        $text = $this->normalizeText( $value );
286 286
         $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
-        $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
-        $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
287
+        $response = glsr( Builder::class )->div( $text, ['class' => 'glsr-review-response-inner'] );
288
+        $background = glsr( Builder::class )->div( ['class' => 'glsr-review-response-background'] );
289 289
         return $response.$background;
290 290
     }
291 291
 
@@ -294,13 +294,13 @@  discard block
 block discarded – undo
294 294
      * @param string $value
295 295
      * @return void|string
296 296
      */
297
-    protected function buildOptionTitle($key, $value)
297
+    protected function buildOptionTitle( $key, $value )
298 298
     {
299
-        if ($this->isHidden($key)) {
299
+        if( $this->isHidden( $key ) ) {
300 300
             return;
301 301
         }
302
-        if (empty($value)) {
303
-            $value = __('No Title', 'site-reviews');
302
+        if( empty($value) ) {
303
+            $value = __( 'No Title', 'site-reviews' );
304 304
         }
305 305
         return '<h3>'.$value.'</h3>';
306 306
     }
@@ -309,18 +309,18 @@  discard block
 block discarded – undo
309 309
      * @param string $avatarUrl
310 310
      * @return string
311 311
      */
312
-    protected function generateAvatar($avatarUrl)
312
+    protected function generateAvatar( $avatarUrl )
313 313
     {
314
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
314
+        if( !$this->isOptionEnabled( 'settings.reviews.avatars_regenerate' ) || 'local' != $this->current->review_type ) {
315 315
             return $avatarUrl;
316 316
         }
317
-        if ($this->current->user_id) {
318
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
317
+        if( $this->current->user_id ) {
318
+        $authorIdOrEmail = get_the_author_meta( 'ID', $this->current->user_id );
319 319
         }
320
-        if (empty($authorIdOrEmail)) {
320
+        if( empty($authorIdOrEmail) ) {
321 321
             $authorIdOrEmail = $this->current->email;
322 322
         }
323
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
323
+        if( $newAvatar = get_avatar_url( $authorIdOrEmail ) ) {
324 324
             return $newAvatar;
325 325
         }
326 326
         return $avatarUrl;
@@ -331,22 +331,22 @@  discard block
 block discarded – undo
331 331
      * @param int $limit
332 332
      * @return int
333 333
      */
334
-    protected function getExcerptIntlSplit($text, $limit)
334
+    protected function getExcerptIntlSplit( $text, $limit )
335 335
     {
336
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
337
-        $words->setText($text);
336
+        $words = IntlRuleBasedBreakIterator::createWordInstance( '' );
337
+        $words->setText( $text );
338 338
         $count = 0;
339
-        foreach ($words as $offset) {
340
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
339
+        foreach( $words as $offset ) {
340
+            if( IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus() ) {
341 341
                 continue;
342 342
             }
343 343
             ++$count;
344
-            if ($count != $limit) {
344
+            if( $count != $limit ) {
345 345
                 continue;
346 346
             }
347 347
             return $offset;
348 348
         }
349
-        return strlen($text);
349
+        return strlen( $text );
350 350
     }
351 351
 
352 352
     /**
@@ -354,13 +354,13 @@  discard block
 block discarded – undo
354 354
      * @param int $limit
355 355
      * @return int
356 356
      */
357
-    protected function getExcerptSplit($text, $limit)
357
+    protected function getExcerptSplit( $text, $limit )
358 358
     {
359
-        if (str_word_count($text, 0) > $limit) {
360
-            $words = array_keys(str_word_count($text, 2));
359
+        if( str_word_count( $text, 0 ) > $limit ) {
360
+            $words = array_keys( str_word_count( $text, 2 ) );
361 361
             return $words[$limit];
362 362
         }
363
-        return strlen($text);
363
+        return strlen( $text );
364 364
     }
365 365
 
366 366
     /**
@@ -368,9 +368,9 @@  discard block
 block discarded – undo
368 368
      * @param mixed $fallback
369 369
      * @return mixed
370 370
      */
371
-    protected function getOption($path, $fallback = '')
371
+    protected function getOption( $path, $fallback = '' )
372 372
     {
373
-        if (array_key_exists($path, $this->options)) {
373
+        if( array_key_exists( $path, $this->options ) ) {
374 374
             return $this->options[$path];
375 375
         }
376 376
         return $fallback;
@@ -380,25 +380,25 @@  discard block
 block discarded – undo
380 380
      * @param string $path
381 381
      * @return bool
382 382
      */
383
-    protected function isOptionEnabled($path)
383
+    protected function isOptionEnabled( $path )
384 384
     {
385
-        return 'yes' == $this->getOption($path);
385
+        return 'yes' == $this->getOption( $path );
386 386
     }
387 387
 
388 388
     /**
389 389
      * @return void
390 390
      */
391
-    protected function wrap(array &$renderedFields, Review $review)
391
+    protected function wrap( array &$renderedFields, Review $review )
392 392
     {
393
-        $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
394
-        array_walk($renderedFields, function (&$value, $key) use ($review) {
395
-            $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
396
-            if (empty($value)) {
393
+        $renderedFields = apply_filters( 'site-reviews/review/wrap', $renderedFields, $review, $this );
394
+        array_walk( $renderedFields, function( &$value, $key ) use ($review) {
395
+            $value = apply_filters( 'site-reviews/review/wrap/'.$key, $value, $review );
396
+            if( empty($value) ) {
397 397
                 return;
398 398
             }
399
-            $value = glsr(Builder::class)->div($value, [
399
+            $value = glsr( Builder::class )->div( $value, [
400 400
                 'class' => 'glsr-review-'.$key,
401
-            ]);
401
+            ] );
402 402
         });
403 403
     }
404 404
 }
Please login to merge, or discard this patch.