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

nette / latte / 22368407632

24 Feb 2026 08:17PM UTC coverage: 94.825% (-0.2%) from 95.054%
22368407632

push

github

dg
phpstan

135 of 147 new or added lines in 38 files covered. (91.84%)

186 existing lines in 70 files now uncovered.

5534 of 5836 relevant lines covered (94.83%)

0.95 hits per line

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

94.44
/src/Latte/Runtime/FunctionExecutor.php
1
<?php declare(strict_types=1);
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
namespace Latte\Runtime;
9

10
use Latte\Helpers;
11
use function array_keys;
12

13

14
/**
15
 * Functions executor.
16
 * @internal
17
 */
18
#[\AllowDynamicProperties]
19
class FunctionExecutor
20
{
21
        /** @var array<string, callable> */
22
        private array $_list = [];
23

24
        /** @var array<string, bool> */
25
        private array $_aware = [];
26

27

28
        /**
29
         * Registers run-time function.
30
         */
31
        public function add(string $name, callable $callback): static
1✔
32
        {
33
                $this->_list[$name] = $callback;
1✔
34
                unset($this->$name, $this->_aware[$name]);
1✔
35
                return $this;
1✔
36
        }
37

38

39
        /**
40
         * Returns all run-time functions.
41
         * @return array<string, callable>
42
         */
43
        public function getAll(): array
44
        {
45
                return $this->_list;
1✔
46
        }
47

48

49
        public function __get(string $name): callable
1✔
50
        {
51
                $callback = $this->_list[$name] ?? null;
1✔
52
                if (!$callback) {
1✔
53
                        $hint = ($t = Helpers::getSuggestion(array_keys($this->_list), $name))
1✔
UNCOV
54
                                ? ", did you mean '$t'?"
×
55
                                : '.';
1✔
56
                        throw new \LogicException("Function '$name' is not defined$hint");
1✔
57

58
                } elseif (!isset($this->_aware[$name])) {
1✔
59
                        $params = Helpers::toReflection($callback)->getParameters();
1✔
60
                        $this->_aware[$name] = $params && (string) $params[0]->getType() === Template::class;
1✔
61
                }
62

63
                return $this->$name = $this->_aware[$name]
1✔
64
                        ? $callback
1✔
65
                        : fn($info, ...$args) => $callback(...$args);
1✔
66
        }
67
}
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