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.
Passed
Pull Request — master (#118)
by Der Mundschenk
03:34
created

Settings::set_diacritic_language()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
rs 9.9332
c 0
b 0
f 0
ccs 10
cts 10
cp 1
cc 4
nc 3
nop 1
crap 4
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
 */
42
class Settings implements \ArrayAccess, \JsonSerializable {
43
44
	/**
45
	 * The current no-break narrow space character.
46
	 *
47
	 * @deprecated 6.5.0
48
	 *
49
	 * @var string
50
	 */
51
	protected $no_break_narrow_space;
52
53
	/**
54
	 * Primary quote style.
55
	 *
56
	 * @var Quotes
57
	 */
58
	protected $primary_quote_style;
59
60
	/**
61
	 * Secondary quote style.
62
	 *
63
	 * @var Quotes
64
	 */
65
	protected $secondary_quote_style;
66
67
	/**
68
	 * A regex pattern for custom units (or the empty string).
69
	 *
70
	 * @var string
71
	 */
72
	protected $custom_units = '';
73
74
	/**
75
	 * A hashmap of settings for the various typographic options.
76
	 *
77
	 * @var array
78
	 */
79
	protected $data = [];
80
81
	/**
82
	 * The current dash style.
83
	 *
84
	 * @var Settings\Dashes
85
	 */
86
	protected $dash_style;
87
88
	/**
89
	 * The Unicode character mapping (some characters still have compatibility issues).
90
	 *
91
	 * @since 6.5.0
92
	 *
93
	 * @var string[]
94
	 */
95
	protected $unicode_mapping;
96
97
	/**
98
	 * An array containing just remapped characters (for optimization).
99
	 *
100
	 * @since 6.5.0
101
	 *
102
	 * @var string[]
103
	 */
104
	protected $remapped_characters;
105
106
	/**
107
	 * Sets up a new Settings object.
108
	 *
109
	 * @since 6.0.0 If $set_defaults is `false`, the settings object is not fully
110
	 *              initialized unless `set_smart_quotes_primary`,
111
	 *              `set_smart_quotes_secondary`, `set_smart_dashes_style` and
112
	 *              `set_true_no_break_narrow_space` are called explicitly.
113
	 * @since 6.5.0 A (partial) character mapping can be given to remap certain
114
	 *              characters.
115
	 *
116
	 * @param bool     $set_defaults If true, set default values for various properties. Defaults to true.
117
	 * @param string[] $mapping      A (partial) Unicode character remapping.
118
	 */
119 1
	public function __construct( $set_defaults = true, array $mapping = [] ) {
120 1
		if ( $set_defaults ) {
121 1
			$this->set_defaults();
122
		}
123
124
		// Merge default character mapping with given mapping.
125 1
		$this->unicode_mapping     = \array_merge( U::DEFAULT_MAPPING, $mapping );
126 1
		$this->remapped_characters = \array_filter(
127 1
			$this->unicode_mapping,
128
			function( $key, $value ) {
129 1
				return $key !== $value;
130 1
			},
131 1
			\ARRAY_FILTER_USE_BOTH
132
		);
133
134
		// Keep backwards compatibility.
135 1
		$this->no_break_narrow_space = $this->unicode_mapping[ U::NO_BREAK_NARROW_SPACE ];
0 ignored issues
show
Deprecated Code introduced by
The property PHP_Typography\Settings::$no_break_narrow_space has been deprecated: 6.5.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

135
		/** @scrutinizer ignore-deprecated */ $this->no_break_narrow_space = $this->unicode_mapping[ U::NO_BREAK_NARROW_SPACE ];

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
136 1
	}
137
138
	/**
139
	 * Provides access to named settings (object syntax).
140
	 *
141
	 * @param string $key The settings key.
142
	 *
143
	 * @return mixed
144
	 */
145 1
	public function &__get( $key ) {
146 1
		return $this->data[ $key ];
147
	}
148
149
	/**
150
	 * Changes a named setting (object syntax).
151
	 *
152
	 * @param string $key   The settings key.
153
	 * @param mixed  $value The settings value.
154
	 */
155 1
	public function __set( $key, $value ) {
156 1
		$this->data[ $key ] = $value;
157 1
	}
158
159
	/**
160
	 * Checks if a named setting exists (object syntax).
161
	 *
162
	 * @param string $key The settings key.
163
	 */
164 1
	public function __isset( $key ) {
165 1
		return isset( $this->data[ $key ] );
166
	}
167
168
	/**
169
	 * Unsets a named setting.
170
	 *
171
	 * @param string $key The settings key.
172
	 */
173 1
	public function __unset( $key ) {
174 1
		unset( $this->data[ $key ] );
175 1
	}
176
177
	/**
178
	 * Changes a named setting (array syntax).
179
	 *
180
	 * @param string $offset The settings key.
181
	 * @param mixed  $value  The settings value.
182
	 */
183 1
	public function offsetSet( $offset, $value ) {
184 1
		if ( ! empty( $offset ) ) {
185 1
			$this->data[ $offset ] = $value;
186
		}
187 1
	}
188
189
	/**
190
	 * Checks if a named setting exists (array syntax).
191
	 *
192
	 * @param string $offset The settings key.
193
	 */
194 1
	public function offsetExists( $offset ) {
195 1
		return isset( $this->data[ $offset ] );
196
	}
197
198
	/**
199
	 * Unsets a named setting (array syntax).
200
	 *
201
	 * @param string $offset The settings key.
202
	 */
203 1
	public function offsetUnset( $offset ) {
204 1
		unset( $this->data[ $offset ] );
205 1
	}
206
207
	/**
208
	 * Provides access to named settings (array syntax).
209
	 *
210
	 * @param string $offset The settings key.
211
	 *
212
	 * @return mixed
213
	 */
214 1
	public function offsetGet( $offset ) {
215 1
		return isset( $this->data[ $offset ] ) ? $this->data[ $offset ] : null;
216
	}
217
218
	/**
219
	 * Provides a JSON serialization of the settings.
220
	 *
221
	 * @return mixed
222
	 */
223 1
	public function jsonSerialize() {
224 1
		return \array_merge(
225 1
			$this->data,
226
			[
227 1
				'unicode_mapping'       => $this->unicode_mapping,
228 1
				'primary_quotes'        => "{$this->primary_quote_style->open()}|{$this->primary_quote_style->close()}",
229 1
				'secondary_quotes'      => "{$this->secondary_quote_style->open()}|{$this->secondary_quote_style->close()}",
230 1
				'dash_style'            => "{$this->dash_style->interval_dash()}|{$this->dash_style->interval_space()}|{$this->dash_style->parenthetical_dash()}|{$this->dash_style->parenthetical_space()}",
231 1
				'custom_units'          => $this->custom_units,
232
			]
233
		);
234
	}
235
236
	/**
237
	 * Retrieves the unicode character array (including any remappings).
238
	 *
239
	 * @since 6.5.0
240
	 *
241
	 * @return string[]
242
	 */
243
	public function character_mapping() {
244
		return $this->unicode_mapping;
245
	}
246
247
	/**
248
	 * Remaps a unicode character to another one.
249
	 *
250
	 * @since 6.5.0
251
	 *
252
	 * @param  string $char     The remapped character.
253
	 * @param  string $new_char The character to actually use.
254
	 *
255
	 * @return bool             Returns true on success, false otherwise.
256
	 */
257
	public function remap_character( $char, $new_char ) {
258
		if ( isset( $this->unicode_mapping[ $char ] ) ) {
259
			$this->unicode_mapping[ $char ] = $new_char;
260
261
			if ( $char !== $new_char ) {
262
				$this->remapped_characters[ $char ] = $new_char;
263
			} else {
264
				unset( $this->remapped_characters[ $char ] );
265
			}
266
267
			// Compatibility with the old way of setting the no-break narrow space.
268
			if ( U::NO_BREAK_NARROW_SPACE === $char ) {
269
				$this->no_break_narrow_space = $new_char;
270
			}
271
272
			return true;
273
		}
274
275
		return false;
276
	}
277
278
	/**
279
	 * Remaps one or more strings.
280
	 *
281
	 * @since 6.5.0
282
	 *
283
	 * @param  string|string[] $input The input string(s).
284
	 *
285
	 * @return string|string[]
286
	 */
287
	public function apply_mapping( $input ) {
288
289
		// Nothing for us to do.
290
		if ( empty( $input ) || empty( $this->remapped_characters ) ) {
291
			return $input;
292
		}
293
294
		$native_array = \is_array( $input );
295
		$data         = (array) $input;
296
297
		foreach ( $data as $key => $string ) {
298
			$data[ $key ] = \strtr( $string, $this->remapped_characters );
299
		}
300
301
		return $native_array ? $data : $data[0];
302
	}
303
304
	/**
305
	 * Retrieves the current non-breaking narrow space character (either the
306
	 * regular non-breaking space &nbsp; or the the true non-breaking narrow space &#8239;).
307
	 *
308
	 * @deprecated 6.5.0 Use ::character_mapping() instead.
309
	 *
310
	 * @return string
311
	 */
312 1
	public function no_break_narrow_space() {
313 1
		return $this->no_break_narrow_space;
0 ignored issues
show
Deprecated Code introduced by
The property PHP_Typography\Settings::$no_break_narrow_space has been deprecated: 6.5.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

313
		return /** @scrutinizer ignore-deprecated */ $this->no_break_narrow_space;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
314
	}
315
316
	/**
317
	 * Retrieves the primary (double) quote style.
318
	 *
319
	 * @return Quotes
320
	 */
321 1
	public function primary_quote_style() {
322 1
		return $this->primary_quote_style;
323
	}
324
325
	/**
326
	 * Retrieves the secondary (single) quote style.
327
	 *
328
	 * @return Quotes
329
	 */
330 1
	public function secondary_quote_style() {
331 1
		return $this->secondary_quote_style;
332
	}
333
334
	/**
335
	 * Retrieves the dash style.
336
	 *
337
	 * @return Settings\Dashes
338
	 */
339 1
	public function dash_style() {
340 1
		return $this->dash_style;
341
	}
342
343
	/**
344
	 * Retrieves the custom units pattern.
345
	 *
346
	 * @return string The pattern is suitable for inclusion into a regular expression.
347
	 */
348 1
	public function custom_units() {
349 1
		return $this->custom_units;
350
	}
351
352
	/**
353
	 * (Re)set various options to their default values.
354
	 */
355 1
	public function set_defaults() {
356
		// General attributes.
357 1
		$this->set_tags_to_ignore();
358 1
		$this->set_classes_to_ignore();
359 1
		$this->set_ids_to_ignore();
360
361
		// Smart characters.
362 1
		$this->set_smart_quotes();
363 1
		$this->set_smart_quotes_primary();
364 1
		$this->set_smart_quotes_secondary();
365 1
		$this->set_smart_quotes_exceptions();
366 1
		$this->set_smart_dashes();
367 1
		$this->set_smart_dashes_style();
368 1
		$this->set_smart_ellipses();
369 1
		$this->set_smart_diacritics();
370 1
		$this->set_diacritic_language();
371 1
		$this->set_diacritic_custom_replacements();
372 1
		$this->set_smart_marks();
373 1
		$this->set_smart_ordinal_suffix();
374 1
		$this->set_smart_ordinal_suffix_match_roman_numerals();
375 1
		$this->set_smart_math();
376 1
		$this->set_smart_fractions();
377 1
		$this->set_smart_exponents();
378 1
		$this->set_smart_area_units();
379
380
		// Smart spacing.
381 1
		$this->set_single_character_word_spacing();
382 1
		$this->set_fraction_spacing();
383 1
		$this->set_unit_spacing();
384 1
		$this->set_french_punctuation_spacing();
385 1
		$this->set_units();
386 1
		$this->set_dash_spacing();
387 1
		$this->set_dewidow();
388 1
		$this->set_max_dewidow_length();
389 1
		$this->set_max_dewidow_pull();
390 1
		$this->set_dewidow_word_number();
391 1
		$this->set_wrap_hard_hyphens();
392 1
		$this->set_url_wrap();
393 1
		$this->set_email_wrap();
394 1
		$this->set_min_after_url_wrap();
395 1
		$this->set_space_collapse();
396 1
		$this->set_true_no_break_narrow_space();
0 ignored issues
show
Deprecated Code introduced by
The function PHP_Typography\Settings:...no_break_narrow_space() has been deprecated: 6.5.0 Use ::remap_character() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

396
		/** @scrutinizer ignore-deprecated */ $this->set_true_no_break_narrow_space();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
397
398
		// Character styling.
399 1
		$this->set_style_ampersands();
400 1
		$this->set_style_caps();
401 1
		$this->set_style_initial_quotes();
402 1
		$this->set_style_numbers();
403 1
		$this->set_style_hanging_punctuation();
404 1
		$this->set_initial_quote_tags();
405
406
		// Hyphenation.
407 1
		$this->set_hyphenation();
408 1
		$this->set_hyphenation_language();
409 1
		$this->set_min_length_hyphenation();
410 1
		$this->set_min_before_hyphenation();
411 1
		$this->set_min_after_hyphenation();
412 1
		$this->set_hyphenate_headings();
413 1
		$this->set_hyphenate_all_caps();
414 1
		$this->set_hyphenate_title_case();
415 1
		$this->set_hyphenate_compounds();
416 1
		$this->set_hyphenation_exceptions();
417
418
		// Parser error handling.
419 1
		$this->set_ignore_parser_errors();
420 1
	}
421
422
	/**
423
	 * Enable lenient parser error handling (HTML is "best guess" if enabled).
424
	 *
425
	 * @param bool $on Optional. Default false.
426
	 */
427 1
	public function set_ignore_parser_errors( $on = false ) {
428 1
		$this->data['parserErrorsIgnore'] = $on;
429 1
	}
430
431
	/**
432
	 * Sets an optional handler for parser errors. Invalid callbacks will be silently ignored.
433
	 *
434
	 * @since 6.0.0. callable type is enforced via typehinting.
435
	 *
436
	 * @param callable|null $handler Optional. A callable that takes an array of error strings as its parameter. Default null.
437
	 */
438 2
	public function set_parser_errors_handler( callable $handler = null ) {
439 2
		$this->data['parserErrorsHandler'] = $handler;
440 2
	}
441
442
	/**
443
	 * Enable usage of true "no-break narrow space" (&#8239;) instead of the normal no-break space (&nbsp;).
444
	 *
445
	 * @deprecated 6.5.0 Use ::remap_character() instead.
446
	 *
447
	 * @param bool $on Optional. Default false.
448
	 */
449 1
	public function set_true_no_break_narrow_space( $on = false ) {
450
451 1
		if ( $on ) {
452 1
			$this->remap_character( U::NO_BREAK_NARROW_SPACE, U::NO_BREAK_NARROW_SPACE );
453
		} else {
454 1
			$this->remap_character( U::NO_BREAK_NARROW_SPACE, U::NO_BREAK_SPACE );
455
		}
456 1
	}
457
458
	/**
459
	 * Sets tags for which the typography of their children will be left untouched.
460
	 *
461
	 * @param string|array $tags A comma separated list or an array of tag names.
462
	 */
463 1
	public function set_tags_to_ignore( $tags = [ 'code', 'head', 'kbd', 'object', 'option', 'pre', 'samp', 'script', 'noscript', 'noembed', 'select', 'style', 'textarea', 'title', 'var', 'math' ] ) {
464
		// Ensure that we pass only lower-case tag names to XPath.
465 1
		$tags = array_filter( array_map( 'strtolower', Strings::maybe_split_parameters( $tags ) ), 'ctype_alnum' );
466
467 1
		$this->data['ignoreTags'] = array_unique( array_merge( $tags, array_flip( DOM::inappropriate_tags() ) ) );
468 1
	}
469
470
	/**
471
	 * Sets classes for which the typography of their children will be left untouched.
472
	 *
473
	 * @param string|array $classes A comma separated list or an array of class names.
474
	 */
475 1
	public function set_classes_to_ignore( $classes = [ 'vcard', 'noTypo' ] ) {
476 1
		$this->data['ignoreClasses'] = Strings::maybe_split_parameters( $classes );
477 1
	}
478
479
	/**
480
	 * Sets IDs for which the typography of their children will be left untouched.
481
	 *
482
	 * @param string|array $ids A comma separated list or an array of tag names.
483
	 */
484 1
	public function set_ids_to_ignore( $ids = [] ) {
485 1
		$this->data['ignoreIDs'] = Strings::maybe_split_parameters( $ids );
486 1
	}
487
488
	/**
489
	 * Enables/disables typographic quotes.
490
	 *
491
	 * @param bool $on Optional. Default true.
492
	 */
493 1
	public function set_smart_quotes( $on = true ) {
494 1
		$this->data['smartQuotes'] = $on;
495 1
	}
496
497
	/**
498
	 * Sets the style for primary ('double') quotemarks.
499
	 *
500
	 * Allowed values for $style:
501
	 * "doubleCurled" => "&ldquo;foo&rdquo;",
502
	 * "doubleCurledReversed" => "&rdquo;foo&rdquo;",
503
	 * "doubleLow9" => "&bdquo;foo&rdquo;",
504
	 * "doubleLow9Reversed" => "&bdquo;foo&ldquo;",
505
	 * "singleCurled" => "&lsquo;foo&rsquo;",
506
	 * "singleCurledReversed" => "&rsquo;foo&rsquo;",
507
	 * "singleLow9" => "&sbquo;foo&rsquo;",
508
	 * "singleLow9Reversed" => "&sbquo;foo&lsquo;",
509
	 * "doubleGuillemetsFrench" => "&laquo;&nbsp;foo&nbsp;&raquo;",
510
	 * "doubleGuillemets" => "&laquo;foo&raquo;",
511
	 * "doubleGuillemetsReversed" => "&raquo;foo&laquo;",
512
	 * "singleGuillemets" => "&lsaquo;foo&rsaquo;",
513
	 * "singleGuillemetsReversed" => "&rsaquo;foo&lsaquo;",
514
	 * "cornerBrackets" => "&#x300c;foo&#x300d;",
515
	 * "whiteCornerBracket" => "&#x300e;foo&#x300f;"
516
	 *
517
	 * @param  Quotes|string $style Optional. A Quotes instance or a quote style constant. Defaults to 'doubleCurled'.
518
	 *
519
	 * @throws \DomainException Thrown if $style constant is invalid.
520
	 */
521 3
	public function set_smart_quotes_primary( $style = Quote_Style::DOUBLE_CURLED ) {
522 3
		$this->primary_quote_style = $this->get_quote_style( $style );
523 2
	}
524
525
	/**
526
	 * Sets the style for secondary ('single') quotemarks.
527
	 *
528
	 * Allowed values for $style:
529
	 * "doubleCurled" => "&ldquo;foo&rdquo;",
530
	 * "doubleCurledReversed" => "&rdquo;foo&rdquo;",
531
	 * "doubleLow9" => "&bdquo;foo&rdquo;",
532
	 * "doubleLow9Reversed" => "&bdquo;foo&ldquo;",
533
	 * "singleCurled" => "&lsquo;foo&rsquo;",
534
	 * "singleCurledReversed" => "&rsquo;foo&rsquo;",
535
	 * "singleLow9" => "&sbquo;foo&rsquo;",
536
	 * "singleLow9Reversed" => "&sbquo;foo&lsquo;",
537
	 * "doubleGuillemetsFrench" => "&laquo;&nbsp;foo&nbsp;&raquo;",
538
	 * "doubleGuillemets" => "&laquo;foo&raquo;",
539
	 * "doubleGuillemetsReversed" => "&raquo;foo&laquo;",
540
	 * "singleGuillemets" => "&lsaquo;foo&rsaquo;",
541
	 * "singleGuillemetsReversed" => "&rsaquo;foo&lsaquo;",
542
	 * "cornerBrackets" => "&#x300c;foo&#x300d;",
543
	 * "whiteCornerBracket" => "&#x300e;foo&#x300f;"
544
	 *
545
	 * @param  Quotes|string $style Optional. A Quotes instance or a quote style constant. Defaults to 'singleCurled'.
546
	 *
547
	 * @throws \DomainException Thrown if $style constant is invalid.
548
	 */
549 3
	public function set_smart_quotes_secondary( $style = Quote_Style::SINGLE_CURLED ) {
550 3
		$this->secondary_quote_style = $this->get_quote_style( $style );
551 2
	}
552
553
	/**
554
	 * Retrieves a Quotes instance from a given style.
555
	 *
556
	 * @param  Quotes|string $style A Quotes instance or a quote style constant.
557
	 *
558
	 * @throws \DomainException Thrown if $style constant is invalid.
559
	 *
560
	 * @return Quotes
561
	 */
562 6
	protected function get_quote_style( $style ) {
563 6
		return $this->get_style( $style, Quotes::class, [ Quote_Style::class, 'get_styled_quotes' ], 'quote' );
564
	}
565
566
	/**
567
	 * Sets the list of exceptional words for smart quotes replacement. Mainly,
568
	 * this is used for contractions beginning with an apostrophe.
569
	 *
570
	 * @param string[] $exceptions Optional. An array of replacements indexed by the ”non-smart" form.
571
	 *                             Default a list of English words beginning with an apostrophy.
572
	 */
573 1
	public function set_smart_quotes_exceptions( $exceptions = [
574
		"'tain't"   => U::APOSTROPHE . 'tain' . U::APOSTROPHE . 't',
575
		"'twere"    => U::APOSTROPHE . 'twere',
576
		"'twas"     => U::APOSTROPHE . 'twas',
577
		"'tis"      => U::APOSTROPHE . 'tis',
578
		"'til"      => U::APOSTROPHE . 'til',
579
		"'bout"     => U::APOSTROPHE . 'bout',
580
		"'nuff"     => U::APOSTROPHE . 'nuff',
581
		"'round"    => U::APOSTROPHE . 'round',
582
		"'cause"    => U::APOSTROPHE . 'cause',
583
		"'splainin" => U::APOSTROPHE . 'splainin',
584
		"'em'"      => U::APOSTROPHE . 'em',
585
	] ) {
586 1
		$this->data['smartQuotesExceptions'] = [
587 1
			'patterns'     => \array_keys( $exceptions ),
588 1
			'replacements' => \array_values( $exceptions ),
589
		];
590 1
	}
591
592
	/**
593
	 * Retrieves an object from a given style.
594
	 *
595
	 * @param  object|string $style          A style object instance or a style constant.
596
	 * @param  string        $expected_class A class name.
597
	 * @param  callable      $get_style      A function that returns a style object from a given style constant.
598
	 * @param  string        $description    Style description for the exception message.
599
	 *
600
	 * @throws \DomainException Thrown if $style constant is invalid.
601
	 *
602
	 * @return object An instance of $expected_class.
603
	 */
604 9
	protected function get_style( $style, $expected_class, callable $get_style, $description ) {
605 9
		if ( $style instanceof $expected_class ) {
606 3
			$object = $style;
607
		} else {
608 6
			$object = $get_style( $style, $this );
609
		}
610
611 9
		if ( ! \is_object( $object ) || ! $object instanceof $expected_class ) {
612 3
			throw new \DomainException( "Invalid $description style $style." );
613
		}
614
615 6
		return $object;
616
	}
617
618
	/**
619
	 * Enables/disables replacement of "a--a" with En Dash " -- " and "---" with Em Dash.
620
	 *
621
	 * @param bool $on Optional. Default true.
622
	 */
623 1
	public function set_smart_dashes( $on = true ) {
624 1
		$this->data['smartDashes'] = $on;
625 1
	}
626
627
	/**
628
	 * Sets the typographical conventions used by smart_dashes.
629
	 *
630
	 * Allowed values for $style:
631
	 * - "traditionalUS"
632
	 * - "international"
633
	 *
634
	 * @param string|Settings\Dashes $style Optional. Default Dash_Style::TRADITIONAL_US.
635
	 *
636
	 * @throws \DomainException Thrown if $style constant is invalid.
637
	 */
638 3
	public function set_smart_dashes_style( $style = Dash_Style::TRADITIONAL_US ) {
639 3
		$this->dash_style = $this->get_style( $style, Settings\Dashes::class, [ Dash_Style::class, 'get_styled_dashes' ], 'dash' );
640 2
	}
641
642
	/**
643
	 * Enables/disables replacement of "..." with "…".
644
	 *
645
	 * @param bool $on Optional. Default true.
646
	 */
647 1
	public function set_smart_ellipses( $on = true ) {
648 1
		$this->data['smartEllipses'] = $on;
649 1
	}
650
651
	/**
652
	 * Enables/disables replacement "creme brulee" with "crème brûlée".
653
	 *
654
	 * @param bool $on Optional. Default true.
655
	 */
656 1
	public function set_smart_diacritics( $on = true ) {
657 1
		$this->data['smartDiacritics'] = $on;
658 1
	}
659
660
	/**
661
	 * Sets the language used for diacritics replacements.
662
	 *
663
	 * @param string $lang Has to correspond to a filename in 'diacritics'. Optional. Default 'en-US'.
664
	 */
665 1
	public function set_diacritic_language( $lang = 'en-US' ) {
666 1
		if ( isset( $this->data['diacriticLanguage'] ) && $this->data['diacriticLanguage'] === $lang ) {
667 1
			return;
668
		}
669
670 1
		$this->data['diacriticLanguage'] = $lang;
671 1
		$language_file_name              = \dirname( __FILE__ ) . '/diacritics/' . $lang . '.json';
672
673 1
		if ( \file_exists( $language_file_name ) ) {
674 1
			$diacritics_file              = \json_decode( \file_get_contents( $language_file_name ), true );
675 1
			$this->data['diacriticWords'] = $diacritics_file['diacritic_words'];
676
		} else {
677 1
			unset( $this->data['diacriticWords'] );
678
		}
679
680 1
		$this->update_diacritics_replacement_arrays();
681 1
	}
682
683
	/**
684
	 * Sets up custom diacritics replacements.
685
	 *
686
	 * @param string|array $custom_replacements An array formatted [needle=>replacement, needle=>replacement...],
687
	 *                                          or a string formatted `"needle"=>"replacement","needle"=>"replacement",...
688
	 */
689 5
	public function set_diacritic_custom_replacements( $custom_replacements = [] ) {
690 5
		if ( ! \is_array( $custom_replacements ) ) {
691 2
			$custom_replacements = $this->parse_diacritics_replacement_string( $custom_replacements );
692
		}
693
694 5
		$this->data['diacriticCustomReplacements'] = self::array_map_assoc(
695
			function( $key, $replacement ) {
696 5
				$key         = \strip_tags( \trim( $key ) );
697 5
				$replacement = \strip_tags( \trim( $replacement ) );
698
699 5
				if ( ! empty( $key ) && ! empty( $replacement ) ) {
700 3
					return [ $key => $replacement ];
701
				} else {
702 2
					return [];
703
				}
704 5
			},
705
			$custom_replacements
706
		);
707
708 5
		$this->update_diacritics_replacement_arrays();
709 5
	}
710
711
	/**
712
	 * Parses a custom diacritics replacement string into an array.
713
	 *
714
	 * @param string $custom_replacements A string formatted `"needle"=>"replacement","needle"=>"replacement",...
715
	 *
716
	 * @return array
717
	 */
718 2
	private function parse_diacritics_replacement_string( $custom_replacements ) {
719 2
		return self::array_map_assoc(
720
			function( $key, $replacement ) {
721
				// Account for single and double quotes in keys in and values, discard everything else.
722 2
				if ( \preg_match( '/(?<kquo>"|\')(?<key>(?:(?!\k<kquo>).)+)\k<kquo>\s*=>\s*(?<rquo>"|\')(?<replacement>(?:(?!\k<rquo>).)+)\k<rquo>/', $replacement, $match ) ) {
723 2
					$key         = $match['key'];
724 2
					$replacement = $match['replacement'];
725
726 2
					return [ $key => $replacement ];
727
				}
728
729
				return [];
730 2
			},
731
			/** RE correct. @scrutinizer ignore-type */
732 2
			\preg_split( '/,/', $custom_replacements, -1, PREG_SPLIT_NO_EMPTY )
733
		);
734
	}
735
736
	/**
737
	 * Provides an array_map implementation with control over resulting array's keys.
738
	 *
739
	 * Based on https://gist.github.com/jasand-pereza/84ecec7907f003564584.
740
	 *
741
	 * @since 6.0.0
742
	 *
743
	 * @param  callable $callback A callback function that needs to return [ $key => $value ] pairs.
744
	 * @param  array    $array    The array.
745
	 *
746
	 * @return array
747
	 */
748 2
	protected static function array_map_assoc( callable $callback, array $array ) {
749 2
		$new = [];
750
751 2
		foreach ( $array as $k => $v ) {
752 2
			$u = $callback( $k, $v );
753
754 2
			if ( ! empty( $u ) ) {
755 1
				$new[ \key( $u ) ] = \current( $u );
756
			}
757
		}
758
759 2
		return $new;
760
	}
761
762
	/**
763
	 * Update the pattern and replacement arrays in $settings['diacriticReplacement'].
764
	 *
765
	 * Should be called whenever a new diacritics replacement language is selected or
766
	 * when the custom replacements are updated.
767
	 */
768 6
	private function update_diacritics_replacement_arrays() {
769 6
		$patterns     = [];
770 6
		$replacements = [];
771
772 6
		if ( ! empty( $this->data['diacriticCustomReplacements'] ) ) {
773 3
			$this->parse_diacritics_rules( $this->data['diacriticCustomReplacements'], $patterns, $replacements );
774
		}
775 6
		if ( ! empty( $this->data['diacriticWords'] ) ) {
776 1
			$this->parse_diacritics_rules( $this->data['diacriticWords'], $patterns, $replacements );
777
		}
778
779 6
		$this->data['diacriticReplacement'] = [
780 6
			'patterns'     => $patterns,
781 6
			'replacements' => $replacements,
782
		];
783 6
	}
784
785
	/**
786
	 * Parse an array of diacritics rules.
787
	 *
788
	 * @param array $diacritics_rules The rules ( $word => $replacement ).
789
	 * @param array $patterns         Resulting patterns. Passed by reference.
790
	 * @param array $replacements     Resulting replacements. Passed by reference.
791
	 */
792 4
	private function parse_diacritics_rules( array $diacritics_rules, array &$patterns, array &$replacements ) {
793
794 4
		foreach ( $diacritics_rules as $needle => $replacement ) {
795 4
			$patterns[]              = '/\b(?<!\w[' . U::NO_BREAK_SPACE . U::SOFT_HYPHEN . '])' . $needle . '\b(?![' . U::NO_BREAK_SPACE . U::SOFT_HYPHEN . ']\w)/u';
796 4
			$replacements[ $needle ] = $replacement;
797
		}
798 4
	}
799
800
	/**
801
	 * Enables/disables replacement of (r) (c) (tm) (sm) (p) (R) (C) (TM) (SM) (P) with ® © ™ ℠ ℗.
802
	 *
803
	 * @param bool $on Optional. Default true.
804
	 */
805 1
	public function set_smart_marks( $on = true ) {
806 1
		$this->data['smartMarks'] = $on;
807 1
	}
808
809
	/**
810
	 * Enables/disables proper mathematical symbols.
811
	 *
812
	 * @param bool $on Optional. Default true.
813
	 */
814 1
	public function set_smart_math( $on = true ) {
815 1
		$this->data['smartMath'] = $on;
816 1
	}
817
818
	/**
819
	 * Enables/disables replacement of 2^2 with 2<sup>2</sup>
820
	 *
821
	 * @param bool $on Optional. Default true.
822
	 */
823 1
	public function set_smart_exponents( $on = true ) {
824 1
		$this->data['smartExponents'] = $on;
825 1
	}
826
827
	/**
828
	 * Enables/disables replacement of 1/4 with <sup>1</sup>&#8260;<sub>4</sub>.
829
	 *
830
	 * @param bool $on Optional. Default true.
831
	 */
832 1
	public function set_smart_fractions( $on = true ) {
833 1
		$this->data['smartFractions'] = $on;
834 1
	}
835
836
	/**
837
	 * Enables/disables replacement of 1st with 1<sup>st</sup>.
838
	 *
839
	 * @param bool $on Optional. Default true.
840
	 */
841 1
	public function set_smart_ordinal_suffix( $on = true ) {
842 1
		$this->data['smartOrdinalSuffix'] = $on;
843 1
	}
844
845
	/**
846
	 * Enables/disables replacement of XXe with XX<sup>e</sup>.
847
	 *
848
	 * @since 6.5.0
849
	 *
850
	 * @param bool $on Optional. Default false.
851
	 */
852 1
	public function set_smart_ordinal_suffix_match_roman_numerals( $on = false ) {
853 1
		$this->data['smartOrdinalSuffixRomanNumerals'] = $on;
854 1
	}
855
856
	/**
857
	 * Enables/disables replacement of m2 with m³ and m3 with m³.
858
	 *
859
	 * @param bool $on Optional. Default true.
860
	 */
861 1
	public function set_smart_area_units( $on = true ) {
862 1
		$this->data['smartAreaVolumeUnits'] = $on;
863 1
	}
864
865
	/**
866
	 * Enables/disables forcing single character words to next line with the insertion of &nbsp;.
867
	 *
868
	 * @param bool $on Optional. Default true.
869
	 */
870 1
	public function set_single_character_word_spacing( $on = true ) {
871 1
		$this->data['singleCharacterWordSpacing'] = $on;
872 1
	}
873
874
	/**
875
	 * Enables/disables fraction spacing.
876
	 *
877
	 * @param bool $on Optional. Default true.
878
	 */
879 1
	public function set_fraction_spacing( $on = true ) {
880 1
		$this->data['fractionSpacing'] = $on;
881 1
	}
882
883
	/**
884
	 * Enables/disables keeping units and values together with the insertion of &nbsp;.
885
	 *
886
	 * @param bool $on Optional. Default true.
887
	 */
888 1
	public function set_unit_spacing( $on = true ) {
889 1
		$this->data['unitSpacing'] = $on;
890 1
	}
891
892
	/**
893
	 * Enables/disables numbered abbreviations like "ISO 9000" together with the insertion of &nbsp;.
894
	 *
895
	 * @param bool $on Optional. Default true.
896
	 */
897 1
	public function set_numbered_abbreviation_spacing( $on = true ) {
898 1
		$this->data['numberedAbbreviationSpacing'] = $on;
899 1
	}
900
901
	/**
902
	 * Enables/disables extra whitespace before certain punction marks, as is the French custom.
903
	 *
904
	 * @since 6.0.0 The default value is now `false`.`
905
	 *
906
	 * @param bool $on Optional. Default false.
907
	 */
908 1
	public function set_french_punctuation_spacing( $on = false ) {
909 1
		$this->data['frenchPunctuationSpacing'] = $on;
910 1
	}
911
912
	/**
913
	 * Sets the list of units to keep together with their values.
914
	 *
915
	 * @param string|array $units A comma separated list or an array of units.
916
	 */
917 1
	public function set_units( $units = [] ) {
918 1
		$this->data['units'] = Strings::maybe_split_parameters( $units );
919 1
		$this->custom_units  = $this->update_unit_pattern( $this->data['units'] );
920 1
	}
921
922
	/**
923
	 * Update pattern for matching custom units.
924
	 *
925
	 * @since 6.4.0 Visibility changed to protected, return value added.
926
	 *
927
	 * @param array $units An array of unit names.
928
	 *
929
	 * @return string
930
	 */
931 2
	protected function update_unit_pattern( array $units ) {
932
		// Update unit regex pattern.
933 2
		foreach ( $units as $index => $unit ) {
934 2
			$units[ $index ] = \preg_quote( $unit, '/' );
935
		}
936
937 2
		$custom_units  = \implode( '|', $units );
938 2
		$custom_units .= ! empty( $custom_units ) ? '|' : '';
939
940 2
		return $custom_units;
941
	}
942
943
	/**
944
	 * Enables/disables wrapping of Em and En dashes are in thin spaces.
945
	 *
946
	 * @param bool $on Optional. Default true.
947
	 */
948 1
	public function set_dash_spacing( $on = true ) {
949 1
		$this->data['dashSpacing'] = $on;
950 1
	}
951
952
	/**
953
	 * Enables/disables removal of extra whitespace characters.
954
	 *
955
	 * @param bool $on Optional. Default true.
956
	 */
957 1
	public function set_space_collapse( $on = true ) {
958 1
		$this->data['spaceCollapse'] = $on;
959 1
	}
960
961
	/**
962
	 * Enables/disables widow handling.
963
	 *
964
	 * @param bool $on Optional. Default true.
965
	 */
966 1
	public function set_dewidow( $on = true ) {
967 1
		$this->data['dewidow'] = $on;
968 1
	}
969
970
	/**
971
	 * Sets the maximum length of widows that will be protected.
972
	 *
973
	 * @param int $length Defaults to 5. Trying to set the value to less than 2 resets the length to the default.
974
	 */
975 1
	public function set_max_dewidow_length( $length = 5 ) {
976 1
		$length = ( $length > 1 ) ? $length : 5;
977
978 1
		$this->data['dewidowMaxLength'] = $length;
979 1
	}
980
981
	/**
982
	 * Sets the maximum number of words considered for dewidowing.
983
	 *
984
	 * @param int $number Defaults to 1. Only 1, 2 and 3 are valid.
985
	 */
986 1
	public function set_dewidow_word_number( $number = 1 ) {
987 1
		$number = ( $number > 3 || $number < 1 ) ? 1 : $number;
988
989 1
		$this->data['dewidowWordNumber'] = $number;
990 1
	}
991
992
	/**
993
	 * Sets the maximum length of pulled text to keep widows company.
994
	 *
995
	 * @param int $length Defaults to 5. Trying to set the value to less than 2 resets the length to the default.
996
	 */
997 1
	public function set_max_dewidow_pull( $length = 5 ) {
998 1
		$length = ( $length > 1 ) ? $length : 5;
999
1000 1
		$this->data['dewidowMaxPull'] = $length;
1001 1
	}
1002
1003
	/**
1004
	 * Enables/disables wrapping at internal hard hyphens with the insertion of a zero-width-space.
1005
	 *
1006
	 * @param bool $on Optional. Default true.
1007
	 */
1008 1
	public function set_wrap_hard_hyphens( $on = true ) {
1009 1
		$this->data['hyphenHardWrap'] = $on;
1010 1
	}
1011
1012
	/**
1013
	 * Enables/disables wrapping of urls.
1014
	 *
1015
	 * @param bool $on Optional. Default true.
1016
	 */
1017 1
	public function set_url_wrap( $on = true ) {
1018 1
		$this->data['urlWrap'] = $on;
1019 1
	}
1020
1021
	/**
1022
	 * Enables/disables wrapping of email addresses.
1023
	 *
1024
	 * @param bool $on Optional. Default true.
1025
	 */
1026 1
	public function set_email_wrap( $on = true ) {
1027 1
		$this->data['emailWrap'] = $on;
1028 1
	}
1029
1030
	/**
1031
	 * Sets the minimum character requirement after an URL wrapping point.
1032
	 *
1033
	 * @param int $length Defaults to 5. Trying to set the value to less than 1 resets the length to the default.
1034
	 */
1035 1
	public function set_min_after_url_wrap( $length = 5 ) {
1036 1
		$length = ( $length > 0 ) ? $length : 5;
1037
1038 1
		$this->data['urlMinAfterWrap'] = $length;
1039 1
	}
1040
1041
	/**
1042
	 * Enables/disables wrapping of ampersands in <span class="amp">.
1043
	 *
1044
	 * @param bool $on Optional. Default true.
1045
	 */
1046 1
	public function set_style_ampersands( $on = true ) {
1047 1
		$this->data['styleAmpersands'] = $on;
1048 1
	}
1049
1050
	/**
1051
	 * Enables/disables wrapping caps in <span class="caps">.
1052
	 *
1053
	 * @param bool $on Optional. Default true.
1054
	 */
1055 1
	public function set_style_caps( $on = true ) {
1056 1
		$this->data['styleCaps'] = $on;
1057 1
	}
1058
1059
	/**
1060
	 * Enables/disables wrapping of initial quotes in <span class="quo"> or <span class="dquo">.
1061
	 *
1062
	 * @param bool $on Optional. Default true.
1063
	 */
1064 1
	public function set_style_initial_quotes( $on = true ) {
1065 1
		$this->data['styleInitialQuotes'] = $on;
1066 1
	}
1067
1068
	/**
1069
	 * Enables/disables wrapping of numbers in <span class="numbers">.
1070
	 *
1071
	 * @param bool $on Optional. Default true.
1072
	 */
1073 1
	public function set_style_numbers( $on = true ) {
1074 1
		$this->data['styleNumbers'] = $on;
1075 1
	}
1076
1077
	/**
1078
	 * Enables/disables wrapping of punctiation and wide characters in <span class="pull-*">.
1079
	 *
1080
	 * @param bool $on Optional. Default true.
1081
	 */
1082 1
	public function set_style_hanging_punctuation( $on = true ) {
1083 1
		$this->data['styleHangingPunctuation'] = $on;
1084 1
	}
1085
1086
	/**
1087
	 * Sets the list of tags where initial quotes and guillemets should be styled.
1088
	 *
1089
	 * @param string|array $tags A comma separated list or an array of tag names.
1090
	 */
1091 1
	public function set_initial_quote_tags( $tags = [ 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'li', 'dd', 'dt' ] ) {
1092
		// Make array if handed a list of tags as a string.
1093 1
		if ( ! \is_array( $tags ) ) {
1094 1
			$tags = \preg_split( '/[^a-z0-9]+/', $tags, -1, PREG_SPLIT_NO_EMPTY );
1095
		}
1096
1097
		// Store the tag array inverted (with the tagName as its index for faster lookup).
1098 1
		$this->data['initialQuoteTags'] = \array_change_key_case( \array_flip( /** Array. @scrutinizer ignore-type */ $tags ), CASE_LOWER );
1099 1
	}
1100
1101
	/**
1102
	 * Enables/disables hyphenation.
1103
	 *
1104
	 * @param bool $on Optional. Default true.
1105
	 */
1106 1
	public function set_hyphenation( $on = true ) {
1107 1
		$this->data['hyphenation'] = $on;
1108 1
	}
1109
1110
	/**
1111
	 * Sets the hyphenation pattern language.
1112
	 *
1113
	 * @param string $lang Has to correspond to a filename in 'lang'. Optional. Default 'en-US'.
1114
	 */
1115 8
	public function set_hyphenation_language( $lang = 'en-US' ) {
1116 8
		if ( isset( $this->data['hyphenLanguage'] ) && $this->data['hyphenLanguage'] === $lang ) {
1117 3
			return; // Bail out, no need to do anything.
1118
		}
1119
1120 8
		$this->data['hyphenLanguage'] = $lang;
1121 8
	}
1122
1123
	/**
1124
	 * Sets the minimum length of a word that may be hyphenated.
1125
	 *
1126
	 * @param int $length Defaults to 5. Trying to set the value to less than 2 resets the length to the default.
1127
	 */
1128 1
	public function set_min_length_hyphenation( $length = 5 ) {
1129 1
		$length = ( $length > 1 ) ? $length : 5;
1130
1131 1
		$this->data['hyphenMinLength'] = $length;
1132 1
	}
1133
1134
	/**
1135
	 * Sets the minimum character requirement before a hyphenation point.
1136
	 *
1137
	 * @param int $length Defaults to 3. Trying to set the value to less than 1 resets the length to the default.
1138
	 */
1139 1
	public function set_min_before_hyphenation( $length = 3 ) {
1140 1
		$length = ( $length > 0 ) ? $length : 3;
1141
1142 1
		$this->data['hyphenMinBefore'] = $length;
1143 1
	}
1144
1145
	/**
1146
	 * Sets the minimum character requirement after a hyphenation point.
1147
	 *
1148
	 * @param int $length Defaults to 2. Trying to set the value to less than 1 resets the length to the default.
1149
	 */
1150 1
	public function set_min_after_hyphenation( $length = 2 ) {
1151 1
		$length = ( $length > 0 ) ? $length : 2;
1152
1153 1
		$this->data['hyphenMinAfter'] = $length;
1154 1
	}
1155
1156
	/**
1157
	 * Enables/disables hyphenation of titles and headings.
1158
	 *
1159
	 * @param bool $on Optional. Default true.
1160
	 */
1161 1
	public function set_hyphenate_headings( $on = true ) {
1162 1
		$this->data['hyphenateTitle'] = $on;
1163 1
	}
1164
1165
	/**
1166
	 * Enables/disables hyphenation of words set completely in capital letters.
1167
	 *
1168
	 * @param bool $on Optional. Default true.
1169
	 */
1170 1
	public function set_hyphenate_all_caps( $on = true ) {
1171 1
		$this->data['hyphenateAllCaps'] = $on;
1172 1
	}
1173
1174
	/**
1175
	 * Enables/disables hyphenation of words starting with a capital letter.
1176
	 *
1177
	 * @param bool $on Optional. Default true.
1178
	 */
1179 1
	public function set_hyphenate_title_case( $on = true ) {
1180 1
		$this->data['hyphenateTitleCase'] = $on;
1181 1
	}
1182
1183
	/**
1184
	 * Enables/disables hyphenation of compound words (e.g. "editor-in-chief").
1185
	 *
1186
	 * @param bool $on Optional. Default true.
1187
	 */
1188 1
	public function set_hyphenate_compounds( $on = true ) {
1189 1
		$this->data['hyphenateCompounds'] = $on;
1190 1
	}
1191
1192
	/**
1193
	 * Sets custom word hyphenations.
1194
	 *
1195
	 * @param string|array $exceptions An array of words with all hyphenation points marked with a hard hyphen (or a string list of such words).
1196
	 *        In the latter case, only alphanumeric characters and hyphens are recognized. The default is empty.
1197
	 */
1198 2
	public function set_hyphenation_exceptions( $exceptions = [] ) {
1199 2
		$this->data['hyphenationCustomExceptions'] = Strings::maybe_split_parameters( $exceptions );
1200 2
	}
1201
1202
	/**
1203
	 * Retrieves a unique hash value for the current settings.
1204
	 *
1205
	 * @since 5.2.0 The new parameter $raw_output has been added.
1206
	 *
1207
	 * @param int  $max_length Optional. The maximum number of bytes returned (0 for unlimited). Default 16.
1208
	 * @param bool $raw_output Optional. Wether to return raw binary data for the hash. Default true.
1209
	 *
1210
	 * @return string A binary hash value for the current settings limited to $max_length.
1211
	 */
1212 1
	public function get_hash( $max_length = 16, $raw_output = true ) {
1213 1
		$hash = \md5( \json_encode( $this ), $raw_output );
1214
1215 1
		if ( $max_length < \strlen( $hash ) && $max_length > 0 ) {
1216 1
			$hash = \substr( $hash, 0, $max_length );
1217
		}
1218
1219 1
		return $hash;
1220
	}
1221
}
1222