Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#95)
by Der Mundschenk
03:34
created

Settings   F

Complexity

Total Complexity 117

Size/Duplication

Total Lines 1104
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 117
eloc 227
c 7
b 0
f 0
dl 0
loc 1104
ccs 355
cts 355
cp 1
rs 2

79 Methods

Rating   Name   Duplication   Size   Complexity  
A dash_style() 0 2 1
A set_smart_fractions() 0 2 1
A set_fraction_spacing() 0 2 1
A apply_character_mapping() 0 15 5
A set_smart_diacritics() 0 2 1
A set_space_collapse() 0 2 1
A __construct() 0 7 2
A set_smart_quotes_secondary() 0 2 1
A set_min_before_hyphenation() 0 4 2
A set_dewidow_word_number() 0 4 3
A __set() 0 2 1
A set_dewidow() 0 2 1
A set_smart_ordinal_suffix() 0 2 1
A set_smart_dashes_style() 0 2 1
A set_smart_area_units() 0 2 1
A __isset() 0 2 1
A set_single_character_word_spacing() 0 2 1
A __get() 0 2 1
A set_smart_dashes() 0 2 1
A offsetUnset() 0 2 1
A set_smart_marks() 0 2 1
A get_quote_style() 0 2 1
A set_max_dewidow_pull() 0 4 2
A set_smart_ellipses() 0 2 1
A parse_diacritics_replacement_string() 0 15 2
A set_hyphenate_headings() 0 2 1
A set_email_wrap() 0 2 1
A parse_diacritics_rules() 0 5 2
A set_min_after_url_wrap() 0 4 2
A primary_quote_style() 0 2 1
A set_smart_exponents() 0 2 1
A set_smart_quotes() 0 2 1
A get_hash() 0 8 3
A set_diacritic_language() 0 16 4
A set_unit_spacing() 0 2 1
A set_smart_quotes_exceptions() 0 16 1
A set_url_wrap() 0 2 1
A update_diacritics_replacement_arrays() 0 14 3
A offsetSet() 0 3 2
A set_hyphenate_all_caps() 0 2 1
A set_ignore_parser_errors() 0 2 1
A custom_units() 0 2 1
A set_smart_math() 0 2 1
A set_ids_to_ignore() 0 2 1
A set_classes_to_ignore() 0 2 1
A remap_character() 0 5 2
A jsonSerialize() 0 9 1
A set_hyphenation_exceptions() 0 2 1
A set_smart_ordinal_suffix_match_roman_numerals() 0 2 1
A offsetExists() 0 2 1
A set_style_numbers() 0 2 1
A __unset() 0 2 1
A get_style() 0 12 4
A set_max_dewidow_length() 0 4 2
A array_map_assoc() 0 12 3
A set_parser_errors_handler() 0 2 1
A set_units() 0 3 1
A set_hyphenate_title_case() 0 2 1
A update_unit_pattern() 0 10 3
A set_tags_to_ignore() 0 5 1
A set_french_punctuation_spacing() 0 2 1
A set_style_ampersands() 0 2 1
A set_wrap_hard_hyphens() 0 2 1
A set_min_length_hyphenation() 0 4 2
A set_smart_quotes_primary() 0 2 1
A set_hyphenation() 0 2 1
A set_initial_quote_tags() 0 8 2
A set_hyphenate_compounds() 0 2 1
A set_diacritic_custom_replacements() 0 20 4
A set_defaults() 0 64 1
A offsetGet() 0 2 2
A secondary_quote_style() 0 2 1
A set_style_initial_quotes() 0 2 1
A set_dash_spacing() 0 2 1
A set_min_after_hyphenation() 0 4 2
A set_style_caps() 0 2 1
A set_numbered_abbreviation_spacing() 0 2 1
A set_hyphenation_language() 0 6 3
A set_style_hanging_punctuation() 0 2 1

How to fix   Complexity   

Complex Class

Complex classes like Settings often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Settings, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 *  This file is part of PHP-Typography.
4
 *
5
 *  Copyright 2014-2019 Peter Putzer.
6
 *  Copyright 2009-2011 KINGdesk, LLC.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  (at your option) any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License along
19
 *  with this program; if not, write to the Free Software Foundation, Inc.,
20
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
 *
22
 *  ***
23
 *
24
 *  @package mundschenk-at/php-typography
25
 *  @license http://www.gnu.org/licenses/gpl-2.0.html
26
 */
27
28
namespace PHP_Typography;
29
30
use PHP_Typography\Settings\Dash_Style;
31
use PHP_Typography\Settings\Quote_Style;
32
use PHP_Typography\Settings\Quotes;
33
34
/**
35
 * Store settings for the PHP_Typography class.
36
 *
37
 * @author Peter Putzer <[email protected]>
38
 *
39
 * @since 4.0.0
40
 * @since 6.5.0 The protected property $no_break_narrow_space has been deprecated.
41
 * @since 7.0.0 Deprecated properties and methods relating to $no_break_narrow_space have been removed.
42
 */
