Passed
Push — master ( 04b043...334ee0 )
by Paul
04:11
created
plugin/Modules/Html/Settings.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -20,31 +20,31 @@  discard block
 block discarded – undo
20 20
      * @param string $id
21 21
      * @return string
22 22
      */
23
-    public function buildFields($id)
23
+    public function buildFields( $id )
24 24
     {
25
-        $this->settings = glsr(DefaultsManager::class)->settings();
26
-        $method = Helper::buildMethodName($id, 'getTemplateDataFor');
27
-        $data = !method_exists($this, $method)
28
-            ? $this->getTemplateData($id)
29
-            : $this->$method($id);
30
-        return glsr(Template::class)->build('pages/settings/'.$id, $data);
25
+        $this->settings = glsr( DefaultsManager::class )->settings();
26
+        $method = Helper::buildMethodName( $id, 'getTemplateDataFor' );
27
+        $data = !method_exists( $this, $method )
28
+            ? $this->getTemplateData( $id )
29
+            : $this->$method( $id );
30
+        return glsr( Template::class )->build( 'pages/settings/'.$id, $data );
31 31
     }
32 32
 
33 33
     /**
34 34
      * @return string
35 35
      */
36
-    protected function getFieldDefault(array $field)
36
+    protected function getFieldDefault( array $field )
37 37
     {
38
-        return Arr::get($field, 'default');
38
+        return Arr::get( $field, 'default' );
39 39
     }
40 40
 
41 41
     /**
42 42
      * @return string
43 43
      */
44
-    protected function getFieldNameForDependsOn($path)
44
+    protected function getFieldNameForDependsOn( $path )
45 45
     {
46
-        $fieldName = Str::convertPathToName($path, OptionManager::databaseKey());
47
-        return $this->isMultiDependency($path)
46
+        $fieldName = Str::convertPathToName( $path, OptionManager::databaseKey() );
47
+        return $this->isMultiDependency( $path )
48 48
             ? $fieldName.'[]'
49 49
             : $fieldName;
50 50
     }
@@ -52,25 +52,25 @@  discard block
 block discarded – undo
52 52
     /**
53 53
      * @return array
54 54
      */
55
-    protected function getSettingFields($path)
55
+    protected function getSettingFields( $path )
56 56
     {
57
-        return array_filter($this->settings, function ($key) use ($path) {
58
-            return Str::startsWith($path, $key);
59
-        }, ARRAY_FILTER_USE_KEY);
57
+        return array_filter( $this->settings, function( $key ) use ($path) {
58
+            return Str::startsWith( $path, $key );
59
+        }, ARRAY_FILTER_USE_KEY );
60 60
     }
61 61
 
62 62
     /**
63 63
      * @return string
64 64
      */
