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

mimmi20 / navigation-helper-htmlify / 14166459531

31 Mar 2025 07:36AM UTC coverage: 100.0%. First build
14166459531

Pull #253

github

web-flow
composer(deps-dev): update symfony/process requirement

Updates the requirements on [symfony/process](https://github.com/symfony/process) to permit the latest version.
- [Release notes](https://github.com/symfony/process/releases)
- [Changelog](https://github.com/symfony/process/blob/7.2/CHANGELOG.md)
- [Commits](https://github.com/symfony/process/compare/v7.2.4...v7.2.5)

---
updated-dependencies:
- dependency-name: symfony/process
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #253: composer(deps-dev): update symfony/process requirement from ^7.2.4 to ^7.2.5

72 of 72 relevant lines covered (100.0%)

7.96 hits per line

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

100.0
/src/Htmlify.php
1
<?php
2

3
/**
4
 * This file is part of the mimmi20/navigation-helper-htmlify package.
5
 *
6
 * Copyright (c) 2021-2025, Thomas Mueller <mimmi20@live.de>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types = 1);
13

14
namespace Mimmi20\NavigationHelper\Htmlify;
15

16
use Laminas\I18n\Exception\RuntimeException;
17
use Laminas\I18n\View\Helper\Translate;
18
use Laminas\Navigation\Page\AbstractPage;
19
use Laminas\View\Exception\InvalidArgumentException;
20
use Laminas\View\Helper\EscapeHtml;
21
use Mimmi20\LaminasView\Helper\HtmlElement\Helper\HtmlElementInterface;
22
use Mimmi20\Mezzio\Navigation\Page\PageInterface;
23
use Override;
24

25
use function array_diff_key;
26
use function array_filter;
27
use function array_flip;
28
use function array_key_exists;
29
use function array_merge;
30
use function assert;
31
use function is_string;
32
use function mb_strrpos;
33
use function mb_strtolower;
34
use function mb_substr;
35
use function trim;
36

37
final readonly class Htmlify implements HtmlifyInterface
38
{
39
    /** @throws void */
40
    public function __construct(
18✔
41
        private EscapeHtml $escaper,
42
        private HtmlElementInterface $htmlElement,
43
        private Translate | null $translator = null,
44
    ) {
45
        // nothing to do
46
    }
18✔
47

48
    /**
49
     * Returns an HTML string for the given page
50
     *
51
     * @param string                     $prefix             prefix to normalize the id attribute
52
     * @param AbstractPage|PageInterface $page               page to generate HTML for
53
     * @param bool                       $escapeLabel        Whether to escape the label
54
     * @param bool                       $addClassToListItem Whether to add the page class to the list item
55
     * @param array<string, string>      $attributes
56
     * @param bool                       $convertToButton    Whether to convert a link to a button
57
     *
58
     * @return string HTML string
59
     *
60
     * @throws InvalidArgumentException
61
     * @throws RuntimeException
62
     */
63
    #[Override]
16✔
64
    public function toHtml(
65
        string $prefix,
66
        AbstractPage | PageInterface $page,
67
        bool $escapeLabel = true,
68
        bool $addClassToListItem = false,
69
        array $attributes = [],
70
        bool $convertToButton = false,
71
    ): string {
72
        $label = (string) $page->getLabel();
16✔
73
        $title = $page->getTitle();
16✔
74

75
        if ($this->translator !== null) {
16✔
76
            $textDomain = $page->getTextDomain();
6✔
77
            assert($textDomain === null || is_string($textDomain));
6✔
78

79
            if (!empty($label)) {
6✔
80
                $label = ($this->translator)($label, $textDomain);
5✔
81
            }
82

83
            if (!empty($title)) {
6✔
84
                $title = ($this->translator)($title, $textDomain);
5✔
85
            }
86
        }
87

88
        // get attribs for element
89

90
        $attributes['id']    = $page->getId();
16✔
91
        $attributes['title'] = $title;
16✔
92

93
        if (!$addClassToListItem) {
16✔
94
            $attributes['class'] = $page->getClass();
14✔
95
        }
96

97
        if ($convertToButton) {
16✔
98
            $element = 'button';
1✔
99
        } elseif ($page->getHref() !== '') {
15✔
100
            $element              = 'a';
10✔
101
            $attributes['href']   = $page->getHref();
10✔
102
            $attributes['target'] = $page->getTarget();
10✔
103
        } else {
104
            $element = 'span';
5✔
105
        }
106

107
        // remove sitemap specific attributes
108
        $attributes = array_diff_key(
16✔
109
            array_merge($attributes, $page->getCustomProperties()),
16✔
110
            array_flip(['lastmod', 'changefreq', 'priority']),
16✔
111
        );
16✔
112

113
        if (!empty($label) && $escapeLabel) {
16✔
114
            $label = ($this->escaper)($label);
7✔
115

116
            assert(is_string($label));
7✔
117
        }
118

119
        if (array_key_exists('id', $attributes) && is_string($attributes['id'])) {
16✔
120
            $attributes['id'] = $this->normalizeId($prefix, $attributes['id']);
15✔
121
        }
122

123
        $attributes = array_filter(
16✔
124
            $attributes,
16✔
125
            static fn (mixed $value): bool => $value !== null && $value !== '',
16✔
126
        );
16✔
127

128
        return $this->htmlElement->toHtml($element, $attributes, $label);
16✔
129
    }
130

131
    /**
132
     * Normalize an ID
133
     *
134
     * @throws void
135
     */
136
    private function normalizeId(string $prefix, string $value): string
15✔
137
    {
138
        $prefix = mb_strtolower(trim(mb_substr($prefix, (int) mb_strrpos($prefix, '\\')), '\\'));
15✔
139

140
        return $prefix . '-' . $value;
15✔
141
    }
142
}
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