@@ -26,31 +26,31 @@ discard block |
||
26 | 26 | |
27 | 27 | public function __construct() |
28 | 28 | { |
29 | - $this->endpoint = glsr(OptionManager::class)->get('settings.general.notification_slack'); |
|
29 | + $this->endpoint = glsr( OptionManager::class )->get( 'settings.general.notification_slack' ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @return Slack |
34 | 34 | */ |
35 | - public function compose(Review $review, array $notification) |
|
35 | + public function compose( Review $review, array $notification ) |
|
36 | 36 | { |
37 | - if (empty($this->endpoint)) { |
|
37 | + if( empty($this->endpoint) ) { |
|
38 | 38 | return $this; |
39 | 39 | } |
40 | - $args = shortcode_atts(glsr(SlackDefaults::class)->defaults(), $notification); |
|
40 | + $args = shortcode_atts( glsr( SlackDefaults::class )->defaults(), $notification ); |
|
41 | 41 | $this->review = $review; |
42 | 42 | $notification = [ |
43 | 43 | 'icon_url' => $args['icon_url'], |
44 | 44 | 'username' => $args['username'], |
45 | 45 | 'attachments' => [[ |
46 | - 'actions' => $this->buildAction($args), |
|
46 | + 'actions' => $this->buildAction( $args ), |
|
47 | 47 | 'pretext' => $args['pretext'], |
48 | 48 | 'color' => $args['color'], |
49 | 49 | 'fallback' => $args['fallback'], |
50 | 50 | 'fields' => $this->buildFields(), |
51 | 51 | ]], |
52 | 52 | ]; |
53 | - $this->notification = apply_filters('site-reviews/slack/compose', $notification, $this); |
|
53 | + $this->notification = apply_filters( 'site-reviews/slack/compose', $notification, $this ); |
|
54 | 54 | return $this; |
55 | 55 | } |
56 | 56 | |
@@ -59,25 +59,25 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function send() |
61 | 61 | { |
62 | - if (empty($this->endpoint)) { |
|
63 | - return new WP_Error('slack', 'Slack notification was not sent: missing endpoint'); |
|
62 | + if( empty($this->endpoint) ) { |
|
63 | + return new WP_Error( 'slack', 'Slack notification was not sent: missing endpoint' ); |
|
64 | 64 | } |
65 | - return wp_remote_post($this->endpoint, [ |
|
65 | + return wp_remote_post( $this->endpoint, [ |
|
66 | 66 | 'blocking' => false, |
67 | - 'body' => json_encode($this->notification), |
|
67 | + 'body' => json_encode( $this->notification ), |
|
68 | 68 | 'headers' => ['Content-Type' => 'application/json'], |
69 | 69 | 'httpversion' => '1.0', |
70 | 70 | 'method' => 'POST', |
71 | 71 | 'redirection' => 5, |
72 | 72 | 'sslverify' => false, |
73 | 73 | 'timeout' => 45, |
74 | - ]); |
|
74 | + ] ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | 78 | * @return array |
79 | 79 | */ |
80 | - protected function buildAction(array $args) |
|
80 | + protected function buildAction( array $args ) |
|
81 | 81 | { |
82 | 82 | return [[ |
83 | 83 | 'text' => $args['button_text'], |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | $email = !empty($this->review->email) |
95 | 95 | ? '<'.$this->review->email.'>' |
96 | 96 | : ''; |
97 | - $author = trim(rtrim($this->review->author).' '.$email); |
|
98 | - return ['value' => implode(' - ', array_filter([$author, $this->review->ip_address]))]; |
|
97 | + $author = trim( rtrim( $this->review->author ).' '.$email ); |
|
98 | + return ['value' => implode( ' - ', array_filter( [$author, $this->review->ip_address] ) )]; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $this->buildContentField(), |
120 | 120 | $this->buildAuthorField(), |
121 | 121 | ]; |
122 | - return array_filter($fields); |
|
122 | + return array_filter( $fields ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function buildStarsField() |
129 | 129 | { |
130 | - $solidStars = str_repeat('★', $this->review->rating); |
|
131 | - $emptyStars = str_repeat('☆', max(0, glsr()->constant('MAX_RATING', Rating::class) - $this->review->rating)); |
|
130 | + $solidStars = str_repeat( '★', $this->review->rating ); |
|
131 | + $emptyStars = str_repeat( '☆', max( 0, glsr()->constant( 'MAX_RATING', Rating::class ) - $this->review->rating ) ); |
|
132 | 132 | $stars = $solidStars.$emptyStars; |
133 | - $stars = apply_filters('site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant('MAX_RATING', Rating::class)); |
|
133 | + $stars = apply_filters( 'site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant( 'MAX_RATING', Rating::class ) ); |
|
134 | 134 | return ['title' => $stars]; |
135 | 135 | } |
136 | 136 |
@@ -26,26 +26,26 @@ |
||
26 | 26 | /** |
27 | 27 | * @return string |
28 | 28 | */ |
29 | - public function relative($date) |
|
29 | + public function relative( $date ) |
|
30 | 30 | { |
31 | - $diff = time() - strtotime($date); |
|
32 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
33 | - if ($diff > $timePeriod[0]) { |
|
31 | + $diff = time() - strtotime( $date ); |
|
32 | + foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
|
33 | + if( $diff > $timePeriod[0] ) { |
|
34 | 34 | continue; |
35 | 35 | } |
36 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
36 | + $unit = intval( floor( $diff / $timePeriod[1] ) ); |
|
37 | 37 | $relativeDates = [ |
38 | - _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
39 | - _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
40 | - _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
41 | - _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
42 | - _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
43 | - _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
44 | - _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
38 | + _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
|
39 | + _n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ), |
|
40 | + _n( 'an hour ago', '%s hours ago', $unit, 'site-reviews' ), |
|
41 | + _n( 'yesterday', '%s days ago', $unit, 'site-reviews' ), |
|
42 | + _n( 'a week ago', '%s weeks ago', $unit, 'site-reviews' ), |
|
43 | + _n( '%s month ago', '%s months ago', $unit, 'site-reviews' ), |
|
44 | + _n( '%s year ago', '%s years ago', $unit, 'site-reviews' ), |
|
45 | 45 | ]; |
46 | 46 | $relativeDate = $relativeDates[$i]; |
47 | - return false !== strpos($relativeDate, '%s') |
|
48 | - ? sprintf($relativeDate, $unit) |
|
47 | + return false !== strpos( $relativeDate, '%s' ) |
|
48 | + ? sprintf( $relativeDate, $unit ) |
|
49 | 49 | : $relativeDate; |
50 | 50 | } |
51 | 51 | } |
@@ -12,11 +12,11 @@ discard block |
||
12 | 12 | * @param string $domain |
13 | 13 | * @return string |
14 | 14 | */ |
15 | - public function filterGettext($translation, $text, $domain) |
|
15 | + public function filterGettext( $translation, $text, $domain ) |
|
16 | 16 | { |
17 | - return $this->translate($translation, $domain, [ |
|
17 | + return $this->translate( $translation, $domain, [ |
|
18 | 18 | 'single' => $text, |
19 | - ]); |
|
19 | + ] ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | * @param string $domain |
27 | 27 | * @return string |
28 | 28 | */ |
29 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
29 | + public function filterGettextWithContext( $translation, $text, $context, $domain ) |
|
30 | 30 | { |
31 | - return $this->translate($translation, $domain, [ |
|
31 | + return $this->translate( $translation, $domain, [ |
|
32 | 32 | 'context' => $context, |
33 | 33 | 'single' => $text, |
34 | - ]); |
|
34 | + ] ); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | * @param string $domain |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
45 | + public function filterNgettext( $translation, $single, $plural, $number, $domain ) |
|
46 | 46 | { |
47 | - return $this->translate($translation, $domain, [ |
|
47 | + return $this->translate( $translation, $domain, [ |
|
48 | 48 | 'number' => $number, |
49 | 49 | 'plural' => $plural, |
50 | 50 | 'single' => $single, |
51 | - ]); |
|
51 | + ] ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | * @param string $domain |
61 | 61 | * @return string |
62 | 62 | */ |
63 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
63 | + public function filterNgettextWithContext( $translation, $single, $plural, $number, $context, $domain ) |
|
64 | 64 | { |
65 | - return $this->translate($translation, $domain, [ |
|
65 | + return $this->translate( $translation, $domain, [ |
|
66 | 66 | 'context' => $context, |
67 | 67 | 'number' => $number, |
68 | 68 | 'plural' => $plural, |
69 | 69 | 'single' => $single, |
70 | - ]); |
|
70 | + ] ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -75,21 +75,21 @@ discard block |
||
75 | 75 | * @param string $domain |
76 | 76 | * @return string |
77 | 77 | */ |
78 | - public function translate($original, $domain, array $args) |
|
78 | + public function translate( $original, $domain, array $args ) |
|
79 | 79 | { |
80 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
81 | - if (!in_array($domain, $domains)) { |
|
80 | + $domains = apply_filters( 'site-reviews/translator/domains', [Application::ID] ); |
|
81 | + if( !in_array( $domain, $domains ) ) { |
|
82 | 82 | return $original; |
83 | 83 | } |
84 | - $args = $this->normalizeTranslationArgs($args); |
|
85 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
86 | - if (empty($strings)) { |
|
84 | + $args = $this->normalizeTranslationArgs( $args ); |
|
85 | + $strings = $this->getTranslationStrings( $args['single'], $args['plural'] ); |
|
86 | + if( empty($strings) ) { |
|
87 | 87 | return $original; |
88 | 88 | } |
89 | - $string = current($strings); |
|
89 | + $string = current( $strings ); |
|
90 | 90 | return 'plural' == $string['type'] |
91 | - ? $this->translatePlural($domain, $string, $args) |
|
92 | - : $this->translateSingle($domain, $string, $args); |
|
91 | + ? $this->translatePlural( $domain, $string, $args ) |
|
92 | + : $this->translateSingle( $domain, $string, $args ); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -97,18 +97,18 @@ discard block |
||
97 | 97 | * @param string $plural |
98 | 98 | * @return array |
99 | 99 | */ |
100 | - protected function getTranslationStrings($single, $plural) |
|
100 | + protected function getTranslationStrings( $single, $plural ) |
|
101 | 101 | { |
102 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
103 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
104 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
102 | + return array_filter( glsr( Translation::class )->translations(), function( $string ) use ($single, $plural) { |
|
103 | + return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' ) |
|
104 | + && $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' ); |
|
105 | 105 | }); |
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
109 | 109 | * @return array |
110 | 110 | */ |
111 | - protected function normalizeTranslationArgs(array $args) |
|
111 | + protected function normalizeTranslationArgs( array $args ) |
|
112 | 112 | { |
113 | 113 | $defaults = [ |
114 | 114 | 'context' => '', |
@@ -116,22 +116,22 @@ discard block |
||
116 | 116 | 'plural' => '', |
117 | 117 | 'single' => '', |
118 | 118 | ]; |
119 | - return shortcode_atts($defaults, $args); |
|
119 | + return shortcode_atts( $defaults, $args ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @param string $domain |
124 | 124 | * @return string |
125 | 125 | */ |
126 | - protected function translatePlural($domain, array $string, array $args) |
|
126 | + protected function translatePlural( $domain, array $string, array $args ) |
|
127 | 127 | { |
128 | - if (!empty($string['s2'])) { |
|
128 | + if( !empty($string['s2']) ) { |
|
129 | 129 | $args['single'] = $string['s2']; |
130 | 130 | } |
131 | - if (!empty($string['p2'])) { |
|
131 | + if( !empty($string['p2']) ) { |
|
132 | 132 | $args['plural'] = $string['p2']; |
133 | 133 | } |
134 | - return get_translations_for_domain($domain)->translate_plural( |
|
134 | + return get_translations_for_domain( $domain )->translate_plural( |
|
135 | 135 | $args['single'], |
136 | 136 | $args['plural'], |
137 | 137 | $args['number'], |
@@ -143,12 +143,12 @@ discard block |
||
143 | 143 | * @param string $domain |
144 | 144 | * @return string |
145 | 145 | */ |
146 | - protected function translateSingle($domain, array $string, array $args) |
|
146 | + protected function translateSingle( $domain, array $string, array $args ) |
|
147 | 147 | { |
148 | - if (!empty($string['s2'])) { |
|
148 | + if( !empty($string['s2']) ) { |
|
149 | 149 | $args['single'] = $string['s2']; |
150 | 150 | } |
151 | - return get_translations_for_domain($domain)->translate( |
|
151 | + return get_translations_for_domain( $domain )->translate( |
|
152 | 152 | $args['single'], |
153 | 153 | $args['context'] |
154 | 154 | ); |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | * @param array $args |
83 | 83 | * @return static |
84 | 84 | */ |
85 | - public function __call($method, $args) |
|
85 | + public function __call( $method, $args ) |
|
86 | 86 | { |
87 | 87 | $args += [[], false]; |
88 | - $constant = 'static::ATTRIBUTES_'.strtoupper($method); |
|
89 | - $allowedAttributeKeys = defined($constant) |
|
90 | - ? constant($constant) |
|
88 | + $constant = 'static::ATTRIBUTES_'.strtoupper( $method ); |
|
89 | + $allowedAttributeKeys = defined( $constant ) |
|
90 | + ? constant( $constant ) |
|
91 | 91 | : []; |
92 | - $this->normalize((array) $args[0], $allowedAttributeKeys); |
|
93 | - $this->normalizeInputType($method); |
|
92 | + $this->normalize( (array)$args[0], $allowedAttributeKeys ); |
|
93 | + $this->normalizeInputType( $method ); |
|
94 | 94 | return $this; |
95 | 95 | } |
96 | 96 | |
@@ -108,21 +108,21 @@ discard block |
||
108 | 108 | public function toString() |
109 | 109 | { |
110 | 110 | $attributes = []; |
111 | - foreach ($this->attributes as $attribute => $value) { |
|
112 | - $quote = $this->getQuoteChar($attribute); |
|
113 | - $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES) |
|
111 | + foreach( $this->attributes as $attribute => $value ) { |
|
112 | + $quote = $this->getQuoteChar( $attribute ); |
|
113 | + $attributes[] = in_array( $attribute, static::BOOLEAN_ATTRIBUTES ) |
|
114 | 114 | ? $attribute |
115 | - : $attribute.'='.$quote.implode(',', (array) $value).$quote; |
|
115 | + : $attribute.'='.$quote.implode( ',', (array)$value ).$quote; |
|
116 | 116 | } |
117 | - return implode(' ', $attributes); |
|
117 | + return implode( ' ', $attributes ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @return array |
122 | 122 | */ |
123 | - protected function filterAttributes(array $allowedAttributeKeys) |
|
123 | + protected function filterAttributes( array $allowedAttributeKeys ) |
|
124 | 124 | { |
125 | - return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys)); |
|
125 | + return array_intersect_key( $this->attributes, array_flip( $allowedAttributeKeys ) ); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -130,15 +130,15 @@ discard block |
||
130 | 130 | */ |
131 | 131 | protected function filterGlobalAttributes() |
132 | 132 | { |
133 | - $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES); |
|
133 | + $globalAttributes = $this->filterAttributes( static::GLOBAL_ATTRIBUTES ); |
|
134 | 134 | $wildcards = []; |
135 | - foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) { |
|
136 | - $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) { |
|
137 | - return glsr(Helper::class)->startsWith($wildcard, $key); |
|
138 | - }, ARRAY_FILTER_USE_KEY); |
|
139 | - $wildcards = array_merge($wildcards, $newWildcards); |
|
135 | + foreach( static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard ) { |
|
136 | + $newWildcards = array_filter( $this->attributes, function( $key ) use ($wildcard) { |
|
137 | + return glsr( Helper::class )->startsWith( $wildcard, $key ); |
|
138 | + }, ARRAY_FILTER_USE_KEY ); |
|
139 | + $wildcards = array_merge( $wildcards, $newWildcards ); |
|
140 | 140 | } |
141 | - return array_merge($globalAttributes, $wildcards); |
|
141 | + return array_merge( $globalAttributes, $wildcards ); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | protected function getPermanentAttributes() |
148 | 148 | { |
149 | 149 | $permanentAttributes = []; |
150 | - if (array_key_exists('value', $this->attributes)) { |
|
150 | + if( array_key_exists( 'value', $this->attributes ) ) { |
|
151 | 151 | $permanentAttributes['value'] = $this->attributes['value']; |
152 | 152 | } |
153 | 153 | return $permanentAttributes; |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * @param string $attribute |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - protected function getQuoteChar($attribute) |
|
160 | + protected function getQuoteChar( $attribute ) |
|
161 | 161 | { |
162 | - return glsr(Helper::class)->startsWith('data-', $attribute) |
|
162 | + return glsr( Helper::class )->startsWith( 'data-', $attribute ) |
|
163 | 163 | ? '\'' |
164 | 164 | : '"'; |
165 | 165 | } |
@@ -169,19 +169,19 @@ discard block |
||
169 | 169 | * @param mixed $value |
170 | 170 | * @return bool |
171 | 171 | */ |
172 | - protected function isAttributeKeyNumeric($key, $value) |
|
172 | + protected function isAttributeKeyNumeric( $key, $value ) |
|
173 | 173 | { |
174 | - return is_string($value) |
|
175 | - && is_numeric($key) |
|
176 | - && !array_key_exists($value, $this->attributes); |
|
174 | + return is_string( $value ) |
|
175 | + && is_numeric( $key ) |
|
176 | + && !array_key_exists( $value, $this->attributes ); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * @return void |
181 | 181 | */ |
182 | - protected function normalize(array $args, array $allowedAttributeKeys) |
|
182 | + protected function normalize( array $args, array $allowedAttributeKeys ) |
|
183 | 183 | { |
184 | - $this->attributes = array_change_key_case($args, CASE_LOWER); |
|
184 | + $this->attributes = array_change_key_case( $args, CASE_LOWER ); |
|
185 | 185 | $this->normalizeBooleanAttributes(); |
186 | 186 | $this->normalizeDataAttributes(); |
187 | 187 | $this->normalizeStringAttributes(); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $this->removeIndexedAttributes(); |
190 | 190 | $this->attributes = array_merge( |
191 | 191 | $this->filterGlobalAttributes(), |
192 | - $this->filterAttributes($allowedAttributeKeys) |
|
192 | + $this->filterAttributes( $allowedAttributeKeys ) |
|
193 | 193 | ); |
194 | 194 | } |
195 | 195 | |
@@ -198,15 +198,15 @@ discard block |
||
198 | 198 | */ |
199 | 199 | protected function normalizeBooleanAttributes() |
200 | 200 | { |
201 | - foreach ($this->attributes as $key => $value) { |
|
202 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
201 | + foreach( $this->attributes as $key => $value ) { |
|
202 | + if( $this->isAttributeKeyNumeric( $key, $value ) ) { |
|
203 | 203 | $key = $value; |
204 | 204 | $value = true; |
205 | 205 | } |
206 | - if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) { |
|
206 | + if( !in_array( $key, static::BOOLEAN_ATTRIBUTES ) ) { |
|
207 | 207 | continue; |
208 | 208 | } |
209 | - $this->attributes[$key] = wp_validate_boolean($value); |
|
209 | + $this->attributes[$key] = wp_validate_boolean( $value ); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
@@ -215,16 +215,16 @@ discard block |
||
215 | 215 | */ |
216 | 216 | protected function normalizeDataAttributes() |
217 | 217 | { |
218 | - foreach ($this->attributes as $key => $value) { |
|
219 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
218 | + foreach( $this->attributes as $key => $value ) { |
|
219 | + if( $this->isAttributeKeyNumeric( $key, $value ) ) { |
|
220 | 220 | $key = $value; |
221 | 221 | $value = ''; |
222 | 222 | } |
223 | - if (!glsr(Helper::class)->startsWith('data-', $key)) { |
|
223 | + if( !glsr( Helper::class )->startsWith( 'data-', $key ) ) { |
|
224 | 224 | continue; |
225 | 225 | } |
226 | - if (is_array($value)) { |
|
227 | - $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
226 | + if( is_array( $value ) ) { |
|
227 | + $value = json_encode( $value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); |
|
228 | 228 | } |
229 | 229 | $this->attributes[$key] = $value; |
230 | 230 | } |
@@ -235,11 +235,11 @@ discard block |
||
235 | 235 | */ |
236 | 236 | protected function normalizeStringAttributes() |
237 | 237 | { |
238 | - foreach ($this->attributes as $key => $value) { |
|
239 | - if (!is_string($value)) { |
|
238 | + foreach( $this->attributes as $key => $value ) { |
|
239 | + if( !is_string( $value ) ) { |
|
240 | 240 | continue; |
241 | 241 | } |
242 | - $this->attributes[$key] = trim($value); |
|
242 | + $this->attributes[$key] = trim( $value ); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | * @param string $method |
248 | 248 | * @return void |
249 | 249 | */ |
250 | - protected function normalizeInputType($method) |
|
250 | + protected function normalizeInputType( $method ) |
|
251 | 251 | { |
252 | - if ('input' != $method) { |
|
252 | + if( 'input' != $method ) { |
|
253 | 253 | return; |
254 | 254 | } |
255 | - $attributes = wp_parse_args($this->attributes, ['type' => '']); |
|
256 | - if (!in_array($attributes['type'], static::INPUT_TYPES)) { |
|
255 | + $attributes = wp_parse_args( $this->attributes, ['type' => ''] ); |
|
256 | + if( !in_array( $attributes['type'], static::INPUT_TYPES ) ) { |
|
257 | 257 | $this->attributes['type'] = 'text'; |
258 | 258 | } |
259 | 259 | } |
@@ -265,16 +265,16 @@ discard block |
||
265 | 265 | { |
266 | 266 | $attributes = $this->attributes; |
267 | 267 | $permanentAttributes = $this->getPermanentAttributes(); |
268 | - foreach ($this->attributes as $key => $value) { |
|
269 | - if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) { |
|
268 | + foreach( $this->attributes as $key => $value ) { |
|
269 | + if( in_array( $key, static::BOOLEAN_ATTRIBUTES ) && !$value ) { |
|
270 | 270 | unset($attributes[$key]); |
271 | 271 | } |
272 | - if (glsr(Helper::class)->startsWith('data-', $key)) { |
|
272 | + if( glsr( Helper::class )->startsWith( 'data-', $key ) ) { |
|
273 | 273 | $permanentAttributes[$key] = $value; |
274 | 274 | unset($attributes[$key]); |
275 | 275 | } |
276 | 276 | } |
277 | - $this->attributes = array_merge(array_filter($attributes), $permanentAttributes); |
|
277 | + $this->attributes = array_merge( array_filter( $attributes ), $permanentAttributes ); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | { |
285 | 285 | $this->attributes = array_diff_key( |
286 | 286 | $this->attributes, |
287 | - array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY) |
|
287 | + array_filter( $this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY ) |
|
288 | 288 | ); |
289 | 289 | } |
290 | 290 | } |
@@ -9,9 +9,9 @@ |
||
9 | 9 | */ |
10 | 10 | public function build() |
11 | 11 | { |
12 | - $this->builder->args = wp_parse_args($this->builder->args, [ |
|
12 | + $this->builder->args = wp_parse_args( $this->builder->args, [ |
|
13 | 13 | 'name' => $this->builder->args['text'], |
14 | - ]); |
|
14 | + ] ); |
|
15 | 15 | $this->builder->tag = 'input'; |
16 | 16 | $this->mergeFieldArgs(); |
17 | 17 | return $this->builder->getOpeningTag(); |
@@ -32,8 +32,8 @@ |
||
32 | 32 | return [ |
33 | 33 | 'is_multi' => true, |
34 | 34 | 'options' => [ |
35 | - 'no' => __('No', 'site-reviews'), |
|
36 | - 'yes' => __('Yes', 'site-reviews'), |
|
35 | + 'no' => __( 'No', 'site-reviews' ), |
|
36 | + 'yes' => __( 'Yes', 'site-reviews' ), |
|
37 | 37 | ], |
38 | 38 | 'type' => 'radio', |
39 | 39 | ]; |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | protected $builder; |
13 | 13 | |
14 | - public function __construct(Builder $builder) |
|
14 | + public function __construct( Builder $builder ) |
|
15 | 15 | { |
16 | 16 | $this->builder = $builder; |
17 | 17 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function build() |
23 | 23 | { |
24 | - glsr_log()->error('Build method is not implemented for '.get_class($this)); |
|
24 | + glsr_log()->error( 'Build method is not implemented for '.get_class( $this ) ); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @return array |
37 | 37 | */ |
38 | - public static function merge(array $args) |
|
38 | + public static function merge( array $args ) |
|
39 | 39 | { |
40 | 40 | $merged = array_merge( |
41 | - wp_parse_args($args, static::defaults()), |
|
41 | + wp_parse_args( $args, static::defaults() ), |
|
42 | 42 | static::required() |
43 | 43 | ); |
44 | - $merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args)); |
|
45 | - $merged['style'] = implode(';', static::mergedAttribute('style', ';', $args)); |
|
44 | + $merged['class'] = implode( ' ', static::mergedAttribute( 'class', ' ', $args ) ); |
|
45 | + $merged['style'] = implode( ';', static::mergedAttribute( 'style', ';', $args ) ); |
|
46 | 46 | return $merged; |
47 | 47 | } |
48 | 48 | |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | * @param string $key |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - public static function mergedAttribute($key, $delimiter, array $args) |
|
54 | + public static function mergedAttribute( $key, $delimiter, array $args ) |
|
55 | 55 | { |
56 | - return array_filter(array_merge( |
|
57 | - explode($delimiter, glsr_get($args, $key)), |
|
58 | - explode($delimiter, glsr_get(static::defaults(), $key)), |
|
59 | - explode($delimiter, glsr_get(static::required(), $key)) |
|
60 | - )); |
|
56 | + return array_filter( array_merge( |
|
57 | + explode( $delimiter, glsr_get( $args, $key ) ), |
|
58 | + explode( $delimiter, glsr_get( static::defaults(), $key ) ), |
|
59 | + explode( $delimiter, glsr_get( static::required(), $key ) ) |
|
60 | + ) ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -73,6 +73,6 @@ discard block |
||
73 | 73 | */ |
74 | 74 | protected function mergeFieldArgs() |
75 | 75 | { |
76 | - $this->builder->args = static::merge($this->builder->args); |
|
76 | + $this->builder->args = static::merge( $this->builder->args ); |
|
77 | 77 | } |
78 | 78 | } |
@@ -21,9 +21,9 @@ |
||
21 | 21 | */ |
22 | 22 | public static function required() |
23 | 23 | { |
24 | - $options = ['' => __('Select a Rating', 'site-reviews')]; |
|
25 | - foreach (range(glsr()->constant('MAX_RATING', RatingModule::class), 1) as $rating) { |
|
26 | - $options[$rating] = sprintf(_n('%s Star', '%s Stars', $rating, 'site-reviews'), $rating); |
|
24 | + $options = ['' => __( 'Select a Rating', 'site-reviews' )]; |
|
25 | + foreach( range( glsr()->constant( 'MAX_RATING', RatingModule::class ), 1 ) as $rating ) { |
|
26 | + $options[$rating] = sprintf( _n( '%s Star', '%s Stars', $rating, 'site-reviews' ), $rating ); |
|
27 | 27 | } |
28 | 28 | return [ |
29 | 29 | 'class' => 'glsr-star-rating', |
@@ -10,17 +10,17 @@ discard block |
||
10 | 10 | * @param string $partialPath |
11 | 11 | * @return string |
12 | 12 | */ |
13 | - public function build($partialPath, array $args = []) |
|
13 | + public function build( $partialPath, array $args = [] ) |
|
14 | 14 | { |
15 | - $className = glsr(Helper::class)->buildClassName($partialPath, 'Modules\Html\Partials'); |
|
16 | - if (!class_exists($className)) { |
|
17 | - glsr_log()->error('Partial missing: '.$className); |
|
15 | + $className = glsr( Helper::class )->buildClassName( $partialPath, 'Modules\Html\Partials' ); |
|
16 | + if( !class_exists( $className ) ) { |
|
17 | + glsr_log()->error( 'Partial missing: '.$className ); |
|
18 | 18 | return; |
19 | 19 | } |
20 | - $args = apply_filters('site-reviews/partial/args/'.$partialPath, $args); |
|
21 | - $partial = glsr($className)->build($args); |
|
22 | - $partial = apply_filters('site-reviews/rendered/partial', $partial, $partialPath, $args); |
|
23 | - $partial = apply_filters('site-reviews/rendered/partial/'.$partialPath, $partial, $args); |
|
20 | + $args = apply_filters( 'site-reviews/partial/args/'.$partialPath, $args ); |
|
21 | + $partial = glsr( $className )->build( $args ); |
|
22 | + $partial = apply_filters( 'site-reviews/rendered/partial', $partial, $partialPath, $args ); |
|
23 | + $partial = apply_filters( 'site-reviews/rendered/partial/'.$partialPath, $partial, $args ); |
|
24 | 24 | return $partial; |
25 | 25 | } |
26 | 26 | |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | * @param string $partialPath |
29 | 29 | * @return void |
30 | 30 | */ |
31 | - public function render($partialPath, array $args = []) |
|
31 | + public function render( $partialPath, array $args = [] ) |
|
32 | 32 | { |
33 | - echo $this->build($partialPath, $args); |
|
33 | + echo $this->build( $partialPath, $args ); |
|
34 | 34 | } |
35 | 35 | } |