65
-    protected function getSettingRows(array $fields)
65
+    protected function getSettingRows( array $fields )
66 66
     {
67 67
         $rows = '';
68
-        foreach ($fields as $name => $field) {
69
-            $field = wp_parse_args($field, [
68
+        foreach( $fields as $name => $field ) {
69
+            $field = wp_parse_args( $field, [
70 70
                 'is_setting' => true,
71 71
                 'name' => $name,
72
-            ]);
73
-            $rows.= new Field($this->normalize($field));
72
+            ] );
73
+            $rows .= new Field( $this->normalize( $field ) );
74 74
         }
75 75
         return $rows;
76 76
     }
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
      * @param string $id
80 80
      * @return array
81 81
      */
82
-    protected function getTemplateData($id)
82
+    protected function getTemplateData( $id )
83 83
     {
84
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
84
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
85 85
         return [
86 86
             'context' => [
87
-                'rows' => $this->getSettingRows($fields),
87
+                'rows' => $this->getSettingRows( $fields ),
88 88
             ],
89 89
         ];
90 90
     }
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
      * @param string $id
94 94
      * @return array
95 95
      */
96
-    protected function getTemplateDataForAddons($id)
96
+    protected function getTemplateDataForAddons( $id )
97 97
     {
98
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
99
-        $settings = Arr::convertDotNotationArray($fields);
100
-        $settingKeys = array_keys($settings['settings']['addons']);
98
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
99
+        $settings = Arr::convertDotNotationArray( $fields );
100
+        $settingKeys = array_keys( $settings['settings']['addons'] );
101 101
         $results = [];
102
-        foreach ($settingKeys as $key) {
103
-            $addonFields = array_filter($fields, function ($path) use ($key) {
104
-                return Str::startsWith('settings.addons.'.$key, $path);
105
-            }, ARRAY_FILTER_USE_KEY);
106
-            $results[$key] = $this->getSettingRows($addonFields);
102
+        foreach( $settingKeys as $key ) {
103
+            $addonFields = array_filter( $fields, function( $path ) use ($key) {
104
+                return Str::startsWith( 'settings.addons.'.$key, $path );
105
+            }, ARRAY_FILTER_USE_KEY );
106
+            $results[$key] = $this->getSettingRows( $addonFields );
107 107
         }
108
-        ksort($results);
108
+        ksort( $results );
109 109
         return [
110 110
             'settings' => $results,
111 111
         ];
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
      * @param string $id
116 116
      * @return array
117 117
      */
118
-    protected function getTemplateDataForLicenses($id)
118
+    protected function getTemplateDataForLicenses( $id )
119 119
     {
120
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
121
-        ksort($fields);
120
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
121
+        ksort( $fields );
122 122
         return [
123 123
             'context' => [
124
-                'rows' => $this->getSettingRows($fields),
124
+                'rows' => $this->getSettingRows( $fields ),
125 125
             ],
126 126
         ];
127 127
     }
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     protected function getTemplateDataForTranslations()
133 133
     {
134
-        $translations = glsr(Translation::class)->renderAll();
134
+        $translations = glsr( Translation::class )->renderAll();
135 135
         $class = empty($translations)
136 136
             ? 'glsr-hidden'
137 137
             : '';
@@ -149,16 +149,16 @@  discard block
 block discarded – undo
149 149
      * @param string|array $expectedValue
150 150
      * @return bool
151 151
      */
152
-    protected function isFieldHidden($path, $expectedValue)
152
+    protected function isFieldHidden( $path, $expectedValue )
153 153
     {
154
-        $optionValue = glsr(OptionManager::class)->get(
154
+        $optionValue = glsr( OptionManager::class )->get(
155 155
             $path,
156
-            Arr::get(glsr()->defaults, $path)
156
+            Arr::get( glsr()->defaults, $path )
157 157
         );
158
-        if (is_array($expectedValue)) {
159
-            return is_array($optionValue)
160
-                ? 0 === count(array_intersect($optionValue, $expectedValue))
161
-                : !in_array($optionValue, $expectedValue);
158
+        if( is_array( $expectedValue ) ) {
159
+            return is_array( $optionValue )
160
+                ? 0 === count( array_intersect( $optionValue, $expectedValue ) )
161
+                : !in_array( $optionValue, $expectedValue );
162 162
         }
163 163
         return $optionValue != $expectedValue;
164 164
     }
@@ -166,9 +166,9 @@  discard block
 block discarded – undo
166 166
     /**
167 167
      * @return bool
168 168
      */
169
-    protected function isMultiDependency($path)
169
+    protected function isMultiDependency( $path )
170 170
     {
171
-        if (isset($this->settings[$path])) {
171
+        if( isset($this->settings[$path]) ) {
172 172
             $field = $this->settings[$path];
173 173
             return ('checkbox' == $field['type'] && !empty($field['options']))
174 174
                 || !empty($field['multiple']);
@@ -179,32 +179,32 @@  discard block
 block discarded – undo
179 179
     /**
180 180
      * @return array
181 181
      */
182
-    protected function normalize(array $field)
182
+    protected function normalize( array $field )
183 183
     {
184
-        $field = $this->normalizeDependsOn($field);
185
-        $field = $this->normalizeLabelAndLegend($field);
186
-        $field = $this->normalizeValue($field);
184
+        $field = $this->normalizeDependsOn( $field );
185
+        $field = $this->normalizeLabelAndLegend( $field );
186
+        $field = $this->normalizeValue( $field );
187 187
         return $field;
188 188
     }
189 189
 
190 190
     /**
191 191
      * @return array
192 192
      */
193
-    protected function normalizeDependsOn(array $field)
193
+    protected function normalizeDependsOn( array $field )
194 194
     {
195
-        if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
195
+        if( !empty($field['depends_on']) && is_array( $field['depends_on'] ) ) {
196 196
             $isFieldHidden = false;
197 197
             $conditions = [];
198
-            foreach ($field['depends_on'] as $path => $value) {
198
+            foreach( $field['depends_on'] as $path => $value ) {
199 199
                 $conditions[] = [
200
-                    'name' => $this->getFieldNameForDependsOn($path),
200
+                    'name' => $this->getFieldNameForDependsOn( $path ),
201 201
                     'value' => $value,
202 202
                 ];
203
-                if ($this->isFieldHidden($path, $value)) {
203
+                if( $this->isFieldHidden( $path, $value ) ) {
204 204
                     $isFieldHidden = true;
205 205
                 }
206 206
             }
207
-            $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
207
+            $field['data-depends'] = json_encode( $conditions, JSON_HEX_APOS | JSON_HEX_QUOT );
208 208
             $field['is_hidden'] = $isFieldHidden;
209 209
         }
210 210
         return $field;
@@ -213,14 +213,14 @@  discard block
 block discarded – undo
213 213
     /**
214 214
      * @return array
215 215
      */
216
-    protected function normalizeLabelAndLegend(array $field)
216
+    protected function normalizeLabelAndLegend( array $field )
217 217
     {
218
-        if (!empty($field['label'])) {
218
+        if( !empty($field['label']) ) {
219 219
             $field['legend'] = $field['label'];
220 220
             unset($field['label']);
221 221
         } else {
222 222
             $field['is_valid'] = false;
223
-            glsr_log()->warning('Setting field is missing a label')->debug($field);
223
+            glsr_log()->warning( 'Setting field is missing a label' )->debug( $field );
224 224
         }
225 225
         return $field;
226 226
     }
@@ -228,12 +228,12 @@  discard block
 block discarded – undo
228 228
     /**
229 229
      * @return array
230 230
      */
231
-    protected function normalizeValue(array $field)
231
+    protected function normalizeValue( array $field )
232 232
     {
233
-        if (!isset($field['value'])) {
234
-            $field['value'] = glsr(OptionManager::class)->get(
233
+        if( !isset($field['value']) ) {
234
+            $field['value'] = glsr( OptionManager::class )->get(
235 235
                 $field['name'],
236
-                $this->getFieldDefault($field)
236
+                $this->getFieldDefault( $field )
237 237
             );
238 238
         }
239 239
         return $field;
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
     /**
243 243
      * @return string
244 244
      */
245
-    protected function normalizeSettingPath($path)
245
+    protected function normalizeSettingPath( $path )
246 246
     {
247
-        return Str::prefix('settings.', rtrim($path, '.'));
247
+        return Str::prefix( 'settings.', rtrim( $path, '.' ) );
248 248
     }
249 249
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Fields/Field.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      */
13 13
     protected $builder;
14 14
 
15
-    public function __construct(Builder $builder)
15
+    public function __construct( Builder $builder )
16 16
     {
17 17
         $this->builder = $builder;
18 18
     }
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      */
23 23
     public function build()
24 24
     {
25
-        glsr_log()->error('Build method is not implemented for '.get_class($this));
25
+        glsr_log()->error( 'Build method is not implemented for '.get_class( $this ) );
26 26
     }
27 27
 
28 28
     /**
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
     /**
37 37
      * @return array
38 38
      */
39
-    public static function merge(array $args)
39
+    public static function merge( array $args )
40 40
     {
41 41
         $merged = array_merge(
42
-            wp_parse_args($args, static::defaults()),
42
+            wp_parse_args( $args, static::defaults() ),
43 43
             static::required()
44 44
         );
45
-        $merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args));
46
-        $merged['style'] = implode(';', static::mergedAttribute('style', ';', $args));
45
+        $merged['class'] = implode( ' ', static::mergedAttribute( 'class', ' ', $args ) );
46
+        $merged['style'] = implode( ';', static::mergedAttribute( 'style', ';', $args ) );
47 47
         return $merged;
48 48
     }
49 49
 
@@ -52,13 +52,13 @@  discard block
 block discarded – undo
52 52
      * @param string $key
53 53
      * @return array
54 54
      */
55
-    public static function mergedAttribute($key, $delimiter, array $args)
55
+    public static function mergedAttribute( $key, $delimiter, array $args )
56 56
     {
57
-        return array_filter(array_merge(
58
-            explode($delimiter, Arr::get($args, $key)),
59
-            explode($delimiter, Arr::get(static::defaults(), $key)),
60
-            explode($delimiter, Arr::get(static::required(), $key))
61
-        ));
57
+        return array_filter( array_merge(
58
+            explode( $delimiter, Arr::get( $args, $key ) ),
59
+            explode( $delimiter, Arr::get( static::defaults(), $key ) ),
60
+            explode( $delimiter, Arr::get( static::required(), $key ) )
61
+        ) );
62 62
     }
63 63
 
64 64
     /**
@@ -74,6 +74,6 @@  discard block
 block discarded – undo
74 74
      */
75 75
     protected function mergeFieldArgs()
76 76
     {
77
-        $this->builder->args = static::merge($this->builder->args);
77
+        $this->builder->args = static::merge( $this->builder->args );
78 78
     }
79 79
 }
Please login to merge, or discard this patch.
plugin/Modules/Style.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 
35 35
     public function __construct()
36 36
     {
37
-        $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default');
37
+        $this->style = glsr( OptionManager::class )->get( 'settings.general.style', 'default' );
38 38
         $this->setConfig();
39 39
     }
40 40
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      * @param string $view
43 43
      * @return string
44 44
      */
45
-    public function filterView($view)
45
+    public function filterView( $view )
46 46
     {
47 47
         $styledViews = [
48 48
             'templates/form/field',
@@ -50,15 +50,15 @@  discard block
 block discarded – undo
50 50
             'templates/form/submit-button',
51 51
             'templates/reviews-form',
52 52
         ];
53
-        if (!preg_match('('.implode('|', $styledViews).')', $view)) {
53
+        if( !preg_match( '('.implode( '|', $styledViews ).')', $view ) ) {
54 54
             return $view;
55 55
         }
56
-        $views = $this->generatePossibleViews($view);
57
-        foreach ($views as $possibleView) {
58
-            if (!file_exists(glsr()->file($possibleView))) {
56
+        $views = $this->generatePossibleViews( $view );
57
+        foreach( $views as $possibleView ) {
58
+            if( !file_exists( glsr()->file( $possibleView ) ) ) {
59 59
                 continue;
60 60
             }
61
-            return Str::removePrefix('views/', $possibleView);
61
+            return Str::removePrefix( 'views/', $possibleView );
62 62
         }
63 63
         return $view;
64 64
     }
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
      */
69 69
     public function get()
70 70
     {
71
-        return apply_filters('site-reviews/style', $this->style);
71
+        return apply_filters( 'site-reviews/style', $this->style );
72 72
     }
73 73
 
74 74
     /**
@@ -77,77 +77,77 @@  discard block
 block discarded – undo
77 77
     public function setConfig()
78 78
     {
79 79
         $config = shortcode_atts(
80
-            array_fill_keys(['fields', 'pagination', 'validation'], []),
81
-            glsr()->config('styles/'.$this->style)
80
+            array_fill_keys( ['fields', 'pagination', 'validation'], [] ),
81
+            glsr()->config( 'styles/'.$this->style )
82 82
         );
83
-        $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']);
84
-        $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']);
85
-        $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']);
83
+        $this->fields = glsr( StyleFieldsDefaults::class )->restrict( $config['fields'] );
84
+        $this->pagination = glsr( PaginationDefaults::class )->restrict( $config['pagination'] );
85
+        $this->validation = glsr( StyleValidationDefaults::class )->restrict( $config['validation'] );
86 86
     }
87 87
 
88 88
     /**
89 89
      * @return void
90 90
      */
91
-    public function modifyField(Builder $instance)
91
+    public function modifyField( Builder $instance )
92 92
     {
93
-        if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) {
93
+        if( !$this->isPublicInstance( $instance ) || empty(array_filter( $this->fields )) ) {
94 94
             return;
95 95
         }
96
-        call_user_func_array([$this, 'customize'], [$instance]);
96
+        call_user_func_array( [$this, 'customize'], [$instance] );
97 97
     }
98 98
 
99 99
     /**
100 100
      * @return array
101 101
      */
102
-    public function paginationArgs(array $args)
102
+    public function paginationArgs( array $args )
103 103
     {
104
-        return wp_parse_args($args, $this->pagination);
104
+        return wp_parse_args( $args, $this->pagination );
105 105
     }
106 106
 
107 107
     /**
108 108
      * @return void
109 109
      */
110
-    protected function customize(Builder $instance)
110
+    protected function customize( Builder $instance )
111 111
     {
112
-        if (!array_key_exists($instance->tag, $this->fields)) {
112
+        if( !array_key_exists( $instance->tag, $this->fields ) ) {
113 113
             return;
114 114
         }
115
-        $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], ''));
115
+        $args = wp_parse_args( $instance->args, array_fill_keys( ['class', 'type'], '' ) );
116 116
         $key = $instance->tag.'_'.$args['type'];
117
-        $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag));
118
-        $instance->args['class'] = trim($args['class'].' '.$classes);
119
-        do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]);
117
+        $classes = Arr::get( $this->fields, $key, Arr::get( $this->fields, $instance->tag ) );
118
+        $instance->args['class'] = trim( $args['class'].' '.$classes );
119
+        do_action_ref_array( 'site-reviews/customize/'.$this->style, [$instance] );
120 120
     }
121 121
 
122 122
     /**
123 123
      * @param string $view
124 124
      * @return array
125 125
      */
126
-    protected function generatePossibleViews($view)
126
+    protected function generatePossibleViews( $view )
127 127
     {
128
-        $basename = basename($view);
129
-        $basepath = rtrim($view, $basename);
128
+        $basename = basename( $view );
129
+        $basepath = rtrim( $view, $basename );
130 130
         $customPath = 'views/partials/styles/'.$this->style.'/';
131
-        $parts = explode('_', $basename);
131
+        $parts = explode( '_', $basename );
132 132
         $views = [
133 133
             $customPath.$basename,
134 134
             $customPath.$parts[0],
135 135
             $view,
136 136
             $basepath.$parts[0],
137 137
         ];
138
-        return array_filter($views);
138
+        return array_filter( $views );
139 139
     }
140 140
 
141 141
     /**
142 142
      * @return bool
143 143
      */
144
-    protected function isPublicInstance(Builder $instance)
144
+    protected function isPublicInstance( Builder $instance )
145 145
     {
146
-        $args = wp_parse_args($instance->args, [
146
+        $args = wp_parse_args( $instance->args, [
147 147
             'is_public' => false,
148 148
             'is_raw' => false,
149
-        ]);
150
-        if (is_admin() || !$args['is_public'] || $args['is_raw']) {
149
+        ] );
150
+        if( is_admin() || !$args['is_public'] || $args['is_raw'] ) {
151 151
             return false;
152 152
         }
153 153
         return true;
Please login to merge, or discard this patch.
plugin/Review.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -33,27 +33,27 @@  discard block
 block discarded – undo
33 33
     public $url;
34 34
     public $user_id;
35 35
 
36
-    public function __construct(WP_Post $post)
36
+    public function __construct( WP_Post $post )
37 37
     {
38
-        if (Application::POST_TYPE != $post->post_type) {
38
+        if( Application::POST_TYPE != $post->post_type ) {
39 39
             return;
40 40
         }
41 41
         $this->content = $post->post_content;
42 42
         $this->date = $post->post_date;
43
-        $this->ID = intval($post->ID);
43
+        $this->ID = intval( $post->ID );
44 44
         $this->status = $post->post_status;
45 45
         $this->title = $post->post_title;
46
-        $this->user_id = intval($post->post_author);
47
-        $this->setProperties($post);
48
-        $this->setTermIds($post);
46
+        $this->user_id = intval( $post->post_author );
47
+        $this->setProperties( $post );
48
+        $this->setTermIds( $post );
49 49
     }
50 50
 
51 51
     /**
52 52
      * @return mixed
53 53
      */
54
-    public function __get($key)
54
+    public function __get( $key )
55 55
     {
56
-        return $this->offsetGet($key);
56
+        return $this->offsetGet( $key );
57 57
     }
58 58
 
59 59
     /**
@@ -61,41 +61,41 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function __toString()
63 63
     {
64
-        return (string) $this->build();
64
+        return (string)$this->build();
65 65
     }
66 66
 
67 67
     /**
68 68
      * @return ReviewHtml
69 69
      */
70
-    public function build(array $args = [])
70
+    public function build( array $args = [] )
71 71
     {
72
-        if (empty($this->ID)) {
73
-            return new ReviewHtml($this);
72
+        if( empty($this->ID) ) {
73
+            return new ReviewHtml( $this );
74 74
         }
75
-        $partial = glsr(SiteReviewsPartial::class);
76
-        $partial->args = glsr(SiteReviewsDefaults::class)->merge($args);
77
-        $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all());
78
-        return $partial->buildReview($this);
75
+        $partial = glsr( SiteReviewsPartial::class );
76
+        $partial->args = glsr( SiteReviewsDefaults::class )->merge( $args );
77
+        $partial->options = Arr::flattenArray( glsr( OptionManager::class )->all() );
78
+        return $partial->buildReview( $this );
79 79
     }
80 80
 
81 81
     /**
82 82
      * @param mixed $key
83 83
      * @return bool
84 84
      */
85
-    public function offsetExists($key)
85
+    public function offsetExists( $key )
86 86
     {
87
-        return property_exists($this, $key) || array_key_exists($key, (array) $this->custom);
87
+        return property_exists( $this, $key ) || array_key_exists( $key, (array)$this->custom );
88 88
     }
89 89
 
90 90
     /**
91 91
      * @param mixed $key
92 92
      * @return mixed
93 93
      */
94
-    public function offsetGet($key)
94
+    public function offsetGet( $key )
95 95
     {
96
-        return property_exists($this, $key)
96
+        return property_exists( $this, $key )
97 97
             ? $this->$key
98
-            : Arr::get($this->custom, $key, null);
98
+            : Arr::get( $this->custom, $key, null );
99 99
     }
100 100
 
101 101
     /**
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
      * @param mixed $value
104 104
      * @return void
105 105
      */
106
-    public function offsetSet($key, $value)
106
+    public function offsetSet( $key, $value )
107 107
     {
108
-        if (property_exists($this, $key)) {
108
+        if( property_exists( $this, $key ) ) {
109 109
             $this->$key = $value;
110 110
             return;
111 111
         }
112
-        if (!is_array($this->custom)) {
113
-            $this->custom = array_filter((array) $this->custom);
112
+        if( !is_array( $this->custom ) ) {
113
+            $this->custom = array_filter( (array)$this->custom );
114 114
         }
115 115
         $this->custom[$key] = $value;
116 116
     }
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
      * @param mixed $key
120 120
      * @return void
121 121
      */
122
-    public function offsetUnset($key)
122
+    public function offsetUnset( $key )
123 123
     {
124
-        $this->offsetSet($key, null);
124
+        $this->offsetSet( $key, null );
125 125
     }
126 126
 
127 127
     /**
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     /**
136 136
      * @return bool
137 137
      */
138
-    protected function isModified(array $properties)
138
+    protected function isModified( array $properties )
139 139
     {
140 140
         return $this->date != $properties['date']
141 141
             || $this->content != $properties['content']
@@ -145,39 +145,39 @@  discard block
 block discarded – undo
145 145
     /**
146 146
      * @return void
147 147
      */
148
-    protected function setProperties(WP_Post $post)
148
+    protected function setProperties( WP_Post $post )
149 149
     {
150 150
         $defaults = [
151
-            'author' => __('Anonymous', 'site-reviews'),
151
+            'author' => __( 'Anonymous', 'site-reviews' ),
152 152
             'date' => '',
153 153
             'review_id' => '',
154 154
             'review_type' => 'local',
155 155
         ];
156 156
         $meta = array_filter(
157
-            array_map('array_shift', array_filter((array) get_post_meta($post->ID))),
157
+            array_map( 'array_shift', array_filter( (array)get_post_meta( $post->ID ) ) ),
158 158
             'strlen'
159 159
         );
160
-        $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta));
161
-        $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta));
162
-        $this->modified = $this->isModified($properties);
163
-        array_walk($properties, function ($value, $key) {
164
-            if (!property_exists($this, $key) || isset($this->$key)) {
160
+        $meta = array_merge( $defaults, Arr::unprefixArrayKeys( $meta ) );
161
+        $properties = glsr( CreateReviewDefaults::class )->restrict( array_merge( $defaults, $meta ) );
162
+        $this->modified = $this->isModified( $properties );
163
+        array_walk( $properties, function( $value, $key ) {
164
+            if( !property_exists( $this, $key ) || isset($this->$key) ) {
165 165
                 return;
166 166
             }
167
-            $this->$key = maybe_unserialize($value);
167
+            $this->$key = maybe_unserialize( $value );
168 168
         });
169 169
     }
170 170
 
171 171
     /**
172 172
      * @return void
173 173
      */
174
-    protected function setTermIds(WP_Post $post)
174
+    protected function setTermIds( WP_Post $post )
175 175
     {
176 176
         $this->term_ids = [];
177
-        if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) {
177
+        if( !is_array( $terms = get_the_terms( $post, Application::TAXONOMY ) ) ) {
178 178
             return;
179 179
         }
180
-        foreach ($terms as $term) {
180
+        foreach( $terms as $term ) {
181 181
             $this->term_ids[] = $term->term_id;
182 182
         }
183 183
     }
Please login to merge, or discard this patch.
plugin/Shortcodes/SiteReviewsPopup.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -10,71 +10,71 @@
 block discarded – undo
10 10
     public function fields()
11 11
     {
12 12
         return [[
13
-            'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')),
13
+            'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' ) ),
14 14
             'minWidth' => 320,
15 15
             'type' => 'container',
16 16
         ], [
17
-            'label' => esc_html__('Title', 'site-reviews'),
17
+            'label' => esc_html__( 'Title', 'site-reviews' ),
18 18
             'name' => 'title',
19
-            'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'),
19
+            'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ),
20 20
             'type' => 'textbox',
21 21
         ], [
22
-            'label' => esc_html__('Display', 'site-reviews'),
22
+            'label' => esc_html__( 'Display', 'site-reviews' ),
23 23
             'maxLength' => 5,
24 24
             'name' => 'display',
25 25
             'size' => 3,
26 26
             'text' => '10',
27
-            'tooltip' => __('How many reviews would you like to display (default: 10)?', 'site-reviews'),
27
+            'tooltip' => __( 'How many reviews would you like to display (default: 10)?', 'site-reviews' ),
28 28
             'type' => 'textbox',
29 29
         ], [
30
-            'label' => esc_html__('Rating', 'site-reviews'),
30
+            'label' => esc_html__( 'Rating', 'site-reviews' ),
31 31
             'name' => 'rating',
32 32
             'options' => [
33
-                '5' => esc_html(sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5)),
34
-                '4' => esc_html(sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4)),
35
-                '3' => esc_html(sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3)),
36
-                '2' => esc_html(sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2)),
37
-                '1' => esc_html(sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1)),
38
-                '0' => esc_html(__('Unrated', 'site-reviews')),
33
+                '5' => esc_html( sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 ) ),
34
+                '4' => esc_html( sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 ) ),
35
+                '3' => esc_html( sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 ) ),
36
+                '2' => esc_html( sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 ) ),
37
+                '1' => esc_html( sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 ) ),
38
+                '0' => esc_html( __( 'Unrated', 'site-reviews' ) ),
39 39
             ],
40
-            'tooltip' => __('What is the minimum rating to display (default: 1 star)?', 'site-reviews'),
40
+            'tooltip' => __( 'What is the minimum rating to display (default: 1 star)?', 'site-reviews' ),
41 41
             'type' => 'listbox',
42 42
         ], [
43
-            'label' => esc_html__('Pagination', 'site-reviews'),
43
+            'label' => esc_html__( 'Pagination', 'site-reviews' ),
44 44
             'name' => 'pagination',
45 45
             'options' => [
46
-                'true' => esc_html__('Enable', 'site-reviews'),
47
-                'ajax' => esc_html__('Enable (using ajax)', 'site-reviews'),
48
-                'false' => esc_html__('Disable', 'site-reviews'),
46
+                'true' => esc_html__( 'Enable', 'site-reviews' ),
47
+                'ajax' => esc_html__( 'Enable (using ajax)', 'site-reviews' ),
48
+                'false' => esc_html__( 'Disable', 'site-reviews' ),
49 49
             ],
50
-            'tooltip' => __('When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews'),
50
+            'tooltip' => __( 'When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews' ),
51 51
             'type' => 'listbox',
52 52
         ],
53
-        $this->getTypes(__('Which type of review would you like to display?', 'site-reviews')),
54
-        $this->getCategories(__('Limit reviews to this category.', 'site-reviews')),
53
+        $this->getTypes( __( 'Which type of review would you like to display?', 'site-reviews' ) ),
54
+        $this->getCategories( __( 'Limit reviews to this category.', 'site-reviews' ) ),
55 55
         [
56
-            'label' => esc_html__('Assigned To', 'site-reviews'),
56
+            'label' => esc_html__( 'Assigned To', 'site-reviews' ),
57 57
             'name' => 'assigned_to',
58
-            'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'),
58
+            'tooltip' => __( 'Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews' ),
59 59
             'type' => 'textbox',
60 60
         ], [
61
-            'label' => esc_html__('Schema', 'site-reviews'),
61
+            'label' => esc_html__( 'Schema', 'site-reviews' ),
62 62
             'name' => 'schema',
63 63
             'options' => [
64
-                'true' => esc_html__('Enable rich snippets', 'site-reviews'),
65
-                'false' => esc_html__('Disable rich snippets', 'site-reviews'),
64
+                'true' => esc_html__( 'Enable rich snippets', 'site-reviews' ),
65
+                'false' => esc_html__( 'Disable rich snippets', 'site-reviews' ),
66 66
             ],
67
-            'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'),
67
+            'tooltip' => __( 'Rich snippets are disabled by default.', 'site-reviews' ),
68 68
             'type' => 'listbox',
69 69
         ], [
70
-            'label' => esc_html__('Classes', 'site-reviews'),
70
+            'label' => esc_html__( 'Classes', 'site-reviews' ),
71 71
             'name' => 'class',
72
-            'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'),
72
+            'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ),
73 73
             'type' => 'textbox',
74 74
         ], [
75 75
             'columns' => 2,
76 76
             'items' => $this->getHideOptions(),
77
-            'label' => esc_html__('Hide', 'site-reviews'),
77
+            'label' => esc_html__( 'Hide', 'site-reviews' ),
78 78
             'layout' => 'grid',
79 79
             'spacing' => 5,
80 80
             'type' => 'container',
Please login to merge, or discard this patch.
plugin/Controllers/WelcomeController.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -12,11 +12,11 @@  discard block
 block discarded – undo
12 12
      * @return array
13 13
      * @filter plugin_action_links_site-reviews/site-reviews.php
14 14
      */
15
-    public function filterActionLinks(array $links)
15
+    public function filterActionLinks( array $links )
16 16
     {
17
-        $links['welcome'] = glsr(Builder::class)->a(__('About', 'site-reviews'), [
18
-            'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome'),
19
-        ]);
17
+        $links['welcome'] = glsr( Builder::class )->a( __( 'About', 'site-reviews' ), [
18
+            'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=welcome' ),
19
+        ] );
20 20
         return $links;
