Settings   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 514
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 137
c 4
b 0
f 0
dl 0
loc 514
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B rules() 0 78 1
1
<?php
2
/**
3
 * Typogrify plugin for Craft CMS
4
 *
5
 * Typogrify prettifies your web typography by preventing ugly quotes and 'widows' and more
6
 *
7
 * @link      https://nystudio107.com/
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\typogrify\models;
12
13
use craft\base\Model;
14
use craft\validators\ArrayValidator;
15
use PHP_Typography\Settings\Dash_Style;
16
use PHP_Typography\Settings\Quote_Style;
17
18
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
19
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
20
 * @package   Typogrify
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
21
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
22
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
23
class Settings extends Model
24
{
25
    // Public Properties
26
    // =========================================================================
27
28
    /**
29
     * sets whether input should be escaped by default
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
30
     *
31
     * @var bool
32
     */
33
    public bool $default_escape = false;
34
35
    /**
36
     * sets tags where typography of children will be untouched
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
37
     *
38
     * @var array
39
     */
40
    public array $set_tags_to_ignore = [
41
        "code",
42
        "head",
43
        "kbd",
44
        "object",
45
        "option",
46
        "pre",
47
        "samp",
48
        "script",
49
        "noscript",
50
        "noembed",
51
        "select",
52
        "style",
53
        "textarea",
54
        "title",
55
        "var",
56
        "math",
57
    ];
58
59
    /**
60
     * sets classes where typography of children will be untouched
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
61
     *
62
     * @var array
63
     */
64
    public array $set_classes_to_ignore = [
65
        "vcard",
66
        "noTypo",
67
    ];
68
69
    /**
70
     * sets IDs where typography of children will be untouched
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
71
     *
72
     * @var array
73
     */
74
    public array $set_ids_to_ignore = [
75
    ];
76
77
    /**
78
     * curl quotemarks
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
79
     *
80
     * @var bool
81
     */
82
    public bool $set_smart_quotes = true;
83
84
    /**
85
     * Primary quotemarks style
86
     * allowed values for $style
87
     *    "doubleCurled = "&ldquo;foo&rdquo;",
88
     *    "doubleCurledReversed = "&rdquo;foo&rdquo;",
89
     *    "doubleLow9 = "&bdquo;foo&rdquo;",
90
     *    "doubleLow9Reversed = "&bdquo;foo&ldquo;",
91
     *    "singleCurled = "&lsquo;foo&rsquo;",
92
     *    "singleCurledReversed = "&rsquo;foo&rsquo;",
93
     *    "singleLow9 = "&sbquo;foo&rsquo;",
94
     *    "singleLow9Reversed = "&sbquo;foo&lsquo;",
95
     *    "doubleGuillemetsFrench = "&laquo;&nbsp;foo&nbsp;&raquo;",
96
     *    "doubleGuillemets = "&laquo;foo&raquo;",
97
     *    "doubleGuillemetsReversed = "&raquo;foo&laquo;",
98
     *    "singleGuillemets = "&lsaquo;foo&rsaquo;",
99
     *    "singleGuillemetsReversed = "&rsaquo;foo&lsaquo;",
100
     *    "cornerBrackets = "&#x300c;foo&#x300d;",
101
     *    "whiteCornerBracket = "&#x300e;foo&#x300f;",
102
     *
103
     * @var string
104
     */
105
    public string $set_smart_quotes_primary = Quote_Style::DOUBLE_CURLED;
