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

voku / simple_html_dom / 25623212060

10 May 2026 07:44AM UTC coverage: 96.766% (-0.03%) from 96.791%
25623212060

Pull #145

github

web-flow
Merge 477330a45 into 7d12f7c70
Pull Request #145: Add Infection + PHPStan CI check on PHP 8.3 and fix PHP 7.x template serialization

8 of 39 new or added lines in 1 file covered. (20.51%)

3 existing lines in 2 files now uncovered.

2184 of 2257 relevant lines covered (96.77%)

301.85 hits per line

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

96.43
/src/voku/helper/HtmlDomHelper.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace voku\helper;
6

7
final class HtmlDomHelper
8
{
9
    /**
10
     * @param string $html
11
     * @param string $optionStr
12
     * @param string $htmlCssSelector
13
     *
14
     * @return string
15
     */
16
    public static function mergeHtmlAttributes(
17
        string $html,
18
        string $optionStr,
19
        string $htmlCssSelector
20
    ): string {
21
        if (!$optionStr) {
28✔
22
            return $html;
14✔
23
        }
24

25
        $dom = \voku\helper\HtmlDomParser::str_get_html($html);
28✔
26
        $domNew = \voku\helper\HtmlDomParser::str_get_html('<textarea ' . $optionStr . '></textarea>');
28✔
27

28
        $domElement = $dom->findOneOrFalse($htmlCssSelector);
28✔
29
        if ($domElement === false) {
28✔
30
            return $html;
14✔
31
        }
32
        $attributes = $domElement->getAllAttributes();
21✔
33
        if (!$attributes) {
21✔
34
            return $html;
7✔
35
        }
36

37
        $domElementNew = $domNew->findOneOrFalse('textarea');
21✔
38
        if ($domElementNew === false) {
21✔
39
            return $html;
×
40
        }
41
        $attributesNew = $domElementNew->getAllAttributes();
21✔
42
        if (!$attributesNew) {
21✔
43
            return $html;
7✔
44
        }
45

46
        foreach ($attributesNew as $attributeNameNew => $attributeValueNew) {
14✔
47
            $attributeNameNew = \strtolower($attributeNameNew);
14✔
48

49
            if (
50
                $attributeNameNew === 'class'
14✔
51
                ||
52
                $attributeNameNew === 'style'
14✔
53
                ||
54
                \strpos($attributeNameNew, 'on') === 0 // e.g. onClick, ...
14✔
55
            ) {
56
                if (isset($attributes[$attributeNameNew])) {
14✔
57
                    $attributes[$attributeNameNew] .= ' ' . $attributeValueNew;
14✔
58
                } else {
UNCOV
59
                    $attributes[$attributeNameNew] = $attributeValueNew;
8✔
60
                }
61
            } else {
62
                $attributes[$attributeNameNew] = $attributeValueNew;
14✔
63
            }
64
        }
65

66
        foreach ($attributes as $attributeName => $attributeValue) {
14✔
67
            $domElement->setAttribute($attributeName, $attributeValue, true);
14✔
68
        }
69

70
        return $domElement->html();
14✔
71
    }
72
}
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