21 21
     }
22 22
 
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
      * @return string
25 25
      * @filter admin_title
26 26
      */
27
-    public function filterAdminTitle($title)
27
+    public function filterAdminTitle( $title )
28 28
     {
29 29
         return Application::POST_TYPE.'_page_welcome' == glsr_current_screen()->id
30
-            ? sprintf(__('Welcome to %s &#8212; WordPress', 'site-reviews'), glsr()->name)
30
+            ? sprintf( __( 'Welcome to %s &#8212; WordPress', 'site-reviews' ), glsr()->name )
31 31
             : $title;
32 32
     }
33 33
 
@@ -36,17 +36,17 @@  discard block
 block discarded – undo
36 36
      * @return string
37 37
      * @filter admin_footer_text
38 38
      */
39
-    public function filterFooterText($text)
39
+    public function filterFooterText( $text )
40 40
     {
41
-        if (Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id) {
41
+        if( Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id ) {
42 42
             return $text;
43 43
         }
44 44
         $url = 'https://wordpress.org/support/view/plugin-reviews/site-reviews?filter=5#new-post';
45
-        return wp_kses_post(sprintf(
46
-            __('Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews'),
45
+        return wp_kses_post( sprintf(
46
+            __( 'Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews' ),
47 47
             '<strong>'.glsr()->name.'</strong> <a href="'.$url.'" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>',
48 48
             '<a href="'.$url.'" target="_blank">wordpress.org</a>'
49
-        ));
49
+        ) );
50 50
     }
51 51
 
52 52
     /**
@@ -55,12 +55,12 @@  discard block
 block discarded – undo
55 55
      * @return void
56 56
      * @action activated_plugin
57 57
      */
58
-    public function redirectOnActivation($plugin, $isNetworkActivation)
58
+    public function redirectOnActivation( $plugin, $isNetworkActivation )
59 59
     {
60
-        if (!$isNetworkActivation
60
+        if( !$isNetworkActivation
61 61
             && 'cli' !== php_sapi_name()
62
-            && $plugin === plugin_basename(glsr()->file)) {
63
-            wp_safe_redirect(admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome'));
62
+            && $plugin === plugin_basename( glsr()->file ) ) {
63
+            wp_safe_redirect( admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=welcome' ) );
64 64
             exit;
65 65
         }
66 66
     }
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function registerPage()
73 73
     {
74
-        add_submenu_page('edit.php?post_type='.Application::POST_TYPE,
75
-            sprintf(__('Welcome to %s', 'site-reviews'), glsr()->name),
74
+        add_submenu_page( 'edit.php?post_type='.Application::POST_TYPE,
75
+            sprintf( __( 'Welcome to %s', 'site-reviews' ), glsr()->name ),
76 76
             glsr()->name,
77
-            glsr()->getPermission('welcome'),
77
+            glsr()->getPermission( 'welcome' ),
78 78
             'welcome',
79 79
             [$this, 'renderPage']
80 80
         );
81
-        remove_submenu_page('edit.php?post_type='.Application::POST_TYPE, 'welcome');
81
+        remove_submenu_page( 'edit.php?post_type='.Application::POST_TYPE, 'welcome' );
82 82
     }
83 83
 
84 84
     /**
@@ -88,17 +88,17 @@  discard block
 block discarded – undo
88 88
      */
89 89
     public function renderPage()
90 90
     {
91
-        $tabs = apply_filters('site-reviews/addon/welcome/tabs', [
92
-            'getting-started' => __('Getting Started', 'site-reviews'),
93
-            'whatsnew' => __('What\'s New', 'site-reviews'),
94
-            'upgrade-guide' => __('Upgrade Guide', 'site-reviews'),
95
-            'support' => __('Support', 'site-reviews'),
96
-        ]);
97
-        glsr()->render('pages/welcome/index', [
91
+        $tabs = apply_filters( 'site-reviews/addon/welcome/tabs', [
92
+            'getting-started' => __( 'Getting Started', 'site-reviews' ),
93
+            'whatsnew' => __( 'What\'s New', 'site-reviews' ),
94
+            'upgrade-guide' => __( 'Upgrade Guide', 'site-reviews' ),
95
+            'support' => __( 'Support', 'site-reviews' ),
96
+        ] );
97
+        glsr()->render( 'pages/welcome/index', [
98 98
             'data' => ['context' => []],
99
-            'http_referer' => (string) wp_get_referer(),
99
+            'http_referer' => (string)wp_get_referer(),
100 100
             'tabs' => $tabs,
101
-            'template' => glsr(Template::class),
102
-        ]);
101
+            'template' => glsr( Template::class ),
102
+        ] );
103 103
     }
104 104
 }
Please login to merge, or discard this patch.
plugin/Defaults/DefaultsAbstract.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
      * @param string $name
30 30
      * @return void|array
31 31
      */
32
-    public function __call($name, array $args = [])
32
+    public function __call( $name, array $args = [] )
33 33
     {
34
-        if (!method_exists($this, $name) || !in_array($name, $this->callable)) {
34
+        if( !method_exists( $this, $name ) || !in_array( $name, $this->callable ) ) {
35 35
             return;
36 36
         }
37
-        $args[0] = $this->mapKeys(Arr::get($args, 0, []));
38
-        $defaults = call_user_func_array([$this, $name], $args);
39
-        $hookName = (new ReflectionClass($this))->getShortName();
40
-        $hookName = str_replace('Defaults', '', $hookName);
41
-        $hookName = Str::dashCase($hookName);
42
-        return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name);
37
+        $args[0] = $this->mapKeys( Arr::get( $args, 0, [] ) );
38
+        $defaults = call_user_func_array( [$this, $name], $args );
39
+        $hookName = (new ReflectionClass( $this ))->getShortName();
40
+        $hookName = str_replace( 'Defaults', '', $hookName );
41
+        $hookName = Str::dashCase( $hookName );
42
+        return apply_filters( 'site-reviews/defaults/'.$hookName, $defaults, $name );
43 43
     }
44 44
 
45 45
     /**
@@ -50,38 +50,38 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * @return array
52 52
      */
53
-    protected function filter(array $values = [])
53
+    protected function filter( array $values = [] )
54 54
     {
55
-        return $this->normalize($this->merge(array_filter($values)), $values);
55
+        return $this->normalize( $this->merge( array_filter( $values ) ), $values );
56 56
     }
57 57
 
58 58
     /**
59 59
      * @return string
60 60
      */
61
-    protected function filteredJson(array $values = [])
61
+    protected function filteredJson( array $values = [] )
62 62
     {
63 63
         $defaults = $this->flattenArray(
64
-            array_diff_key($this->defaults(), array_flip($this->guarded))
64
+            array_diff_key( $this->defaults(), array_flip( $this->guarded ) )
65 65
         );
66 66
         $values = $this->flattenArray(
67
-            shortcode_atts($defaults, $values)
67
+            shortcode_atts( $defaults, $values )
68 68
         );
69
-        $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) {
70
-            return !$this->isEmpty($value);
69
+        $filtered = array_filter( array_diff_assoc( $values, $defaults ), function( $value ) {
70
+            return !$this->isEmpty( $value );
71 71
         });
72
-        return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
72
+        return json_encode( $filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
73 73
     }
74 74
 
75 75
     /**
76 76
      * @return array
77 77
      */
78
-    protected function flattenArray(array $values)
78
+    protected function flattenArray( array $values )
79 79
     {
80
-        array_walk($values, function (&$value) {
81
-            if (!is_array($value)) {
80
+        array_walk( $values, function( &$value ) {
81
+            if( !is_array( $value ) ) {
82 82
                 return;
83 83
             }
84
-            $value = implode(',', $value);
84
+            $value = implode( ',', $value );
85 85
         });
86 86
         return $values;
87 87
     }
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
      * @param mixed $var
91 91
      * @return bool
92 92
      */
93
-    protected function isEmpty($var)
93
+    protected function isEmpty( $var )
94 94
     {
95
-        return !is_numeric($var) && !is_bool($var) && empty($var);
95
+        return !is_numeric( $var ) && !is_bool( $var ) && empty($var);
96 96
     }
97 97
 
98 98
     /**
99 99
      * @return array
100 100
      */
101
-    protected function mapKeys(array $args)
101
+    protected function mapKeys( array $args )
102 102
     {
103
-        foreach ($this->mapped as $old => $new) {
104
-            if (array_key_exists($old, $args)) {
103
+        foreach( $this->mapped as $old => $new ) {
104
+            if( array_key_exists( $old, $args ) ) {
105 105
                 $args[$new] = $args[$old];
106 106
                 unset($args[$old]);
107 107
             }
@@ -112,26 +112,26 @@  discard block
 block discarded – undo
112 112
     /**
113 113
      * @return array
114 114
      */
115
-    protected function merge(array $values = [])
115
+    protected function merge( array $values = [] )
116 116
     {
117
-        return $this->normalize(wp_parse_args($values, $this->defaults()), $values);
117
+        return $this->normalize( wp_parse_args( $values, $this->defaults() ), $values );
118 118
     }
119 119
 
120 120
     /**
121 121
      * @return array
122 122
      */
123
-    protected function normalize(array $values, array $originalValues)
123
+    protected function normalize( array $values, array $originalValues )
124 124
     {
125
-        $values['json'] = $this->filteredJson($originalValues);
125
+        $values['json'] = $this->filteredJson( $originalValues );
126 126
         return $values;
127 127
     }
128 128
 
129 129
     /**
130 130
      * @return array
131 131
      */
132
-    protected function restrict(array $values = [])
132
+    protected function restrict( array $values = [] )
133 133
     {
134
-        return $this->normalize(shortcode_atts($this->defaults(), $values), $values);
134
+        return $this->normalize( shortcode_atts( $this->defaults(), $values ), $values );
135 135
     }
136 136
 
137 137
     /**
@@ -139,6 +139,6 @@  discard block
 block discarded – undo
139 139
      */
140 140
     protected function unguarded()
141 141
     {
142
-        return array_diff_key($this->defaults(), array_flip($this->guarded));
142
+        return array_diff_key( $this->defaults(), array_flip( $this->guarded ) );
143 143
     }
144 144
 }
Please login to merge, or discard this patch.
plugin/Container.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      */
46 46
     public static function load()
47 47
     {
48
-        if (empty(static::$instance)) {
48
+        if( empty(static::$instance) ) {
49 49
             static::$instance = new static();
50 50
         }
51 51
         return static::$instance;
@@ -55,16 +55,16 @@  discard block
 block discarded – undo
55 55
      * @param string $property
56 56
      * @return mixed
57 57
      */
58
-    public function __get($property)
58
+    public function __get( $property )
59 59
     {
60
-        if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) {
60
+        if( property_exists( $this, $property ) && !in_array( $property, static::PROTECTED_PROPERTIES ) ) {
61 61
             return $this->$property;
62 62
         }
63
-        $constant = 'static::'.strtoupper(Str::snakeCase($property));
64
-        if (defined($constant)) {
65
-            return constant($constant);
63
+        $constant = 'static::'.strtoupper( Str::snakeCase( $property ) );
64
+        if( defined( $constant ) ) {
65
+            return constant( $constant );
66 66
         }
67
-        return Arr::get($this->storage, $property, null);
67
+        return Arr::get( $this->storage, $property, null );
68 68
     }
69 69
 
70 70
     /**
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
      * @param string $value
73 73
      * @return void
74 74
      */
75
-    public function __set($property, $value)
75
+    public function __set( $property, $value )
76 76
     {
77
-        if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) {
77
+        if( !property_exists( $this, $property ) || in_array( $property, static::PROTECTED_PROPERTIES ) ) {
78 78
             $this->storage[$property] = $value;
79
-        } elseif (!isset($this->$property)) {
79
+        } elseif( !isset($this->$property) ) {
80 80
             $this->$property = $value;
81 81
         } else {
82
-            throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property));
82
+            throw new Exception( sprintf( 'The "%s" property cannot be changed once set.', $property ) );
83 83
         }
84 84
     }
85 85
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      * @param mixed $concrete
90 90
      * @return mixed
91 91
      */
92
-    public function bind($alias, $concrete)
92
+    public function bind( $alias, $concrete )
93 93
     {
94 94
         $this->services[$alias] = $concrete;
95 95
     }
@@ -99,21 +99,21 @@  discard block
 block discarded – undo
99 99
      * @param mixed $abstract
100 100
      * @return mixed
101 101
      */
102
-    public function make($abstract)
102
+    public function make( $abstract )
103 103
     {
104
-        if (!isset($this->services[$abstract])) {
105
-            $abstract = $this->addNamespace($abstract);
104
+        if( !isset($this->services[$abstract]) ) {
105
+            $abstract = $this->addNamespace( $abstract );
106 106
         }
107
-        if (isset($this->services[$abstract])) {
107
+        if( isset($this->services[$abstract]) ) {
108 108
             $abstract = $this->services[$abstract];
109 109
         }
110
-        if (is_callable($abstract)) {
111
-            return call_user_func_array($abstract, [$this]);
110
+        if( is_callable( $abstract ) ) {
111
+            return call_user_func_array( $abstract, [$this] );
112 112
         }
113
-        if (is_object($abstract)) {
113
+        if( is_object( $abstract ) ) {
114 114
             return $abstract;
115 115
         }
116
-        return $this->resolve($abstract);
116
+        return $this->resolve( $abstract );
117 117
     }
118 118
 
119 119
     /**
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
     /**
128 128
      * @return mixed
129 129
      */
130
-    public function sessionGet($key, $fallback = '')
130
+    public function sessionGet( $key, $fallback = '' )
131 131
     {
132
-        $value = Arr::get($this->session, $key, $fallback);
132
+        $value = Arr::get( $this->session, $key, $fallback );
133 133
         unset($this->session[$key]);
134 134
         return $value;
135 135
     }
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     /**
138 138
      * @return void
139 139
      */
140
-    public function sessionSet($key, $value)
140
+    public function sessionSet( $key, $value )
141 141
     {
142 142
         $this->session[$key] = $value;
143 143
     }
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
      * @param callable|string|null $binding
149 149
      * @return void
150 150
      */
151
-    public function singleton($alias, $binding)
151
+    public function singleton( $alias, $binding )
152 152
     {
153
-        $this->bind($alias, $this->make($binding));
153
+        $this->bind( $alias, $this->make( $binding ) );
154 154
     }
155 155
 
156 156
     /**
@@ -158,9 +158,9 @@  discard block
 block discarded – undo
158 158
      * @param string $abstract
159 159
      * @return string
160 160
      */
161
-    protected function addNamespace($abstract)
161
+    protected function addNamespace( $abstract )
162 162
     {
163
-        if (!Str::contains($abstract, __NAMESPACE__) && !class_exists($abstract)) {
163
+        if( !Str::contains( $abstract, __NAMESPACE__ ) && !class_exists( $abstract ) ) {
164 164
             $abstract = __NAMESPACE__.'\\'.$abstract;
165 165
         }
166 166
         return $abstract;
@@ -172,21 +172,21 @@  discard block
 block discarded – undo
172 172
      * @return mixed
173 173
      * @throws Exception
174 174
      */
175
-    protected function resolve($concrete)
175
+    protected function resolve( $concrete )
176 176
     {
177
-        if ($concrete instanceof Closure) {
178
-            return $concrete($this);
177
+        if( $concrete instanceof Closure ) {
178
+            return $concrete( $this );
179 179
         }
180
-        $reflector = new ReflectionClass($concrete);
181
-        if (!$reflector->isInstantiable()) {
182
-            throw new Exception('Target ['.$concrete.'] is not instantiable.');
180
+        $reflector = new ReflectionClass( $concrete );
181
+        if( !$reflector->isInstantiable() ) {
182
+            throw new Exception( 'Target ['.$concrete.'] is not instantiable.' );
183 183
         }
184 184
         $constructor = $reflector->getConstructor();
185
-        if (empty($constructor)) {
185
+        if( empty($constructor) ) {
186 186
             return new $concrete();
187 187
         }
188 188
         return $reflector->newInstanceArgs(
189
-            $this->resolveDependencies($constructor->getParameters())
189
+            $this->resolveDependencies( $constructor->getParameters() )
190 190
         );
191 191
     }
192 192
 
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
      * @return mixed
196 196
      * @throws Exception
197 197
      */
198
-    protected function resolveClass(ReflectionParameter $parameter)
198
+    protected function resolveClass( ReflectionParameter $parameter )
199 199
     {
200 200
         try {
201
-            return $this->make($parameter->getClass()->name);
202
-        } catch (Exception $error) {
203
-            if ($parameter->isOptional()) {
201
+            return $this->make( $parameter->getClass()->name );
202
+        } catch( Exception $error ) {
203
+            if( $parameter->isOptional() ) {
204 204
                 return $parameter->getDefaultValue();
205 205
             }
206 206
             throw $error;
@@ -211,13 +211,13 @@  discard block
 block discarded – undo
211 211
      * Resolve all of the dependencies from the ReflectionParameters.
212 212
      * @return array
213 213
      */
214
-    protected function resolveDependencies(array $dependencies)
214
+    protected function resolveDependencies( array $dependencies )
215 215
     {
216 216
         $results = [];
217
-        foreach ($dependencies as $dependency) {
218
-            $results[] = !is_null($class = $dependency->getClass())
219
-                ? $this->resolveClass($dependency)
220
-                : $this->resolveDependency($dependency);
217
+        foreach( $dependencies as $dependency ) {
218
+            $results[] = !is_null( $class = $dependency->getClass() )
219
+                ? $this->resolveClass( $dependency )
220
+                : $this->resolveDependency( $dependency );
221 221
         }
222 222
         return $results;
223 223
     }
@@ -226,9 +226,9 @@  discard block
 block discarded – undo
226 226
      * Resolve a single ReflectionParameter dependency.
227 227
      * @return array|null
228 228
      */
229
-    protected function resolveDependency(ReflectionParameter $parameter)
229
+    protected function resolveDependency( ReflectionParameter $parameter )
230 230
     {
231
-        if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) {
231
+        if( $parameter->isArray() && $parameter->isDefaultValueAvailable() ) {
232 232
             return $parameter->getDefaultValue();
233 233
         }
234 234
         return null;
Please login to merge, or discard this patch.
plugin/Modules/Translation.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
     public function all()
31 31
     {
32 32
         $translations = $this->translations();
33
-        $entries = $this->filter($translations, $this->entries())->results();
34
-        array_walk($translations, function (&$entry) use ($entries) {
35
-            $entry['desc'] = array_key_exists($entry['id'], $entries)
36
-                ? $this->getEntryString($entries[$entry['id']], 'msgctxt')
33
+        $entries = $this->filter( $translations, $this->entries() )->results();
34
+        array_walk( $translations, function( &$entry ) use ($entries) {
35
+            $entry['desc'] = array_key_exists( $entry['id'], $entries )
36
+                ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' )
37 37
                 : '';
38 38
         });
39 39
         return $translations;
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
      */
45 45
     public function entries()
46 46
     {
47
-        if (!isset($this->entries)) {
48
-            $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot');
49
-            $entries = $this->extractEntriesFromPotFile($potFile);
50
-            $entries = apply_filters('site-reviews/translation/entries', $entries);
47
+        if( !isset($this->entries) ) {
48
+            $potFile = glsr()->path( glsr()->languages.'/'.Application::ID.'.pot' );
49
+            $entries = $this->extractEntriesFromPotFile( $potFile );
50
+            $entries = apply_filters( 'site-reviews/translation/entries', $entries );
51 51
             $this->entries = $entries;
52 52
         }
53 53
         return $this->entries;
@@ -58,24 +58,24 @@  discard block
 block discarded – undo
58 58
      * @param array|null $entries
59 59
      * @return static
60 60
      */
61
-    public function exclude($entriesToExclude = null, $entries = null)
61
+    public function exclude( $entriesToExclude = null, $entries = null )
62 62
     {
63
-        return $this->filter($entriesToExclude, $entries, false);
63
+        return $this->filter( $entriesToExclude, $entries, false );
64 64
     }
65 65
 
66 66
     /**
67 67
      * @param string $potFile
68 68
      * @return array
69 69
      */
70
-    public function extractEntriesFromPotFile($potFile, array $entries = [])
70
+    public function extractEntriesFromPotFile( $potFile, array $entries = [] )
71 71
     {
72 72
         try {
73
-            $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries());
74
-            foreach ($potEntries as $key => $entry) {
75
-                $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry;
73
+            $potEntries = $this->normalize( Parser::parseFile( $potFile )->getEntries() );
74
+            foreach( $potEntries as $key => $entry ) {
75
+                $entries[html_entity_decode( $key, ENT_COMPAT, 'UTF-8' )] = $entry;
76 76
             }
77
-        } catch (Exception $e) {
78
-            glsr_log()->error($e->getMessage());
77
+        } catch( Exception $e ) {
78
+            glsr_log()->error( $e->getMessage() );
79 79
         }
80 80
         return $entries;
81 81
     }
@@ -86,18 +86,18 @@  discard block
 block discarded – undo
86 86
      * @param bool $intersect
87 87
      * @return static
88 88
      */
89
-    public function filter($filterWith = null, $entries = null, $intersect = true)
89
+    public function filter( $filterWith = null, $entries = null, $intersect = true )
90 90
     {
91
-        if (!is_array($entries)) {
91
+        if( !is_array( $entries ) ) {
92 92
             $entries = $this->results;
93 93
         }
94
-        if (!is_array($filterWith)) {
94
+        if( !is_array( $filterWith ) ) {
95 95
             $filterWith = $this->translations();
96 96
         }
97
-        $keys = array_flip(glsr_array_column($filterWith, 'id'));
97
+        $keys = array_flip( glsr_array_column( $filterWith, 'id' ) );
98 98
         $this->results = $intersect
99
-            ? array_intersect_key($entries, $keys)
100
-            : array_diff_key($entries, $keys);
99
+            ? array_intersect_key( $entries, $keys )
100
+            : array_diff_key( $entries, $keys );
101 101
         return $this;
102 102
     }
103 103
 
@@ -105,20 +105,20 @@  discard block
 block discarded – undo
105 105
      * @param string $template
106 106
      * @return string
107 107
      */
108
-    public function render($template, array $entry)
108
+    public function render( $template, array $entry )
109 109
     {
110 110
         $data = array_combine(
111
-            array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)),
111
+            array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ),
112 112
             $entry
113 113
         );
114 114
         $data['data.class'] = $data['data.error'] = '';
115
-        if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) {
115
+        if( false === array_search( $entry['s1'], glsr_array_column( $this->entries(), 'msgid' ) ) ) {
116 116
             $data['data.class'] = 'is-invalid';
117
-            $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews');
117
+            $data['data.error'] = __( 'This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews' );
118 118
         }
119
-        return glsr(Template::class)->build('partials/translations/'.$template, [
120
-            'context' => array_map('esc_html', $data),
121
-        ]);
119
+        return glsr( Template::class )->build( 'partials/translations/'.$template, [
120
+            'context' => array_map( 'esc_html', $data ),
121
+        ] );
122 122
     }
123 123
 
124 124
     /**
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
     public function renderAll()
129 129
     {
130 130
         $rendered = '';
131
-        foreach ($this->all() as $index => $entry) {
131
+        foreach( $this->all() as $index => $entry ) {
132 132
             $entry['index'] = $index;
133 133
             $entry['prefix'] = OptionManager::databaseKey();
134
-            $rendered.= $this->render($entry['type'], $entry);
134
+            $rendered .= $this->render( $entry['type'], $entry );
135 135
         }
136 136
         return $rendered;
137 137
     }
@@ -140,25 +140,25 @@  discard block
 block discarded – undo
140 140
      * @param bool $resetAfterRender
141 141
      * @return string
142 142
      */
143
-    public function renderResults($resetAfterRender = true)
143
+    public function renderResults( $resetAfterRender = true )
144 144
     {
145 145
         $rendered = '';
146
-        foreach ($this->results as $id => $entry) {
146
+        foreach( $this->results as $id => $entry ) {
147 147
             $data = [
148
-                'desc' => $this->getEntryString($entry, 'msgctxt'),
148
+                'desc' => $this->getEntryString( $entry, 'msgctxt' ),
149 149
                 'id' => $id,
150
-                'p1' => $this->getEntryString($entry, 'msgid_plural'),
151
-                's1' => $this->getEntryString($entry, 'msgid'),
150
+                'p1' => $this->getEntryString( $entry, 'msgid_plural' ),
151
+                's1' => $this->getEntryString( $entry, 'msgid' ),
152 152
             ];
153 153
             $text = !empty($data['p1'])
154
-                ? sprintf('%s | %s', $data['s1'], $data['p1'])
154
+                ? sprintf( '%s | %s', $data['s1'], $data['p1'] )
155 155
                 : $data['s1'];
156
-            $rendered.= $this->render('result', [
157
-                'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
158
-                'text' => wp_strip_all_tags($text),
159
-            ]);
156
+            $rendered .= $this->render( 'result', [
157
+                'entry' => json_encode( $data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ),
158
+                'text' => wp_strip_all_tags( $text ),
159
+            ] );
160 160
         }
161
-        if ($resetAfterRender) {
161
+        if( $resetAfterRender ) {
162 162
             $this->reset();
163 163
         }
164 164
         return $rendered;
@@ -186,18 +186,18 @@  discard block
 block discarded – undo
186 186
      * @param string $needle
187 187
      * @return static
188 188
      */
189
-    public function search($needle = '')
189
+    public function search( $needle = '' )
190 190
     {
191 191
         $this->reset();
192
-        $needle = trim(strtolower($needle));
193
-        foreach ($this->entries() as $key => $entry) {
194
-            $single = strtolower($this->getEntryString($entry, 'msgid'));
195
-            $plural = strtolower($this->getEntryString($entry, 'msgid_plural'));
196
-            if (strlen($needle) < static::SEARCH_THRESHOLD) {
197
-                if (in_array($needle, [$single, $plural])) {
192
+        $needle = trim( strtolower( $needle ) );
193
+        foreach( $this->entries() as $key => $entry ) {
194
+            $single = strtolower( $this->getEntryString( $entry, 'msgid' ) );
195
+            $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) );
196
+            if( strlen( $needle ) < static::SEARCH_THRESHOLD ) {
197
+                if( in_array( $needle, [$single, $plural] ) ) {
198 198
                     $this->results[$key] = $entry;
199 199
                 }
200
-            } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) {
200
+            } elseif( Str::contains( sprintf( '%s %s', $single, $plural ), $needle ) ) {
201 201
                 $this->results[$key] = $entry;
202 202
             }
203 203
         }
@@ -211,10 +211,10 @@  discard block
 block discarded – undo
211 211
     public function translations()
212 212
     {
213 213
         static $translations;
214
-        if (empty($translations)) {
215
-            $settings = glsr(OptionManager::class)->get('settings');
214
+        if( empty($translations) ) {
215
+            $settings = glsr( OptionManager::class )->get( 'settings' );
216 216
             $translations = isset($settings['strings'])
217
-                ? $this->normalizeSettings((array) $settings['strings'])
217
+                ? $this->normalizeSettings( (array)$settings['strings'] )
218 218
                 : [];
219 219
         }
220 220
         return $translations;
@@ -224,28 +224,28 @@  discard block
 block discarded – undo
224 224
      * @param string $key
225 225
      * @return string
226 226
      */
227
-    protected function getEntryString(array $entry, $key)
227
+    protected function getEntryString( array $entry, $key )
228 228
     {
229 229
         return isset($entry[$key])
230
-            ? implode('', (array) $entry[$key])
230
+            ? implode( '', (array)$entry[$key] )
231 231
             : '';
232 232
     }
233 233
 
234 234
     /**
235 235
      * @return array
236 236
      */
237
-    protected function normalize(array $entries)
237
+    protected function normalize( array $entries )
238 238
     {
239 239
         $keys = [
240 240
             'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]',
241 241
         ];
242
-        array_walk($entries, function (&$entry) use ($keys) {
243
-            foreach ($keys as $key) {
242
+        array_walk( $entries, function( &$entry ) use ($keys) {
243
+            foreach( $keys as $key ) {
244 244
                 try {
245
-                    $entry = $this->normalizeEntryString($entry, $key);
246
-                } catch (\TypeError $error) {
247
-                    glsr_log()->once('error', 'Translation/normalize', $error);
248
-                    glsr_log()->once('debug', 'Translation/normalize', $entry);
245
+                    $entry = $this->normalizeEntryString( $entry, $key );
246
+                } catch( \TypeError $error ) {
247
+                    glsr_log()->once( 'error', 'Translation/normalize', $error );
248
+                    glsr_log()->once( 'debug', 'Translation/normalize', $entry );
249 249
                 }
250 250
             }
251 251
         });
@@ -256,10 +256,10 @@  discard block
 block discarded – undo
256 256
      * @param string $key
257 257
      * @return array
258 258
      */
259
-    protected function normalizeEntryString(array $entry, $key)
259
+    protected function normalizeEntryString( array $entry, $key )
260 260
     {
261
-        if (isset($entry[$key])) {
262
-            $entry[$key] = $this->getEntryString($entry, $key);
261
+        if( isset($entry[$key]) ) {
262
+            $entry[$key] = $this->getEntryString( $entry, $key );
263 263
         }
264 264
         return $entry;
265 265
     }
@@ -267,15 +267,15 @@  discard block
 block discarded – undo
267 267
     /**
268 268
      * @return array
269 269
      */
270
-    protected function normalizeSettings(array $strings)
270
+    protected function normalizeSettings( array $strings )
271 271
     {
272
-        $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], '');
273
-        $strings = array_filter($strings, 'is_array');
274
-        foreach ($strings as &$string) {
272
+        $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' );
273
+        $strings = array_filter( $strings, 'is_array' );
274
+        foreach( $strings as &$string ) {
275 275
             $string['type'] = isset($string['p1']) ? 'plural' : 'single';
276
-            $string = wp_parse_args($string, $defaultString);
276
+            $string = wp_parse_args( $string, $defaultString );
277 277
         }
278
-        return array_filter($strings, function ($string) {
278
+        return array_filter( $strings, function( $string ) {
279 279
             return !empty($string['id']);
280 280
         });
281 281
     }
Please login to merge, or discard this patch.