106
107
    /**
108
     * Secondary quotemarks style
109
     * allowed values for $style
110
     *    "doubleCurled = "&ldquo;foo&rdquo;",
111
     *    "doubleCurledReversed = "&rdquo;foo&rdquo;",
112
     *    "doubleLow9 = "&bdquo;foo&rdquo;",
113
     *    "doubleLow9Reversed = "&bdquo;foo&ldquo;",
114
     *    "singleCurled = "&lsquo;foo&rsquo;",
115
     *    "singleCurledReversed = "&rsquo;foo&rsquo;",
116
     *    "singleLow9 = "&sbquo;foo&rsquo;",
117
     *    "singleLow9Reversed = "&sbquo;foo&lsquo;",
118
     *    "doubleGuillemetsFrench = "&laquo;&nbsp;foo&nbsp;&raquo;",
119
     *    "doubleGuillemets = "&laquo;foo&raquo;",
120
     *    "doubleGuillemetsReversed = "&raquo;foo&laquo;",
121
     *    "singleGuillemets = "&lsaquo;foo&rsaquo;",
122
     *    "singleGuillemetsReversed = "&rsaquo;foo&lsaquo;",
123
     *    "cornerBrackets = "&#x300c;foo&#x300d;",
124
     *    "whiteCornerBracket = "&#x300e;foo&#x300f;",
125
     *
126
     * @var string
127
     */
128
    public string $set_smart_quotes_secondary = Quote_Style::SINGLE_CURLED;
129
130
    /**
131
     * replaces "a--a" with En Dash " -- " and "---" with Em Dash
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
132
     *
133
     * @var bool
134
     */
135
    public bool $set_smart_dashes = true;
136
137
    /**
138
     * Sets the typographical conventions used by smart_dashes.
139
     *
140
     * Allowed values for $style:
141
     * - "traditionalUS"
142
     * - "international"
143
     *
144
     * @var string
145
     */
146
    public string $set_smart_dashes_style = Dash_Style::TRADITIONAL_US;
147
148
    /**
149
     * replaces "..." with "…"
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
150
     *
151
     * @var bool
152
     */
153
    public bool $set_smart_ellipses = true;
154
155
    /**
156
     * replaces "creme brulee" with "crème brûlée"
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
157
     *
158
     * @var bool
159
     */
160
    public bool $set_smart_diacritics = true;
161
162
    /**
163
     * defines hyphenation language for text
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
164
     *
165
     * @var string
166
     */
167
    public string $set_diacritic_language = "en-US";
168
169
    /**
170
     * $customReplacements must be
171
     *    an array formatted array(needle=>replacement, needle=>replacement...), or
172
     *    a string formatted `"needle"=>"replacement","needle"=>"replacement",...`
173
     *
174
     * @var array
175
     */
176
    public array $set_diacritic_custom_replacements = [
177
    ];
178
179
    /**
180
     * replaces (r) (c) (tm) (sm) (p) (R) (C) (TM) (SM) (P) with ® © ™ ℠ ℗
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
181
     *
182
     * @var bool
183
     */
184
    public bool $set_smart_marks = true;
185
186
    /**
187
     * replaces 1*4 with 1x4, etc.
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
188
     *
189
     * @var bool
190
     */
191
    public bool $set_smart_math = true;
192
193
    /**
194
     * replaces 2^4 with 2<sup>4</sup>
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
195
     *
196
     * @var bool
197
     */
198
    public bool $set_smart_exponents = true;
199
200
    /**
201
     * replaces 1/4  with <sup>1</sup>&#8260;<sub>4</sub>
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
202
     *
203
     * @var bool
204
     */
205
    public bool $set_smart_fractions = true;
206
207
    /**
208
     * Enables/disables replacement of 1st with 1<sup>st</sup>
209
     *
210
     * @var bool
211
     */
212
    public bool $set_smart_ordinal_suffix = true;
213
214
    /**
215
     * single character words are forced to next line with insertion of &nbsp;
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
216
     *
217
     * @var bool
218
     */
219
    public bool $set_single_character_word_spacing = true;
220
221
    /**
222
     * fractions are kept together with insertion of &nbsp;
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
223
     *
224
     * @var bool
225
     */
226
    public bool $set_fraction_spacing = true;
227
228
    /**
229
     * units and values are kept together with insertion of &nbsp;
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
230
     *
231
     * @var bool
232
     */
233
    public bool $set_unit_spacing = true;
234
235
    /**
236
     * Enables/disables extra whitespace before certain punction marks, as is the French custom.
237
     *
238
     * @var bool
239
     */
240
    public bool $set_french_punctuation_spacing = false;