43
class Settings implements \ArrayAccess, \JsonSerializable {
44
45
	/**
46
	 * Primary quote style.
47
	 *
48
	 * @var Quotes
49
	 */
50
	protected $primary_quote_style;
51
52
	/**
53
	 * Secondary quote style.
54
	 *
55
	 * @var Quotes
56
	 */
57
	protected $secondary_quote_style;
58
59
	/**
60
	 * A regex pattern for custom units (or the empty string).
61
	 *
62
	 * @var string
63
	 */
64
	protected $custom_units = '';
65
66
	/**
67
	 * A hashmap of settings for the various typographic options.
68
	 *
69
	 * @var array
70
	 */
71
	protected $data = [];
72
73
	/**
74
	 * The current dash style.
75
	 *
76
	 * @var Settings\Dashes
77
	 */
78
	protected $dash_style;
79
80
	/**
81
	 * The Unicode character mapping (some characters still have compatibility issues).
82
	 *
83
	 * @since 6.5.0
84
	 *
85
	 * @var string[]
86
	 */
87
	protected $unicode_mapping;
88
89
	/**
90
	 * An array containing just remapped characters (for optimization).
91
	 *
92
	 * @since 6.5.0
93
	 *
94
	 * @var string[]
95
	 */
96
	protected $remapped_characters;
97
98
	/**
99
	 * Sets up a new Settings object.
100
	 *
101
	 * @since 6.0.0 If $set_defaults is `false`, the settings object is not fully
102
	 *              initialized unless `set_smart_quotes_primary`,
103
	 *              `set_smart_quotes_secondary`, `set_smart_dashes_style` and
104
	 *              `set_true_no_break_narrow_space` are called explicitly.
105
	 * @since 6.5.0 A (partial) character mapping can be given to remap certain
106
	 *              characters.
107
	 *
108
	 * @param bool     $set_defaults Optional. If true, set default values for various properties. Default true.
109
	 * @param string[] $mapping      Optional. Unicode characters to remap. The default maps the narrow no-break space to the normal NO-BREAK SPACE and the apostrophe to the RIGHT SINGLE QUOTATION MARK.
110
	 */
111 1
	public function __construct( $set_defaults = true, array $mapping = [ U::NO_BREAK_NARROW_SPACE => U::NO_BREAK_SPACE, U::APOSTROPHE => U::SINGLE_QUOTE_CLOSE ] ) { // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing
112 1
		if ( $set_defaults ) {
113 1
			$this->set_defaults();
114
		}
115
116
		// Merge default character mapping with given mapping.
117 1
		$this->unicode_mapping = $mapping;
118 1
	}
119
120
	/**
121
	 * Provides access to named settings (object syntax).
122
	 *
123
	 * @param string $key The settings key.
124
	 *
125
	 * @return mixed
126
	 */
127 1
	public function &__get( $key ) {
128 1
		return $this->data[ $key ];
129
	}
130
131
	/**
132
	 * Changes a named setting (object syntax).
133
	 *
134
	 * @param string $key   The settings key.
135
	 * @param mixed  $value The settings value.
136
	 */
137 1
	public function __set( $key, $value ) {
138 1
		$this->data[ $key ] = $value;
139 1
	}
140
141
	/**
142
	 * Checks if a named setting exists (object syntax).
143
	 *
144
	 * @param string $key The settings key.
145
	 */
146 1
	public function __isset( $key ) {
147 1
		return isset( $this->data[ $key ] );
148
	}
149
150
	/**
151
	 * Unsets a named setting.
152
	 *
153
	 * @param string $key The settings key.
154
	 */
155 1
	public function __unset( $key ) {
156 1
		unset( $this->data[ $key ] );
157 1
	}
158
159
	/**
160
	 * Changes a named setting (array syntax).
161
	 *
162
	 * @param string $offset The settings key.
163
	 * @param mixed  $value  The settings value.
164
	 */
165 1
	public function offsetSet( $offset, $value ) {
166 1
		if ( ! empty( $offset ) ) {
167 1
			$this->data[ $offset ] = $value;
168
		}
169 1
	}
170
171
	/**
172
	 * Checks if a named setting exists (array syntax).
173
	 *
174
	 * @param string $offset The settings key.
175
	 */
176 1
	public function offsetExists( $offset ) {
177 1
		return isset( $this->data[ $offset ] );
178
	}
179
180
	/**
181
	 * Unsets a named setting (array syntax).
182
	 *
183
	 * @param string $offset The settings key.
184
	 */
185 1
	public function offsetUnset( $offset ) {
186 1
		unset( $this->data[ $offset ] );
187 1
	}
188
189
	/**
190
	 * Provides access to named settings (array syntax).
191
	 *
192
	 * @param string $offset The settings key.
193
	 *
194
	 * @return mixed
195
	 */
196 1
	public function offsetGet( $offset ) {
197 1
		return isset( $this->data[ $offset ] ) ? $this->data[ $offset ] : null;
198
	}
199
200
	/**
201
	 * Provides a JSON serialization of the settings.
202
	 *
203
	 * @return mixed
204
	 */
205 1
	public function jsonSerialize() {
206 1
		return \array_merge(
207 1
			$this->data,
208
			[
209 1
				'unicode_mapping'       => $this->unicode_mapping,
210 1
				'primary_quotes'        => "{$this->primary_quote_style->open()}|{$this->primary_quote_style->close()}",
211 1
				'secondary_quotes'      => "{$this->secondary_quote_style->open()}|{$this->secondary_quote_style->close()}",
212 1
				'dash_style'            => "{$this->dash_style->interval_dash()}|{$this->dash_style->interval_space()}|{$this->dash_style->parenthetical_dash()}|{$this->dash_style->parenthetical_space()}",
213 1
				'custom_units'          => $this->custom_units,
214
			]
215
		);
216
	}
217
218
	/**
219
	 * Remaps a unicode character to another one.
220
	 *
221
	 * @since 6.5.0
222
	 *
223
	 * @param  string $char     The remapped character.
224
	 * @param  string $new_char The character to actually use.
225
	 */
226 1
	public function remap_character( $char, $new_char ) {
227 1
		if ( $char !== $new_char ) {
228 1
			$this->unicode_mapping[ $char ] = $new_char;
229
		} else {
230 1
			unset( $this->unicode_mapping[ $char ] );
231
		}
232 1
	}
233
234
	/**
235
	 * Remaps one or more strings.
236
	 *
237
	 * @since 6.5.0
238
	 *
239
	 * @param  string|string[] $input The input string(s).
240
	 *
241
	 * @return string|string[]
242
	 */
243 4
	public function apply_character_mapping( $input ) {
244
245
		// Nothing for us to do.
246 4
		if ( empty( $input ) || empty( $this->unicode_mapping ) ) {
247 1
			return $input;
248
		}
249
250 3
		$native_array = \is_array( $input );
251 3
		$data         = (array) $input;
252
253 3
		foreach ( $data as $key => $string ) {
254 3
			$data[ $key ] = \strtr( $string, $this->unicode_mapping );
255
		}
256
257 3
		return $native_array ? $data : $data[0];
258
	}
259
260
	/**
261
	 * Retrieves the primary (double) quote style.
262
	 *
263
	 * @return Quotes
264
	 */
265 1
	public function primary_quote_style() {
266 1
		return $this->primary_quote_style;
267
	}
268
269
	/**
270
	 * Retrieves the secondary (single) quote style.
271
	 *
272
	 * @return Quotes
273
	 */
274 1
	public function secondary_quote_style() {
275 1
		return $this->secondary_quote_style;
276
	}
277
278
	/**
279
	 * Retrieves the dash style.
280
	 *
281
	 * @return Settings\Dashes
282
	 */
283 1
	public function dash_style() {
284 1
		return $this->dash_style;
285
	}
286
287
	/**
288
	 * Retrieves the custom units pattern.
289
	 *
290
	 * @return string The pattern is suitable for inclusion into a regular expression.
291
	 */
292 1
	public function custom_units() {
293 1
		return $this->custom_units;
294
	}
295
296
	/**
297
	 * (Re)set various options to their default values.
298
	 */
299 1
	public function set_defaults() {
300
		// General attributes.
301 1
		$this->set_tags_to_ignore();
302 1
		$this->set_classes_to_ignore();
303 1
		$this->set_ids_to_ignore();
304
305
		// Smart characters.
306 1
		$this->set_smart_quotes();
307 1
		$this->set_smart_quotes_primary();
308 1
		$this->set_smart_quotes_secondary();
309 1
		$this->set_smart_quotes_exceptions();
310 1
		$this->set_smart_dashes();
311 1
		$this->set_smart_dashes_style();
312 1
		$this->set_smart_ellipses();
313 1
		$this->set_smart_diacritics();
314 1
		$this->set_diacritic_language();
315 1
		$this->set_diacritic_custom_replacements();
316 1
		$this->set_smart_marks();
317 1
		$this->set_smart_ordinal_suffix();
318 1
		$this->set_smart_ordinal_suffix_match_roman_numerals();
319 1
		$this->set_smart_math();
320 1
		$this->set_smart_fractions();
321 1
		$this->set_smart_exponents();
322 1
		$this->set_smart_area_units();
323
324
		// Smart spacing.
325 1
		$this->set_single_character_word_spacing();
326 1
		$this->set_fraction_spacing();
327 1
		$this->set_unit_spacing();
328 1
		$this->set_french_punctuation_spacing();
329 1
		$this->set_units();
330 1
		$this->set_dash_spacing();
331 1
		$this->set_dewidow();
332 1
		$this->set_max_dewidow_length();
333 1
		$this->set_max_dewidow_pull();
334 1
		$this->set_dewidow_word_number();
335 1
		$this->set_wrap_hard_hyphens();
336 1
		$this->set_url_wrap();
337 1
		$this->set_email_wrap();
338 1
		$this->set_min_after_url_wrap();
339 1
		$this->set_space_collapse();
340
341
		// Character styling.
342 1
		$this->set_style_ampersands();
343 1
		$this->set_style_caps();
344 1
		$this->set_style_initial_quotes();
345 1
		$this->set_style_numbers();
346 1
		$this->set_style_hanging_punctuation();
347 1
		$this->set_initial_quote_tags();
348
349
		// Hyphenation.
350 1
		$this->set_hyphenation();
351 1
		$this->set_hyphenation_language();
352 1
		$this->set_min_length_hyphenation();
353 1
		$this->set_min_before_hyphenation();
354 1
		$this->set_min_after_hyphenation();
355 1
		$this->set_hyphenate_headings();
356 1
		$this->set_hyphenate_all_caps();
357 1
		$this->set_hyphenate_title_case();
358 1
		$this->set_hyphenate_compounds();
359 1
		$this->set_hyphenation_exceptions();
360
361
		// Parser error handling.
362 1
		$this->set_ignore_parser_errors();
363 1
	}
364
365
	/**
366
	 * Enable lenient parser error handling (HTML is "best guess" if enabled).
367
	 *
368
	 * @param bool $on Optional. Default false.
369
	 */
370 1
	public function set_ignore_parser_errors( $on = false ) {
371 1
		$this->data['parserErrorsIgnore'] = $on;
372 1
	}
373
374
	/**
375
	 * Sets an optional handler for parser errors. Invalid callbacks will be silently ignored.
376
	 *
377
	 * @since 6.0.0. callable type is enforced via typehinting.
378
	 *
379
	 * @param callable|null $handler Optional. A callable that takes an array of error strings as its parameter. Default null.
380
	 */
381 2
	public function set_parser_errors_handler( callable $handler = null ) {
382 2
		$this->data['parserErrorsHandler'] = $handler;
383 2
	}
384
385
	/**
386
	 * Sets tags for which the typography of their children will be left untouched.
387
	 *
388
	 * @param string|array $tags A comma separated list or an array of tag names.
389
	 */
390 1
	public function set_tags_to_ignore( $tags = [ 'code', 'head', 'kbd', 'object', 'option', 'pre', 'samp', 'script', 'noscript', 'noembed', 'select', 'style', 'textarea', 'title', 'var', 'math' ] ) {
391
		// Ensure that we pass only lower-case tag names to XPath.
392 1
		$tags = array_filter( array_map( 'strtolower', Strings::maybe_split_parameters( $tags ) ), 'ctype_alnum' );
393
394 1
		$this->data['ignoreTags'] = array_unique( array_merge( $tags, array_flip( DOM::inappropriate_tags() ) ) );
395 1
	}
396
397
	/**
398
	 * Sets classes for which the typography of their children will be left untouched.
399
	 *
400
	 * @param string|array $classes A comma separated list or an array of class names.
401
	 */
402 1
	public function set_classes_to_ignore( $classes = [ 'vcard', 'noTypo' ] ) {
403 1
		$this->data['ignoreClasses'] = Strings::maybe_split_parameters( $classes );
404 1
	}
405
406
	/**
407
	 * Sets IDs for which the typography of their children will be left untouched.
408
	 *
409
	 * @param string|array $ids A comma separated list or an array of tag names.
410
	 */
411 1
	public function set_ids_to_ignore( $ids = [] ) {
412 1
		$this->data['ignoreIDs'] = Strings::maybe_split_parameters( $ids );
413 1
	}
414
415
	/**
416
	 * Enables/disables typographic quotes.
417
	 *
418
	 * @param bool $on Optional. Default true.
419
	 */
420 1
	public function set_smart_quotes( $on = true ) {
421 1
		$this->data['smartQuotes'] = $on;
422 1
	}
423
424
	/**
425
	 * Sets the style for primary ('double') quotemarks.
426
	 *
427
	 * Allowed values for $style:
428
	 * "doubleCurled" => "&ldquo;foo&rdquo;",
429
	 * "doubleCurledReversed" => "&rdquo;foo&rdquo;",
430
	 * "doubleLow9" => "&bdquo;foo&rdquo;",
431
	 * "doubleLow9Reversed" => "&bdquo;foo&ldquo;",
432
	 * "singleCurled" => "&lsquo;foo&rsquo;",
433
	 * "singleCurledReversed" => "&rsquo;foo&rsquo;",
434
	 * "singleLow9" => "&sbquo;foo&rsquo;",
435
	 * "singleLow9Reversed" => "&sbquo;foo&lsquo;",
436
	 * "doubleGuillemetsFrench" => "&laquo;&nbsp;foo&nbsp;&raquo;",
437
	 * "doubleGuillemets" => "&laquo;foo&raquo;",
438
	 * "doubleGuillemetsReversed" => "&raquo;foo&laquo;",
439
	 * "singleGuillemets" => "&lsaquo;foo&rsaquo;",
440
	 * "singleGuillemetsReversed" => "&rsaquo;foo&lsaquo;",
441
	 * "cornerBrackets" => "&#x300c;foo&#x300d;",
442
	 * "whiteCornerBracket" => "&#x300e;foo&#x300f;"
443
	 *
444
	 * @param  Quotes|string $style Optional. A Quotes instance or a quote style constant. Defaults to 'doubleCurled'.
445
	 *
446
	 * @throws \DomainException Thrown if $style constant is invalid.
447
	 */
448 3
	public function set_smart_quotes_primary( $style = Quote_Style::DOUBLE_CURLED ) {
449 3
		$this->primary_quote_style = $this->get_quote_style( $style );
450 2
	}
451
452
	/**
453
	 * Sets the style for secondary ('single') quotemarks.
454
	 *
455
	 * Allowed values for $style:
456
	 * "doubleCurled" => "&ldquo;foo&rdquo;",
457
	 * "doubleCurledReversed" => "&rdquo;foo&rdquo;",
458
	 * "doubleLow9" => "&bdquo;foo&rdquo;",
459
	 * "doubleLow9Reversed" => "&bdquo;foo&ldquo;",
460
	 * "singleCurled" => "&lsquo;foo&rsquo;",
461
	 * "singleCurledReversed" => "&rsquo;foo&rsquo;",
462
	 * "singleLow9" => "&sbquo;foo&rsquo;",
463
	 * "singleLow9Reversed" => "&sbquo;foo&lsquo;",
464
	 * "doubleGuillemetsFrench" => "&laquo;&nbsp;foo&nbsp;&raquo;",
465
	 * "doubleGuillemets" => "&laquo;foo&raquo;",
466
	 * "doubleGuillemetsReversed" => "&raquo;foo&laquo;",
467
	 * "singleGuillemets" => "&lsaquo;foo&rsaquo;",
468
	 * "singleGuillemetsReversed" => "&rsaquo;foo&lsaquo;",
469
	 * "cornerBrackets" => "&#x300c;foo&#x300d;",
470
	 * "whiteCornerBracket" => "&#x300e;foo&#x300f;"
471
	 *
472
	 * @param  Quotes|string $style Optional. A Quotes instance or a quote style constant. Defaults to 'singleCurled'.
473
	 *
474
	 * @throws \DomainException Thrown if $style constant is invalid.
475
	 */
476 3
	public function set_smart_quotes_secondary( $style = Quote_Style::SINGLE_CURLED ) {
477 3
		$this->secondary_quote_style = $this->get_quote_style( $style );
478 2
	}
479
480
	/**
481
	 * Retrieves a Quotes instance from a given style.
482
	 *
483
	 * @param  Quotes|string $style A Quotes instance or a quote style constant.
484
	 *
485
	 * @throws \DomainException Thrown if $style constant is invalid.
486
	 *
487
	 * @return Quotes
488
	 */
489 6
	protected function get_quote_style( $style ) {
490 6
		return $this->get_style( $style, Quotes::class, [ Quote_Style::class, 'get_styled_quotes' ], 'quote' );
491
	}
492
493
	/**
494
	 * Sets the list of exceptional words for smart quotes replacement. Mainly,
495
	 * this is used for contractions beginning with an apostrophe.
496
	 *
497
	 * @param string[] $exceptions Optional. An array of replacements indexed by the ”non-smart" form.
498
	 *                             Default a list of English words beginning with an apostrophy.
499
	 */
500 1
	public function set_smart_quotes_exceptions( $exceptions = [
501
		"'tain't"   => U::APOSTROPHE . 'tain' . U::APOSTROPHE . 't',
502
		"'twere"    => U::APOSTROPHE . 'twere',
503
		"'twas"     => U::APOSTROPHE . 'twas',
504
		"'tis"      => U::APOSTROPHE . 'tis',
505
		"'til"      => U::APOSTROPHE . 'til',
506
		"'bout"     => U::APOSTROPHE . 'bout',
507
		"'nuff"     => U::APOSTROPHE . 'nuff',
508
		"'round"    => U::APOSTROPHE . 'round',
509
		"'cause"    => U::APOSTROPHE . 'cause',
510
		"'splainin" => U::APOSTROPHE . 'splainin',
511
		"'em'"      => U::APOSTROPHE . 'em',
512
	] ) {
513 1
		$this->data['smartQuotesExceptions'] = [
514 1
			'patterns'     => \array_keys( $exceptions ),
515 1
			'replacements' => \array_values( $exceptions ),
516
		];
517 1
	}
518
519
	/**
520
	 * Retrieves an object from a given style.
521
	 *
522
	 * @param  object|string $style          A style object instance or a style constant.
523
	 * @param  string        $expected_class A class name.
524
	 * @param  callable      $get_style      A function that returns a style object from a given style constant.
525
	 * @param  string        $description    Style description for the exception message.
526
	 *
527
	 * @throws \DomainException Thrown if $style constant is invalid.
528
	 *
529
	 * @return object An instance of $expected_class.
530
	 */
531 9
	protected function get_style( $style, $expected_class, callable $get_style, $description ) {
532 9
		if ( $style instanceof $expected_class ) {
533 3
			$object = $style;
534
		} else {
535 6
			$object = $get_style( $style, $this );
536
		}
537
538 9
		if ( ! \is_object( $object ) || ! $object instanceof $expected_class ) {
539 3
			throw new \DomainException( "Invalid $description style $style." );
540
		}
541
542 6
		return $object;
543
	}
544
545
	/**
546
	 * Enables/disables replacement of "a--a" with En Dash " -- " and "---" with Em Dash.
547
	 *
548
	 * @param bool $on Optional. Default true.
549
	 */
550 1
	public function set_smart_dashes( $on = true ) {
551 1
		$this->data['smartDashes'] = $on;
552 1
	}
553
554
	/**
555
	 * Sets the typographical conventions used by smart_dashes.
556
	 *
557
	 * Allowed values for $style:
558
	 * - "traditionalUS"
559
	 * - "international"
560
	 *
561
	 * @param string|Settings\Dashes $style Optional. Default Dash_Style::TRADITIONAL_US.
562
	 *
563
	 * @throws \DomainException Thrown if $style constant is invalid.
564
	 */
565 3
	public function set_smart_dashes_style( $style = Dash_Style::TRADITIONAL_US ) {
566 3
		$this->dash_style = $this->get_style( $style, Settings\Dashes::class, [ Dash_Style::class, 'get_styled_dashes' ], 'dash' );
567 2
	}
568
569
	/**
570
	 * Enables/disables replacement of "..." with "…".
571
	 *
572
	 * @param bool $on Optional. Default true.
573
	 */
574 1
	public function set_smart_ellipses( $on = true ) {
575 1
		$this->data['smartEllipses'] = $on;
576 1
	}
577
578
	/**
579
	 * Enables/disables replacement "creme brulee" with "crème brûlée".
580
	 *
581
	 * @param bool $on Optional. Default true.
582
	 */
583 1
	public function set_smart_diacritics( $on = true ) {
584 1
		$this->data['smartDiacritics'] = $on;
585 1
	}
586
587
	/**
588
	 * Sets the language used for diacritics replacements.
589
	 *
590
	 * @param string $lang Has to correspond to a filename in 'diacritics'. Optional. Default 'en-US'.
591
	 */
592 1
	public function set_diacritic_language( $lang = 'en-US' ) {
593 1
		if ( isset( $this->data['diacriticLanguage'] ) && $this->data['diacriticLanguage'] === $lang ) {
594 1
			return;
595
		}
596
597 1
		$this->data['diacriticLanguage'] = $lang;
598 1
		$language_file_name              = \dirname( __FILE__ ) . '/diacritics/' . $lang . '.json';
599
600 1
		if ( \file_exists( $language_file_name ) ) {
601 1
			$diacritics_file              = \json_decode( \file_get_contents( $language_file_name ), true );
602 1
			$this->data['diacriticWords'] = $diacritics_file['diacritic_words'];
603
		} else {
604 1
			unset( $this->data['diacriticWords'] );
605
		}
606
607 1
		$this->update_diacritics_replacement_arrays();
608 1
	}
609
610
	/**
611
	 * Sets up custom diacritics replacements.
612
	 *
613
	 * @param string|array $custom_replacements An array formatted [needle=>replacement, needle=>replacement...],
614
	 *                                          or a string formatted `"needle"=>"replacement","needle"=>"replacement",...
615
	 */
616 6
	public function set_diacritic_custom_replacements( $custom_replacements = [] ) {
617 6
		if ( ! \is_array( $custom_replacements ) ) {
618 3
			$custom_replacements = $this->parse_diacritics_replacement_string( $custom_replacements );
619
		}
620
621 6
		$this->data['diacriticCustomReplacements'] = self::array_map_assoc(
622
			function( $key, $replacement ) {
623 5
				$key         = \strip_tags( \trim( $key ) );
624 5
				$replacement = \strip_tags( \trim( $replacement ) );
625
626 5
				if ( ! empty( $key ) && ! empty( $replacement ) ) {
627 3
					return [ $key => $replacement ];
628
				} else {
629 2
					return [];
630
				}
631 6
			},
632
			$custom_replacements
633
		);
634
635 6
		$this->update_diacritics_replacement_arrays();
636 6
	}
637
638
	/**
639
	 * Parses a custom diacritics replacement string into an array.
640
	 *
641
	 * @param string $custom_replacements A string formatted `"needle"=>"replacement","needle"=>"replacement",...
642
	 *
643
	 * @return array
644
	 */
645 3
	private function parse_diacritics_replacement_string( $custom_replacements ) {
646 3
		return self::array_map_assoc(
647
			function( $key, $replacement ) {
648
				// Account for single and double quotes in keys in and values, discard everything else.
649 3
				if ( \preg_match( '/(?<kquo>"|\')(?<key>(?:(?!\k<kquo>).)+)\k<kquo>\s*=>\s*(?<rquo>"|\')(?<replacement>(?:(?!\k<rquo>).)+)\k<rquo>/', $replacement, $match ) ) {
650 2
					$key         = $match['key'];
651 2
					$replacement = $match['replacement'];
652
653 2
					return [ $key => $replacement ];
654
				}
655
656 1
				return [];
657 3
			},
658
			/** RE correct. @scrutinizer ignore-type */
659 3
			\preg_split( '/,/', $custom_replacements, -1, PREG_SPLIT_NO_EMPTY )
660
		);
661
	}
662
663
	/**
664
	 * Provides an array_map implementation with control over resulting array's keys.
665
	 *
666
	 * Based on https://gist.github.com/jasand-pereza/84ecec7907f003564584.
667
	 *
668
	 * @since 6.0.0
669
	 *
670
	 * @param  callable $callback A callback function that needs to return [ $key => $value ] pairs.
671
	 * @param  array    $array    The array.
672
	 *
673
	 * @return array
674
	 */
675 2
	protected static function array_map_assoc( callable $callback, array $array ) {
676 2
		$new = [];
677
678 2
		foreach ( $array as $k => $v ) {
679 2
			$u = $callback( $k, $v );
680
681 2
			if ( ! empty( $u ) ) {
682 1
				$new[ \key( $u ) ] = \current( $u );
683
			}
684
		}
685
686 2
		return $new;
687
	}
688
689
	/**
690
	 * Update the pattern and replacement arrays in $settings['diacriticReplacement'].
691
	 *
692
	 * Should be called whenever a new diacritics replacement language is selected or
693
	 * when the custom replacements are updated.
694
	 */
695 7
	private function update_diacritics_replacement_arrays() {
696 7
		$patterns     = [];
697 7
		$replacements = [];
698
699 7
		if ( ! empty( $this->data['diacriticCustomReplacements'] ) ) {
700 3
			$this->parse_diacritics_rules( $this->data['diacriticCustomReplacements'], $patterns, $replacements );
701
		}
702 7
		if ( ! empty( $this->data['diacriticWords'] ) ) {
703 1
			$this->parse_diacritics_rules( $this->data['diacriticWords'], $patterns, $replacements );
704
		}
705
706 7
		$this->data['diacriticReplacement'] = [
707 7
			'patterns'     => $patterns,
708 7
			'replacements' => $replacements,
709
		];
710 7
	}
711
712
	/**
713
	 * Parse an array of diacritics rules.
714
	 *
715
	 * @param array $diacritics_rules The rules ( $word => $replacement ).
716
	 * @param array $patterns         Resulting patterns. Passed by reference.
717
	 * @param array $replacements     Resulting replacements. Passed by reference.
718
	 */
719 4
	private function parse_diacritics_rules( array $diacritics_rules, array &$patterns, array &$replacements ) {
720
721 4
		foreach ( $diacritics_rules as $needle => $replacement ) {
722 4
			$patterns[]              = '/\b(?<!\w[' . U::NO_BREAK_SPACE . U::SOFT_HYPHEN . '])' . $needle . '\b(?![' . U::NO_BREAK_SPACE . U::SOFT_HYPHEN . ']\w)/u';
723 4
			$replacements[ $needle ] = $replacement;
724
		}
725 4
	}
726
727
	/**
728
	 * Enables/disables replacement of (r) (c) (tm) (sm) (p) (R) (C) (TM) (SM) (P) with ® © ™ ℠ ℗.
729
	 *
730
	 * @param bool $on Optional. Default true.
731
	 */
732 1
	public function set_smart_marks( $on = true ) {
733 1
		$this->data['smartMarks'] = $on;
734 1
	}
735
736
	/**
737
	 * Enables/disables proper mathematical symbols.
738
	 *
739
	 * @param bool $on Optional. Default true.
740
	 */
741 1
	public function set_smart_math( $on = true ) {
742 1
		$this->data['smartMath'] = $on;
743 1
	}
744
745
	/**
746
	 * Enables/disables replacement of 2^2 with 2<sup>2</sup>
747
	 *
748
	 * @param bool $on Optional. Default true.
749
	 */
750 1
	public function set_smart_exponents( $on = true ) {
751 1
		$this->data['smartExponents'] = $on;
752 1
	}
753
754
	/**
755
	 * Enables/disables replacement of 1/4 with <sup>1</sup>&#8260;<sub>4</sub>.
756
	 *
757
	 * @param bool $on Optional. Default true.
758
	 */
759 1
	public function set_smart_fractions( $on = true ) {
760 1
		$this->data['smartFractions'] = $on;
761 1
	}
762
763
	/**
764
	 * Enables/disables replacement of 1st with 1<sup>st</sup>.
765
	 *
766
	 * @param bool $on Optional. Default true.
767
	 */
768 1
	public function set_smart_ordinal_suffix( $on = true ) {
769 1
		$this->data['smartOrdinalSuffix'] = $on;
770 1
	}
771
772
	/**
773
	 * Enables/disables replacement of XXe with XX<sup>e</sup>.
774
	 *
775
	 * @since 6.5.0
776
	 *
777
	 * @param bool $on Optional. Default false.
778
	 */
779 1
	public function set_smart_ordinal_suffix_match_roman_numerals( $on = false ) {
780 1
		$this->data['smartOrdinalSuffixRomanNumerals'] = $on;
781 1
	}
782
783
	/**
784
	 * Enables/disables replacement of m2 with m³ and m3 with m³.
785
	 *
786
	 * @param bool $on Optional. Default true.
787
	 */
788 1
	public function set_smart_area_units( $on = true ) {
789 1
		$this->data['smartAreaVolumeUnits'] = $on;
790 1
	}
791
792
	/**
793
	 * Enables/disables forcing single character words to next line with the insertion of &nbsp;.
794
	 *
795
	 * @param bool $on Optional. Default true.
796
	 */
797 1
	public function set_single_character_word_spacing( $on = true ) {
798 1
		$this->data['singleCharacterWordSpacing'] = $on;
799 1
	}
800
801
	/**
802
	 * Enables/disables fraction spacing.
803
	 *
804
	 * @param bool $on Optional. Default true.
805
	 */
806 1
	public function set_fraction_spacing( $on = true ) {
807 1
		$this->data['fractionSpacing'] = $on;
808 1
	}
809
810
	/**
811
	 * Enables/disables keeping units and values together with the insertion of &nbsp;.
812
	 *
813
	 * @param bool $on Optional. Default true.
814
	 */
815 1
	public function set_unit_spacing( $on = true ) {
816 1
		$this->data['unitSpacing'] = $on;
817 1
	}
818
819
	/**
820
	 * Enables/disables numbered abbreviations like "ISO 9000" together with the insertion of &nbsp;.
821
	 *
822
	 * @param bool $on Optional. Default true.
823
	 */
824 1
	public function set_numbered_abbreviation_spacing( $on = true ) {
825 1
		$this->data['numberedAbbreviationSpacing'] = $on;
826 1
	}
827
828
	/**
829
	 * Enables/disables extra whitespace before certain punction marks, as is the French custom.
830
	 *
831
	 * @since 6.0.0 The default value is now `false`.`
832
	 *
833
	 * @param bool $on Optional. Default false.
834
	 */
835 1
	public function set_french_punctuation_spacing( $on = false ) {
836 1
		$this->data['frenchPunctuationSpacing'] = $on;
837 1
	}
838
839
	/**
840
	 * Sets the list of units to keep together with their values.
841
	 *
842
	 * @param string|array $units A comma separated list or an array of units.
843
	 */
844 1
	public function set_units( $units = [] ) {
845 1
		$this->data['units'] = Strings::maybe_split_parameters( $units );
846 1
		$this->custom_units  = $this->update_unit_pattern( $this->data['units'] );
847 1
	}
848
849
	/**
850
	 * Update pattern for matching custom units.
851
	 *
852
	 * @since 6.4.0 Visibility changed to protected, return value added.
853
	 *
854
	 * @param array $units An array of unit names.
855
	 *
856
	 * @return string
857
	 */
858 2
	protected function update_unit_pattern( array $units ) {
859
		// Update unit regex pattern.
860 2
		foreach ( $units as $index => $unit ) {
861 2
			$units[ $index ] = \preg_quote( $unit, '/' );
862
		}
863
864 2
		$custom_units  = \implode( '|', $units );
865 2
		$custom_units .= ! empty( $custom_units ) ? '|' : '';
866
867 2
		return $custom_units;
868
	}
869
870
	/**
871
	 * Enables/disables wrapping of Em and En dashes are in thin spaces.
872
	 *
873
	 * @param bool $on Optional. Default true.
874
	 */
875 1
	public function set_dash_spacing( $on = true ) {
876 1
		$this->data['dashSpacing'] = $on;
877 1
	}
878
879
	/**
880
	 * Enables/disables removal of extra whitespace characters.
881
	 *
882
	 * @param bool $on Optional. Default true.
883
	 */
884 1
	public function set_space_collapse( $on = true ) {
885 1
		$this->data['spaceCollapse'] = $on;
886 1
	}
887
888
	/**
889
	 * Enables/disables widow handling.
890
	 *
891
	 * @param bool $on Optional. Default true.
892
	 */
893 1
	public function set_dewidow( $on = true ) {
894 1
		$this->data['dewidow'] = $on;
895 1
	}
896
897
	/**
898
	 * Sets the maximum length of widows that will be protected.
899
	 *
900
	 * @param int $length Defaults to 5. Trying to set the value to less than 2 resets the length to the default.
901
	 */
902 1
	public function set_max_dewidow_length( $length = 5 ) {
903 1
		$length = ( $length > 1 ) ? $length : 5;
904
905 1
		$this->data['dewidowMaxLength'] = $length;
906 1
	}
907
908
	/**
909
	 * Sets the maximum number of words considered for dewidowing.
910
	 *
911
	 * @param int $number Defaults to 1. Only 1, 2 and 3 are valid.
912
	 */
913 1
	public function set_dewidow_word_number( $number = 1 ) {
914 1
		$number = ( $number > 3 || $number < 1 ) ? 1 : $number;
915
916 1
		$this->data['dewidowWordNumber'] = $number;
917 1
	}
918
919
	/**
920
	 * Sets the maximum length of pulled text to keep widows company.
921
	 *
922
	 * @param int $length Defaults to 5. Trying to set the value to less than 2 resets the length to the default.
923
	 */
924 1
	public function set_max_dewidow_pull( $length = 5 ) {
925 1
		$length = ( $length > 1 ) ? $length : 5;
926
927 1
		$this->data['dewidowMaxPull'] = $length;
928 1
	}
929
930
	/**
931
	 * Enables/disables wrapping at internal hard hyphens with the insertion of a zero-width-space.
932
	 *
933
	 * @param bool $on Optional. Default true.
934
	 */
935 1
	public function set_wrap_hard_hyphens( $on = true ) {
936 1
		$this->data['hyphenHardWrap'] = $on;
937 1
	}
938
939
	/**
940
	 * Enables/disables wrapping of urls.
941
	 *
942
	 * @param bool $on Optional. Default true.
943
	 */
944 1
	public function set_url_wrap( $on = true ) {
945 1
		$this->data['urlWrap'] = $on;
946 1
	}
947
948
	/**
949
	 * Enables/disables wrapping of email addresses.
950
	 *
951
	 * @param bool $on Optional. Default true.
952
	 */
953 1
	public function set_email_wrap( $on = true ) {
954 1
		$this->data['emailWrap'] = $on;
955 1
	}
956
957
	/**
958
	 * Sets the minimum character requirement after an URL wrapping point.
959
	 *
960
	 * @param int $length Defaults to 5. Trying to set the value to less than 1 resets the length to the default.
961
	 */
962 1
	public function set_min_after_url_wrap( $length = 5 ) {
963 1
		$length = ( $length > 0 ) ? $length : 5;
964
965 1
		$this->data['urlMinAfterWrap'] = $length;
966 1
	}
967
968
	/**
969
	 * Enables/disables wrapping of ampersands in <span class="amp">.
970
	 *
971
	 * @param bool $on Optional. Default true.
972
	 */
973 1
	public function set_style_ampersands( $on = true ) {
974 1
		$this->data['styleAmpersands'] = $on;
975 1
	}
976
977
	/**
978
	 * Enables/disables wrapping caps in <span class="caps">.
979
	 *
980
	 * @param bool $on Optional. Default true.
981
	 */
982 1
	public function set_style_caps( $on = true ) {
983 1
		$this->data['styleCaps'] = $on;
984 1
	}
985
986
	/**
987
	 * Enables/disables wrapping of initial quotes in <span class="quo"> or <span class="dquo">.
988
	 *
989
	 * @param bool $on Optional. Default true.
990
	 */
991 1
	public function set_style_initial_quotes( $on = true ) {
992 1
		$this->data['styleInitialQuotes'] = $on;
993 1
	}
994
995
	/**
996
	 * Enables/disables wrapping of numbers in <span class="numbers">.
997
	 *
998
	 * @param bool $on Optional. Default true.
999
	 */
1000 1
	public function set_style_numbers( $on = true ) {
1001 1
		$this->data['styleNumbers'] = $on;
1002 1
	}
1003
1004
	/**
1005
	 * Enables/disables wrapping of punctiation and wide characters in <span class="pull-*">.
1006
	 *
1007
	 * @param bool $on Optional. Default true.
1008
	 */
1009 1
	public function set_style_hanging_punctuation( $on = true ) {
1010 1
		$this->data['styleHangingPunctuation'] = $on;
1011 1
	}
1012
1013
	/**
1014
	 * Sets the list of tags where initial quotes and guillemets should be styled.
1015
	 *
1016
	 * @param string|array $tags A comma separated list or an array of tag names.
1017
	 */
1018 1
	public function set_initial_quote_tags( $tags = [ 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'li', 'dd', 'dt' ] ) {
1019
		// Make array if handed a list of tags as a string.
1020 1
		if ( ! \is_array( $tags ) ) {
1021 1
			$tags = \preg_split( '/[^a-z0-9]+/', $tags, -1, PREG_SPLIT_NO_EMPTY );
1022
		}
1023
1024
		// Store the tag array inverted (with the tagName as its index for faster lookup).
1025 1
		$this->data['initialQuoteTags'] = \array_change_key_case( \array_flip( /** Array. @scrutinizer ignore-type */ $tags ), CASE_LOWER );
1026 1
	}
1027
1028
	/**
1029
	 * Enables/disables hyphenation.
1030
	 *
1031
	 * @param bool $on Optional. Default true.
1032
	 */
1033 1
	public function set_hyphenation( $on = true ) {
1034 1
		$this->data['hyphenation'] = $on;
1035 1
	}
1036
1037
	/**
1038
	 * Sets the hyphenation pattern language.
1039
	 *
1040
	 * @param string $lang Has to correspond to a filename in 'lang'. Optional. Default 'en-US'.
1041
	 */
1042 8
	public function set_hyphenation_language( $lang = 'en-US' ) {
1043 8
		if ( isset( $this->data['hyphenLanguage'] ) && $this->data['hyphenLanguage'] === $lang ) {
1044 3
			return; // Bail out, no need to do anything.
1045
		}
1046
1047 8
		$this->data['hyphenLanguage'] = $lang;
1048 8
	}
1049
1050
	/**
1051
	 * Sets the minimum length of a word that may be hyphenated.
1052
	 *
1053
	 * @param int $length Defaults to 5. Trying to set the value to less than 2 resets the length to the default.
1054
	 */
1055 1
	public function set_min_length_hyphenation( $length = 5 ) {
1056 1
		$length = ( $length > 1 ) ? $length : 5;
1057
1058 1
		$this->data['hyphenMinLength'] = $length;
1059 1
	}
1060
1061
	/**
1062
	 * Sets the minimum character requirement before a hyphenation point.
1063
	 *
1064
	 * @param int $length Defaults to 3. Trying to set the value to less than 1 resets the length to the default.
1065
	 */
1066 1
	public function set_min_before_hyphenation( $length = 3 ) {
1067 1
		$length = ( $length > 0 ) ? $length : 3;
1068
1069 1
		$this->data['hyphenMinBefore'] = $length;
1070 1
	}
1071
1072
	/**
1073
	 * Sets the minimum character requirement after a hyphenation point.
1074
	 *
1075
	 * @param int $length Defaults to 2. Trying to set the value to less than 1 resets the length to the default.
1076
	 */
1077 1
	public function set_min_after_hyphenation( $length = 2 ) {
1078 1
		$length = ( $length > 0 ) ? $length : 2;
1079
1080 1
		$this->data['hyphenMinAfter'] = $length;
1081 1
	}
1082
1083
	/**
1084
	 * Enables/disables hyphenation of titles and headings.
1085
	 *
1086
	 * @param bool $on Optional. Default true.
1087
	 */
1088 1
	public function set_hyphenate_headings( $on = true ) {
1089 1
		$this->data['hyphenateTitle'] = $on;
1090 1
	}
1091
1092
	/**
1093
	 * Enables/disables hyphenation of words set completely in capital letters.
1094
	 *
1095
	 * @param bool $on Optional. Default true.
1096
	 */
1097 1
	public function set_hyphenate_all_caps( $on = true ) {
1098 1
		$this->data['hyphenateAllCaps'] = $on;
1099 1
	}
1100
1101
	/**
1102
	 * Enables/disables hyphenation of words starting with a capital letter.
1103
	 *
1104
	 * @param bool $on Optional. Default true.
1105
	 */
1106 1
	public function set_hyphenate_title_case( $on = true ) {
1107 1
		$this->data['hyphenateTitleCase'] = $on;
1108 1
	}
1109
1110
	/**
1111
	 * Enables/disables hyphenation of compound words (e.g. "editor-in-chief").
1112
	 *
1113
	 * @param bool $on Optional. Default true.
1114
	 */
1115 1
	public function set_hyphenate_compounds( $on = true ) {
1116 1
		$this->data['hyphenateCompounds'] = $on;
1117 1
	}
1118
1119
	/**
1120
	 * Sets custom word hyphenations.
1121
	 *
1122
	 * @param string|array $exceptions An array of words with all hyphenation points marked with a hard hyphen (or a string list of such words).
1123
	 *        In the latter case, only alphanumeric characters and hyphens are recognized. The default is empty.
1124
	 */
1125 2
	public function set_hyphenation_exceptions( $exceptions = [] ) {
1126 2
		$this->data['hyphenationCustomExceptions'] = Strings::maybe_split_parameters( $exceptions );
1127 2
	}
1128
1129
	/**
1130
	 * Retrieves a unique hash value for the current settings.
1131
	 *
1132
	 * @since 5.2.0 The new parameter $raw_output has been added.
1133
	 *
1134
	 * @param int  $max_length Optional. The maximum number of bytes returned (0 for unlimited). Default 16.
1135
	 * @param bool $raw_output Optional. Wether to return raw binary data for the hash. Default true.
1136
	 *
1137
	 * @return string A binary hash value for the current settings limited to $max_length.
1138
	 */
1139 1
	public function get_hash( $max_length = 16, $raw_output = true ) {
1140 1
		$hash = \md5( \json_encode( $this ), $raw_output );
1141
1142 1
		if ( $max_length < \strlen( $hash ) && $max_length > 0 ) {
1143 1
			$hash = \substr( $hash, 0, $max_length );
1144
		}
1145
1146 1
		return $hash;
1147
	}
1148
}
1149