@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | { |
| 31 | 31 | $translations = $this->getTranslations(); |
| 32 | 32 | $entries = $this->filter( $translations, $this->entries() )->results(); |
| 33 | - array_walk( $translations, function( &$entry ) use( $entries ) { |
|
| 33 | + array_walk( $translations, function( &$entry ) use($entries) { |
|
| 34 | 34 | $entry['desc'] = array_key_exists( $entry['id'], $entries ) |
| 35 | 35 | ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' ) |
| 36 | 36 | : ''; |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function entries() |
| 45 | 45 | { |
| 46 | - if( !isset( $this->entries )) { |
|
| 46 | + if( !isset($this->entries) ) { |
|
| 47 | 47 | try { |
| 48 | 48 | $potFile = glsr()->path( glsr()->languages.'/'.Application::ID.'.pot' ); |
| 49 | 49 | $entries = $this->normalize( Parser::parseFile( $potFile )->getEntries() ); |
@@ -76,13 +76,13 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function filter( $filterWith = null, $entries = null, $intersect = true ) |
| 78 | 78 | { |
| 79 | - if( !is_array( $entries )) { |
|
| 79 | + if( !is_array( $entries ) ) { |
|
| 80 | 80 | $entries = $this->results; |
| 81 | 81 | } |
| 82 | - if( !is_array( $filterWith )) { |
|
| 82 | + if( !is_array( $filterWith ) ) { |
|
| 83 | 83 | $filterWith = $this->getTranslations(); |
| 84 | 84 | } |
| 85 | - $keys = array_flip( array_column( $filterWith, 'id' )); |
|
| 85 | + $keys = array_flip( array_column( $filterWith, 'id' ) ); |
|
| 86 | 86 | $this->results = $intersect |
| 87 | 87 | ? array_intersect_key( $entries, $keys ) |
| 88 | 88 | : array_diff_key( $entries, $keys ); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | { |
| 100 | 100 | return $this->translate( $translation, $domain, [ |
| 101 | 101 | 'single' => $text, |
| 102 | - ]); |
|
| 102 | + ] ); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | return $this->translate( $translation, $domain, [ |
| 115 | 115 | 'context' => $context, |
| 116 | 116 | 'single' => $text, |
| 117 | - ]); |
|
| 117 | + ] ); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | 'number' => $number, |
| 132 | 132 | 'plural' => $plural, |
| 133 | 133 | 'single' => $single, |
| 134 | - ]); |
|
| 134 | + ] ); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | 'number' => $number, |
| 151 | 151 | 'plural' => $plural, |
| 152 | 152 | 'single' => $single, |
| 153 | - ]); |
|
| 153 | + ] ); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | public function render( $template, array $entry ) |
| 161 | 161 | { |
| 162 | 162 | $data = array_combine( |
| 163 | - array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry )), |
|
| 163 | + array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ), |
|
| 164 | 164 | $entry |
| 165 | 165 | ); |
| 166 | 166 | ob_start(); |
@@ -197,13 +197,13 @@ discard block |
||
| 197 | 197 | 'p1' => $this->getEntryString( $entry, 'msgid_plural' ), |
| 198 | 198 | 's1' => $this->getEntryString( $entry, 'msgid' ), |
| 199 | 199 | ]; |
| 200 | - $text = !empty( $data['p1'] ) |
|
| 200 | + $text = !empty($data['p1']) |
|
| 201 | 201 | ? sprintf( '%s | %s', $data['s1'], $data['p1'] ) |
| 202 | 202 | : $data['s1']; |
| 203 | 203 | $rendered .= $this->render( 'result', [ |
| 204 | 204 | 'entry' => wp_json_encode( $data ), |
| 205 | 205 | 'text' => wp_strip_all_tags( $text ), |
| 206 | - ]); |
|
| 206 | + ] ); |
|
| 207 | 207 | } |
| 208 | 208 | if( $resetAfterRender ) { |
| 209 | 209 | $this->reset(); |
@@ -236,12 +236,12 @@ discard block |
||
| 236 | 236 | public function search( $needle = '' ) |
| 237 | 237 | { |
| 238 | 238 | $this->reset(); |
| 239 | - $needle = trim( strtolower( $needle )); |
|
| 239 | + $needle = trim( strtolower( $needle ) ); |
|
| 240 | 240 | foreach( $this->entries() as $key => $entry ) { |
| 241 | - $single = strtolower( $this->getEntryString( $entry, 'msgid' )); |
|
| 242 | - $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' )); |
|
| 241 | + $single = strtolower( $this->getEntryString( $entry, 'msgid' ) ); |
|
| 242 | + $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) ); |
|
| 243 | 243 | if( strlen( $needle ) < static::SEARCH_THRESHOLD ) { |
| 244 | - if( in_array( $needle, [$single, $plural] )) { |
|
| 244 | + if( in_array( $needle, [$single, $plural] ) ) { |
|
| 245 | 245 | $this->results[$key] = $entry; |
| 246 | 246 | } |
| 247 | 247 | } |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | } |
| 265 | 265 | $args = $this->normalizeTranslationArgs( $args ); |
| 266 | 266 | $strings = $this->getTranslationStrings( $args['single'], $args['plural'] ); |
| 267 | - if( empty( $strings )) { |
|
| 267 | + if( empty($strings) ) { |
|
| 268 | 268 | return $original; |
| 269 | 269 | } |
| 270 | 270 | $string = current( $strings ); |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | protected function getEntryString( array $entry, $key ) |
| 281 | 281 | { |
| 282 | - return isset( $entry[$key] ) |
|
| 283 | - ? implode( '', (array) $entry[$key] ) |
|
| 282 | + return isset($entry[$key]) |
|
| 283 | + ? implode( '', (array)$entry[$key] ) |
|
| 284 | 284 | : ''; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | protected function getTranslations() |
| 291 | 291 | { |
| 292 | 292 | $settings = glsr( OptionManager::class )->get( 'settings' ); |
| 293 | - return isset( $settings['translations'] ) |
|
| 294 | - ? $this->normalizeSettings( (array) $settings['translations'] ) |
|
| 293 | + return isset($settings['translations']) |
|
| 294 | + ? $this->normalizeSettings( (array)$settings['translations'] ) |
|
| 295 | 295 | : []; |
| 296 | 296 | } |
| 297 | 297 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | protected function getTranslationStrings( $single, $plural ) |
| 304 | 304 | { |
| 305 | - return array_filter( $this->getTranslations(), function( $string ) use( $single, $plural ) { |
|
| 305 | + return array_filter( $this->getTranslations(), function( $string ) use($single, $plural) { |
|
| 306 | 306 | return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' ) |
| 307 | 307 | && $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' ); |
| 308 | 308 | }); |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | $keys = [ |
| 317 | 317 | 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
| 318 | 318 | ]; |
| 319 | - array_walk( $entries, function( &$entry ) use( $keys ) { |
|
| 319 | + array_walk( $entries, function( &$entry ) use($keys) { |
|
| 320 | 320 | foreach( $keys as $key ) { |
| 321 | 321 | $entry = $this->normalizeEntryString( $entry, $key ); |
| 322 | 322 | } |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | protected function normalizeEntryString( array $entry, $key ) |
| 332 | 332 | { |
| 333 | - if( isset( $entry[$key] )) { |
|
| 333 | + if( isset($entry[$key]) ) { |
|
| 334 | 334 | $entry[$key] = $this->getEntryString( $entry, $key ); |
| 335 | 335 | } |
| 336 | 336 | return $entry; |
@@ -344,11 +344,11 @@ discard block |
||
| 344 | 344 | $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' ); |
| 345 | 345 | $strings = array_filter( $strings, 'is_array' ); |
| 346 | 346 | foreach( $strings as &$string ) { |
| 347 | - $string['type'] = isset( $string['p1'] ) ? 'plural' : 'single'; |
|
| 347 | + $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
| 348 | 348 | $string = wp_parse_args( $string, $defaultString ); |
| 349 | 349 | } |
| 350 | 350 | return array_filter( $strings, function( $string ) { |
| 351 | - return !empty( $string['id'] ); |
|
| 351 | + return !empty($string['id']); |
|
| 352 | 352 | }); |
| 353 | 353 | } |
| 354 | 354 | |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | protected function translatePlural( $domain, array $string, array $args ) |
| 374 | 374 | { |
| 375 | - if( !empty( $string['p2'] )) { |
|
| 375 | + if( !empty($string['p2']) ) { |
|
| 376 | 376 | $args['plural'] = $string['p2']; |
| 377 | 377 | } |
| 378 | 378 | return get_translations_for_domain( $domain )->translate_plural( |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | protected function translateSingle( $domain, array $string, array $args ) |
| 391 | 391 | { |
| 392 | - if( !empty( $string['s2'] )) { |
|
| 392 | + if( !empty($string['s2']) ) { |
|
| 393 | 393 | $args['single'] = $string['s2']; |
| 394 | 394 | } |
| 395 | 395 | return get_translations_for_domain( $domain )->translate( |