• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPOffice / PHPWord / 13025401639

29 Jan 2025 05:48AM UTC coverage: 96.825% (-0.4%) from 97.217%
13025401639

Pull #2562

github

web-flow
Merge ebe3e5dac into 2d2759585
Pull Request #2562: TemplateProcessor SetComplexBlock/Value and Sections

6 of 7 new or added lines in 1 file covered. (85.71%)

245 existing lines in 40 files now uncovered.

12227 of 12628 relevant lines covered (96.82%)

34.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/src/PhpWord/Shared/Css.php
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 Css
23
{
24
    /**
25
     * @var string
26
     */
27
    private $cssContent;
28

29
    /**
30
     * @var array<string, array<string, string>>
31
     */
32
    private $styles = [];
33

34
    public function __construct(string $cssContent)
35
    {
36
        $this->cssContent = $cssContent;
4✔
37
    }
38

39
    public function process(): void
40
    {
41
        $cssContent = str_replace(["\r", "\n"], '', $this->cssContent);
4✔
42
        preg_match_all('/(.+?)\s?\{\s?(.+?)\s?\}/', $cssContent, $cssExtracted);
4✔
43
        // Check if there are x selectors and x rules
44
        if (count($cssExtracted[1]) != count($cssExtracted[2])) {
4✔
UNCOV
45
            return;
×
46
        }
47

48
        foreach ($cssExtracted[1] as $key => $selector) {
4✔
49
            $rules = trim($cssExtracted[2][$key]);
3✔
50
            $rules = explode(';', $rules);
3✔
51
            foreach ($rules as $rule) {
3✔
52
                if (empty($rule)) {
3✔
53
                    continue;
3✔
54
                }
55
                [$key, $value] = explode(':', trim($rule));
3✔
56
                $this->styles[$this->sanitize($selector)][$this->sanitize($key)] = $this->sanitize($value);
3✔
57
            }
58
        }
59
    }
60

61
    public function getStyles(): array
62
    {
63
        return $this->styles;
2✔
64
    }
65

66
    public function getStyle(string $selector): array
67
    {
68
        $selector = $this->sanitize($selector);
3✔
69

70
        return $this->styles[$selector] ?? [];
3✔
71
    }
72

73
    private function sanitize(string $value): string
74
    {
75
        return addslashes(trim($value));
3✔
76
    }
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc