@@ -37,18 +37,18 @@ discard block |
||
37 | 37 | * @param string $method |
38 | 38 | * @return static |
39 | 39 | */ |
40 | - public function __call($method, array $arguments) |
|
40 | + public function __call( $method, array $arguments ) |
|
41 | 41 | { |
42 | - return $this->setProperty($method, Arr::get($arguments, 0)); |
|
42 | + return $this->setProperty( $method, Arr::get( $arguments, 0 ) ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @param string $type |
47 | 47 | */ |
48 | - public function __construct($type = null) |
|
48 | + public function __construct( $type = null ) |
|
49 | 49 | { |
50 | - $this->type = !is_string($type) |
|
51 | - ? (new ReflectionClass($this))->getShortName() |
|
50 | + $this->type = !is_string( $type ) |
|
51 | + ? (new ReflectionClass( $this ))->getShortName() |
|
52 | 52 | : $type; |
53 | 53 | $this->setAllowedProperties(); |
54 | 54 | } |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | /** |
65 | 65 | * @return static |
66 | 66 | */ |
67 | - public function addProperties(array $properties) |
|
67 | + public function addProperties( array $properties ) |
|
68 | 68 | { |
69 | - foreach ($properties as $property => $value) { |
|
70 | - $this->setProperty($property, $value); |
|
69 | + foreach( $properties as $property => $value ) { |
|
70 | + $this->setProperty( $property, $value ); |
|
71 | 71 | } |
72 | 72 | return $this; |
73 | 73 | } |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | * @param mixed $default |
94 | 94 | * @return mixed |
95 | 95 | */ |
96 | - public function getProperty($property, $default = null) |
|
96 | + public function getProperty( $property, $default = null ) |
|
97 | 97 | { |
98 | - return Arr::get($this->properties, $property, $default); |
|
98 | + return Arr::get( $this->properties, $property, $default ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | * @param mixed $callback |
112 | 112 | * @return static |
113 | 113 | */ |
114 | - public function doIf($condition, $callback) |
|
114 | + public function doIf( $condition, $callback ) |
|
115 | 115 | { |
116 | - if ($condition) { |
|
117 | - $callback($this); |
|
116 | + if( $condition ) { |
|
117 | + $callback( $this ); |
|
118 | 118 | } |
119 | 119 | return $this; |
120 | 120 | } |
@@ -131,18 +131,18 @@ discard block |
||
131 | 131 | * @param mixed $offset |
132 | 132 | * @return bool |
133 | 133 | */ |
134 | - public function offsetExists($offset) |
|
134 | + public function offsetExists( $offset ) |
|
135 | 135 | { |
136 | - return array_key_exists($offset, $this->properties); |
|
136 | + return array_key_exists( $offset, $this->properties ); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
140 | 140 | * @param string $offset |
141 | 141 | * @return mixed |
142 | 142 | */ |
143 | - public function offsetGet($offset) |
|
143 | + public function offsetGet( $offset ) |
|
144 | 144 | { |
145 | - return $this->getProperty($offset); |
|
145 | + return $this->getProperty( $offset ); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -150,16 +150,16 @@ discard block |
||
150 | 150 | * @param mixed $value |
151 | 151 | * @return void |
152 | 152 | */ |
153 | - public function offsetSet($offset, $value) |
|
153 | + public function offsetSet( $offset, $value ) |
|
154 | 154 | { |
155 | - $this->setProperty($offset, $value); |
|
155 | + $this->setProperty( $offset, $value ); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * @param string $offset |
160 | 160 | * @return void |
161 | 161 | */ |
162 | - public function offsetUnset($offset) |
|
162 | + public function offsetUnset( $offset ) |
|
163 | 163 | { |
164 | 164 | unset($this->properties[$offset]); |
165 | 165 | } |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param mixed $value |
170 | 170 | * @return static |
171 | 171 | */ |
172 | - public function setProperty($property, $value) |
|
172 | + public function setProperty( $property, $value ) |
|
173 | 173 | { |
174 | - if (!in_array($property, $this->allowed) |
|
175 | - && 'UnknownType' != (new ReflectionClass($this))->getShortName()) { |
|
176 | - glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property'); |
|
174 | + if( !in_array( $property, $this->allowed ) |
|
175 | + && 'UnknownType' != (new ReflectionClass( $this ))->getShortName() ) { |
|
176 | + glsr_log()->warning( $this->getType().' does not allow the "'.$property.'" property' ); |
|
177 | 177 | return $this; |
178 | 178 | } |
179 | 179 | $this->properties[$property] = $value; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | return [ |
189 | 189 | '@context' => $this->getContext(), |
190 | 190 | '@type' => $this->getType(), |
191 | - ] + $this->serializeProperty($this->getProperties()); |
|
191 | + ] + $this->serializeProperty( $this->getProperties() ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function toScript() |
198 | 198 | { |
199 | - return sprintf('<script type="application/ld+json">%s</script>', |
|
200 | - json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) |
|
199 | + return sprintf( '<script type="application/ld+json">%s</script>', |
|
200 | + json_encode( $this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) |
|
201 | 201 | ); |
202 | 202 | } |
203 | 203 | |
@@ -205,20 +205,20 @@ discard block |
||
205 | 205 | * @param array|null $parents |
206 | 206 | * @return array |
207 | 207 | */ |
208 | - protected function getParents($parents = null) |
|
208 | + protected function getParents( $parents = null ) |
|
209 | 209 | { |
210 | - if (!isset($parents)) { |
|
210 | + if( !isset($parents) ) { |
|
211 | 211 | $parents = $this->parents; |
212 | 212 | } |
213 | 213 | $newParents = $parents; |
214 | - foreach ($parents as $parent) { |
|
215 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
216 | - if (!class_exists($parentClass)) { |
|
214 | + foreach( $parents as $parent ) { |
|
215 | + $parentClass = Helper::buildClassName( $parent, __NAMESPACE__ ); |
|
216 | + if( !class_exists( $parentClass ) ) { |
|
217 | 217 | continue; |
218 | 218 | } |
219 | - $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents)); |
|
219 | + $newParents = array_merge( $newParents, $this->getParents( (new $parentClass())->parents ) ); |
|
220 | 220 | } |
221 | - return array_values(array_unique($newParents)); |
|
221 | + return array_values( array_unique( $newParents ) ); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | protected function setAllowedProperties() |
228 | 228 | { |
229 | 229 | $parents = $this->getParents(); |
230 | - foreach ($parents as $parent) { |
|
231 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
232 | - if (!class_exists($parentClass)) { |
|
230 | + foreach( $parents as $parent ) { |
|
231 | + $parentClass = Helper::buildClassName( $parent, __NAMESPACE__ ); |
|
232 | + if( !class_exists( $parentClass ) ) { |
|
233 | 233 | continue; |
234 | 234 | } |
235 | - $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed))); |
|
235 | + $this->allowed = array_values( array_unique( array_merge( (new $parentClass())->allowed, $this->allowed ) ) ); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
@@ -240,19 +240,19 @@ discard block |
||
240 | 240 | * @param mixed $property |
241 | 241 | * @return array|string |
242 | 242 | */ |
243 | - protected function serializeProperty($property) |
|
243 | + protected function serializeProperty( $property ) |
|
244 | 244 | { |
245 | - if (is_array($property)) { |
|
246 | - return array_map([$this, 'serializeProperty'], $property); |
|
245 | + if( is_array( $property ) ) { |
|
246 | + return array_map( [$this, 'serializeProperty'], $property ); |
|
247 | 247 | } |
248 | - if ($property instanceof Type) { |
|
248 | + if( $property instanceof Type ) { |
|
249 | 249 | $property = $property->toArray(); |
250 | 250 | unset($property['@context']); |
251 | 251 | } |
252 | - if ($property instanceof DateTimeInterface) { |
|
253 | - $property = $property->format(DateTime::ATOM); |
|
252 | + if( $property instanceof DateTimeInterface ) { |
|
253 | + $property = $property->format( DateTime::ATOM ); |
|
254 | 254 | } |
255 | - if (is_object($property)) { |
|
255 | + if( is_object( $property ) ) { |
|
256 | 256 | throw new InvalidProperty(); |
257 | 257 | } |
258 | 258 | return $property; |
@@ -20,31 +20,31 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public $reviews; |
30 | 30 | |
31 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
31 | + public function __construct( array $reviews, $maxPageCount, array $args ) |
|
32 | 32 | { |
33 | 33 | $this->args = $args; |
34 | 34 | $this->max_num_pages = $maxPageCount; |
35 | 35 | $this->reviews = $reviews; |
36 | 36 | $this->pagination = $this->buildPagination(); |
37 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
37 | + parent::__construct( $reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function __toString() |
44 | 44 | { |
45 | - return glsr(Template::class)->build('templates/reviews', [ |
|
45 | + return glsr( Template::class )->build( 'templates/reviews', [ |
|
46 | 46 | 'args' => $this->args, |
47 | 47 | 'context' => [ |
48 | 48 | 'assigned_to' => $this->args['assigned_to'], |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | 'pagination' => $this->getPagination(), |
53 | 53 | 'reviews' => $this->getReviews(), |
54 | 54 | ], |
55 | - ]); |
|
55 | + ] ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function getPagination() |
62 | 62 | { |
63 | - return wp_validate_boolean($this->args['pagination']) |
|
63 | + return wp_validate_boolean( $this->args['pagination'] ) |
|
64 | 64 | ? $this->pagination |
65 | 65 | : ''; |
66 | 66 | } |
@@ -72,26 +72,26 @@ discard block |
||
72 | 72 | { |
73 | 73 | $html = empty($this->reviews) |
74 | 74 | ? $this->getReviewsFallback() |
75 | - : implode(PHP_EOL, $this->reviews); |
|
75 | + : implode( PHP_EOL, $this->reviews ); |
|
76 | 76 | $wrapper = '<div class="glsr-reviews">%s</div>'; |
77 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | - return sprintf($wrapper, $html); |
|
77 | + $wrapper = apply_filters( 'site-reviews/reviews/reviews-wrapper', $wrapper ); |
|
78 | + return sprintf( $wrapper, $html ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @param mixed $key |
83 | 83 | * @return mixed |
84 | 84 | */ |
85 | - public function offsetGet($key) |
|
85 | + public function offsetGet( $key ) |
|
86 | 86 | { |
87 | - if ('navigation' == $key) { |
|
87 | + if( 'navigation' == $key ) { |
|
88 | 88 | glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
89 | 89 | return $this->pagination; |
90 | 90 | } |
91 | - if (property_exists($this, $key)) { |
|
91 | + if( property_exists( $this, $key ) ) { |
|
92 | 92 | return $this->$key; |
93 | 93 | } |
94 | - return array_key_exists($key, $this->reviews) |
|
94 | + return array_key_exists( $key, $this->reviews ) |
|
95 | 95 | ? $this->reviews[$key] |
96 | 96 | : null; |
97 | 97 | } |
@@ -101,15 +101,15 @@ discard block |
||
101 | 101 | */ |
102 | 102 | protected function buildPagination() |
103 | 103 | { |
104 | - $html = glsr(Partial::class)->build('pagination', [ |
|
105 | - 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | - 'current' => Arr::get($this->args, 'paged'), |
|
104 | + $html = glsr( Partial::class )->build( 'pagination', [ |
|
105 | + 'baseUrl' => Arr::get( $this->args, 'pagedUrl' ), |
|
106 | + 'current' => Arr::get( $this->args, 'paged' ), |
|
107 | 107 | 'total' => $this->max_num_pages, |
108 | - ]); |
|
109 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
108 | + ] ); |
|
109 | + $html .= sprintf( '<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json'] ); |
|
110 | 110 | $wrapper = '<div class="glsr-pagination">%s</div>'; |
111 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | - return sprintf($wrapper, $html); |
|
111 | + $wrapper = apply_filters( 'site-reviews/reviews/pagination-wrapper', $wrapper ); |
|
112 | + return sprintf( $wrapper, $html ); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | $defaults = [ |
121 | 121 | 'glsr-default', |
122 | 122 | ]; |
123 | - if ('ajax' == $this->args['pagination']) { |
|
123 | + if( 'ajax' == $this->args['pagination'] ) { |
|
124 | 124 | $defaults[] = 'glsr-ajax-pagination'; |
125 | 125 | } |
126 | - $classes = explode(' ', $this->args['class']); |
|
127 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | - return implode(' ', $classes); |
|
126 | + $classes = explode( ' ', $this->args['class'] ); |
|
127 | + $classes = array_unique( array_merge( $defaults, array_filter( $classes ) ) ); |
|
128 | + return implode( ' ', $classes ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function getReviewsFallback() |
135 | 135 | { |
136 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
136 | + if( empty($this->args['fallback']) && glsr( OptionManager::class )->getBool( 'settings.reviews.fallback' ) ) { |
|
137 | + $this->args['fallback'] = __( 'There are no reviews yet. Be the first one to write one.', 'site-reviews' ); |
|
138 | 138 | } |
139 | 139 | $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
140 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
140 | + return apply_filters( 'site-reviews/reviews/fallback', $fallback, $this->args ); |
|
141 | 141 | } |
142 | 142 | } |
@@ -12,7 +12,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -11,17 +11,17 @@ discard block |
||
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); |
|
16 | + $data = $this->normalize( $data ); |
|
17 | 17 | ob_start(); |
18 | - glsr()->render($templatePath, $data); |
|
18 | + glsr()->render( $templatePath, $data ); |
|
19 | 19 | $template = ob_get_clean(); |
20 | - $path = Str::removePrefix('templates/', $templatePath); |
|
21 | - $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
22 | - $template = $this->interpolate($template, $data, $path); |
|
23 | - $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
24 | - $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
20 | + $path = Str::removePrefix( 'templates/', $templatePath ); |
|
21 | + $template = apply_filters( 'site-reviews/build/template/'.$path, $template, $data ); |
|
22 | + $template = $this->interpolate( $template, $data, $path ); |
|
23 | + $template = apply_filters( 'site-reviews/rendered/template', $template, $templatePath, $data ); |
|
24 | + $template = apply_filters( 'site-reviews/rendered/template/'.$path, $template, $data ); |
|
25 | 25 | return $template; |
26 | 26 | } |
27 | 27 | |
@@ -31,37 +31,37 @@ discard block |
||
31 | 31 | * @param string $templatePath |
32 | 32 | * @return string |
33 | 33 | */ |
34 | - public function interpolate($template, array $data = [], $templatePath) |
|
34 | + public function interpolate( $template, array $data = [], $templatePath ) |
|
35 | 35 | { |
36 | - $context = $this->normalizeContext(Arr::get($data, 'context', [])); |
|
37 | - $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
38 | - foreach ($context as $key => $value) { |
|
36 | + $context = $this->normalizeContext( Arr::get( $data, 'context', [] ) ); |
|
37 | + $context = apply_filters( 'site-reviews/interpolate/'.$templatePath, $context, $template, $data ); |
|
38 | + foreach( $context as $key => $value ) { |
|
39 | 39 | $template = strtr( |
40 | 40 | $template, |
41 | - array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
41 | + array_fill_keys( ['{'.$key.'}', '{{ '.$key.' }}'], $value ) |
|
42 | 42 | ); |
43 | 43 | } |
44 | - return trim($template); |
|
44 | + return trim( $template ); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @param string $templatePath |
49 | 49 | * @return void|string |
50 | 50 | */ |
51 | - public function render($templatePath, array $data = []) |
|
51 | + public function render( $templatePath, array $data = [] ) |
|
52 | 52 | { |
53 | - echo $this->build($templatePath, $data); |
|
53 | + echo $this->build( $templatePath, $data ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * @return array |
58 | 58 | */ |
59 | - protected function normalize(array $data) |
|
59 | + protected function normalize( array $data ) |
|
60 | 60 | { |
61 | 61 | $arrayKeys = ['context', 'globals']; |
62 | - $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
63 | - foreach ($arrayKeys as $key) { |
|
64 | - if (is_array($data[$key])) { |
|
62 | + $data = wp_parse_args( $data, array_fill_keys( $arrayKeys, [] ) ); |
|
63 | + foreach( $arrayKeys as $key ) { |
|
64 | + if( is_array( $data[$key] ) ) { |
|
65 | 65 | continue; |
66 | 66 | } |
67 | 67 | $data[$key] = []; |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | /** |
73 | 73 | * @return array |
74 | 74 | */ |
75 | - protected function normalizeContext(array $context) |
|
75 | + protected function normalizeContext( array $context ) |
|
76 | 76 | { |
77 | - $context = array_filter($context, function ($value) { |
|
78 | - return !is_array($value) && !is_object($value); |
|
77 | + $context = array_filter( $context, function( $value ) { |
|
78 | + return !is_array( $value ) && !is_object( $value ); |
|
79 | 79 | }); |
80 | - return array_map(function ($value) { |
|
81 | - return (string) $value; |
|
82 | - }, $context); |
|
80 | + return array_map( function( $value ) { |
|
81 | + return (string)$value; |
|
82 | + }, $context ); |
|
83 | 83 | } |
84 | 84 | } |
@@ -18,19 +18,19 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @return void|string |
20 | 20 | */ |
21 | - public function build(array $args = []) |
|
21 | + public function build( array $args = [] ) |
|
22 | 22 | { |
23 | - $this->args = $this->normalize($args); |
|
24 | - if ($this->args['total'] < 2) { |
|
23 | + $this->args = $this->normalize( $args ); |
|
24 | + if( $this->args['total'] < 2 ) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
27 | + return glsr( Template::class )->build( 'templates/pagination', [ |
|
28 | 28 | 'context' => [ |
29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
29 | + 'links' => apply_filters( 'site-reviews/paginate_links', $this->buildLinks(), $this->args ), |
|
30 | 30 | 'loader' => '<div class="glsr-loader"></div>', |
31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
31 | + 'screen_reader_text' => __( 'Site Reviews navigation', 'site-reviews' ), |
|
32 | 32 | ], |
33 | - ]); |
|
33 | + ] ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,27 +38,27 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected function buildLinks() |
40 | 40 | { |
41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | - if (is_front_page()) { |
|
41 | + $args = glsr( Style::class )->paginationArgs( $this->args ); |
|
42 | + if( is_front_page() ) { |
|
43 | 43 | unset($args['format']); |
44 | 44 | } |
45 | - if ('array' == $args['type']) { |
|
45 | + if( 'array' == $args['type'] ) { |
|
46 | 46 | $args['type'] = 'plain'; |
47 | 47 | } |
48 | - return paginate_links($args); |
|
48 | + return paginate_links( $args ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - protected function normalize(array $args) |
|
54 | + protected function normalize( array $args ) |
|
55 | 55 | { |
56 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
56 | + if( $baseUrl = Arr::get( $args, 'baseUrl' ) ) { |
|
57 | 57 | $args['base'] = $baseUrl.'%_%'; |
58 | 58 | } |
59 | - return wp_parse_args(array_filter($args), [ |
|
60 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
59 | + return wp_parse_args( array_filter( $args ), [ |
|
60 | + 'current' => glsr( QueryBuilder::class )->getPaged(), |
|
61 | 61 | 'total' => 1, |
62 | - ]); |
|
62 | + ] ); |
|
63 | 63 | } |
64 | 64 | } |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | { |
72 | 72 | $this->newSettings = $this->getNewSettings(); |
73 | 73 | $this->oldSettings = $this->getOldSettings(); |
74 | - if (empty($this->oldSettings)) { |
|
74 | + if( empty($this->oldSettings) ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
78 | - if (empty($this->oldSettings[$old])) { |
|
77 | + foreach( static::MAPPED_SETTINGS as $old => $new ) { |
|
78 | + if( empty($this->oldSettings[$old]) ) { |
|
79 | 79 | continue; |
80 | 80 | } |
81 | 81 | $this->newSettings[$new] = $this->oldSettings[$old]; |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | $this->migrateNotificationSettings(); |
84 | 84 | $this->migrateRecaptchaSettings(); |
85 | 85 | $this->migrateRequiredSettings(); |
86 | - $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
87 | - $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
88 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
86 | + $oldSettings = Arr::convertDotNotationArray( $this->oldSettings ); |
|
87 | + $newSettings = Arr::convertDotNotationArray( $this->newSettings ); |
|
88 | + if( isset($oldSettings['settings']['strings']) && is_array( $oldSettings['settings']['strings'] ) ) { |
|
89 | 89 | $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
90 | 90 | } |
91 | - glsr(OptionManager::class)->set($newSettings); |
|
91 | + glsr( OptionManager::class )->set( $newSettings ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | protected function getNewSettings() |
98 | 98 | { |
99 | 99 | return wp_parse_args( |
100 | - Arr::flattenArray(glsr(OptionManager::class)->all()), |
|
101 | - glsr(DefaultsManager::class)->defaults() |
|
100 | + Arr::flattenArray( glsr( OptionManager::class )->all() ), |
|
101 | + glsr( DefaultsManager::class )->defaults() |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | */ |
108 | 108 | protected function getOldSettings() |
109 | 109 | { |
110 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
111 | - $settings = Arr::flattenArray((array) get_option('geminilabs_site_reviews-v2', [])); |
|
112 | - if (!empty($settings)) { |
|
113 | - $settings = wp_parse_args($settings, $defaults); |
|
110 | + $defaults = array_fill_keys( array_keys( static::MAPPED_SETTINGS ), '' ); |
|
111 | + $settings = Arr::flattenArray( (array)get_option( 'geminilabs_site_reviews-v2', [] ) ); |
|
112 | + if( !empty($settings) ) { |
|
113 | + $settings = wp_parse_args( $settings, $defaults ); |
|
114 | 114 | } |
115 | 115 | return $settings; |
116 | 116 | } |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | 'webhook' => 'slack', |
127 | 127 | ]; |
128 | 128 | $this->newSettings['settings.general.notifications'] = []; |
129 | - foreach ($notifications as $old => $new) { |
|
130 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
129 | + foreach( $notifications as $old => $new ) { |
|
130 | + if( $this->oldSettings['settings.general.notification'] != $old ) { |
|
131 | 131 | continue; |
132 | 132 | } |
133 | 133 | $this->newSettings['settings.general.notifications'][] = $new; |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
145 | 145 | 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
146 | 146 | ]; |
147 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
147 | + if( in_array( $this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'] ) ) { |
|
148 | 148 | $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
149 | 149 | } |
150 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
151 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
150 | + if( 'invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration'] ) { |
|
151 | + $recaptcha = wp_parse_args( (array)get_site_option( 'ic-settings', [], false ), $recaptcha ); |
|
152 | 152 | } |
153 | 153 | $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
154 | 154 | $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | protected function migrateRequiredSettings() |
162 | 162 | { |
163 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
163 | + $this->newSettings['settings.submissions.required'] = array_filter( (array)$this->oldSettings['settings.reviews-form.required'] ); |
|
164 | 164 | $this->newSettings['settings.submissions.required'][] = 'rating'; |
165 | 165 | $this->newSettings['settings.submissions.required'][] = 'terms'; |
166 | 166 | } |
@@ -34,7 +34,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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; |
@@ -19,24 +19,24 @@ discard block |
||
19 | 19 | public function run() |
20 | 20 | { |
21 | 21 | $filenames = []; |
22 | - $iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader'); |
|
23 | - foreach ($iterator as $fileinfo) { |
|
24 | - if ($fileinfo->isFile()) { |
|
22 | + $iterator = new DirectoryIterator( dirname( __FILE__ ).'/Upgrader' ); |
|
23 | + foreach( $iterator as $fileinfo ) { |
|
24 | + if( $fileinfo->isFile() ) { |
|
25 | 25 | $filenames[] = $fileinfo->getFilename(); |
26 | 26 | } |
27 | 27 | } |
28 | - natsort($filenames); |
|
28 | + natsort( $filenames ); |
|
29 | 29 | $this->currentVersion = $this->currentVersion(); |
30 | - array_walk($filenames, function ($file) { |
|
31 | - $className = str_replace('.php', '', $file); |
|
32 | - $upgradeFromVersion = str_replace(['Upgrade_', '_'], ['', '.'], $className); |
|
33 | - $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
34 | - if ('0.0.0' == $this->currentVersion |
|
35 | - || version_compare($this->currentVersion, $upgradeFromVersion.$suffix, '>=')) { |
|
30 | + array_walk( $filenames, function( $file ) { |
|
31 | + $className = str_replace( '.php', '', $file ); |
|
32 | + $upgradeFromVersion = str_replace( ['Upgrade_', '_'], ['', '.'], $className ); |
|
33 | + $suffix = preg_replace( '/[\d.]+(.+)?/', '${1}', glsr()->version ); // allow alpha/beta versions |
|
34 | + if( '0.0.0' == $this->currentVersion |
|
35 | + || version_compare( $this->currentVersion, $upgradeFromVersion.$suffix, '>=' ) ) { |
|
36 | 36 | return; |
37 | 37 | } |
38 | - glsr('Modules\\Upgrader\\'.$className); |
|
39 | - glsr_log()->notice('Completed Upgrade for v'.$upgradeFromVersion.$suffix); |
|
38 | + glsr( 'Modules\\Upgrader\\'.$className ); |
|
39 | + glsr_log()->notice( 'Completed Upgrade for v'.$upgradeFromVersion.$suffix ); |
|
40 | 40 | }); |
41 | 41 | $this->finish(); |
42 | 42 | } |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function finish() |
48 | 48 | { |
49 | - if ($this->currentVersion !== glsr()->version) { |
|
49 | + if( $this->currentVersion !== glsr()->version ) { |
|
50 | 50 | $this->setReviewCounts(); |
51 | - $this->updateVersionFrom($this->currentVersion); |
|
52 | - } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
51 | + $this->updateVersionFrom( $this->currentVersion ); |
|
52 | + } elseif( !glsr( OptionManager::class )->get( 'last_review_count', false ) ) { |
|
53 | 53 | $this->setReviewCounts(); |
54 | 54 | } |
55 | 55 | } |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | { |
62 | 62 | $fallback = '0.0.0'; |
63 | 63 | $majorVersions = [4, 3, 2]; |
64 | - foreach ($majorVersions as $majorVersion) { |
|
65 | - $settings = get_option(OptionManager::databaseKey($majorVersion)); |
|
66 | - $version = Arr::get($settings, 'version', $fallback); |
|
67 | - if (version_compare($version, $fallback, '>')) { |
|
64 | + foreach( $majorVersions as $majorVersion ) { |
|
65 | + $settings = get_option( OptionManager::databaseKey( $majorVersion ) ); |
|
66 | + $version = Arr::get( $settings, 'version', $fallback ); |
|
67 | + if( version_compare( $version, $fallback, '>' ) ) { |
|
68 | 68 | return $version; |
69 | 69 | } |
70 | 70 | } |
@@ -76,16 +76,16 @@ discard block |
||
76 | 76 | */ |
77 | 77 | protected function setReviewCounts() |
78 | 78 | { |
79 | - add_action('admin_init', 'glsr_calculate_ratings'); |
|
79 | + add_action( 'admin_init', 'glsr_calculate_ratings' ); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * @param string $previousVersion |
84 | 84 | * @return void |
85 | 85 | */ |
86 | - protected function updateVersionFrom($previousVersion) |
|
86 | + protected function updateVersionFrom( $previousVersion ) |
|
87 | 87 | { |
88 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
89 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
88 | + glsr( OptionManager::class )->set( 'version', glsr()->version ); |
|
89 | + glsr( OptionManager::class )->set( 'version_upgraded_from', $previousVersion ); |
|
90 | 90 | } |
91 | 91 | } |