241
242
    /**
243
     * a list of units to keep with their values
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
244
     *
245
     * @var array
246
     */
247
    public array $set_units = [
248
    ];
249
250
    /**
251
     * Em and En dashes are wrapped in thin spaces
252
     *
253
     * @var bool
254
     */
255
    public bool $set_dash_spacing = true;
256
257
    /**
258
     * Remove extra space characters
259
     *
260
     * @var bool
261
     */
262
    public bool $set_space_collapse = true;
263
264
    /**
265
     * Enable usage of true "no-break narrow space" (&#8239;) instead of the normal no-break space (&nbsp;).
266
     *
267
     * @var bool
268
     */
269
    public bool $set_true_no_break_narrow_space = false;
270
271
    /**
272
     * enables widow handling
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
273
     *
274
     * @var bool
275
     */
276
    public bool $set_dewidow = true;
277
278
    /**
279
     * establishes maximum length of a widows that will be protected
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
280
     *
281
     * @var int
282
     */
283
    public int $set_max_dewidow_length = 5;
284
285
    /**
286
     * establishes the maximum number of words considered for dewidowing.
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
287
     *
288
     * @var int
289
     */
290
    public int $set_dewidow_word_number = 1;
291
292
    /**
293
     * establishes maximum length of pulled text to keep widows company
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
294
     *
295
     * @var int
296
     */
297
    public int $set_max_dewidow_pull = 5;
298
299
    /**
300
     * enables wrapping at hard hyphens internal to a word with the insertion of a zero-width-space
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
301
     *
302
     * @var bool
303
     */
304
    public bool $set_wrap_hard_hyphens = true;
305
306
    /**
307
     * enables wrapping of urls
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
308
     *
309
     * @var bool
310
     */
311
    public bool $set_url_wrap = true;
312
313
    /**
314
     * enables wrapping of email addresses
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
315
     *
316
     * @var bool
317
     */
318
    public bool $set_email_wrap = true;
319
320
    /**
321
     * establishes minimum character requirement after a url wrapping point
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
322
     *
323
     * @var int
324
     */
325
    public int $set_min_after_url_wrap = 5;
326
327
    /**
328
     * wrap ampersands in <span class="amp">
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
329
     *
330
     * @var bool
331
     */
332
    public bool $set_style_ampersands = true;
333
334
    /**
335
     * wrap caps in <span class="caps">
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
336
     *
337
     * @var bool
338
     */
339
    public bool $set_style_caps = true;
340
341
    /**
342
     * wrap initial quotes in <span class="quo"> or <span class="dquo">
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
343
     *
344
     * @var bool
345
     */
346
    public bool $set_style_initial_quotes = true;
347
348
    /**
349
     * wrap numbers in <span class="numbers">
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
350
     *
351
     * @var bool
352
     */
353
    public bool $set_style_numbers = true;
354
355
    /**
356
     * sets tags where initial quotes and guillemets should be styled
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
357
     *
358
     * @var array
359
     */
360
    public array $set_initial_quote_tags = [
361
        "p",
362
        "h1",
363
        "h2",
364
        "h3",
365
        "h4",
366
        "h5",
367
        "h6",
368
        "blockquote",
369
        "li",
370
        "dd",
371
        "dt",
372
    ];
373
374
    /**
375
     * enables hyphenation of text
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
376
     *
377
     * @var bool
378
     */
379
    public bool $set_hyphenation = true;
380
381
    /**
382
     * defines hyphenation language for text
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
383
     *
384
     * @var string
385
     */
386
    public string $set_hyphenation_language = "en-US";
387
388
    /**
389
     * establishes minimum length of a word that may be hyphenated
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
390
     *
391
     * @var int
392
     */
393
    public int $set_min_length_hyphenation = 5;
394
395
    /**
396
     * establishes minimum character requirement before a hyphenation point
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
397
     *
398
     * @var int
399
     */
400
    public int $set_min_before_hyphenation = 3;
401
402
    /**
403
     * establishes minimum character requirement after a hyphenation point
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
404
     *
405
     * @var int
406
     */
