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

nette / php-generator / 16781746162

06 Aug 2025 03:44PM UTC coverage: 92.006%. Remained the same
16781746162

push

github

dg
added support for final promoted property

14 of 14 new or added lines in 4 files covered. (100.0%)

15 existing lines in 4 files now uncovered.

1761 of 1914 relevant lines covered (92.01%)

0.92 hits per line

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

94.74
/src/PhpGenerator/Property.php
1
<?php
2

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

8
declare(strict_types=1);
9

10
namespace Nette\PhpGenerator;
11

12
use Nette;
13
use Nette\Utils\Type;
14

15

16
/**
17
 * Definition of a class property.
18
 */
19
final class Property
20
{
21
        use Traits\NameAware;
22
        use Traits\PropertyLike;
23
        use Traits\CommentAware;
24
        use Traits\AttributeAware;
25

26
        private mixed $value = null;
27
        private bool $static = false;
28
        private ?string $type = null;
29
        private bool $nullable = false;
30
        private bool $initialized = false;
31
        private bool $abstract = false;
32

33

34
        public function setValue(mixed $val): static
1✔
35
        {
36
                $this->value = $val;
1✔
37
                $this->initialized = true;
1✔
38
                return $this;
1✔
39
        }
40

41

42
        public function &getValue(): mixed
43
        {
44
                return $this->value;
1✔
45
        }
46

47

48
        public function setStatic(bool $state = true): static
1✔
49
        {
50
                $this->static = $state;
1✔
51
                return $this;
1✔
52
        }
53

54

55
        public function isStatic(): bool
56
        {
57
                return $this->static;
1✔
58
        }
59

60

61
        public function setType(?string $type): static
1✔
62
        {
63
                $this->type = Helpers::validateType($type, $this->nullable);
1✔
64
                return $this;
1✔
65
        }
66

67

68
        /** @return ($asObject is true ? ?Type : ?string) */
69
        public function getType(bool $asObject = false): Type|string|null
1✔
70
        {
71
                return $asObject && $this->type
1✔
UNCOV
72
                        ? Type::fromString($this->type)
×
73
                        : $this->type;
1✔
74
        }
75

76

77
        public function setNullable(bool $state = true): static
1✔
78
        {
79
                $this->nullable = $state;
1✔
80
                return $this;
1✔
81
        }
82

83

84
        public function isNullable(): bool
85
        {
86
                return $this->nullable || ($this->initialized && $this->value === null);
1✔
87
        }
88

89

90
        public function setInitialized(bool $state = true): static
1✔
91
        {
92
                $this->initialized = $state;
1✔
93
                return $this;
1✔
94
        }
95

96

97
        public function isInitialized(): bool
98
        {
99
                return $this->initialized || $this->value !== null;
1✔
100
        }
101

102

103
        public function setAbstract(bool $state = true): static
1✔
104
        {
105
                $this->abstract = $state;
1✔
106
                return $this;
1✔
107
        }
108

109

110
        public function isAbstract(): bool
111
        {
112
                return $this->abstract;
1✔
113
        }
114

115

116
        /** @throws Nette\InvalidStateException */
117
        public function validate(): void
118
        {
119
                if ($this->readOnly && !$this->type) {
1✔
UNCOV
120
                        throw new Nette\InvalidStateException("Property \$$this->name: Read-only properties are only supported on typed property.");
×
121

122
                } elseif ($this->abstract && $this->final) {
1✔
123
                        throw new Nette\InvalidStateException("Property \$$this->name cannot be abstract and final at the same time.");
1✔
124

125
                } elseif (
126
                        $this->abstract
1✔
127
                        && !Nette\Utils\Arrays::some($this->getHooks(), fn($hook) => $hook->isAbstract())
1✔
128
                ) {
129
                        throw new Nette\InvalidStateException("Property \$$this->name: Abstract property must have at least one abstract hook.");
1✔
130
                }
131
        }
1✔
132

133

134
        public function __clone(): void
135
        {
136
                $this->hooks = array_map(fn($item) => $item ? clone $item : $item, $this->hooks);
1✔
137
        }
1✔
138
}
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