• 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

96.15
/src/Latte/exceptions.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;
9

10

11
/**
12
 * Common interface for all Latte exceptions.
13
 */
14
interface Exception
15
{
16
}
17

18

19
/**
20
 * @internal
21
 */
22
trait PositionAwareException
23
{
24
        public ?string $sourceCode = null;
25
        public ?string $sourceName = null;
26
        public ?Compiler\Position $position = null;
27
        private string $origMessage;
28

29

30
        public function setSource(string $code, ?string $name = null): self
1✔
31
        {
32
                $this->sourceCode = $code;
1✔
33
                $this->sourceName = $name;
1✔
34
                $this->generateMessage();
1✔
35
                return $this;
1✔
36
        }
37

38

39
        private function generateMessage(): void
40
        {
41
                $this->origMessage ??= $this->message;
1✔
42
                $info = [];
1✔
43
                if ($this->sourceName && @is_file($this->sourceName)) { // @ - may trigger error
1✔
UNCOV
44
                        $info[] = "in '" . str_replace(dirname($this->sourceName, 2), '...', $this->sourceName) . "'";
×
45
                }
46
                if ($this->position) {
1✔
47
                        $info[] = $this->position;
1✔
48
                }
49
                $this->message = $info
1✔
50
                        ? rtrim($this->origMessage, '.') . ' (' . implode(' ', $info) . ')'
1✔
51
                        : $this->origMessage;
1✔
52
        }
1✔
53
}
54

55

56
/**
57
 * Template compilation failed.
58
 */
59
class CompileException extends \Exception implements Exception
60
{
61
        use PositionAwareException;
62

63
        /** @deprecated */
64
        public ?int $sourceLine;
65

66

67
        public function __construct(string $message, ?Compiler\Position $position = null, ?\Throwable $previous = null)
1✔
68
        {
69
                parent::__construct($message, 0, $previous);
1✔
70
                $this->position = $position;
1✔
71
                $this->sourceLine = $position?->line;
1✔
72
                $this->generateMessage();
1✔
73
        }
1✔
74
}
75

76

77
/**
78
 * Template rendering failed.
79
 */
80
class RuntimeException extends \RuntimeException implements Exception
81
{
82
}
83

84

85
/**
86
 * Template file not found or could not be loaded.
87
 */
88
class TemplateNotFoundException extends RuntimeException
89
{
90
}
91

92

93
/**
94
 * Template uses forbidden function, filter or variable in sandbox mode.
95
 */
96
class SecurityViolationException extends \Exception implements Exception
97
{
98
        use PositionAwareException;
99

100
        public function __construct(string $message, ?Compiler\Position $position = null)
1✔
101
        {
102
                parent::__construct($message);
1✔
103
                $this->position = $position;
1✔
104
                $this->generateMessage();
1✔
105
        }
1✔
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