407
    public int $set_min_after_hyphenation = 2;
408
409
    /**
410
     * allows/disallows hyphenation of title/heading text
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
411
     *
412
     * @var bool
413
     */
414
    public bool $set_hyphenate_headings = true;
415
416
    /**
417
     * allows hyphenation of strings of all capital characters
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
418
     *
419
     * @var bool
420
     */
421
    public bool $set_hyphenate_all_caps = true;
422
423
    /**
424
     * allows hyphenation of strings of all capital characters
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
425
     *
426
     * @var bool
427
     */
428
    public bool $set_hyphenate_title_case = true;
429
430
    /**
431
     * defines custom word hyphenations
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
432
     * expected input is an array of words with all hyphenation points marked with a hard hyphen
433
     *
434
     * @var array
435
     */
436
    public array $set_hyphenation_exceptions = [
437
    ];
438
439
    /**
440
     * Enable lenient parser error handling (HTML is "best guess" if enabled).
441
     *
442
     * @var bool
443
     */
444
    public bool $set_ignore_parser_errors = true;
445
446
    /**
447
     * Sets an optional handler for parser errors. Invalid callbacks will be silently ignored
448
     *
449
     * @var callable|null
450
     */
451
    public $set_parser_errors_handler = null;
452
453
    // Public Methods
454
    // =========================================================================
455
456
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
457
     * @inheritdoc
458
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
459
    public function rules(): array
460
    {
461
        return [
462
            [
463
                [
464
                    'set_smart_quotes_primary',
465
                    'set_smart_quotes_secondary',
466
                    'set_smart_quotes_secondary',
467
                    'set_diacritic_language',
468
                    'set_hyphenation_language',
469
                ],
470
                'string',
471
            ],
472
            [
473
                [
474
                    'set_max_dewidow_length',
475
                    'set_dewidow_word_number',
476
                    'set_max_dewidow_pull',
477
                    'set_min_after_url_wrap',
478
                    'set_min_length_hyphenation',
479
                    'set_min_before_hyphenation',
480
                    'set_min_after_hyphenation',
481
                ],
482
                'integer',
483
            ],
484
            [
485
                [
486
                    'set_smart_quotes',
487
                    'set_smart_dashes',
488
                    'set_smart_ellipses',
489
                    'set_smart_diacritics',
490
                    'set_smart_dashes',
491
                    'set_smart_ellipses',
492
                    'set_smart_diacritics',
493
                    'set_smart_marks',
494
                    'set_smart_math',
495
                    'set_smart_exponents',
496
                    'set_smart_fractions',
497
                    'set_smart_ordinal_suffix',
498
                    'set_single_character_word_spacing',
499
                    'set_fraction_spacing',
500
                    'set_unit_spacing',
501
                    'set_dash_spacing',
502
                    'set_space_collapse',
503
                    'set_true_no_break_narrow_space',
504
                    'set_dewidow',
505
                    'set_wrap_hard_hyphens',
506
                    'set_url_wrap',
507
                    'set_email_wrap',
508
                    'set_style_ampersands',
509
                    'set_style_caps',
510
                    'set_style_initial_quotes',
511
                    'set_style_numbers',
512
                    'set_hyphenation',
513
                    'set_hyphenate_headings',
514
                    'set_hyphenate_all_caps',
515
                    'set_hyphenate_title_case',
516
                    'set_ignore_parser_errors',
517
                ],
518
                'boolean',
519
            ],
520
            [
521
                [
522
                    'set_tags_to_ignore',
523
                    'set_classes_to_ignore',
524
                    'set_ids_to_ignore',
525
                    'set_diacritic_custom_replacements',
526
                    'set_units',
527
                    'set_initial_quote_tags',
528
                    'set_hyphenation_exceptions',
529
                ],
530
                ArrayValidator::class,
531
            ],
532
            [
533
                [
534
                    'set_parser_errors_handler',
535
                ],
536
                'safe',
537
            ],
538
        ];
539
    }
540
}
541