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

nette / latte / 15081934954

17 May 2025 05:07AM UTC coverage: 93.691% (+0.05%) from 93.641%
15081934954

push

github

web-flow
Support property hooks in template params (#395)

4 of 12 new or added lines in 1 file covered. (33.33%)

36 existing lines in 4 files now uncovered.

5138 of 5484 relevant lines covered (93.69%)

0.94 hits per line

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

77.5
/src/Latte/Helpers.php
1
<?php
2

3
/**
4
 * This file is part of the Latte (https://latte.nette.org)
5
 * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Latte;
11

12

13
/**
14
 * Latte helpers.
15
 * @internal
16
 */
17
class Helpers
18
{
19
        /** @var array<string, int>  empty (void) HTML elements */
20
        public static array $emptyElements = [
21
                'img' => 1, 'hr' => 1, 'br' => 1, 'input' => 1, 'meta' => 1, 'area' => 1, 'embed' => 1, 'keygen' => 1, 'source' => 1, 'base' => 1,
22
                'col' => 1, 'link' => 1, 'param' => 1, 'basefont' => 1, 'frame' => 1, 'isindex' => 1, 'wbr' => 1, 'command' => 1, 'track' => 1,
23
        ];
24

25
        /** @var array<string, int>  boolean HTML attributes */
26
        public static array $booleanAttributes = [
27
                'allowfullscreen' => 1, 'async' => 1, 'autofocus' => 1, 'autoplay' => 1, 'checked' => 1, 'controls' => 1, 'default' => 1, 'defer' => 1,
28
                'disabled' => 1, 'formnovalidate' => 1, 'inert' => 1, 'ismap' => 1, 'itemscope' => 1, 'loop' => 1, 'multiple' => 1, 'muted' => 1,
29
                'nomodule' => 1, 'novalidate' => 1, 'open' => 1, 'playsinline' => 1, 'readonly' => 1, 'required' => 1, 'reversed' => 1, 'selected' => 1,
30
                'shadowrootclonable' => 1, 'shadowrootdelegatesfocus' => 1, 'shadowrootserializable' => 1,
31
        ];
32

33

34
        /**
35
         * Finds the best suggestion.
36
         * @param  string[]  $items
37
         */
38
        public static function getSuggestion(array $items, string $value): ?string
1✔
39
        {
40
                $best = null;
1✔
41
                $min = (strlen($value) / 4 + 1) * 10 + .1;
1✔
42
                foreach (array_unique($items) as $item) {
1✔
43
                        if (($len = levenshtein($item, $value, 10, 11, 10)) > 0 && $len < $min) {
1✔
44
                                $min = $len;
1✔
45
                                $best = $item;
1✔
46
                        }
47
                }
48

49
                return $best;
1✔
50
        }
51

52

53
        /** intentionally without callable typehint, because it generates bad error messages */
54
        public static function toReflection($callable): \ReflectionFunctionAbstract
55
        {
56
                if (is_string($callable) && strpos($callable, '::')) {
1✔
57
                        return PHP_VERSION_ID < 80300
1✔
UNCOV
58
                                ? new \ReflectionMethod($callable)
×
59
                                : \ReflectionMethod::createFromMethodName($callable);
1✔
60
                } elseif (is_array($callable)) {
1✔
61
                        return new \ReflectionMethod($callable[0], $callable[1]);
1✔
62
                } elseif (is_object($callable) && !$callable instanceof \Closure) {
1✔
63
                        return new \ReflectionMethod($callable, '__invoke');
1✔
64
                } else {
65
                        return new \ReflectionFunction($callable);
1✔
66
                }
67
        }
68

69

70
        public static function sortBeforeAfter(array $list): array
1✔
71
        {
72
                foreach ($list as $name => $info) {
1✔
73
                        if (!$info instanceof \stdClass || !($info->before ?? $info->after ?? null)) {
1✔
74
                                continue;
1✔
75
                        }
76

77
                        unset($list[$name]);
1✔
78
                        $names = array_keys($list);
1✔
79
                        $best = null;
1✔
80

81
                        foreach ((array) $info->before as $target) {
1✔
82
                                if ($target === '*') {
1✔
83
                                        $best = 0;
1✔
84
                                } elseif (isset($list[$target])) {
×
85
                                        $pos = array_search($target, $names, true);
×
86
                                        $best = min($pos, $best ?? $pos);
×
87
                                }
88
                        }
89

90
                        foreach ((array) ($info->after ?? null) as $target) {
1✔
UNCOV
91
                                if ($target === '*') {
×
UNCOV
92
                                        $best = count($names);
×
UNCOV
93
                                } elseif (isset($list[$target])) {
×
UNCOV
94
                                        $pos = array_search($target, $names, true);
×
UNCOV
95
                                        $best = max($pos + 1, $best);
×
96
                                }
97
                        }
98

99
                        $list = array_slice($list, 0, $best, true)
1✔
100
                                + [$name => $info]
1✔
101
                                + array_slice($list, $best, null, true);
1✔
102
                }
103

104
                return $list;
1✔
105
        }
106
}
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