We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | * @param Hyphenator_Cache|null $cache Optional. Default null. |
| 61 | 61 | * @param bool $feed_compatible Optional. Default false. |
| 62 | 62 | */ |
| 63 | - public function __construct( Hyphenator_Cache $cache = null, $feed_compatible = false ) { |
|
| 64 | - parent::__construct( $cache, Token_Fix::OTHER, $feed_compatible ); |
|
| 63 | + public function __construct(Hyphenator_Cache $cache = null, $feed_compatible = false) { |
|
| 64 | + parent::__construct($cache, Token_Fix::OTHER, $feed_compatible); |
|
| 65 | 65 | |
| 66 | 66 | // Combined URL pattern. |
| 67 | 67 | $this->url_pattern = '`(?: |
@@ -106,59 +106,59 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @return array An array of tokens. |
| 108 | 108 | */ |
| 109 | - public function apply( array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null ) { |
|
| 110 | - if ( empty( $settings['urlWrap'] ) || empty( $settings['urlMinAfterWrap'] ) ) { |
|
| 109 | + public function apply(array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null) { |
|
| 110 | + if (empty($settings['urlWrap']) || empty($settings['urlMinAfterWrap'])) { |
|
| 111 | 111 | return $tokens; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // Test for and parse urls. |
| 115 | - foreach ( $tokens as $token_index => $text_token ) { |
|
| 116 | - if ( preg_match( $this->url_pattern, $text_token->value, $url_match ) ) { |
|
| 115 | + foreach ($tokens as $token_index => $text_token) { |
|
| 116 | + if (preg_match($this->url_pattern, $text_token->value, $url_match)) { |
|
| 117 | 117 | |
| 118 | 118 | // $url_match['schema'] holds "http://". |
| 119 | 119 | // $url_match['domain'] holds "subdomains.domain.tld". |
| 120 | 120 | // $url_match['path'] holds the path after the domain. |
| 121 | - $http = ( $url_match['schema'] ) ? $url_match[1] . U::ZERO_WIDTH_SPACE : ''; |
|
| 121 | + $http = ($url_match['schema']) ? $url_match[1] . U::ZERO_WIDTH_SPACE : ''; |
|
| 122 | 122 | |
| 123 | - $domain_parts = preg_split( self::WRAP_URLS_DOMAIN_PARTS, $url_match['domain'], -1, PREG_SPLIT_DELIM_CAPTURE ); |
|
| 123 | + $domain_parts = preg_split(self::WRAP_URLS_DOMAIN_PARTS, $url_match['domain'], -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 124 | 124 | |
| 125 | 125 | // This is a hack, but it works. |
| 126 | 126 | // First, we hyphenate each part, we need it formated like a group of words. |
| 127 | 127 | $parsed_words_like = []; |
| 128 | - foreach ( $domain_parts as $key => $part ) { |
|
| 129 | - $parsed_words_like[ $key ] = new Text_Parser\Token( $part, Text_Parser\Token::OTHER ); |
|
| 128 | + foreach ($domain_parts as $key => $part) { |
|
| 129 | + $parsed_words_like[$key] = new Text_Parser\Token($part, Text_Parser\Token::OTHER); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // Do the hyphenation. |
| 133 | - $parsed_words_like = $this->do_hyphenate( $parsed_words_like, $settings, U::ZERO_WIDTH_SPACE ); |
|
| 133 | + $parsed_words_like = $this->do_hyphenate($parsed_words_like, $settings, U::ZERO_WIDTH_SPACE); |
|
| 134 | 134 | |
| 135 | 135 | // Restore format. |
| 136 | - foreach ( $parsed_words_like as $key => $parsed_word ) { |
|
| 136 | + foreach ($parsed_words_like as $key => $parsed_word) { |
|
| 137 | 137 | $value = $parsed_word->value; |
| 138 | 138 | |
| 139 | - if ( $key > 0 && 1 === strlen( $value ) ) { |
|
| 140 | - $domain_parts[ $key ] = U::ZERO_WIDTH_SPACE . $value; |
|
| 139 | + if ($key > 0 && 1 === strlen($value)) { |
|
| 140 | + $domain_parts[$key] = U::ZERO_WIDTH_SPACE . $value; |
|
| 141 | 141 | } else { |
| 142 | - $domain_parts[ $key ] = $value; |
|
| 142 | + $domain_parts[$key] = $value; |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // Lastly let's recombine. |
| 147 | - $domain = implode( $domain_parts ); |
|
| 147 | + $domain = implode($domain_parts); |
|
| 148 | 148 | |
| 149 | 149 | // Break up the URL path to individual characters. |
| 150 | - $path_parts = str_split( $url_match['path'], 1 ); |
|
| 151 | - $path_count = count( $path_parts ); |
|
| 150 | + $path_parts = str_split($url_match['path'], 1); |
|
| 151 | + $path_count = count($path_parts); |
|
| 152 | 152 | $path = ''; |
| 153 | - foreach ( $path_parts as $index => $path_part ) { |
|
| 154 | - if ( 0 === $index || $path_count - $index < $settings['urlMinAfterWrap'] ) { |
|
| 153 | + foreach ($path_parts as $index => $path_part) { |
|
| 154 | + if (0 === $index || $path_count - $index < $settings['urlMinAfterWrap']) { |
|
| 155 | 155 | $path .= $path_part; |
| 156 | 156 | } else { |
| 157 | 157 | $path .= U::ZERO_WIDTH_SPACE . $path_part; |
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $tokens[ $token_index ] = $text_token->with_value( $http . $domain . $path ); |
|
| 161 | + $tokens[$token_index] = $text_token->with_value($http . $domain . $path); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @param int $target Required. |
| 59 | 59 | * @param bool $feed_compatible Optional. Default false. |
| 60 | 60 | */ |
| 61 | - protected function __construct( $target, $feed_compatible = false ) { |
|
| 61 | + protected function __construct($target, $feed_compatible = false) { |
|
| 62 | 62 | $this->target = $target; |
| 63 | 63 | $this->feed_compatible = $feed_compatible; |
| 64 | 64 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return array An array of tokens. |
| 75 | 75 | */ |
| 76 | - abstract public function apply( array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null ); |
|
| 76 | + abstract public function apply(array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null); |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * Determines whether the fix should be applied to (RSS) feeds. |
@@ -80,7 +80,7 @@ |
||
| 80 | 80 | * |
| 81 | 81 | * @param bool $feed_compatible Optional. Default false. |
| 82 | 82 | */ |
| 83 | - public function __construct( $feed_compatible = false ) { |
|
| 84 | - parent::__construct( self::REGEX, self::REPLACEMENT, self::SETTING, $feed_compatible ); |
|
| 83 | + public function __construct($feed_compatible = false) { |
|
| 84 | + parent::__construct(self::REGEX, self::REPLACEMENT, self::SETTING, $feed_compatible); |
|
| 85 | 85 | } |
| 86 | 86 | } |
@@ -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 | } |