We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -51,11 +51,11 @@ discard block |
||
| 51 | 51 | * @param array|string $classes HTML class(es). |
| 52 | 52 | * @param bool $feed_compatible Optional. Default false. |
| 53 | 53 | */ |
| 54 | - public function __construct( $classes, $feed_compatible = false ) { |
|
| 55 | - parent::__construct( $feed_compatible ); |
|
| 54 | + public function __construct($classes, $feed_compatible = false) { |
|
| 55 | + parent::__construct($feed_compatible); |
|
| 56 | 56 | |
| 57 | - if ( ! is_array( $classes ) ) { |
|
| 58 | - $classes = [ $classes ]; |
|
| 57 | + if ( ! is_array($classes)) { |
|
| 58 | + $classes = [$classes]; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $this->classes_to_avoid = $classes; |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return void |
| 72 | 72 | */ |
| 73 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 74 | - if ( ! DOM::has_class( $textnode, $this->classes_to_avoid ) ) { |
|
| 75 | - $this->apply_internal( $textnode, $settings, $is_title ); |
|
| 73 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 74 | + if ( ! DOM::has_class($textnode, $this->classes_to_avoid)) { |
|
| 75 | + $this->apply_internal($textnode, $settings, $is_title); |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
@@ -85,5 +85,5 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @return void |
| 87 | 87 | */ |
| 88 | - abstract public function apply_internal( \DOMText $textnode, Settings $settings, $is_title = false ); |
|
| 88 | + abstract public function apply_internal(\DOMText $textnode, Settings $settings, $is_title = false); |
|
| 89 | 89 | } |
@@ -104,19 +104,19 @@ discard block |
||
| 104 | 104 | * @param string $css_denominator CSS class applied to the denominator part. |
| 105 | 105 | * @param bool $feed_compatible Optional. Default false. |
| 106 | 106 | */ |
| 107 | - public function __construct( $css_numerator, $css_denominator, $feed_compatible = false ) { |
|
| 108 | - parent::__construct( $feed_compatible ); |
|
| 107 | + public function __construct($css_numerator, $css_denominator, $feed_compatible = false) { |
|
| 108 | + parent::__construct($feed_compatible); |
|
| 109 | 109 | |
| 110 | 110 | // Escape consecutive years. |
| 111 | 111 | $year_regex = []; |
| 112 | - for ( $year = 1900; $year < 2100; ++$year ) { |
|
| 113 | - $year_regex[] = "(?: ( $year ) (\s?\/\s?" . U::ZERO_WIDTH_SPACE . '?) ( ' . ( $year + 1 ) . ' ) )'; |
|
| 112 | + for ($year = 1900; $year < 2100; ++$year) { |
|
| 113 | + $year_regex[] = "(?: ( $year ) (\s?\/\s?" . U::ZERO_WIDTH_SPACE . '?) ( ' . ($year + 1) . ' ) )'; |
|
| 114 | 114 | } |
| 115 | 115 | $this->escape_consecutive_years = '/ |
| 116 | 116 | # lookbehind assertion: makes sure we are not messing up a url |
| 117 | 117 | (?<=\A|\s|' . U::NO_BREAK_SPACE . '|' . U::NO_BREAK_NARROW_SPACE . ') |
| 118 | 118 | |
| 119 | - (?| ' . implode( '|', $year_regex ) . ' ) |
|
| 119 | + (?| ' . implode('|', $year_regex) . ' ) |
|
| 120 | 120 | ( |
| 121 | 121 | # makes sure we are not messing up a url |
| 122 | 122 | (?:\Z|\s|' . U::NO_BREAK_SPACE . '|' . U::NO_BREAK_NARROW_SPACE . '|\.|\!|\?|\)|\;|\:|\'|\") |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | /xu'; |
| 125 | 125 | |
| 126 | 126 | // Replace fractions. |
| 127 | - $numerator_css = empty( $css_numerator ) ? '' : ' class="' . $css_numerator . '"'; |
|
| 128 | - $denominator_css = empty( $css_denominator ) ? '' : ' class="' . $css_denominator . '"'; |
|
| 127 | + $numerator_css = empty($css_numerator) ? '' : ' class="' . $css_numerator . '"'; |
|
| 128 | + $denominator_css = empty($css_denominator) ? '' : ' class="' . $css_denominator . '"'; |
|
| 129 | 129 | $this->replacement = "<sup{$numerator_css}>\$1</sup>" . U::FRACTION_SLASH . "<sub{$denominator_css}>\$2</sub>\$3"; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -136,27 +136,27 @@ discard block |
||
| 136 | 136 | * @param Settings $settings Required. |
| 137 | 137 | * @param bool $is_title Optional. Default false. |
| 138 | 138 | */ |
| 139 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 140 | - if ( empty( $settings['smartFractions'] ) && empty( $settings['fractionSpacing'] ) ) { |
|
| 139 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 140 | + if (empty($settings['smartFractions']) && empty($settings['fractionSpacing'])) { |
|
| 141 | 141 | return; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ( ! empty( $settings['fractionSpacing'] ) && ! empty( $settings['smartFractions'] ) ) { |
|
| 145 | - $textnode->data = preg_replace( self::SPACING, '$1' . $settings->no_break_narrow_space() . '$2', $textnode->data ); |
|
| 146 | - } elseif ( ! empty( $settings['fractionSpacing'] ) && empty( $settings['smartFractions'] ) ) { |
|
| 147 | - $textnode->data = preg_replace( self::SPACING, '$1' . U::NO_BREAK_SPACE . '$2', $textnode->data ); |
|
| 144 | + if ( ! empty($settings['fractionSpacing']) && ! empty($settings['smartFractions'])) { |
|
| 145 | + $textnode->data = preg_replace(self::SPACING, '$1' . $settings->no_break_narrow_space() . '$2', $textnode->data); |
|
| 146 | + } elseif ( ! empty($settings['fractionSpacing']) && empty($settings['smartFractions'])) { |
|
| 147 | + $textnode->data = preg_replace(self::SPACING, '$1' . U::NO_BREAK_SPACE . '$2', $textnode->data); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - if ( ! empty( $settings['smartFractions'] ) ) { |
|
| 150 | + if ( ! empty($settings['smartFractions'])) { |
|
| 151 | 151 | // Escape sequences we don't want fractionified. |
| 152 | - $textnode->data = preg_replace( $this->escape_consecutive_years, '$1' . RE::ESCAPE_MARKER . '$2$3$4', $textnode->data ); |
|
| 153 | - $textnode->data = preg_replace( self::ESCAPE_DATE_MM_YYYY, '$1' . RE::ESCAPE_MARKER . '$2$3$4', $textnode->data ); |
|
| 152 | + $textnode->data = preg_replace($this->escape_consecutive_years, '$1' . RE::ESCAPE_MARKER . '$2$3$4', $textnode->data); |
|
| 153 | + $textnode->data = preg_replace(self::ESCAPE_DATE_MM_YYYY, '$1' . RE::ESCAPE_MARKER . '$2$3$4', $textnode->data); |
|
| 154 | 154 | |
| 155 | 155 | // Replace fractions. |
| 156 | - $textnode->data = preg_replace( self::FRACTION_MATCHING, $this->replacement, $textnode->data ); |
|
| 156 | + $textnode->data = preg_replace(self::FRACTION_MATCHING, $this->replacement, $textnode->data); |
|
| 157 | 157 | |
| 158 | 158 | // Unescape escaped sequences. |
| 159 | - $textnode->data = str_replace( RE::ESCAPE_MARKER, '', $textnode->data ); |
|
| 159 | + $textnode->data = str_replace(RE::ESCAPE_MARKER, '', $textnode->data); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * @param string $css_double Required. |
| 62 | 62 | * @param bool $feed_compatible Optional. Default false. |
| 63 | 63 | */ |
| 64 | - public function __construct( $css_single, $css_double, $feed_compatible = false ) { |
|
| 65 | - parent::__construct( [ $css_single, $css_double ], $feed_compatible ); |
|
| 64 | + public function __construct($css_single, $css_double, $feed_compatible = false) { |
|
| 65 | + parent::__construct([$css_single, $css_double], $feed_compatible); |
|
| 66 | 66 | |
| 67 | 67 | $this->single_quote_class = $css_single; |
| 68 | 68 | $this->double_quote_class = $css_double; |
@@ -75,32 +75,32 @@ discard block |
||
| 75 | 75 | * @param Settings $settings Required. |
| 76 | 76 | * @param bool $is_title Optional. Default false. |
| 77 | 77 | */ |
| 78 | - public function apply_internal( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 79 | - if ( empty( $settings['styleInitialQuotes'] ) || empty( $settings['initialQuoteTags'] ) ) { |
|
| 78 | + public function apply_internal(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 79 | + if (empty($settings['styleInitialQuotes']) || empty($settings['initialQuoteTags'])) { |
|
| 80 | 80 | return; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if ( '' === DOM::get_prev_chr( $textnode ) ) { // we have the first text in a block level element. |
|
| 83 | + if ('' === DOM::get_prev_chr($textnode)) { // we have the first text in a block level element. |
|
| 84 | 84 | |
| 85 | - $func = Strings::functions( $textnode->data ); |
|
| 86 | - $first_character = $func['substr']( $textnode->data, 0, 1 ); |
|
| 85 | + $func = Strings::functions($textnode->data); |
|
| 86 | + $first_character = $func['substr']($textnode->data, 0, 1); |
|
| 87 | 87 | |
| 88 | - if ( self::is_single_quote( $first_character ) || self::is_double_quote( $first_character ) ) { |
|
| 89 | - $block_level_parent = DOM::get_block_parent_name( $textnode ); |
|
| 88 | + if (self::is_single_quote($first_character) || self::is_double_quote($first_character)) { |
|
| 89 | + $block_level_parent = DOM::get_block_parent_name($textnode); |
|
| 90 | 90 | |
| 91 | - if ( $is_title ) { |
|
| 91 | + if ($is_title) { |
|
| 92 | 92 | // Assume page title is h2. |
| 93 | 93 | $block_level_parent = 'h2'; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if ( ! empty( $block_level_parent ) && isset( $settings['initialQuoteTags'][ $block_level_parent ] ) ) { |
|
| 97 | - if ( self::is_single_quote( $first_character ) ) { |
|
| 96 | + if ( ! empty($block_level_parent) && isset($settings['initialQuoteTags'][$block_level_parent])) { |
|
| 97 | + if (self::is_single_quote($first_character)) { |
|
| 98 | 98 | $span_class = $this->single_quote_class; |
| 99 | 99 | } else { |
| 100 | 100 | $span_class = $this->double_quote_class; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $textnode->data = '<span class="' . $span_class . '">' . $first_character . '</span>' . $func['substr']( $textnode->data, 1, $func['strlen']( $textnode->data ) ); |
|
| 103 | + $textnode->data = '<span class="' . $span_class . '">' . $first_character . '</span>' . $func['substr']($textnode->data, 1, $func['strlen']($textnode->data)); |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return bool |
| 115 | 115 | */ |
| 116 | - private static function is_single_quote( $quote ) { |
|
| 117 | - return ( "'" === $quote || U::SINGLE_QUOTE_OPEN === $quote || U::SINGLE_LOW_9_QUOTE === $quote || U::SINGLE_ANGLE_QUOTE_OPEN === $quote || U::SINGLE_ANGLE_QUOTE_CLOSE === $quote || ',' === $quote ); |
|
| 116 | + private static function is_single_quote($quote) { |
|
| 117 | + return ("'" === $quote || U::SINGLE_QUOTE_OPEN === $quote || U::SINGLE_LOW_9_QUOTE === $quote || U::SINGLE_ANGLE_QUOTE_OPEN === $quote || U::SINGLE_ANGLE_QUOTE_CLOSE === $quote || ',' === $quote); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * |
| 125 | 125 | * @return bool |
| 126 | 126 | */ |
| 127 | - private static function is_double_quote( $quote ) { |
|
| 128 | - return ( '"' === $quote || U::DOUBLE_QUOTE_OPEN === $quote || U::GUILLEMET_OPEN === $quote || U::GUILLEMET_CLOSE === $quote || U::DOUBLE_LOW_9_QUOTE === $quote ); |
|
| 127 | + private static function is_double_quote($quote) { |
|
| 128 | + return ('"' === $quote || U::DOUBLE_QUOTE_OPEN === $quote || U::GUILLEMET_OPEN === $quote || U::GUILLEMET_CLOSE === $quote || U::DOUBLE_LOW_9_QUOTE === $quote); |
|
| 129 | 129 | } |
| 130 | 130 | } |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | * @param string $pull_double_class Required. |
| 100 | 100 | * @param bool $feed_compatible Optional. Default false. |
| 101 | 101 | */ |
| 102 | - public function __construct( $push_single_class, $push_double_class, $pull_single_class, $pull_double_class, $feed_compatible = false ) { |
|
| 103 | - parent::__construct( [ $pull_single_class, $pull_double_class ], $feed_compatible ); |
|
| 102 | + public function __construct($push_single_class, $push_double_class, $pull_single_class, $pull_double_class, $feed_compatible = false) { |
|
| 103 | + parent::__construct([$pull_single_class, $pull_double_class], $feed_compatible); |
|
| 104 | 104 | |
| 105 | 105 | $this->push_single_class = $push_single_class; |
| 106 | 106 | $this->push_double_class = $push_double_class; |
@@ -115,34 +115,34 @@ discard block |
||
| 115 | 115 | * @param Settings $settings Required. |
| 116 | 116 | * @param bool $is_title Optional. Default false. |
| 117 | 117 | */ |
| 118 | - public function apply_internal( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 119 | - if ( empty( $settings['styleHangingPunctuation'] ) ) { |
|
| 118 | + public function apply_internal(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 119 | + if (empty($settings['styleHangingPunctuation'])) { |
|
| 120 | 120 | return; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | // We need the parent. |
| 124 | - $block = DOM::get_block_parent( $textnode ); |
|
| 125 | - $firstnode = ! empty( $block ) ? DOM::get_first_textnode( $block ) : null; |
|
| 124 | + $block = DOM::get_block_parent($textnode); |
|
| 125 | + $firstnode = ! empty($block) ? DOM::get_first_textnode($block) : null; |
|
| 126 | 126 | |
| 127 | 127 | // Need to get context of adjacent characters outside adjacent inline tags or HTML comment |
| 128 | 128 | // if we have adjacent characters add them to the text. |
| 129 | - $next_character = DOM::get_next_chr( $textnode ); |
|
| 130 | - if ( '' !== $next_character ) { |
|
| 129 | + $next_character = DOM::get_next_chr($textnode); |
|
| 130 | + if ('' !== $next_character) { |
|
| 131 | 131 | $textnode->data = $textnode->data . $next_character; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - $textnode->data = preg_replace( self::STYLE_DOUBLE, '$1<span class="' . $this->push_double_class . '"></span>' . U::ZERO_WIDTH_SPACE . '<span class="' . $this->pull_double_class . '">$2</span>$3', $textnode->data ); |
|
| 135 | - $textnode->data = preg_replace( self::STYLE_SINGLE, '$1<span class="' . $this->push_single_class . '"></span>' . U::ZERO_WIDTH_SPACE . '<span class="' . $this->pull_single_class . '">$2</span>$3', $textnode->data ); |
|
| 134 | + $textnode->data = preg_replace(self::STYLE_DOUBLE, '$1<span class="' . $this->push_double_class . '"></span>' . U::ZERO_WIDTH_SPACE . '<span class="' . $this->pull_double_class . '">$2</span>$3', $textnode->data); |
|
| 135 | + $textnode->data = preg_replace(self::STYLE_SINGLE, '$1<span class="' . $this->push_single_class . '"></span>' . U::ZERO_WIDTH_SPACE . '<span class="' . $this->pull_single_class . '">$2</span>$3', $textnode->data); |
|
| 136 | 136 | |
| 137 | - if ( empty( $block ) || $firstnode === $textnode ) { |
|
| 138 | - $textnode->data = preg_replace( self::STYLE_INITIAL_DOUBLE, '<span class="' . $this->pull_double_class . '">$1</span>$2', $textnode->data ); |
|
| 139 | - $textnode->data = preg_replace( self::STYLE_INITIAL_SINGLE, '<span class="' . $this->pull_single_class . '">$1</span>$2', $textnode->data ); |
|
| 137 | + if (empty($block) || $firstnode === $textnode) { |
|
| 138 | + $textnode->data = preg_replace(self::STYLE_INITIAL_DOUBLE, '<span class="' . $this->pull_double_class . '">$1</span>$2', $textnode->data); |
|
| 139 | + $textnode->data = preg_replace(self::STYLE_INITIAL_SINGLE, '<span class="' . $this->pull_single_class . '">$1</span>$2', $textnode->data); |
|
| 140 | 140 | } else { |
| 141 | - $textnode->data = preg_replace( self::STYLE_INITIAL_DOUBLE, '<span class="' . $this->push_double_class . '"></span>' . U::ZERO_WIDTH_SPACE . '<span class="' . $this->pull_double_class . '">$1</span>$2', $textnode->data ); |
|
| 142 | - $textnode->data = preg_replace( self::STYLE_INITIAL_SINGLE, '<span class="' . $this->push_single_class . '"></span>' . U::ZERO_WIDTH_SPACE . '<span class="' . $this->pull_single_class . '">$1</span>$2', $textnode->data ); |
|
| 141 | + $textnode->data = preg_replace(self::STYLE_INITIAL_DOUBLE, '<span class="' . $this->push_double_class . '"></span>' . U::ZERO_WIDTH_SPACE . '<span class="' . $this->pull_double_class . '">$1</span>$2', $textnode->data); |
|
| 142 | + $textnode->data = preg_replace(self::STYLE_INITIAL_SINGLE, '<span class="' . $this->push_single_class . '"></span>' . U::ZERO_WIDTH_SPACE . '<span class="' . $this->pull_single_class . '">$1</span>$2', $textnode->data); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // Remove any added characters. |
| 146 | - $textnode->data = self::remove_adjacent_characters( $textnode->data, '', $next_character ); |
|
| 146 | + $textnode->data = self::remove_adjacent_characters($textnode->data, '', $next_character); |
|
| 147 | 147 | } |
| 148 | 148 | } |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | * @param string|null $css_class Optional. Default null. |
| 55 | 55 | * @param bool $feed_compatible Optional. Default false. |
| 56 | 56 | */ |
| 57 | - public function __construct( $css_class = null, $feed_compatible = false ) { |
|
| 58 | - parent::__construct( $feed_compatible ); |
|
| 57 | + public function __construct($css_class = null, $feed_compatible = false) { |
|
| 58 | + parent::__construct($feed_compatible); |
|
| 59 | 59 | |
| 60 | - $ordinal_class = empty( $css_class ) ? '' : ' class="' . $css_class . '"'; |
|
| 60 | + $ordinal_class = empty($css_class) ? '' : ' class="' . $css_class . '"'; |
|
| 61 | 61 | $this->replacement = "\$1<sup{$ordinal_class}>\$2</sup>"; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | * @param Settings $settings Required. |
| 69 | 69 | * @param bool $is_title Optional. Default false. |
| 70 | 70 | */ |
| 71 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 72 | - if ( empty( $settings['smartOrdinalSuffix'] ) ) { |
|
| 71 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 72 | + if (empty($settings['smartOrdinalSuffix'])) { |
|
| 73 | 73 | return; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - $textnode->data = preg_replace( "/\b(\d+)(st|nd|rd|th)\b/", $this->replacement, $textnode->data ); |
|
| 76 | + $textnode->data = preg_replace("/\b(\d+)(st|nd|rd|th)\b/", $this->replacement, $textnode->data); |
|
| 77 | 77 | } |
| 78 | 78 | } |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @param bool $feed_compatible Optional. Default false. |
| 79 | 79 | */ |
| 80 | - public function __construct( $feed_compatible = false ) { |
|
| 81 | - parent::__construct( self::REGEX, self::REPLACEMENT, self::SETTING, $feed_compatible ); |
|
| 80 | + public function __construct($feed_compatible = false) { |
|
| 81 | + parent::__construct(self::REGEX, self::REPLACEMENT, self::SETTING, $feed_compatible); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | * @param Settings $settings Required. |
| 89 | 89 | * @param bool $is_title Optional. Default false. |
| 90 | 90 | */ |
| 91 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 91 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 92 | 92 | // Update replacement with current non-breaking narrow space. |
| 93 | 93 | $this->replacement = "\$1{$settings->no_break_narrow_space()}\$2"; |
| 94 | 94 | |
| 95 | 95 | // Update regex with custom units. |
| 96 | 96 | $this->regex = "/(\d\.?)\s({$settings->custom_units()}" . self::_STANDARD_UNITS . ')\b/x'; |
| 97 | 97 | |
| 98 | - parent::apply( $textnode, $settings, $is_title ); |
|
| 98 | + parent::apply($textnode, $settings, $is_title); |
|
| 99 | 99 | } |
| 100 | 100 | } |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | * @param Settings $settings Required. |
| 59 | 59 | * @param bool $is_title Optional. Default false. |
| 60 | 60 | */ |
| 61 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 62 | - if ( empty( $settings['frenchPunctuationSpacing'] ) ) { |
|
| 61 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 62 | + if (empty($settings['frenchPunctuationSpacing'])) { |
|
| 63 | 63 | return; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -68,25 +68,25 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | // Need to get context of adjacent characters outside adjacent inline tags or HTML comment |
| 70 | 70 | // if we have adjacent characters add them to the text. |
| 71 | - $previous_character = DOM::get_prev_chr( $textnode ); |
|
| 72 | - if ( '' !== $previous_character ) { |
|
| 71 | + $previous_character = DOM::get_prev_chr($textnode); |
|
| 72 | + if ('' !== $previous_character) { |
|
| 73 | 73 | $textnode->data = $previous_character . $textnode->data; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - $textnode->data = preg_replace( self::INSERT_SPACE_BEFORE_CLOSING_QUOTE, '$1' . $no_break_narrow_space . '$3$4', $textnode->data ); |
|
| 77 | - $textnode->data = preg_replace( self::INSERT_NARROW_SPACE, '$1' . $no_break_narrow_space . '$3$4', $textnode->data ); |
|
| 78 | - $textnode->data = preg_replace( self::INSERT_FULL_SPACE, '$1' . U::NO_BREAK_SPACE . '$3$4', $textnode->data ); |
|
| 79 | - $textnode->data = preg_replace( self::INSERT_SPACE_BEFORE_SEMICOLON, '$1' . $no_break_narrow_space . '$3$4', $textnode->data ); |
|
| 76 | + $textnode->data = preg_replace(self::INSERT_SPACE_BEFORE_CLOSING_QUOTE, '$1' . $no_break_narrow_space . '$3$4', $textnode->data); |
|
| 77 | + $textnode->data = preg_replace(self::INSERT_NARROW_SPACE, '$1' . $no_break_narrow_space . '$3$4', $textnode->data); |
|
| 78 | + $textnode->data = preg_replace(self::INSERT_FULL_SPACE, '$1' . U::NO_BREAK_SPACE . '$3$4', $textnode->data); |
|
| 79 | + $textnode->data = preg_replace(self::INSERT_SPACE_BEFORE_SEMICOLON, '$1' . $no_break_narrow_space . '$3$4', $textnode->data); |
|
| 80 | 80 | |
| 81 | 81 | // The next rule depends on the following characters as well. |
| 82 | - $next_character = DOM::get_next_chr( $textnode ); |
|
| 83 | - if ( '' !== $next_character ) { |
|
| 82 | + $next_character = DOM::get_next_chr($textnode); |
|
| 83 | + if ('' !== $next_character) { |
|
| 84 | 84 | $textnode->data = $textnode->data . $next_character; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - $textnode->data = preg_replace( self::INSERT_SPACE_AFTER_OPENING_QUOTE, '$1$2' . $no_break_narrow_space . '$4', $textnode->data ); |
|
| 87 | + $textnode->data = preg_replace(self::INSERT_SPACE_AFTER_OPENING_QUOTE, '$1$2' . $no_break_narrow_space . '$4', $textnode->data); |
|
| 88 | 88 | |
| 89 | 89 | // If we have adjacent characters remove them from the text. |
| 90 | - $textnode->data = self::remove_adjacent_characters( $textnode->data, $previous_character, $next_character ); |
|
| 90 | + $textnode->data = self::remove_adjacent_characters($textnode->data, $previous_character, $next_character); |
|
| 91 | 91 | } |
| 92 | 92 | } |
@@ -67,23 +67,23 @@ 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 | /* |
| 89 | 89 | $parsed_mixed_words = $this->wrap_hard_hyphens( $parsed_mixed_words, $settings ); |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | |
| 96 | 96 | // Process individual text parts here. |
| 97 | - foreach ( $this->token_fixes as $fix ) { |
|
| 97 | + foreach ($this->token_fixes as $fix) { |
|
| 98 | 98 | $t = $fix->target(); |
| 99 | 99 | |
| 100 | - $tokens[ $t ] = $fix->apply( $tokens[ $t ], $settings, $is_title, $textnode ); |
|
| 100 | + $tokens[$t] = $fix->apply($tokens[$t], $settings, $is_title, $textnode); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | // Apply updates to our text. |
| 104 | - $text_parser->update( $tokens[ Token_Fix::MIXED_WORDS ] + $tokens[ Token_Fix::COMPOUND_WORDS ] + $tokens[ Token_Fix::WORDS ] + $tokens[ Token_Fix::OTHER ] ); |
|
| 104 | + $text_parser->update($tokens[Token_Fix::MIXED_WORDS] + $tokens[Token_Fix::COMPOUND_WORDS] + $tokens[Token_Fix::WORDS] + $tokens[Token_Fix::OTHER]); |
|
| 105 | 105 | $textnode->data = $text_parser->unload(); |
| 106 | 106 | } |
| 107 | 107 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | public function get_text_parser() { |
| 114 | 114 | // Lazy-load text parser. |
| 115 | - if ( ! isset( $this->text_parser ) ) { |
|
| 115 | + if ( ! isset($this->text_parser)) { |
|
| 116 | 116 | $this->text_parser = new Text_Parser(); |
| 117 | 117 | } |
| 118 | 118 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * |
| 125 | 125 | * @param Token_Fix $fix Required. |
| 126 | 126 | */ |
| 127 | - public function register_token_fix( Token_Fix $fix ) { |
|
| 127 | + public function register_token_fix(Token_Fix $fix) { |
|
| 128 | 128 | $this->token_fixes[] = $fix; |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | // Standard dashes. |
| 45 | 45 | const PARENTHETICAL_DOUBLE_DASH = '/(\s|' . RE::HTML_SPACES . ')--(\s|' . RE::HTML_SPACES . ')/xui'; // ' -- '. |
| 46 | - const PARENTHETICAL_SINGLE_DASH = '/(\s|' . RE::HTML_SPACES . ')-(\s|' . RE::HTML_SPACES . ')/xui'; // ' - '. |
|
| 46 | + const PARENTHETICAL_SINGLE_DASH = '/(\s|' . RE::HTML_SPACES . ')-(\s|' . RE::HTML_SPACES . ')/xui'; // ' - '. |
|
| 47 | 47 | const EN_DASH_WORDS = '/([\w])\-(' . U::THIN_SPACE . '|' . U::HAIR_SPACE . '|' . U::NO_BREAK_NARROW_SPACE . '|' . U::NO_BREAK_SPACE . ')/u'; |
| 48 | 48 | const EN_DASH_NUMBERS = "/(\b\d+(\.?))\-(\d+\\2)/"; |
| 49 | 49 | const EN_DASH_PHONE_NUMBERS = "/(\b\d{3})" . U::EN_DASH . "(\d{4}\b)/"; |
@@ -119,30 +119,30 @@ discard block |
||
| 119 | 119 | * @param Settings $settings Required. |
| 120 | 120 | * @param bool $is_title Optional. Default false. |
| 121 | 121 | */ |
| 122 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
| 123 | - if ( empty( $settings['smartDashes'] ) ) { |
|
| 122 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
| 123 | + if (empty($settings['smartDashes'])) { |
|
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // Various special characters and regular expressions. |
| 128 | 128 | $s = $settings->dash_style(); |
| 129 | 129 | |
| 130 | - $textnode->data = str_replace( '---', U::EM_DASH, $textnode->data ); |
|
| 131 | - $textnode->data = preg_replace( self::PARENTHETICAL_DOUBLE_DASH, "\$1{$s->parenthetical_dash()}\$2", $textnode->data ); |
|
| 132 | - $textnode->data = str_replace( '--', U::EN_DASH, $textnode->data ); |
|
| 133 | - $textnode->data = preg_replace( self::PARENTHETICAL_SINGLE_DASH, "\$1{$s->parenthetical_dash()}\$2", $textnode->data ); |
|
| 130 | + $textnode->data = str_replace('---', U::EM_DASH, $textnode->data); |
|
| 131 | + $textnode->data = preg_replace(self::PARENTHETICAL_DOUBLE_DASH, "\$1{$s->parenthetical_dash()}\$2", $textnode->data); |
|
| 132 | + $textnode->data = str_replace('--', U::EN_DASH, $textnode->data); |
|
| 133 | + $textnode->data = preg_replace(self::PARENTHETICAL_SINGLE_DASH, "\$1{$s->parenthetical_dash()}\$2", $textnode->data); |
|
| 134 | 134 | |
| 135 | - $textnode->data = preg_replace( self::EN_DASH_WORDS , '$1' . U::EN_DASH . '$2', $textnode->data ); |
|
| 136 | - $textnode->data = preg_replace( self::EN_DASH_NUMBERS, "\$1{$s->interval_dash()}\$3", $textnode->data ); |
|
| 137 | - $textnode->data = preg_replace( self::EN_DASH_PHONE_NUMBERS, '$1' . U::NO_BREAK_HYPHEN . '$2', $textnode->data ); // phone numbers. |
|
| 138 | - $textnode->data = str_replace( 'xn' . U::EN_DASH, 'xn--', $textnode->data ); // revert messed-up punycode. |
|
| 135 | + $textnode->data = preg_replace(self::EN_DASH_WORDS, '$1' . U::EN_DASH . '$2', $textnode->data); |
|
| 136 | + $textnode->data = preg_replace(self::EN_DASH_NUMBERS, "\$1{$s->interval_dash()}\$3", $textnode->data); |
|
| 137 | + $textnode->data = preg_replace(self::EN_DASH_PHONE_NUMBERS, '$1' . U::NO_BREAK_HYPHEN . '$2', $textnode->data); // phone numbers. |
|
| 138 | + $textnode->data = str_replace('xn' . U::EN_DASH, 'xn--', $textnode->data); // revert messed-up punycode. |
|
| 139 | 139 | |
| 140 | 140 | // Revert dates back to original formats |
| 141 | 141 | // YYYY-MM-DD. |
| 142 | - $textnode->data = preg_replace( self::DATE_YYYY_MM_DD, '$1-$2-$3', $textnode->data ); |
|
| 142 | + $textnode->data = preg_replace(self::DATE_YYYY_MM_DD, '$1-$2-$3', $textnode->data); |
|
| 143 | 143 | // MM-DD-YYYY or DD-MM-YYYY. |
| 144 | - $textnode->data = preg_replace( self::DATE_MM_DD_YYYY, '$1$3-$2$4-$5', $textnode->data ); |
|
| 144 | + $textnode->data = preg_replace(self::DATE_MM_DD_YYYY, '$1$3-$2$4-$5', $textnode->data); |
|
| 145 | 145 | // YYYY-MM or YYYY-DDDD next. |
| 146 | - $textnode->data = preg_replace( self::DATE_YYYY_MM, '$1-$2', $textnode->data ); |
|
| 146 | + $textnode->data = preg_replace(self::DATE_YYYY_MM, '$1-$2', $textnode->data); |
|
| 147 | 147 | } |
| 148 | 148 | } |