We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | * @param string $css_class HTML class used in markup. |
| 54 | 54 | * @param bool $feed_compatible Optional. Default false. |
| 55 | 55 | */ |
| 56 | - public function __construct( $css_class, $feed_compatible = false ) { |
|
| 57 | - parent::__construct( self::REGEX, self::SETTINGS_SWITCH, $css_class, $feed_compatible ); |
|
| 56 | + public function __construct($css_class, $feed_compatible = false) { |
|
| 57 | + parent::__construct(self::REGEX, self::SETTINGS_SWITCH, $css_class, $feed_compatible); |
|
| 58 | 58 | } |
| 59 | 59 | } |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | * @param string $css_class HTML class used in markup. |
| 54 | 54 | * @param bool $feed_compatible Optional. Default false. |
| 55 | 55 | */ |
| 56 | - public function __construct( $css_class, $feed_compatible = false ) { |
|
| 57 | - parent::__construct( self::REGEX, self::SETTINGS_SWITCH, $css_class, $feed_compatible ); |
|
| 56 | + public function __construct($css_class, $feed_compatible = false) { |
|
| 57 | + parent::__construct(self::REGEX, self::SETTINGS_SWITCH, $css_class, $feed_compatible); |
|
| 58 | 58 | } |
| 59 | 59 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @var array |
| 47 | 47 | */ |
| 48 | - const _ENCODINGS = [ 'ASCII', 'UTF-8' ]; |
|
| 48 | + const _ENCODINGS = ['ASCII', 'UTF-8']; |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * A hash map for string functions according to encoding. |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | const _STRING_FUNCTIONS = [ |
| 56 | 56 | 'UTF-8' => [ |
| 57 | 57 | 'strlen' => 'mb_strlen', |
| 58 | - 'str_split' => [ __CLASS__, 'mb_str_split' ], |
|
| 58 | + 'str_split' => [__CLASS__, 'mb_str_split'], |
|
| 59 | 59 | 'strtolower' => 'mb_strtolower', |
| 60 | 60 | 'strtoupper' => 'mb_strtoupper', |
| 61 | 61 | 'substr' => 'mb_substr', |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | * 'u' => modifier string |
| 88 | 88 | * } |
| 89 | 89 | */ |
| 90 | - public static function functions( $str ) { |
|
| 91 | - return self::_STRING_FUNCTIONS[ mb_detect_encoding( $str, self::_ENCODINGS, true ) ]; |
|
| 90 | + public static function functions($str) { |
|
| 91 | + return self::_STRING_FUNCTIONS[mb_detect_encoding($str, self::_ENCODINGS, true)]; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -102,13 +102,13 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @return array An array of $split_length character chunks. |
| 104 | 104 | */ |
| 105 | - public static function mb_str_split( $str, $split_length = 1 ) { |
|
| 106 | - $result = preg_split( '//u', $str , -1, PREG_SPLIT_NO_EMPTY ); |
|
| 105 | + public static function mb_str_split($str, $split_length = 1) { |
|
| 106 | + $result = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY); |
|
| 107 | 107 | |
| 108 | - if ( $split_length > 1 ) { |
|
| 108 | + if ($split_length > 1) { |
|
| 109 | 109 | $splits = []; |
| 110 | - foreach ( array_chunk( $result, $split_length ) as $chunk ) { |
|
| 111 | - $splits[] = join( '', $chunk ); |
|
| 110 | + foreach (array_chunk($result, $split_length) as $chunk) { |
|
| 111 | + $splits[] = join('', $chunk); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $result = $splits; |
@@ -124,17 +124,17 @@ discard block |
||
| 124 | 124 | * |
| 125 | 125 | * @return string Unicode character(s). |
| 126 | 126 | */ |
| 127 | - public static function uchr( $codes ) { |
|
| 127 | + public static function uchr($codes) { |
|
| 128 | 128 | |
| 129 | 129 | // Single character code. |
| 130 | - if ( is_scalar( $codes ) ) { |
|
| 130 | + if (is_scalar($codes)) { |
|
| 131 | 131 | $codes = func_get_args(); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | // Deal with an array of character codes. |
| 135 | 135 | $str = ''; |
| 136 | - foreach ( $codes as $code ) { |
|
| 137 | - $str .= self::_uchr( (int) $code ); |
|
| 136 | + foreach ($codes as $code) { |
|
| 137 | + $str .= self::_uchr((int) $code); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | return $str; |
@@ -148,8 +148,8 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return string Unicode character. |
| 150 | 150 | */ |
| 151 | - public static function _uchr( $code ) { |
|
| 152 | - return html_entity_decode( '&#' . $code . ';', ENT_NOQUOTES, 'UTF-8' ); |
|
| 151 | + public static function _uchr($code) { |
|
| 152 | + return html_entity_decode('&#' . $code . ';', ENT_NOQUOTES, 'UTF-8'); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return array |
| 161 | 161 | */ |
| 162 | - public static function maybe_split_parameters( $params ) { |
|
| 163 | - if ( ! is_array( $params ) ) { |
|
| 164 | - $params = preg_split( self::_RE_PARAMETER_SPLITTING, $params, -1, PREG_SPLIT_NO_EMPTY ); |
|
| 162 | + public static function maybe_split_parameters($params) { |
|
| 163 | + if ( ! is_array($params)) { |
|
| 164 | + $params = preg_split(self::_RE_PARAMETER_SPLITTING, $params, -1, PREG_SPLIT_NO_EMPTY); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | return $params; |
@@ -74,40 +74,40 @@ discard block |
||
| 74 | 74 | * @param Settings $settings Required. |
| 75 | 75 | * @param bool $is_title Optional. Default false. |
| 76 | 76 | */ |
| 77 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 77 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 78 | 78 | // Intervening inline tags may interfere with widow identification, but that is a sacrifice of using the parser. |
| 79 | 79 | // Intervening tags will only interfere if they separate the widow from previous or preceding whitespace. |
| 80 | - if ( empty( $settings['dewidow'] ) || empty( $settings['dewidowMaxPull'] ) || empty( $settings['dewidowMaxLength'] ) ) { |
|
| 80 | + if (empty($settings['dewidow']) || empty($settings['dewidowMaxPull']) || empty($settings['dewidowMaxLength'])) { |
|
| 81 | 81 | return; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if ( '' === DOM::get_next_chr( $textnode ) ) { |
|
| 84 | + if ('' === DOM::get_next_chr($textnode)) { |
|
| 85 | 85 | // We have the last type "text" child of a block level element. |
| 86 | - $textnode->data = preg_replace_callback( self::REGEX, function( array $widow ) use ( $settings ) { |
|
| 87 | - $func = Strings::functions( $widow[0] ); |
|
| 86 | + $textnode->data = preg_replace_callback(self::REGEX, function(array $widow) use ($settings) { |
|
| 87 | + $func = Strings::functions($widow[0]); |
|
| 88 | 88 | |
| 89 | 89 | // If we are here, we know that widows are being protected in some fashion |
| 90 | 90 | // with that, we will assert that widows should never be hyphenated or wrapped |
| 91 | 91 | // as such, we will strip soft hyphens and zero-width-spaces. |
| 92 | - $widow['widow'] = str_replace( U::ZERO_WIDTH_SPACE, '', $widow['widow'] ); |
|
| 93 | - $widow['widow'] = str_replace( U::SOFT_HYPHEN, '', $widow['widow'] ); |
|
| 94 | - $widow['trailing'] = preg_replace( "/\s+/{$func['u']}", U::NO_BREAK_SPACE, $widow['trailing'] ); |
|
| 95 | - $widow['trailing'] = str_replace( U::ZERO_WIDTH_SPACE, '', $widow['trailing'] ); |
|
| 96 | - $widow['trailing'] = str_replace( U::SOFT_HYPHEN, '', $widow['trailing'] ); |
|
| 92 | + $widow['widow'] = str_replace(U::ZERO_WIDTH_SPACE, '', $widow['widow']); |
|
| 93 | + $widow['widow'] = str_replace(U::SOFT_HYPHEN, '', $widow['widow']); |
|
| 94 | + $widow['trailing'] = preg_replace("/\s+/{$func['u']}", U::NO_BREAK_SPACE, $widow['trailing']); |
|
| 95 | + $widow['trailing'] = str_replace(U::ZERO_WIDTH_SPACE, '', $widow['trailing']); |
|
| 96 | + $widow['trailing'] = str_replace(U::SOFT_HYPHEN, '', $widow['trailing']); |
|
| 97 | 97 | |
| 98 | 98 | // Eject if widows neighbor is proceeded by a no break space (the pulled text would be too long). |
| 99 | - if ( '' === $widow['space_before'] || strstr( U::NO_BREAK_SPACE, $widow['space_before'] ) ) { |
|
| 99 | + if ('' === $widow['space_before'] || strstr(U::NO_BREAK_SPACE, $widow['space_before'])) { |
|
| 100 | 100 | return $widow['space_before'] . $widow['neighbor'] . $widow['space_between'] . $widow['widow'] . $widow['trailing']; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | // Eject if widows neighbor length exceeds the max allowed or widow length exceeds max allowed. |
| 104 | - if ( $func['strlen']( $widow['neighbor'] ) > $settings['dewidowMaxPull'] || |
|
| 105 | - $func['strlen']( $widow['widow'] ) > $settings['dewidowMaxLength'] ) { |
|
| 104 | + if ($func['strlen']($widow['neighbor']) > $settings['dewidowMaxPull'] || |
|
| 105 | + $func['strlen']($widow['widow']) > $settings['dewidowMaxLength']) { |
|
| 106 | 106 | return $widow['space_before'] . $widow['neighbor'] . $widow['space_between'] . $widow['widow'] . $widow['trailing']; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // Never replace thin and hair spaces with . |
| 110 | - switch ( $widow['space_between'] ) { |
|
| 110 | + switch ($widow['space_between']) { |
|
| 111 | 111 | case U::THIN_SPACE: |
| 112 | 112 | case U::HAIR_SPACE: |
| 113 | 113 | return $widow['space_before'] . $widow['neighbor'] . $widow['space_between'] . $widow['widow'] . $widow['trailing']; |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | // Let's protect some widows! |
| 117 | 117 | return $widow['space_before'] . $widow['neighbor'] . U::NO_BREAK_SPACE . $widow['widow'] . $widow['trailing']; |
| 118 | - }, $textnode->data ); |
|
| 118 | + }, $textnode->data); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | const SPACING_POST_WORDS = 40; |
| 54 | 54 | const HTML_INSERTION = 50; |
| 55 | 55 | |
| 56 | - const GROUPS = [ self::CHARACTERS, self::SPACING_PRE_WORDS, self::PROCESS_WORDS, self::SPACING_POST_WORDS, self::HTML_INSERTION ]; |
|
| 56 | + const GROUPS = [self::CHARACTERS, self::SPACING_PRE_WORDS, self::PROCESS_WORDS, self::SPACING_POST_WORDS, self::HTML_INSERTION]; |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * A DOM-based HTML5 parser. |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @var string |
| 116 | 116 | */ |
| 117 | - const INIT_NOW = 'now'; |
|
| 117 | + const INIT_NOW = 'now'; |
|
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * Constant for signalling lazy (manual) initialization to the constructor. |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @param string $init Optional. Flag to control initialization. Valid inputs are INIT_NOW and INIT_LAZY. Default INIT_NOW. |
| 130 | 130 | */ |
| 131 | - public function __construct( $init = self::INIT_NOW ) { |
|
| 132 | - if ( self::INIT_NOW === $init ) { |
|
| 131 | + public function __construct($init = self::INIT_NOW) { |
|
| 132 | + if (self::INIT_NOW === $init) { |
|
| 133 | 133 | $this->init(); |
| 134 | 134 | } |
| 135 | 135 | } |
@@ -141,46 +141,46 @@ discard block |
||
| 141 | 141 | $this->process_words_fix = new Node_Fixes\Process_Words_Fix(); |
| 142 | 142 | |
| 143 | 143 | // Nodify anything that requires adjacent text awareness here. |
| 144 | - $this->register_node_fix( new Node_Fixes\Smart_Maths_Fix(), self::CHARACTERS ); |
|
| 145 | - $this->register_node_fix( new Node_Fixes\Smart_Diacritics_Fix(), self::CHARACTERS ); |
|
| 146 | - $this->register_node_fix( new Node_Fixes\Smart_Quotes_Fix( true ), self::CHARACTERS ); |
|
| 147 | - $this->register_node_fix( new Node_Fixes\Smart_Dashes_Fix( true ), self::CHARACTERS ); |
|
| 148 | - $this->register_node_fix( new Node_Fixes\Smart_Ellipses_Fix( true ), self::CHARACTERS ); |
|
| 149 | - $this->register_node_fix( new Node_Fixes\Smart_Marks_Fix( true ), self::CHARACTERS ); |
|
| 144 | + $this->register_node_fix(new Node_Fixes\Smart_Maths_Fix(), self::CHARACTERS); |
|
| 145 | + $this->register_node_fix(new Node_Fixes\Smart_Diacritics_Fix(), self::CHARACTERS); |
|
| 146 | + $this->register_node_fix(new Node_Fixes\Smart_Quotes_Fix(true), self::CHARACTERS); |
|
| 147 | + $this->register_node_fix(new Node_Fixes\Smart_Dashes_Fix(true), self::CHARACTERS); |
|
| 148 | + $this->register_node_fix(new Node_Fixes\Smart_Ellipses_Fix(true), self::CHARACTERS); |
|
| 149 | + $this->register_node_fix(new Node_Fixes\Smart_Marks_Fix(true), self::CHARACTERS); |
|
| 150 | 150 | |
| 151 | 151 | // Keep spacing after smart character replacement. |
| 152 | - $this->register_node_fix( new Node_Fixes\Single_Character_Word_Spacing_Fix(), self::SPACING_PRE_WORDS ); |
|
| 153 | - $this->register_node_fix( new Node_Fixes\Dash_Spacing_Fix(), self::SPACING_PRE_WORDS ); |
|
| 154 | - $this->register_node_fix( new Node_Fixes\Unit_Spacing_Fix(), self::SPACING_PRE_WORDS ); |
|
| 155 | - $this->register_node_fix( new Node_Fixes\Numbered_Abbreviation_Spacing_Fix(), self::SPACING_PRE_WORDS ); |
|
| 156 | - $this->register_node_fix( new Node_Fixes\French_Punctuation_Spacing_Fix(), self::SPACING_PRE_WORDS ); |
|
| 152 | + $this->register_node_fix(new Node_Fixes\Single_Character_Word_Spacing_Fix(), self::SPACING_PRE_WORDS); |
|
| 153 | + $this->register_node_fix(new Node_Fixes\Dash_Spacing_Fix(), self::SPACING_PRE_WORDS); |
|
| 154 | + $this->register_node_fix(new Node_Fixes\Unit_Spacing_Fix(), self::SPACING_PRE_WORDS); |
|
| 155 | + $this->register_node_fix(new Node_Fixes\Numbered_Abbreviation_Spacing_Fix(), self::SPACING_PRE_WORDS); |
|
| 156 | + $this->register_node_fix(new Node_Fixes\French_Punctuation_Spacing_Fix(), self::SPACING_PRE_WORDS); |
|
| 157 | 157 | |
| 158 | 158 | // Parse and process individual words. |
| 159 | - $this->register_node_fix( $this->process_words_fix, self::PROCESS_WORDS ); |
|
| 159 | + $this->register_node_fix($this->process_words_fix, self::PROCESS_WORDS); |
|
| 160 | 160 | |
| 161 | 161 | // Some final space manipulation. |
| 162 | - $this->register_node_fix( new Node_Fixes\Dewidow_Fix(), self::SPACING_POST_WORDS ); |
|
| 163 | - $this->register_node_fix( new Node_Fixes\Space_Collapse_Fix(), self::SPACING_POST_WORDS ); |
|
| 162 | + $this->register_node_fix(new Node_Fixes\Dewidow_Fix(), self::SPACING_POST_WORDS); |
|
| 163 | + $this->register_node_fix(new Node_Fixes\Space_Collapse_Fix(), self::SPACING_POST_WORDS); |
|
| 164 | 164 | |
| 165 | 165 | // Everything that requires HTML injection occurs here (functions above assume tag-free content) |
| 166 | 166 | // pay careful attention to functions below for tolerance of injected tags. |
| 167 | - $this->register_node_fix( new Node_Fixes\Smart_Ordinal_Suffix_Fix( $this->css_classes['ordinal'] ), self::HTML_INSERTION ); // call before "style_numbers" and "smart_fractions". |
|
| 168 | - $this->register_node_fix( new Node_Fixes\Smart_Exponents_Fix(), self::HTML_INSERTION ); // call before "style_numbers". |
|
| 169 | - $this->register_node_fix( new Node_Fixes\Smart_Fractions_Fix( $this->css_classes['numerator'], $this->css_classes['denominator'] ), self::HTML_INSERTION ); // call before "style_numbers" and after "smart_ordinal_suffix". |
|
| 170 | - $this->register_node_fix( new Node_Fixes\Style_Caps_Fix( $this->css_classes['caps'] ), self::HTML_INSERTION ); // Call before "style_numbers". |
|
| 171 | - $this->register_node_fix( new Node_Fixes\Style_Numbers_Fix( $this->css_classes['numbers'] ), self::HTML_INSERTION ); // Call after "smart_ordinal_suffix", "smart_exponents", "smart_fractions", and "style_caps". |
|
| 172 | - $this->register_node_fix( new Node_Fixes\Style_Ampersands_Fix( $this->css_classes['amp'] ), self::HTML_INSERTION ); |
|
| 173 | - $this->register_node_fix( new Node_Fixes\Style_Initial_Quotes_Fix( $this->css_classes['quo'], $this->css_classes['dquo'] ), self::HTML_INSERTION ); |
|
| 174 | - $this->register_node_fix( new Node_Fixes\Style_Hanging_Punctuation_Fix( $this->css_classes['push-single'], $this->css_classes['push-double'], $this->css_classes['pull-single'], $this->css_classes['pull-double'] ), self::HTML_INSERTION ); |
|
| 167 | + $this->register_node_fix(new Node_Fixes\Smart_Ordinal_Suffix_Fix($this->css_classes['ordinal']), self::HTML_INSERTION); // call before "style_numbers" and "smart_fractions". |
|
| 168 | + $this->register_node_fix(new Node_Fixes\Smart_Exponents_Fix(), self::HTML_INSERTION); // call before "style_numbers". |
|
| 169 | + $this->register_node_fix(new Node_Fixes\Smart_Fractions_Fix($this->css_classes['numerator'], $this->css_classes['denominator']), self::HTML_INSERTION); // call before "style_numbers" and after "smart_ordinal_suffix". |
|
| 170 | + $this->register_node_fix(new Node_Fixes\Style_Caps_Fix($this->css_classes['caps']), self::HTML_INSERTION); // Call before "style_numbers". |
|
| 171 | + $this->register_node_fix(new Node_Fixes\Style_Numbers_Fix($this->css_classes['numbers']), self::HTML_INSERTION); // Call after "smart_ordinal_suffix", "smart_exponents", "smart_fractions", and "style_caps". |
|
| 172 | + $this->register_node_fix(new Node_Fixes\Style_Ampersands_Fix($this->css_classes['amp']), self::HTML_INSERTION); |
|
| 173 | + $this->register_node_fix(new Node_Fixes\Style_Initial_Quotes_Fix($this->css_classes['quo'], $this->css_classes['dquo']), self::HTML_INSERTION); |
|
| 174 | + $this->register_node_fix(new Node_Fixes\Style_Hanging_Punctuation_Fix($this->css_classes['push-single'], $this->css_classes['push-double'], $this->css_classes['pull-single'], $this->css_classes['pull-double']), self::HTML_INSERTION); |
|
| 175 | 175 | |
| 176 | 176 | // Register token fixes. |
| 177 | 177 | $cache = $this->get_hyphenator_cache(); |
| 178 | 178 | |
| 179 | - $this->register_token_fix( new Token_Fixes\Wrap_Hard_Hyphens_Fix() ); |
|
| 180 | - $this->register_token_fix( new Token_Fixes\Hyphenate_Compounds_Fix( $cache ) ); |
|
| 181 | - $this->register_token_fix( new Token_Fixes\Hyphenate_Fix( $cache ) ); |
|
| 182 | - $this->register_token_fix( new Token_Fixes\Wrap_URLs_Fix( $cache ) ); |
|
| 183 | - $this->register_token_fix( new Token_Fixes\Wrap_Emails_Fix() ); |
|
| 179 | + $this->register_token_fix(new Token_Fixes\Wrap_Hard_Hyphens_Fix()); |
|
| 180 | + $this->register_token_fix(new Token_Fixes\Hyphenate_Compounds_Fix($cache)); |
|
| 181 | + $this->register_token_fix(new Token_Fixes\Hyphenate_Fix($cache)); |
|
| 182 | + $this->register_token_fix(new Token_Fixes\Wrap_URLs_Fix($cache)); |
|
| 183 | + $this->register_token_fix(new Token_Fixes\Wrap_Emails_Fix()); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -192,8 +192,8 @@ discard block |
||
| 192 | 192 | * |
| 193 | 193 | * @return string The processed $html. |
| 194 | 194 | */ |
| 195 | - public function process( $html, Settings $settings, $is_title = false ) { |
|
| 196 | - return $this->process_textnodes( $html, [ $this, 'apply_fixes_to_html_node' ], $settings, $is_title ); |
|
| 195 | + public function process($html, Settings $settings, $is_title = false) { |
|
| 196 | + return $this->process_textnodes($html, [$this, 'apply_fixes_to_html_node'], $settings, $is_title); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -206,8 +206,8 @@ discard block |
||
| 206 | 206 | * |
| 207 | 207 | * @return string The processed $html. |
| 208 | 208 | */ |
| 209 | - public function process_feed( $html, Settings $settings, $is_title = false ) { |
|
| 210 | - return $this->process_textnodes( $html, [ $this, 'apply_fixes_to_feed_node' ], $settings, $is_title ); |
|
| 209 | + public function process_feed($html, Settings $settings, $is_title = false) { |
|
| 210 | + return $this->process_textnodes($html, [$this, 'apply_fixes_to_feed_node'], $settings, $is_title); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @return string The processed $html. |
| 222 | 222 | */ |
| 223 | - public function process_textnodes( $html, callable $fixer, Settings $settings, $is_title = false ) { |
|
| 224 | - if ( isset( $settings['ignoreTags'] ) && $is_title && ( in_array( 'h1', $settings['ignoreTags'], true ) || in_array( 'h2', $settings['ignoreTags'], true ) ) ) { |
|
| 223 | + public function process_textnodes($html, callable $fixer, Settings $settings, $is_title = false) { |
|
| 224 | + if (isset($settings['ignoreTags']) && $is_title && (in_array('h1', $settings['ignoreTags'], true) || in_array('h2', $settings['ignoreTags'], true))) { |
|
| 225 | 225 | return $html; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -229,41 +229,41 @@ discard block |
||
| 229 | 229 | $html5_parser = $this->get_html5_parser(); |
| 230 | 230 | |
| 231 | 231 | // Parse the HTML. |
| 232 | - $dom = $this->parse_html( $html5_parser, $html, $settings ); |
|
| 232 | + $dom = $this->parse_html($html5_parser, $html, $settings); |
|
| 233 | 233 | |
| 234 | 234 | // Abort if there were parsing errors. |
| 235 | - if ( empty( $dom ) ) { |
|
| 235 | + if (empty($dom)) { |
|
| 236 | 236 | return $html; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // Query some nodes in the DOM. |
| 240 | - $xpath = new \DOMXPath( $dom ); |
|
| 241 | - $body_node = $xpath->query( '/html/body' )->item( 0 ); |
|
| 242 | - $all_textnodes = $xpath->query( '//text()', $body_node ); |
|
| 243 | - $tags_to_ignore = $this->query_tags_to_ignore( $xpath, $body_node, $settings ); |
|
| 240 | + $xpath = new \DOMXPath($dom); |
|
| 241 | + $body_node = $xpath->query('/html/body')->item(0); |
|
| 242 | + $all_textnodes = $xpath->query('//text()', $body_node); |
|
| 243 | + $tags_to_ignore = $this->query_tags_to_ignore($xpath, $body_node, $settings); |
|
| 244 | 244 | |
| 245 | 245 | // Start processing. |
| 246 | - foreach ( $all_textnodes as $textnode ) { |
|
| 247 | - if ( self::arrays_intersect( DOM::get_ancestors( $textnode ), $tags_to_ignore ) ) { |
|
| 246 | + foreach ($all_textnodes as $textnode) { |
|
| 247 | + if (self::arrays_intersect(DOM::get_ancestors($textnode), $tags_to_ignore)) { |
|
| 248 | 248 | continue; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | // We won't be doing anything with spaces, so we can jump ship if that is all we have. |
| 252 | - if ( $textnode->isWhitespaceInElementContent() ) { |
|
| 252 | + if ($textnode->isWhitespaceInElementContent()) { |
|
| 253 | 253 | continue; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // Decode all characters except < > &. |
| 257 | - $textnode->data = htmlspecialchars( $textnode->data, ENT_NOQUOTES, 'UTF-8' ); // returns < > & to encoded HTML characters (< > and & respectively). |
|
| 257 | + $textnode->data = htmlspecialchars($textnode->data, ENT_NOQUOTES, 'UTF-8'); // returns < > & to encoded HTML characters (< > and & respectively). |
|
| 258 | 258 | |
| 259 | 259 | // Apply fixes. |
| 260 | - call_user_func( $fixer, $textnode, $settings, $is_title ); |
|
| 260 | + call_user_func($fixer, $textnode, $settings, $is_title); |
|
| 261 | 261 | |
| 262 | 262 | // Until now, we've only been working on a textnode: HTMLify result. |
| 263 | - $this->replace_node_with_html( $textnode, $textnode->data ); |
|
| 263 | + $this->replace_node_with_html($textnode, $textnode->data); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - return $html5_parser->saveHTML( $body_node->childNodes ); |
|
| 266 | + return $html5_parser->saveHTML($body_node->childNodes); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -275,9 +275,9 @@ discard block |
||
| 275 | 275 | * |
| 276 | 276 | * @return boolean |
| 277 | 277 | */ |
| 278 | - protected static function arrays_intersect( array $array1, array $array2 ) { |
|
| 279 | - foreach ( $array1 as $value ) { |
|
| 280 | - if ( isset( $array2[ spl_object_hash( $value ) ] ) ) { |
|
| 278 | + protected static function arrays_intersect(array $array1, array $array2) { |
|
| 279 | + foreach ($array1 as $value) { |
|
| 280 | + if (isset($array2[spl_object_hash($value)])) { |
|
| 281 | 281 | return true; |
| 282 | 282 | } |
| 283 | 283 | } |
@@ -292,10 +292,10 @@ discard block |
||
| 292 | 292 | * @param Settings $settings The settings to apply. |
| 293 | 293 | * @param bool $is_title Optional. Default false. |
| 294 | 294 | */ |
| 295 | - protected function apply_fixes_to_html_node( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 296 | - foreach ( self::GROUPS as $group ) { |
|
| 297 | - foreach ( $this->node_fixes[ $group ] as $fix ) { |
|
| 298 | - $fix->apply( $textnode, $settings, $is_title ); |
|
| 295 | + protected function apply_fixes_to_html_node(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 296 | + foreach (self::GROUPS as $group) { |
|
| 297 | + foreach ($this->node_fixes[$group] as $fix) { |
|
| 298 | + $fix->apply($textnode, $settings, $is_title); |
|
| 299 | 299 | } |
| 300 | 300 | } |
| 301 | 301 | } |
@@ -307,11 +307,11 @@ discard block |
||
| 307 | 307 | * @param Settings $settings The settings to apply. |
| 308 | 308 | * @param bool $is_title Optional. Default false. |
| 309 | 309 | */ |
| 310 | - protected function apply_fixes_to_feed_node( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 311 | - foreach ( self::GROUPS as $group ) { |
|
| 312 | - foreach ( $this->node_fixes[ $group ] as $fix ) { |
|
| 313 | - if ( $fix->feed_compatible() ) { |
|
| 314 | - $fix->apply( $textnode, $settings, $is_title ); |
|
| 310 | + protected function apply_fixes_to_feed_node(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 311 | + foreach (self::GROUPS as $group) { |
|
| 312 | + foreach ($this->node_fixes[$group] as $fix) { |
|
| 313 | + if ($fix->feed_compatible()) { |
|
| 314 | + $fix->apply($textnode, $settings, $is_title); |
|
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | } |
@@ -326,28 +326,28 @@ discard block |
||
| 326 | 326 | * |
| 327 | 327 | * @return \DOMDocument|null The encoding has already been set to UTF-8. Returns null if there were parsing errors. |
| 328 | 328 | */ |
| 329 | - public function parse_html( \Masterminds\HTML5 $parser, $html, Settings $settings ) { |
|
| 329 | + public function parse_html(\Masterminds\HTML5 $parser, $html, Settings $settings) { |
|
| 330 | 330 | // Silence some parsing errors for invalid HTML. |
| 331 | - set_error_handler( [ $this, 'handle_parsing_errors' ] ); // @codingStandardsIgnoreLine |
|
| 332 | - $xml_error_handling = libxml_use_internal_errors( true ); |
|
| 331 | + set_error_handler([$this, 'handle_parsing_errors']); // @codingStandardsIgnoreLine |
|
| 332 | + $xml_error_handling = libxml_use_internal_errors(true); |
|
| 333 | 333 | |
| 334 | 334 | // Do the actual parsing. |
| 335 | - $dom = $parser->loadHTML( '<!DOCTYPE html><html><body>' . $html . '</body></html>' ); |
|
| 335 | + $dom = $parser->loadHTML('<!DOCTYPE html><html><body>' . $html . '</body></html>'); |
|
| 336 | 336 | $dom->encoding = 'UTF-8'; |
| 337 | 337 | |
| 338 | 338 | // Restore original error handling. |
| 339 | 339 | libxml_clear_errors(); |
| 340 | - libxml_use_internal_errors( $xml_error_handling ); |
|
| 340 | + libxml_use_internal_errors($xml_error_handling); |
|
| 341 | 341 | restore_error_handler(); |
| 342 | 342 | |
| 343 | 343 | // Handle any parser errors. |
| 344 | 344 | $errors = $parser->getErrors(); |
| 345 | - if ( ! empty( $settings['parserErrorsHandler'] ) && ! empty( $errors ) ) { |
|
| 346 | - $errors = call_user_func( $settings['parserErrorsHandler'], $errors ); |
|
| 345 | + if ( ! empty($settings['parserErrorsHandler']) && ! empty($errors)) { |
|
| 346 | + $errors = call_user_func($settings['parserErrorsHandler'], $errors); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | // Return null if there are still unhandled parsing errors. |
| 350 | - if ( ! empty( $errors ) && ! $settings['parserErrorsIgnore'] ) { |
|
| 350 | + if ( ! empty($errors) && ! $settings['parserErrorsIgnore']) { |
|
| 351 | 351 | $dom = null; |
| 352 | 352 | } |
| 353 | 353 | |
@@ -365,13 +365,13 @@ discard block |
||
| 365 | 365 | * |
| 366 | 366 | * @return boolean Returns true if the error was handled, false otherwise. |
| 367 | 367 | */ |
| 368 | - public function handle_parsing_errors( $errno, $errstr, $errfile, $errline, array $errcontext ) { |
|
| 369 | - if ( ! ( error_reporting() & $errno ) ) { // @codingStandardsIgnoreLine. |
|
| 368 | + public function handle_parsing_errors($errno, $errstr, $errfile, $errline, array $errcontext) { |
|
| 369 | + if ( ! (error_reporting() & $errno)) { // @codingStandardsIgnoreLine. |
|
| 370 | 370 | return true; // not interesting. |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | // Ignore warnings from parser & let PHP handle the rest. |
| 374 | - return $errno & E_USER_WARNING && 0 === substr_compare( $errfile, 'DOMTreeBuilder.php', -18 ); |
|
| 374 | + return $errno & E_USER_WARNING && 0 === substr_compare($errfile, 'DOMTreeBuilder.php', -18); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -383,25 +383,25 @@ discard block |
||
| 383 | 383 | * |
| 384 | 384 | * @return array An array of \DOMNode (can be empty). |
| 385 | 385 | */ |
| 386 | - public function query_tags_to_ignore( \DOMXPath $xpath, \DOMNode $initial_node, Settings $settings ) { |
|
| 386 | + public function query_tags_to_ignore(\DOMXPath $xpath, \DOMNode $initial_node, Settings $settings) { |
|
| 387 | 387 | $elements = []; |
| 388 | 388 | $query_parts = []; |
| 389 | - if ( ! empty( $settings['ignoreTags'] ) ) { |
|
| 390 | - $query_parts[] = '//' . implode( ' | //', $settings['ignoreTags'] ); |
|
| 389 | + if ( ! empty($settings['ignoreTags'])) { |
|
| 390 | + $query_parts[] = '//' . implode(' | //', $settings['ignoreTags']); |
|
| 391 | 391 | } |
| 392 | - if ( ! empty( $settings['ignoreClasses'] ) ) { |
|
| 393 | - $query_parts[] = "//*[contains(concat(' ', @class, ' '), ' " . implode( " ') or contains(concat(' ', @class, ' '), ' ", $settings['ignoreClasses'] ) . " ')]"; |
|
| 392 | + if ( ! empty($settings['ignoreClasses'])) { |
|
| 393 | + $query_parts[] = "//*[contains(concat(' ', @class, ' '), ' " . implode(" ') or contains(concat(' ', @class, ' '), ' ", $settings['ignoreClasses']) . " ')]"; |
|
| 394 | 394 | } |
| 395 | - if ( ! empty( $settings['ignoreIDs'] ) ) { |
|
| 396 | - $query_parts[] = '//*[@id=\'' . implode( '\' or @id=\'', $settings['ignoreIDs'] ) . '\']'; |
|
| 395 | + if ( ! empty($settings['ignoreIDs'])) { |
|
| 396 | + $query_parts[] = '//*[@id=\'' . implode('\' or @id=\'', $settings['ignoreIDs']) . '\']'; |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - if ( ! empty( $query_parts ) ) { |
|
| 400 | - $ignore_query = implode( ' | ', $query_parts ); |
|
| 399 | + if ( ! empty($query_parts)) { |
|
| 400 | + $ignore_query = implode(' | ', $query_parts); |
|
| 401 | 401 | |
| 402 | - $nodelist = $xpath->query( $ignore_query, $initial_node ); |
|
| 403 | - if ( false !== $nodelist ) { |
|
| 404 | - $elements = DOM::nodelist_to_array( $nodelist ); |
|
| 402 | + $nodelist = $xpath->query($ignore_query, $initial_node); |
|
| 403 | + if (false !== $nodelist) { |
|
| 404 | + $elements = DOM::nodelist_to_array($nodelist); |
|
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | |
@@ -416,25 +416,25 @@ discard block |
||
| 416 | 416 | * |
| 417 | 417 | * @return \DOMNode|array An array of \DOMNode containing the new nodes or the old \DOMNode if the replacement failed. |
| 418 | 418 | */ |
| 419 | - public function replace_node_with_html( \DOMNode $node, $content ) { |
|
| 419 | + public function replace_node_with_html(\DOMNode $node, $content) { |
|
| 420 | 420 | $result = $node; |
| 421 | 421 | |
| 422 | 422 | $parent = $node->parentNode; |
| 423 | - if ( empty( $parent ) ) { |
|
| 423 | + if (empty($parent)) { |
|
| 424 | 424 | return $node; // abort early to save cycles. |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - set_error_handler( [ $this, 'handle_parsing_errors' ] ); // @codingStandardsIgnoreLine. |
|
| 427 | + set_error_handler([$this, 'handle_parsing_errors']); // @codingStandardsIgnoreLine. |
|
| 428 | 428 | |
| 429 | - $html_fragment = $this->get_html5_parser()->loadHTMLFragment( $content ); |
|
| 430 | - if ( ! empty( $html_fragment ) ) { |
|
| 431 | - $imported_fragment = $node->ownerDocument->importNode( $html_fragment, true ); |
|
| 429 | + $html_fragment = $this->get_html5_parser()->loadHTMLFragment($content); |
|
| 430 | + if ( ! empty($html_fragment)) { |
|
| 431 | + $imported_fragment = $node->ownerDocument->importNode($html_fragment, true); |
|
| 432 | 432 | |
| 433 | - if ( ! empty( $imported_fragment ) ) { |
|
| 433 | + if ( ! empty($imported_fragment)) { |
|
| 434 | 434 | // Save the children of the imported DOMDocumentFragment before replacement. |
| 435 | - $children = DOM::nodelist_to_array( $imported_fragment->childNodes ); |
|
| 435 | + $children = DOM::nodelist_to_array($imported_fragment->childNodes); |
|
| 436 | 436 | |
| 437 | - if ( false !== $parent->replaceChild( $imported_fragment, $node ) ) { |
|
| 437 | + if (false !== $parent->replaceChild($imported_fragment, $node)) { |
|
| 438 | 438 | // Success! We return the saved array of DOMNodes as |
| 439 | 439 | // $imported_fragment is just an empty DOMDocumentFragment now. |
| 440 | 440 | $result = $children; |
@@ -454,10 +454,10 @@ discard block |
||
| 454 | 454 | */ |
| 455 | 455 | public function get_html5_parser() { |
| 456 | 456 | // Lazy-load HTML5 parser. |
| 457 | - if ( ! isset( $this->html5_parser ) ) { |
|
| 458 | - $this->html5_parser = new \Masterminds\HTML5( [ |
|
| 457 | + if ( ! isset($this->html5_parser)) { |
|
| 458 | + $this->html5_parser = new \Masterminds\HTML5([ |
|
| 459 | 459 | 'disable_html_ns' => true, |
| 460 | - ] ); |
|
| 460 | + ]); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | return $this->html5_parser; |
@@ -469,7 +469,7 @@ discard block |
||
| 469 | 469 | * @return Hyphenator_Cache |
| 470 | 470 | */ |
| 471 | 471 | public function get_hyphenator_cache() { |
| 472 | - if ( ! isset( $this->hyphenator_cache ) ) { |
|
| 472 | + if ( ! isset($this->hyphenator_cache)) { |
|
| 473 | 473 | $this->hyphenator_cache = new Hyphenator_Cache(); |
| 474 | 474 | } |
| 475 | 475 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | * |
| 482 | 482 | * @param Hyphenator_Cache $cache A hyphenator cache instance. |
| 483 | 483 | */ |
| 484 | - public function set_hyphenator_cache( Hyphenator_Cache $cache ) { |
|
| 484 | + public function set_hyphenator_cache(Hyphenator_Cache $cache) { |
|
| 485 | 485 | $this->hyphenator_cache = $cache; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -495,8 +495,8 @@ discard block |
||
| 495 | 495 | * |
| 496 | 496 | * @throws \InvalidArgumentException Group is invalid. |
| 497 | 497 | */ |
| 498 | - public function register_node_fix( Node_Fix $fix, $group ) { |
|
| 499 | - switch ( $group ) { |
|
| 498 | + public function register_node_fix(Node_Fix $fix, $group) { |
|
| 499 | + switch ($group) { |
|
| 500 | 500 | case self::CHARACTERS: |
| 501 | 501 | case self::SPACING_PRE_WORDS: |
| 502 | 502 | case self::PROCESS_WORDS: // Used internally. |
@@ -505,10 +505,10 @@ discard block |
||
| 505 | 505 | break; |
| 506 | 506 | |
| 507 | 507 | default: |
| 508 | - throw new \InvalidArgumentException( "Invalid fixer group $group." ); |
|
| 508 | + throw new \InvalidArgumentException("Invalid fixer group $group."); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - $this->node_fixes[ $group ][] = $fix; |
|
| 511 | + $this->node_fixes[$group][] = $fix; |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | /** |
@@ -518,8 +518,8 @@ discard block |
||
| 518 | 518 | * |
| 519 | 519 | * @param Token_Fix $fix Required. |
| 520 | 520 | */ |
| 521 | - public function register_token_fix( Token_Fix $fix ) { |
|
| 522 | - $this->process_words_fix->register_token_fix( $fix ); |
|
| 521 | + public function register_token_fix(Token_Fix $fix) { |
|
| 522 | + $this->process_words_fix->register_token_fix($fix); |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | /** |
@@ -529,27 +529,27 @@ discard block |
||
| 529 | 529 | * |
| 530 | 530 | * @return array An array in the form ( $language_code => $language_name ). |
| 531 | 531 | */ |
| 532 | - private static function get_language_plugin_list( $path ) { |
|
| 532 | + private static function get_language_plugin_list($path) { |
|
| 533 | 533 | $language_name_pattern = '/"language"\s*:\s*((".+")|(\'.+\'))\s*,/'; |
| 534 | 534 | $languages = []; |
| 535 | - $handler = opendir( $path ); |
|
| 535 | + $handler = opendir($path); |
|
| 536 | 536 | |
| 537 | 537 | // Read all files in directory. |
| 538 | - while ( $file = readdir( $handler ) ) { |
|
| 538 | + while ($file = readdir($handler)) { |
|
| 539 | 539 | // We only want the JSON files. |
| 540 | - if ( '.json' === substr( $file, -5 ) ) { |
|
| 541 | - $file_content = file_get_contents( $path . $file ); |
|
| 542 | - if ( preg_match( $language_name_pattern, $file_content, $matches ) ) { |
|
| 543 | - $language_name = substr( $matches[1], 1, -1 ); |
|
| 544 | - $language_code = substr( $file, 0, -5 ); |
|
| 545 | - $languages[ $language_code ] = $language_name; |
|
| 540 | + if ('.json' === substr($file, -5)) { |
|
| 541 | + $file_content = file_get_contents($path . $file); |
|
| 542 | + if (preg_match($language_name_pattern, $file_content, $matches)) { |
|
| 543 | + $language_name = substr($matches[1], 1, -1); |
|
| 544 | + $language_code = substr($file, 0, -5); |
|
| 545 | + $languages[$language_code] = $language_name; |
|
| 546 | 546 | } |
| 547 | 547 | } |
| 548 | 548 | } |
| 549 | - closedir( $handler ); |
|
| 549 | + closedir($handler); |
|
| 550 | 550 | |
| 551 | 551 | // Sort translated language names according to current locale. |
| 552 | - asort( $languages ); |
|
| 552 | + asort($languages); |
|
| 553 | 553 | |
| 554 | 554 | return $languages; |
| 555 | 555 | } |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | * @return array An array in the form of ( LANG_CODE => LANGUAGE ). |
| 563 | 563 | */ |
| 564 | 564 | public static function get_hyphenation_languages() { |
| 565 | - return self::get_language_plugin_list( __DIR__ . '/lang/' ); |
|
| 565 | + return self::get_language_plugin_list(__DIR__ . '/lang/'); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | /** |
@@ -573,6 +573,6 @@ discard block |
||
| 573 | 573 | * @return array An array in the form of ( LANG_CODE => LANGUAGE ). |
| 574 | 574 | */ |
| 575 | 575 | public static function get_diacritic_languages() { |
| 576 | - return self::get_language_plugin_list( __DIR__ . '/diacritics/' ); |
|
| 576 | + return self::get_language_plugin_list(__DIR__ . '/diacritics/'); |
|
| 577 | 577 | } |
| 578 | 578 | } |
@@ -31,31 +31,31 @@ |
||
| 31 | 31 | /** |
| 32 | 32 | * Autoload parser classes |
| 33 | 33 | */ |
| 34 | -$autoload = dirname( dirname( __DIR__ ) ) . '/vendor/autoload.php'; |
|
| 35 | -if ( file_exists( $autoload ) ) { |
|
| 34 | +$autoload = dirname(dirname(__DIR__)) . '/vendor/autoload.php'; |
|
| 35 | +if (file_exists($autoload)) { |
|
| 36 | 36 | require_once $autoload; |
| 37 | 37 | } else { |
| 38 | 38 | // We are a dependency of another project. |
| 39 | - require_once dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) . '/autoload.php'; |
|
| 39 | + require_once dirname(dirname(dirname(dirname(__DIR__)))) . '/autoload.php'; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | -$target_directory = dirname( __DIR__ ) . '/lang'; |
|
| 43 | -$patterns_list = json_decode( file_get_contents( __DIR__ . '/patterns.json' ), true ); |
|
| 42 | +$target_directory = dirname(__DIR__) . '/lang'; |
|
| 43 | +$patterns_list = json_decode(file_get_contents(__DIR__ . '/patterns.json'), true); |
|
| 44 | 44 | |
| 45 | -foreach ( $patterns_list['list'] as $pattern ) { |
|
| 45 | +foreach ($patterns_list['list'] as $pattern) { |
|
| 46 | 46 | $language = $pattern['name']; |
| 47 | 47 | $url = $pattern['url']; |
| 48 | 48 | $filename = $pattern['short'] . '.json'; |
| 49 | 49 | |
| 50 | - $converter = new Pattern_Converter( $url, $language ); |
|
| 50 | + $converter = new Pattern_Converter($url, $language); |
|
| 51 | 51 | |
| 52 | 52 | echo "Parsing $language TeX file and converting it to lang/$filename ..."; // phpcs: XSS ok. |
| 53 | 53 | |
| 54 | 54 | try { |
| 55 | 55 | $json_pattern = $converter->convert(); |
| 56 | - file_put_contents( $target_directory . '/' . $filename, $json_pattern ); |
|
| 56 | + file_put_contents($target_directory . '/' . $filename, $json_pattern); |
|
| 57 | 57 | echo " done\n"; |
| 58 | - } catch ( \Exception $e ) { |
|
| 58 | + } catch (\Exception $e) { |
|
| 59 | 59 | echo " error, skipping\n"; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @param bool $set_defaults If true, set default values for various properties. Defaults to true. |
| 100 | 100 | */ |
| 101 | - public function __construct( $set_defaults = true ) { |
|
| 102 | - $this->init( $set_defaults ); |
|
| 101 | + public function __construct($set_defaults = true) { |
|
| 102 | + $this->init($set_defaults); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @return mixed |
| 111 | 111 | */ |
| 112 | - public function &__get( $key ) { |
|
| 113 | - return $this->data[ $key ]; |
|
| 112 | + public function &__get($key) { |
|
| 113 | + return $this->data[$key]; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -119,8 +119,8 @@ discard block |
||
| 119 | 119 | * @param string $key The settings key. |
| 120 | 120 | * @param mixed $value The settings value. |
| 121 | 121 | */ |
| 122 | - public function __set( $key, $value ) { |
|
| 123 | - $this->data[ $key ] = $value; |
|
| 122 | + public function __set($key, $value) { |
|
| 123 | + $this->data[$key] = $value; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @param string $key The settings key. |
| 130 | 130 | */ |
| 131 | - public function __isset( $key ) { |
|
| 132 | - return isset( $this->data[ $key ] ); |
|
| 131 | + public function __isset($key) { |
|
| 132 | + return isset($this->data[$key]); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -137,8 +137,8 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @param string $key The settings key. |
| 139 | 139 | */ |
| 140 | - public function __unset( $key ) { |
|
| 141 | - unset( $this->data[ $key ] ); |
|
| 140 | + public function __unset($key) { |
|
| 141 | + unset($this->data[$key]); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -147,11 +147,11 @@ discard block |
||
| 147 | 147 | * @param string $offset The settings key. |
| 148 | 148 | * @param mixed $value The settings value. |
| 149 | 149 | */ |
| 150 | - public function offsetSet( $offset, $value ) { |
|
| 151 | - if ( is_null( $offset ) ) { |
|
| 150 | + public function offsetSet($offset, $value) { |
|
| 151 | + if (is_null($offset)) { |
|
| 152 | 152 | $this->data[] = $value; |
| 153 | 153 | } else { |
| 154 | - $this->data[ $offset ] = $value; |
|
| 154 | + $this->data[$offset] = $value; |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @param string $offset The settings key. |
| 162 | 162 | */ |
| 163 | - public function offsetExists( $offset ) { |
|
| 164 | - return isset( $this->data[ $offset ] ); |
|
| 163 | + public function offsetExists($offset) { |
|
| 164 | + return isset($this->data[$offset]); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -169,8 +169,8 @@ discard block |
||
| 169 | 169 | * |
| 170 | 170 | * @param string $offset The settings key. |
| 171 | 171 | */ |
| 172 | - public function offsetUnset( $offset ) { |
|
| 173 | - unset( $this->data[ $offset ] ); |
|
| 172 | + public function offsetUnset($offset) { |
|
| 173 | + unset($this->data[$offset]); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -180,8 +180,8 @@ discard block |
||
| 180 | 180 | * |
| 181 | 181 | * @return mixed |
| 182 | 182 | */ |
| 183 | - public function offsetGet( $offset ) { |
|
| 184 | - return isset( $this->data[ $offset ] ) ? $this->data[ $offset ] : null; |
|
| 183 | + public function offsetGet($offset) { |
|
| 184 | + return isset($this->data[$offset]) ? $this->data[$offset] : null; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -235,21 +235,21 @@ discard block |
||
| 235 | 235 | * |
| 236 | 236 | * @param bool $set_defaults If true, set default values for various properties. Defaults to true. |
| 237 | 237 | */ |
| 238 | - private function init( $set_defaults = true ) { |
|
| 239 | - $this->no_break_narrow_space = U::NO_BREAK_SPACE; // used in unit spacing - can be changed to 8239 via set_true_no_break_narrow_space. |
|
| 238 | + private function init($set_defaults = true) { |
|
| 239 | + $this->no_break_narrow_space = U::NO_BREAK_SPACE; // used in unit spacing - can be changed to 8239 via set_true_no_break_narrow_space. |
|
| 240 | 240 | |
| 241 | - $this->dash_style = new Settings\Simple_Dashes( U::EM_DASH, U::THIN_SPACE, U::EN_DASH, U::THIN_SPACE ); |
|
| 241 | + $this->dash_style = new Settings\Simple_Dashes(U::EM_DASH, U::THIN_SPACE, U::EN_DASH, U::THIN_SPACE); |
|
| 242 | 242 | |
| 243 | - $this->primary_quote_style = new Settings\Simple_Quotes( U::DOUBLE_QUOTE_OPEN, U::DOUBLE_QUOTE_CLOSE ); |
|
| 244 | - $this->secondary_quote_style = new Settings\Simple_Quotes( U::SINGLE_QUOTE_OPEN, U::SINGLE_QUOTE_CLOSE ); |
|
| 243 | + $this->primary_quote_style = new Settings\Simple_Quotes(U::DOUBLE_QUOTE_OPEN, U::DOUBLE_QUOTE_CLOSE); |
|
| 244 | + $this->secondary_quote_style = new Settings\Simple_Quotes(U::SINGLE_QUOTE_OPEN, U::SINGLE_QUOTE_CLOSE); |
|
| 245 | 245 | |
| 246 | 246 | // Set up some arrays for quick HTML5 introspection. |
| 247 | - $this->self_closing_tags = array_filter( array_keys( \Masterminds\HTML5\Elements::$html5 ), function( $tag ) { |
|
| 248 | - return \Masterminds\HTML5\Elements::isA( $tag, \Masterminds\HTML5\Elements::VOID_TAG ); |
|
| 247 | + $this->self_closing_tags = array_filter(array_keys(\Masterminds\HTML5\Elements::$html5), function($tag) { |
|
| 248 | + return \Masterminds\HTML5\Elements::isA($tag, \Masterminds\HTML5\Elements::VOID_TAG); |
|
| 249 | 249 | } ); |
| 250 | - $this->inappropriate_tags = [ 'iframe', 'textarea', 'button', 'select', 'optgroup', 'option', 'map', 'style', 'head', 'title', 'script', 'applet', 'object', 'param' ]; |
|
| 250 | + $this->inappropriate_tags = ['iframe', 'textarea', 'button', 'select', 'optgroup', 'option', 'map', 'style', 'head', 'title', 'script', 'applet', 'object', 'param']; |
|
| 251 | 251 | |
| 252 | - if ( $set_defaults ) { |
|
| 252 | + if ($set_defaults) { |
|
| 253 | 253 | $this->set_defaults(); |
| 254 | 254 | } |
| 255 | 255 | } |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | * |
| 326 | 326 | * @param bool $on Optional. Default false. |
| 327 | 327 | */ |
| 328 | - public function set_ignore_parser_errors( $on = false ) { |
|
| 328 | + public function set_ignore_parser_errors($on = false) { |
|
| 329 | 329 | $this->data['parserErrorsIgnore'] = $on; |
| 330 | 330 | } |
| 331 | 331 | |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | * |
| 335 | 335 | * @param callable|null $handler Optional. A callable that takes an array of error strings as its parameter. Default null. |
| 336 | 336 | */ |
| 337 | - public function set_parser_errors_handler( $handler = null ) { |
|
| 338 | - if ( ! empty( $handler ) && ! is_callable( $handler ) ) { |
|
| 337 | + public function set_parser_errors_handler($handler = null) { |
|
| 338 | + if ( ! empty($handler) && ! is_callable($handler)) { |
|
| 339 | 339 | return; // Invalid handler, abort. |
| 340 | 340 | } |
| 341 | 341 | |
@@ -347,9 +347,9 @@ discard block |
||
| 347 | 347 | * |
| 348 | 348 | * @param bool $on Optional. Default false. |
| 349 | 349 | */ |
| 350 | - public function set_true_no_break_narrow_space( $on = false ) { |
|
| 350 | + public function set_true_no_break_narrow_space($on = false) { |
|
| 351 | 351 | |
| 352 | - if ( $on ) { |
|
| 352 | + if ($on) { |
|
| 353 | 353 | $this->no_break_narrow_space = U::NO_BREAK_NARROW_SPACE; |
| 354 | 354 | } else { |
| 355 | 355 | $this->no_break_narrow_space = U::NO_BREAK_SPACE; |
@@ -361,12 +361,12 @@ discard block |
||
| 361 | 361 | * |
| 362 | 362 | * @param string|array $tags A comma separated list or an array of tag names. |
| 363 | 363 | */ |
| 364 | - public function set_tags_to_ignore( $tags = [ 'code', 'head', 'kbd', 'object', 'option', 'pre', 'samp', 'script', 'noscript', 'noembed', 'select', 'style', 'textarea', 'title', 'var', 'math' ] ) { |
|
| 364 | + public function set_tags_to_ignore($tags = ['code', 'head', 'kbd', 'object', 'option', 'pre', 'samp', 'script', 'noscript', 'noembed', 'select', 'style', 'textarea', 'title', 'var', 'math']) { |
|
| 365 | 365 | // Ensure that we pass only lower-case tag names to XPath. |
| 366 | - $tags = array_filter( array_map( 'strtolower', Strings::maybe_split_parameters( $tags ) ), 'ctype_alnum' ); |
|
| 366 | + $tags = array_filter(array_map('strtolower', Strings::maybe_split_parameters($tags)), 'ctype_alnum'); |
|
| 367 | 367 | |
| 368 | 368 | // Self closing tags shouldn't be in $tags. |
| 369 | - $this->data['ignoreTags'] = array_unique( array_merge( array_diff( $tags, $this->self_closing_tags ), $this->inappropriate_tags ) ); |
|
| 369 | + $this->data['ignoreTags'] = array_unique(array_merge(array_diff($tags, $this->self_closing_tags), $this->inappropriate_tags)); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -374,8 +374,8 @@ discard block |
||
| 374 | 374 | * |
| 375 | 375 | * @param string|array $classes A comma separated list or an array of class names. |
| 376 | 376 | */ |
| 377 | - public function set_classes_to_ignore( $classes = [ 'vcard', 'noTypo' ] ) { |
|
| 378 | - $this->data['ignoreClasses'] = Strings::maybe_split_parameters( $classes ); |
|
| 377 | + public function set_classes_to_ignore($classes = ['vcard', 'noTypo']) { |
|
| 378 | + $this->data['ignoreClasses'] = Strings::maybe_split_parameters($classes); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -383,8 +383,8 @@ discard block |
||
| 383 | 383 | * |
| 384 | 384 | * @param string|array $ids A comma separated list or an array of tag names. |
| 385 | 385 | */ |
| 386 | - public function set_ids_to_ignore( $ids = [] ) { |
|
| 387 | - $this->data['ignoreIDs'] = Strings::maybe_split_parameters( $ids ); |
|
| 386 | + public function set_ids_to_ignore($ids = []) { |
|
| 387 | + $this->data['ignoreIDs'] = Strings::maybe_split_parameters($ids); |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | /** |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | * |
| 393 | 393 | * @param bool $on Optional. Default true. |
| 394 | 394 | */ |
| 395 | - public function set_smart_quotes( $on = true ) { |
|
| 395 | + public function set_smart_quotes($on = true) { |
|
| 396 | 396 | $this->data['smartQuotes'] = $on; |
| 397 | 397 | } |
| 398 | 398 | |
@@ -420,8 +420,8 @@ discard block |
||
| 420 | 420 | * |
| 421 | 421 | * @throws \DomainException Thrown if $style constant is invalid. |
| 422 | 422 | */ |
| 423 | - public function set_smart_quotes_primary( $style = Quote_Style::DOUBLE_CURLED ) { |
|
| 424 | - $this->primary_quote_style = $this->get_quote_style( $style ); |
|
| 423 | + public function set_smart_quotes_primary($style = Quote_Style::DOUBLE_CURLED) { |
|
| 424 | + $this->primary_quote_style = $this->get_quote_style($style); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -448,8 +448,8 @@ discard block |
||
| 448 | 448 | * |
| 449 | 449 | * @throws \DomainException Thrown if $style constant is invalid. |
| 450 | 450 | */ |
| 451 | - public function set_smart_quotes_secondary( $style = Quote_Style::SINGLE_CURLED ) { |
|
| 452 | - $this->secondary_quote_style = $this->get_quote_style( $style ); |
|
| 451 | + public function set_smart_quotes_secondary($style = Quote_Style::SINGLE_CURLED) { |
|
| 452 | + $this->secondary_quote_style = $this->get_quote_style($style); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
@@ -461,8 +461,8 @@ discard block |
||
| 461 | 461 | * |
| 462 | 462 | * @return Settings\Quotes |
| 463 | 463 | */ |
| 464 | - protected function get_quote_style( $style ) { |
|
| 465 | - return $this->get_style( $style, Settings\Quotes::class, [ Quote_Style::class, 'get_styled_quotes' ], 'quote' ); |
|
| 464 | + protected function get_quote_style($style) { |
|
| 465 | + return $this->get_style($style, Settings\Quotes::class, [Quote_Style::class, 'get_styled_quotes'], 'quote'); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -477,15 +477,15 @@ discard block |
||
| 477 | 477 | * |
| 478 | 478 | * @return object An instance of $expected_class. |
| 479 | 479 | */ |
| 480 | - protected function get_style( $style, $expected_class, callable $get_style, $description ) { |
|
| 481 | - if ( $style instanceof $expected_class ) { |
|
| 480 | + protected function get_style($style, $expected_class, callable $get_style, $description) { |
|
| 481 | + if ($style instanceof $expected_class) { |
|
| 482 | 482 | $object = $style; |
| 483 | 483 | } else { |
| 484 | - $object = $get_style( $style, $this ); |
|
| 484 | + $object = $get_style($style, $this); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | - if ( empty( $object ) ) { |
|
| 488 | - throw new \DomainException( "Invalid $description style $style." ); |
|
| 487 | + if (empty($object)) { |
|
| 488 | + throw new \DomainException("Invalid $description style $style."); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | return $object; |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | * |
| 497 | 497 | * @param bool $on Optional. Default true. |
| 498 | 498 | */ |
| 499 | - public function set_smart_dashes( $on = true ) { |
|
| 499 | + public function set_smart_dashes($on = true) { |
|
| 500 | 500 | $this->data['smartDashes'] = $on; |
| 501 | 501 | } |
| 502 | 502 | |
@@ -511,8 +511,8 @@ discard block |
||
| 511 | 511 | * |
| 512 | 512 | * @throws \DomainException Thrown if $style constant is invalid. |
| 513 | 513 | */ |
| 514 | - public function set_smart_dashes_style( $style = Dash_Style::TRADITIONAL_US ) { |
|
| 515 | - $this->dash_style = $this->get_style( $style, Settings\Dashes::class, [ Dash_Style::class, 'get_styled_dashes' ], 'dash' ); |
|
| 514 | + public function set_smart_dashes_style($style = Dash_Style::TRADITIONAL_US) { |
|
| 515 | + $this->dash_style = $this->get_style($style, Settings\Dashes::class, [Dash_Style::class, 'get_styled_dashes'], 'dash'); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | * |
| 521 | 521 | * @param bool $on Optional. Default true. |
| 522 | 522 | */ |
| 523 | - public function set_smart_ellipses( $on = true ) { |
|
| 523 | + public function set_smart_ellipses($on = true) { |
|
| 524 | 524 | $this->data['smartEllipses'] = $on; |
| 525 | 525 | } |
| 526 | 526 | |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | * |
| 530 | 530 | * @param bool $on Optional. Default true. |
| 531 | 531 | */ |
| 532 | - public function set_smart_diacritics( $on = true ) { |
|
| 532 | + public function set_smart_diacritics($on = true) { |
|
| 533 | 533 | $this->data['smartDiacritics'] = $on; |
| 534 | 534 | } |
| 535 | 535 | |
@@ -538,19 +538,19 @@ discard block |
||
| 538 | 538 | * |
| 539 | 539 | * @param string $lang Has to correspond to a filename in 'diacritics'. Optional. Default 'en-US'. |
| 540 | 540 | */ |
| 541 | - public function set_diacritic_language( $lang = 'en-US' ) { |
|
| 542 | - if ( isset( $this->data['diacriticLanguage'] ) && $this->data['diacriticLanguage'] === $lang ) { |
|
| 541 | + public function set_diacritic_language($lang = 'en-US') { |
|
| 542 | + if (isset($this->data['diacriticLanguage']) && $this->data['diacriticLanguage'] === $lang) { |
|
| 543 | 543 | return; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | $this->data['diacriticLanguage'] = $lang; |
| 547 | - $language_file_name = dirname( __FILE__ ) . '/diacritics/' . $lang . '.json'; |
|
| 547 | + $language_file_name = dirname(__FILE__) . '/diacritics/' . $lang . '.json'; |
|
| 548 | 548 | |
| 549 | - if ( file_exists( $language_file_name ) ) { |
|
| 550 | - $diacritics_file = json_decode( file_get_contents( $language_file_name ), true ); |
|
| 549 | + if (file_exists($language_file_name)) { |
|
| 550 | + $diacritics_file = json_decode(file_get_contents($language_file_name), true); |
|
| 551 | 551 | $this->data['diacriticWords'] = $diacritics_file['diacritic_words']; |
| 552 | 552 | } else { |
| 553 | - unset( $this->data['diacriticWords'] ); |
|
| 553 | + unset($this->data['diacriticWords']); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | $this->update_diacritics_replacement_arrays(); |
@@ -562,21 +562,21 @@ discard block |
||
| 562 | 562 | * @param string|array $custom_replacements An array formatted [needle=>replacement, needle=>replacement...], |
| 563 | 563 | * or a string formatted `"needle"=>"replacement","needle"=>"replacement",... |
| 564 | 564 | */ |
| 565 | - public function set_diacritic_custom_replacements( $custom_replacements = [] ) { |
|
| 566 | - if ( ! is_array( $custom_replacements ) ) { |
|
| 567 | - $custom_replacements = $this->parse_diacritics_replacement_string( $custom_replacements ); |
|
| 565 | + public function set_diacritic_custom_replacements($custom_replacements = []) { |
|
| 566 | + if ( ! is_array($custom_replacements)) { |
|
| 567 | + $custom_replacements = $this->parse_diacritics_replacement_string($custom_replacements); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - $this->data['diacriticCustomReplacements'] = Arrays::array_map_assoc( function( $key, $replacement ) { |
|
| 571 | - $key = strip_tags( trim( $key ) ); |
|
| 572 | - $replacement = strip_tags( trim( $replacement ) ); |
|
| 570 | + $this->data['diacriticCustomReplacements'] = Arrays::array_map_assoc(function($key, $replacement) { |
|
| 571 | + $key = strip_tags(trim($key)); |
|
| 572 | + $replacement = strip_tags(trim($replacement)); |
|
| 573 | 573 | |
| 574 | - if ( ! empty( $key ) && ! empty( $replacement ) ) { |
|
| 575 | - return [ $key, $replacement ]; |
|
| 574 | + if ( ! empty($key) && ! empty($replacement)) { |
|
| 575 | + return [$key, $replacement]; |
|
| 576 | 576 | } else { |
| 577 | 577 | return []; |
| 578 | 578 | } |
| 579 | - }, $custom_replacements ); |
|
| 579 | + }, $custom_replacements); |
|
| 580 | 580 | |
| 581 | 581 | $this->update_diacritics_replacement_arrays(); |
| 582 | 582 | } |
@@ -588,21 +588,21 @@ discard block |
||
| 588 | 588 | * |
| 589 | 589 | * @return array |
| 590 | 590 | */ |
| 591 | - private function parse_diacritics_replacement_string( $custom_replacements ) { |
|
| 592 | - return Arrays::array_map_assoc( function( $key, $replacement ) { |
|
| 591 | + private function parse_diacritics_replacement_string($custom_replacements) { |
|
| 592 | + return Arrays::array_map_assoc(function($key, $replacement) { |
|
| 593 | 593 | |
| 594 | 594 | // Account for single and double quotes in keys ... |
| 595 | - if ( preg_match( '/("|\')((?:(?!\1).)+)(?:\1\s*=>)/', $replacement, $match ) ) { |
|
| 595 | + if (preg_match('/("|\')((?:(?!\1).)+)(?:\1\s*=>)/', $replacement, $match)) { |
|
| 596 | 596 | $key = $match[2]; |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | // ... and values. |
| 600 | - if ( preg_match( '/(?:=>\s*("|\'))((?:(?!\1).)+)(?:\1)/', $replacement, $match ) ) { |
|
| 600 | + if (preg_match('/(?:=>\s*("|\'))((?:(?!\1).)+)(?:\1)/', $replacement, $match)) { |
|
| 601 | 601 | $replacement = $match[2]; |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | - return [ $key, $replacement ]; |
|
| 605 | - }, preg_split( '/,/', $custom_replacements, -1, PREG_SPLIT_NO_EMPTY ) ); |
|
| 604 | + return [$key, $replacement]; |
|
| 605 | + }, preg_split('/,/', $custom_replacements, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | /** |
@@ -615,11 +615,11 @@ discard block |
||
| 615 | 615 | $patterns = []; |
| 616 | 616 | $replacements = []; |
| 617 | 617 | |
| 618 | - if ( ! empty( $this->data['diacriticCustomReplacements'] ) ) { |
|
| 619 | - $this->parse_diacritics_rules( $this->data['diacriticCustomReplacements'], $patterns, $replacements ); |
|
| 618 | + if ( ! empty($this->data['diacriticCustomReplacements'])) { |
|
| 619 | + $this->parse_diacritics_rules($this->data['diacriticCustomReplacements'], $patterns, $replacements); |
|
| 620 | 620 | } |
| 621 | - if ( ! empty( $this->data['diacriticWords'] ) ) { |
|
| 622 | - $this->parse_diacritics_rules( $this->data['diacriticWords'], $patterns, $replacements ); |
|
| 621 | + if ( ! empty($this->data['diacriticWords'])) { |
|
| 622 | + $this->parse_diacritics_rules($this->data['diacriticWords'], $patterns, $replacements); |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | $this->data['diacriticReplacement'] = [ |
@@ -635,11 +635,11 @@ discard block |
||
| 635 | 635 | * @param array $patterns Resulting patterns. Passed by reference. |
| 636 | 636 | * @param array $replacements Resulting replacements. Passed by reference. |
| 637 | 637 | */ |
| 638 | - private function parse_diacritics_rules( array $diacritics_rules, array &$patterns, array &$replacements ) { |
|
| 638 | + private function parse_diacritics_rules(array $diacritics_rules, array &$patterns, array &$replacements) { |
|
| 639 | 639 | |
| 640 | - foreach ( $diacritics_rules as $needle => $replacement ) { |
|
| 640 | + foreach ($diacritics_rules as $needle => $replacement) { |
|
| 641 | 641 | $patterns[] = '/\b(?<!\w[' . U::NO_BREAK_SPACE . U::SOFT_HYPHEN . '])' . $needle . '\b(?![' . U::NO_BREAK_SPACE . U::SOFT_HYPHEN . ']\w)/u'; |
| 642 | - $replacements[ $needle ] = $replacement; |
|
| 642 | + $replacements[$needle] = $replacement; |
|
| 643 | 643 | } |
| 644 | 644 | } |
| 645 | 645 | |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | * |
| 649 | 649 | * @param bool $on Optional. Default true. |
| 650 | 650 | */ |
| 651 | - public function set_smart_marks( $on = true ) { |
|
| 651 | + public function set_smart_marks($on = true) { |
|
| 652 | 652 | $this->data['smartMarks'] = $on; |
| 653 | 653 | } |
| 654 | 654 | |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | * |
| 658 | 658 | * @param bool $on Optional. Default true. |
| 659 | 659 | */ |
| 660 | - public function set_smart_math( $on = true ) { |
|
| 660 | + public function set_smart_math($on = true) { |
|
| 661 | 661 | $this->data['smartMath'] = $on; |
| 662 | 662 | } |
| 663 | 663 | |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | * |
| 667 | 667 | * @param bool $on Optional. Default true. |
| 668 | 668 | */ |
| 669 | - public function set_smart_exponents( $on = true ) { |
|
| 669 | + public function set_smart_exponents($on = true) { |
|
| 670 | 670 | $this->data['smartExponents'] = $on; |
| 671 | 671 | } |
| 672 | 672 | |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | * |
| 676 | 676 | * @param bool $on Optional. Default true. |
| 677 | 677 | */ |
| 678 | - public function set_smart_fractions( $on = true ) { |
|
| 678 | + public function set_smart_fractions($on = true) { |
|
| 679 | 679 | $this->data['smartFractions'] = $on; |
| 680 | 680 | } |
| 681 | 681 | |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | * |
| 685 | 685 | * @param bool $on Optional. Default true. |
| 686 | 686 | */ |
| 687 | - public function set_smart_ordinal_suffix( $on = true ) { |
|
| 687 | + public function set_smart_ordinal_suffix($on = true) { |
|
| 688 | 688 | $this->data['smartOrdinalSuffix'] = $on; |
| 689 | 689 | } |
| 690 | 690 | |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | * |
| 694 | 694 | * @param bool $on Optional. Default true. |
| 695 | 695 | */ |
| 696 | - public function set_single_character_word_spacing( $on = true ) { |
|
| 696 | + public function set_single_character_word_spacing($on = true) { |
|
| 697 | 697 | $this->data['singleCharacterWordSpacing'] = $on; |
| 698 | 698 | } |
| 699 | 699 | |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | * |
| 703 | 703 | * @param bool $on Optional. Default true. |
| 704 | 704 | */ |
| 705 | - public function set_fraction_spacing( $on = true ) { |
|
| 705 | + public function set_fraction_spacing($on = true) { |
|
| 706 | 706 | $this->data['fractionSpacing'] = $on; |
| 707 | 707 | } |
| 708 | 708 | |
@@ -711,7 +711,7 @@ discard block |
||
| 711 | 711 | * |
| 712 | 712 | * @param bool $on Optional. Default true. |
| 713 | 713 | */ |
| 714 | - public function set_unit_spacing( $on = true ) { |
|
| 714 | + public function set_unit_spacing($on = true) { |
|
| 715 | 715 | $this->data['unitSpacing'] = $on; |
| 716 | 716 | } |
| 717 | 717 | |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | * |
| 721 | 721 | * @param bool $on Optional. Default true. |
| 722 | 722 | */ |
| 723 | - public function set_numbered_abbreviation_spacing( $on = true ) { |
|
| 723 | + public function set_numbered_abbreviation_spacing($on = true) { |
|
| 724 | 724 | $this->data['numberedAbbreviationSpacing'] = $on; |
| 725 | 725 | } |
| 726 | 726 | |
@@ -729,7 +729,7 @@ discard block |
||
| 729 | 729 | * |
| 730 | 730 | * @param bool $on Optional. Default true. |
| 731 | 731 | */ |
| 732 | - public function set_french_punctuation_spacing( $on = true ) { |
|
| 732 | + public function set_french_punctuation_spacing($on = true) { |
|
| 733 | 733 | $this->data['frenchPunctuationSpacing'] = $on; |
| 734 | 734 | } |
| 735 | 735 | |
@@ -738,9 +738,9 @@ discard block |
||
| 738 | 738 | * |
| 739 | 739 | * @param string|array $units A comma separated list or an array of units. |
| 740 | 740 | */ |
| 741 | - public function set_units( $units = [] ) { |
|
| 742 | - $this->data['units'] = Strings::maybe_split_parameters( $units ); |
|
| 743 | - $this->update_unit_pattern( $this->data['units'] ); |
|
| 741 | + public function set_units($units = []) { |
|
| 742 | + $this->data['units'] = Strings::maybe_split_parameters($units); |
|
| 743 | + $this->update_unit_pattern($this->data['units']); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | /** |
@@ -748,14 +748,14 @@ discard block |
||
| 748 | 748 | * |
| 749 | 749 | * @param array $units An array of unit names. |
| 750 | 750 | */ |
| 751 | - private function update_unit_pattern( array $units ) { |
|
| 751 | + private function update_unit_pattern(array $units) { |
|
| 752 | 752 | // Update components & regex pattern. |
| 753 | - foreach ( $units as $index => $unit ) { |
|
| 753 | + foreach ($units as $index => $unit) { |
|
| 754 | 754 | // Escape special chars. |
| 755 | - $units[ $index ] = preg_replace( '#([\[\\\^\$\.\|\?\*\+\(\)\{\}])#', '\\\\$1', $unit ); |
|
| 755 | + $units[$index] = preg_replace('#([\[\\\^\$\.\|\?\*\+\(\)\{\}])#', '\\\\$1', $unit); |
|
| 756 | 756 | } |
| 757 | - $this->custom_units = implode( '|', $units ); |
|
| 758 | - $this->custom_units .= ( $this->custom_units ) ? '|' : ''; |
|
| 757 | + $this->custom_units = implode('|', $units); |
|
| 758 | + $this->custom_units .= ($this->custom_units) ? '|' : ''; |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | /** |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | * |
| 764 | 764 | * @param bool $on Optional. Default true. |
| 765 | 765 | */ |
| 766 | - public function set_dash_spacing( $on = true ) { |
|
| 766 | + public function set_dash_spacing($on = true) { |
|
| 767 | 767 | $this->data['dashSpacing'] = $on; |
| 768 | 768 | } |
| 769 | 769 | |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | * |
| 773 | 773 | * @param bool $on Optional. Default true. |
| 774 | 774 | */ |
| 775 | - public function set_space_collapse( $on = true ) { |
|
| 775 | + public function set_space_collapse($on = true) { |
|
| 776 | 776 | $this->data['spaceCollapse'] = $on; |
| 777 | 777 | } |
| 778 | 778 | |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | * |
| 782 | 782 | * @param bool $on Optional. Default true. |
| 783 | 783 | */ |
| 784 | - public function set_dewidow( $on = true ) { |
|
| 784 | + public function set_dewidow($on = true) { |
|
| 785 | 785 | $this->data['dewidow'] = $on; |
| 786 | 786 | } |
| 787 | 787 | |
@@ -790,8 +790,8 @@ discard block |
||
| 790 | 790 | * |
| 791 | 791 | * @param int $length Defaults to 5. Trying to set the value to less than 2 resets the length to the default. |
| 792 | 792 | */ |
| 793 | - public function set_max_dewidow_length( $length = 5 ) { |
|
| 794 | - $length = ( $length > 1 ) ? $length : 5; |
|
| 793 | + public function set_max_dewidow_length($length = 5) { |
|
| 794 | + $length = ($length > 1) ? $length : 5; |
|
| 795 | 795 | |
| 796 | 796 | $this->data['dewidowMaxLength'] = $length; |
| 797 | 797 | } |
@@ -801,8 +801,8 @@ discard block |
||
| 801 | 801 | * |
| 802 | 802 | * @param int $length Defaults to 5. Trying to set the value to less than 2 resets the length to the default. |
| 803 | 803 | */ |
| 804 | - public function set_max_dewidow_pull( $length = 5 ) { |
|
| 805 | - $length = ( $length > 1 ) ? $length : 5; |
|
| 804 | + public function set_max_dewidow_pull($length = 5) { |
|
| 805 | + $length = ($length > 1) ? $length : 5; |
|
| 806 | 806 | |
| 807 | 807 | $this->data['dewidowMaxPull'] = $length; |
| 808 | 808 | } |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | * |
| 813 | 813 | * @param bool $on Optional. Default true. |
| 814 | 814 | */ |
| 815 | - public function set_wrap_hard_hyphens( $on = true ) { |
|
| 815 | + public function set_wrap_hard_hyphens($on = true) { |
|
| 816 | 816 | $this->data['hyphenHardWrap'] = $on; |
| 817 | 817 | } |
| 818 | 818 | |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | * |
| 822 | 822 | * @param bool $on Optional. Default true. |
| 823 | 823 | */ |
| 824 | - public function set_url_wrap( $on = true ) { |
|
| 824 | + public function set_url_wrap($on = true) { |
|
| 825 | 825 | $this->data['urlWrap'] = $on; |
| 826 | 826 | } |
| 827 | 827 | |
@@ -830,7 +830,7 @@ discard block |
||
| 830 | 830 | * |
| 831 | 831 | * @param bool $on Optional. Default true. |
| 832 | 832 | */ |
| 833 | - public function set_email_wrap( $on = true ) { |
|
| 833 | + public function set_email_wrap($on = true) { |
|
| 834 | 834 | $this->data['emailWrap'] = $on; |
| 835 | 835 | } |
| 836 | 836 | |
@@ -839,8 +839,8 @@ discard block |
||
| 839 | 839 | * |
| 840 | 840 | * @param int $length Defaults to 5. Trying to set the value to less than 1 resets the length to the default. |
| 841 | 841 | */ |
| 842 | - public function set_min_after_url_wrap( $length = 5 ) { |
|
| 843 | - $length = ( $length > 0 ) ? $length : 5; |
|
| 842 | + public function set_min_after_url_wrap($length = 5) { |
|
| 843 | + $length = ($length > 0) ? $length : 5; |
|
| 844 | 844 | |
| 845 | 845 | $this->data['urlMinAfterWrap'] = $length; |
| 846 | 846 | } |
@@ -850,7 +850,7 @@ discard block |
||
| 850 | 850 | * |
| 851 | 851 | * @param bool $on Optional. Default true. |
| 852 | 852 | */ |
| 853 | - public function set_style_ampersands( $on = true ) { |
|
| 853 | + public function set_style_ampersands($on = true) { |
|
| 854 | 854 | $this->data['styleAmpersands'] = $on; |
| 855 | 855 | } |
| 856 | 856 | |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | * |
| 860 | 860 | * @param bool $on Optional. Default true. |
| 861 | 861 | */ |
| 862 | - public function set_style_caps( $on = true ) { |
|
| 862 | + public function set_style_caps($on = true) { |
|
| 863 | 863 | $this->data['styleCaps'] = $on; |
| 864 | 864 | } |
| 865 | 865 | |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | * |
| 869 | 869 | * @param bool $on Optional. Default true. |
| 870 | 870 | */ |
| 871 | - public function set_style_initial_quotes( $on = true ) { |
|
| 871 | + public function set_style_initial_quotes($on = true) { |
|
| 872 | 872 | $this->data['styleInitialQuotes'] = $on; |
| 873 | 873 | } |
| 874 | 874 | |
@@ -877,7 +877,7 @@ discard block |
||
| 877 | 877 | * |
| 878 | 878 | * @param bool $on Optional. Default true. |
| 879 | 879 | */ |
| 880 | - public function set_style_numbers( $on = true ) { |
|
| 880 | + public function set_style_numbers($on = true) { |
|
| 881 | 881 | $this->data['styleNumbers'] = $on; |
| 882 | 882 | } |
| 883 | 883 | |
@@ -886,7 +886,7 @@ discard block |
||
| 886 | 886 | * |
| 887 | 887 | * @param bool $on Optional. Default true. |
| 888 | 888 | */ |
| 889 | - public function set_style_hanging_punctuation( $on = true ) { |
|
| 889 | + public function set_style_hanging_punctuation($on = true) { |
|
| 890 | 890 | $this->data['styleHangingPunctuation'] = $on; |
| 891 | 891 | } |
| 892 | 892 | |
@@ -895,14 +895,14 @@ discard block |
||
| 895 | 895 | * |
| 896 | 896 | * @param string|array $tags A comma separated list or an array of tag names. |
| 897 | 897 | */ |
| 898 | - public function set_initial_quote_tags( $tags = [ 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'li', 'dd', 'dt' ] ) { |
|
| 898 | + public function set_initial_quote_tags($tags = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'li', 'dd', 'dt']) { |
|
| 899 | 899 | // Make array if handed a list of tags as a string. |
| 900 | - if ( ! is_array( $tags ) ) { |
|
| 901 | - $tags = preg_split( '/[^a-z0-9]+/', $tags, -1, PREG_SPLIT_NO_EMPTY ); |
|
| 900 | + if ( ! is_array($tags)) { |
|
| 901 | + $tags = preg_split('/[^a-z0-9]+/', $tags, -1, PREG_SPLIT_NO_EMPTY); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | // Store the tag array inverted (with the tagName as its index for faster lookup). |
| 905 | - $this->data['initialQuoteTags'] = array_change_key_case( array_flip( $tags ), CASE_LOWER ); |
|
| 905 | + $this->data['initialQuoteTags'] = array_change_key_case(array_flip($tags), CASE_LOWER); |
|
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | /** |
@@ -910,7 +910,7 @@ discard block |
||
| 910 | 910 | * |
| 911 | 911 | * @param bool $on Optional. Default true. |
| 912 | 912 | */ |
| 913 | - public function set_hyphenation( $on = true ) { |
|
| 913 | + public function set_hyphenation($on = true) { |
|
| 914 | 914 | $this->data['hyphenation'] = $on; |
| 915 | 915 | } |
| 916 | 916 | |
@@ -919,8 +919,8 @@ discard block |
||
| 919 | 919 | * |
| 920 | 920 | * @param string $lang Has to correspond to a filename in 'lang'. Optional. Default 'en-US'. |
| 921 | 921 | */ |
| 922 | - public function set_hyphenation_language( $lang = 'en-US' ) { |
|
| 923 | - if ( isset( $this->data['hyphenLanguage'] ) && $this->data['hyphenLanguage'] === $lang ) { |
|
| 922 | + public function set_hyphenation_language($lang = 'en-US') { |
|
| 923 | + if (isset($this->data['hyphenLanguage']) && $this->data['hyphenLanguage'] === $lang) { |
|
| 924 | 924 | return; // Bail out, no need to do anything. |
| 925 | 925 | } |
| 926 | 926 | |
@@ -932,8 +932,8 @@ discard block |
||
| 932 | 932 | * |
| 933 | 933 | * @param int $length Defaults to 5. Trying to set the value to less than 2 resets the length to the default. |
| 934 | 934 | */ |
| 935 | - public function set_min_length_hyphenation( $length = 5 ) { |
|
| 936 | - $length = ( $length > 1 ) ? $length : 5; |
|
| 935 | + public function set_min_length_hyphenation($length = 5) { |
|
| 936 | + $length = ($length > 1) ? $length : 5; |
|
| 937 | 937 | |
| 938 | 938 | $this->data['hyphenMinLength'] = $length; |
| 939 | 939 | } |
@@ -943,8 +943,8 @@ discard block |
||
| 943 | 943 | * |
| 944 | 944 | * @param int $length Defaults to 3. Trying to set the value to less than 1 resets the length to the default. |
| 945 | 945 | */ |
| 946 | - public function set_min_before_hyphenation( $length = 3 ) { |
|
| 947 | - $length = ( $length > 0 ) ? $length : 3; |
|
| 946 | + public function set_min_before_hyphenation($length = 3) { |
|
| 947 | + $length = ($length > 0) ? $length : 3; |
|
| 948 | 948 | |
| 949 | 949 | $this->data['hyphenMinBefore'] = $length; |
| 950 | 950 | } |
@@ -954,8 +954,8 @@ discard block |
||
| 954 | 954 | * |
| 955 | 955 | * @param int $length Defaults to 2. Trying to set the value to less than 1 resets the length to the default. |
| 956 | 956 | */ |
| 957 | - public function set_min_after_hyphenation( $length = 2 ) { |
|
| 958 | - $length = ( $length > 0 ) ? $length : 2; |
|
| 957 | + public function set_min_after_hyphenation($length = 2) { |
|
| 958 | + $length = ($length > 0) ? $length : 2; |
|
| 959 | 959 | |
| 960 | 960 | $this->data['hyphenMinAfter'] = $length; |
| 961 | 961 | } |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | * |
| 966 | 966 | * @param bool $on Optional. Default true. |
| 967 | 967 | */ |
| 968 | - public function set_hyphenate_headings( $on = true ) { |
|
| 968 | + public function set_hyphenate_headings($on = true) { |
|
| 969 | 969 | $this->data['hyphenateTitle'] = $on; |
| 970 | 970 | } |
| 971 | 971 | |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | * |
| 975 | 975 | * @param bool $on Optional. Default true. |
| 976 | 976 | */ |
| 977 | - public function set_hyphenate_all_caps( $on = true ) { |
|
| 977 | + public function set_hyphenate_all_caps($on = true) { |
|
| 978 | 978 | $this->data['hyphenateAllCaps'] = $on; |
| 979 | 979 | } |
| 980 | 980 | |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | * |
| 984 | 984 | * @param bool $on Optional. Default true. |
| 985 | 985 | */ |
| 986 | - public function set_hyphenate_title_case( $on = true ) { |
|
| 986 | + public function set_hyphenate_title_case($on = true) { |
|
| 987 | 987 | $this->data['hyphenateTitleCase'] = $on; |
| 988 | 988 | } |
| 989 | 989 | |
@@ -992,7 +992,7 @@ discard block |
||
| 992 | 992 | * |
| 993 | 993 | * @param bool $on Optional. Default true. |
| 994 | 994 | */ |
| 995 | - public function set_hyphenate_compounds( $on = true ) { |
|
| 995 | + public function set_hyphenate_compounds($on = true) { |
|
| 996 | 996 | $this->data['hyphenateCompounds'] = $on; |
| 997 | 997 | } |
| 998 | 998 | |
@@ -1002,8 +1002,8 @@ discard block |
||
| 1002 | 1002 | * @param string|array $exceptions An array of words with all hyphenation points marked with a hard hyphen (or a string list of such words). |
| 1003 | 1003 | * In the latter case, only alphanumeric characters and hyphens are recognized. The default is empty. |
| 1004 | 1004 | */ |
| 1005 | - public function set_hyphenation_exceptions( $exceptions = [] ) { |
|
| 1006 | - $this->data['hyphenationCustomExceptions'] = Strings::maybe_split_parameters( $exceptions ); |
|
| 1005 | + public function set_hyphenation_exceptions($exceptions = []) { |
|
| 1006 | + $this->data['hyphenationCustomExceptions'] = Strings::maybe_split_parameters($exceptions); |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | /** |
@@ -1013,11 +1013,11 @@ discard block |
||
| 1013 | 1013 | * |
| 1014 | 1014 | * @return string A binary hash value for the current settings limited to $max_length. |
| 1015 | 1015 | */ |
| 1016 | - public function get_hash( $max_length = 16 ) { |
|
| 1017 | - $hash = md5( json_encode( $this->data ), true ); |
|
| 1016 | + public function get_hash($max_length = 16) { |
|
| 1017 | + $hash = md5(json_encode($this->data), true); |
|
| 1018 | 1018 | |
| 1019 | - if ( $max_length < strlen( $hash ) ) { |
|
| 1020 | - $hash = substr( $hash, 0, $max_length ); |
|
| 1019 | + if ($max_length < strlen($hash)) { |
|
| 1020 | + $hash = substr($hash, 0, $max_length); |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | return $hash; |
@@ -67,33 +67,33 @@ discard block |
||
| 67 | 67 | * @param Settings $settings Required. |
| 68 | 68 | * @param bool $is_title Optional. Default false. |
| 69 | 69 | */ |
| 70 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 70 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 71 | 71 | // Lazy-load text parser. |
| 72 | - $text_parser = $this->get_text_parser(); |
|
| 72 | + $text_parser = $this->get_text_parser(); |
|
| 73 | 73 | $tokens = []; |
| 74 | 74 | |
| 75 | 75 | // Set up parameters for word categories. |
| 76 | - $mixed_caps = empty( $settings['hyphenateAllCaps'] ) ? Text_Parser::ALLOW_ALL_CAPS : Text_Parser::NO_ALL_CAPS; |
|
| 77 | - $letter_caps = empty( $settings['hyphenateAllCaps'] ) ? Text_Parser::NO_ALL_CAPS : Text_Parser::ALLOW_ALL_CAPS; |
|
| 78 | - $mixed_compounds = empty( $settings['hyphenateCompounds'] ) ? Text_Parser::ALLOW_COMPOUNDS : Text_Parser::NO_COMPOUNDS; |
|
| 79 | - $letter_compounds = empty( $settings['hyphenateCompounds'] ) ? Text_Parser::NO_COMPOUNDS : Text_Parser::ALLOW_COMPOUNDS; |
|
| 76 | + $mixed_caps = empty($settings['hyphenateAllCaps']) ? Text_Parser::ALLOW_ALL_CAPS : Text_Parser::NO_ALL_CAPS; |
|
| 77 | + $letter_caps = empty($settings['hyphenateAllCaps']) ? Text_Parser::NO_ALL_CAPS : Text_Parser::ALLOW_ALL_CAPS; |
|
| 78 | + $mixed_compounds = empty($settings['hyphenateCompounds']) ? Text_Parser::ALLOW_COMPOUNDS : Text_Parser::NO_COMPOUNDS; |
|
| 79 | + $letter_compounds = empty($settings['hyphenateCompounds']) ? Text_Parser::NO_COMPOUNDS : Text_Parser::ALLOW_COMPOUNDS; |
|
| 80 | 80 | |
| 81 | 81 | // Break text down for a bit more granularity. |
| 82 | - $text_parser->load( $textnode->data ); |
|
| 83 | - $tokens[ Token_Fix::MIXED_WORDS ] = $text_parser->get_words( Text_Parser::NO_ALL_LETTERS, $mixed_caps, $mixed_compounds ); // prohibit letter-only words, allow caps, allow compounds (or not). |
|
| 84 | - $tokens[ Token_Fix::COMPOUND_WORDS ] = ! empty( $settings['hyphenateCompounds'] ) ? $text_parser->get_words( Text_Parser::NO_ALL_LETTERS, $letter_caps, Text_Parser::REQUIRE_COMPOUNDS ) : []; |
|
| 85 | - $tokens[ Token_Fix::WORDS ] = $text_parser->get_words( Text_Parser::REQUIRE_ALL_LETTERS, $letter_caps, $letter_compounds ); // require letter-only words allow/prohibit caps & compounds vice-versa. |
|
| 86 | - $tokens[ Token_Fix::OTHER ] = $text_parser->get_other(); |
|
| 82 | + $text_parser->load($textnode->data); |
|
| 83 | + $tokens[Token_Fix::MIXED_WORDS] = $text_parser->get_words(Text_Parser::NO_ALL_LETTERS, $mixed_caps, $mixed_compounds); // prohibit letter-only words, allow caps, allow compounds (or not). |
|
| 84 | + $tokens[Token_Fix::COMPOUND_WORDS] = ! empty($settings['hyphenateCompounds']) ? $text_parser->get_words(Text_Parser::NO_ALL_LETTERS, $letter_caps, Text_Parser::REQUIRE_COMPOUNDS) : []; |
|
| 85 | + $tokens[Token_Fix::WORDS] = $text_parser->get_words(Text_Parser::REQUIRE_ALL_LETTERS, $letter_caps, $letter_compounds); // require letter-only words allow/prohibit caps & compounds vice-versa. |
|
| 86 | + $tokens[Token_Fix::OTHER] = $text_parser->get_other(); |
|
| 87 | 87 | |
| 88 | 88 | // Process individual text parts here. |
| 89 | - foreach ( $this->token_fixes as $fix ) { |
|
| 89 | + foreach ($this->token_fixes as $fix) { |
|
| 90 | 90 | $t = $fix->target(); |
| 91 | 91 | |
| 92 | - $tokens[ $t ] = $fix->apply( $tokens[ $t ], $settings, $is_title, $textnode ); |
|
| 92 | + $tokens[$t] = $fix->apply($tokens[$t], $settings, $is_title, $textnode); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Apply updates to our text. |
| 96 | - $text_parser->update( $tokens[ Token_Fix::MIXED_WORDS ] + $tokens[ Token_Fix::COMPOUND_WORDS ] + $tokens[ Token_Fix::WORDS ] + $tokens[ Token_Fix::OTHER ] ); |
|
| 96 | + $text_parser->update($tokens[Token_Fix::MIXED_WORDS] + $tokens[Token_Fix::COMPOUND_WORDS] + $tokens[Token_Fix::WORDS] + $tokens[Token_Fix::OTHER]); |
|
| 97 | 97 | $textnode->data = $text_parser->unload(); |
| 98 | 98 | } |
| 99 | 99 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public function get_text_parser() { |
| 106 | 106 | // Lazy-load text parser. |
| 107 | - if ( ! isset( $this->text_parser ) ) { |
|
| 107 | + if ( ! isset($this->text_parser)) { |
|
| 108 | 108 | $this->text_parser = new Text_Parser(); |
| 109 | 109 | } |
| 110 | 110 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @param Token_Fix $fix Required. |
| 118 | 118 | */ |
| 119 | - public function register_token_fix( Token_Fix $fix ) { |
|
| 119 | + public function register_token_fix(Token_Fix $fix) { |
|
| 120 | 120 | $this->token_fixes[] = $fix; |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -103,22 +103,22 @@ discard block |
||
| 103 | 103 | * @param Settings $settings Required. |
| 104 | 104 | * @param bool $is_title Optional. Default false. |
| 105 | 105 | */ |
| 106 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 107 | - if ( empty( $settings['dashSpacing'] ) ) { |
|
| 106 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 107 | + if (empty($settings['dashSpacing'])) { |
|
| 108 | 108 | return; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // Various special characters and regular expressions. |
| 112 | 112 | $s = $settings->dash_style(); |
| 113 | 113 | |
| 114 | - if ( $s != $this->cached_dash_style ) { // WPCS: loose comparison ok. |
|
| 115 | - $this->update_dash_spacing_regex( $s->parenthetical_dash(), $s->parenthetical_space(), $s->interval_dash(), $s->interval_space() ); |
|
| 114 | + if ($s != $this->cached_dash_style) { // WPCS: loose comparison ok. |
|
| 115 | + $this->update_dash_spacing_regex($s->parenthetical_dash(), $s->parenthetical_space(), $s->interval_dash(), $s->interval_space()); |
|
| 116 | 116 | $this->cached_dash_style = $s; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $textnode->data = preg_replace( self::EM_DASH_SPACING, $this->em_dash_replacement, $textnode->data ); |
|
| 120 | - $textnode->data = preg_replace( $this->parenthetical_dash_spacing, $this->parenthetical_dash_replacement, $textnode->data ); |
|
| 121 | - $textnode->data = preg_replace( $this->interval_dash_spacing, $this->interval_dash_replacement, $textnode->data ); |
|
| 119 | + $textnode->data = preg_replace(self::EM_DASH_SPACING, $this->em_dash_replacement, $textnode->data); |
|
| 120 | + $textnode->data = preg_replace($this->parenthetical_dash_spacing, $this->parenthetical_dash_replacement, $textnode->data); |
|
| 121 | + $textnode->data = preg_replace($this->interval_dash_spacing, $this->interval_dash_replacement, $textnode->data); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | * @param string $interval The dash character used for interval dashes. |
| 130 | 130 | * @param string $interval_space The space character used around interval dashes. |
| 131 | 131 | */ |
| 132 | - private function update_dash_spacing_regex( $parenthetical, $parenthetical_space, $interval, $interval_space ) { |
|
| 132 | + private function update_dash_spacing_regex($parenthetical, $parenthetical_space, $interval, $interval_space) { |
|
| 133 | 133 | $this->parenthetical_dash_spacing = "/ |
| 134 | 134 | (?: |
| 135 | 135 | \s |