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

nette / latte / 20107372588

10 Dec 2025 05:19PM UTC coverage: 94.875% (-0.09%) from 94.966%
20107372588

push

github

dg
fixed operator ! priority

3 of 3 new or added lines in 1 file covered. (100.0%)

10 existing lines in 3 files now uncovered.

5517 of 5815 relevant lines covered (94.88%)

0.95 hits per line

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

75.0
/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.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\Compiler\Nodes\Php\Expression;
11

12
use Latte\Compiler\Nodes\Php\ExpressionNode;
13
use Latte\Compiler\Nodes\Php\OperatorNode;
14
use Latte\Compiler\Position;
15
use Latte\Compiler\PrintContext;
16

17

18
class UnaryOpNode extends ExpressionNode implements OperatorNode
19
{
20
        private const Ops = ['+' => 1, '-' => 1, '~' => 1, '@' => 1, '!' => 1];
21

22

23
        public function __construct(
1✔
24
                public ExpressionNode $expr,
25
                public string $operator,
26
                public ?Position $position = null,
27
        ) {
28
                if (!isset(self::Ops[$this->operator])) {
1✔
29
                        throw new \InvalidArgumentException("Unexpected operator '$this->operator'");
×
30
                }
31
        }
1✔
32

33

34
        public function print(PrintContext $context): string
1✔
35
        {
36
                $pos = $this->expr instanceof self || $this->expr instanceof PreOpNode ? self::AssocLeft : self::AssocRight; // Enforce -(-$expr) instead of --$expr
1✔
37
                return $this->operator . $context->parenthesize($this, $this->expr, $pos);
1✔
38
        }
39

40

41
        public function getOperatorPrecedence(): array
42
        {
43
                return match ($this->operator) {
1✔
44
                        '+', '-', '~', '@' => [240, self::AssocRight],
1✔
45
                        '!' => [220, self::AssocRight],
1✔
46
                };
47
        }
48

49

UNCOV
50
        public function &getIterator(): \Generator
×
51
        {
UNCOV
52
                yield $this->expr;
×
53
        }
54
}
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