Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Validate | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
validateCSSWhiteSpace | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
validateCSSGenericFont | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * This file is part of PHPWord - A pure PHP library for reading and writing |
5 | * word processing documents. |
6 | * |
7 | * PHPWord is free software distributed under the terms of the GNU Lesser |
8 | * General Public License version 3 as published by the Free Software Foundation. |
9 | * |
10 | * For the full copyright and license information, please read the LICENSE |
11 | * file that was distributed with this source code. For the full list of |
12 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
13 | * |
14 | * @see https://github.com/PHPOffice/PHPWord |
15 | * |
16 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
17 | */ |
18 | declare(strict_types=1); |
19 | |
20 | namespace PhpOffice\PhpWord\Shared; |
21 | |
22 | class Validate |
23 | { |
24 | public const CSS_WHITESPACE = [ |
25 | 'pre-wrap', |
26 | 'normal', |
27 | 'nowrap', |
28 | 'pre', |
29 | 'pre-line', |
30 | 'initial', |
31 | 'inherit', |
32 | ]; |
33 | |
34 | public const CSS_GENERICFONT = [ |
35 | 'serif', |
36 | 'sans-serif', |
37 | 'monospace', |
38 | 'cursive', |
39 | 'fantasy', |
40 | 'system-ui', |
41 | 'math', |
42 | 'emoji', |
43 | 'fangsong', |
44 | ]; |
45 | |
46 | /** |
47 | * Validate html css white-space value. It is expected that only pre-wrap and normal (default) are useful. |
48 | * |
49 | * @param string $value CSS White space |
50 | * |
51 | * @return string value if valid, empty string if not |
52 | */ |
53 | public static function validateCSSWhiteSpace(?string $value): string |
54 | { |
55 | if (in_array($value, self::CSS_WHITESPACE)) { |
56 | return $value; |
57 | } |
58 | |
59 | return ''; |
60 | } |
61 | |
62 | /** |
63 | * Validate generic font for fallback for html. |
64 | * |
65 | * @param string $value Generic font name |
66 | * |
67 | * @return string Value if legitimate, empty string if not |
68 | */ |
69 | public static function validateCSSGenericFont(?string $value): string |
70 | { |
71 | if (in_array($value, self::CSS_GENERICFONT)) { |
72 | return $value; |
73 | } |
74 | |
75 | return ''; |
76 | } |
77 | } |