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

nette / php-generator / 11958852939

21 Nov 2024 05:51PM UTC coverage: 93.129% (-0.3%) from 93.464%
11958852939

push

github

dg
Interfaces can have properties hooks

14 of 16 new or added lines in 2 files covered. (87.5%)

4 existing lines in 1 file now uncovered.

1613 of 1732 relevant lines covered (93.13%)

0.93 hits per line

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

90.7
/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
 * Class property description.
18
 */
19
final class Property
20
{
21
        use Traits\NameAware;
22
        use Traits\VisibilityAware;
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 $readOnly = false;
32
        private ?PropertyHook $getHook = null;
33
        private ?PropertyHook $setHook = null;
34

35

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

43

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

49

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

56

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

62

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

69

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

78

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

85

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

91

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

98

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

104

105
        public function setReadOnly(bool $state = true): static
1✔
106
        {
107
                $this->readOnly = $state;
1✔
108
                return $this;
1✔
109
        }
110

111

112
        public function isReadOnly(): bool
113
        {
114
                return $this->readOnly;
1✔
115
        }
116

117

118
        public function setSetHook(?PropertyHook $hook): static
1✔
119
        {
120
                $this->setHook = $hook;
1✔
121
                return $this;
1✔
122
        }
123

124

125
        public function getSetHook(): ?PropertyHook
126
        {
127
                return $this->setHook;
1✔
128
        }
129

130

131
        public function addSetHook(string $body, bool $shortcut = false): PropertyHook
132
        {
UNCOV
133
                return $this->setHook = (new PropertyHook)->setBody($body, $shortcut);
×
134
        }
135

136

137
        public function hasSetHook(): bool
138
        {
139
                return $this->setHook !== null;
1✔
140
        }
141

142

143
        public function setGetHook(?PropertyHook $hook): static
1✔
144
        {
145
                $this->getHook = $hook;
1✔
146
                return $this;
1✔
147
        }
148

149

150
        public function getGetHook(): ?PropertyHook
151
        {
152
                return $this->getHook;
1✔
153
        }
154

155

156
        public function addGetHook(string $body, bool $shortcut = false): PropertyHook
157
        {
UNCOV
158
                return $this->getHook = (new PropertyHook)->setBody($body, $shortcut);
×
159
        }
160

161

162
        public function hasGetHook(): bool
163
        {
164
                return $this->getHook !== null;
1✔
165
        }
166

167

168
        /** @throws Nette\InvalidStateException */
169
        public function validate(): void
170
        {
171
                if ($this->readOnly && !$this->type) {
1✔
UNCOV
172
                        throw new Nette\InvalidStateException("Property \$$this->name: Read-only properties are only supported on typed property.");
×
173
                }
174
        }
1✔
175
}
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