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