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

nette / php-generator / 22836119803

09 Mar 2026 02:40AM UTC coverage: 94.264% (+0.2%) from 94.029%
22836119803

push

github

dg
added CLAUDE.md

1890 of 2005 relevant lines covered (94.26%)

0.94 hits per line

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

82.76
/src/PhpGenerator/PropertyHook.php
1
<?php declare(strict_types=1);
1✔
2

3
namespace Nette\PhpGenerator;
4

5
use JetBrains\PhpStorm\Language;
6

7

8
/**
9
 * Definition of a property hook.
10
 */
11
final class PropertyHook
12
{
13
        use Traits\AttributeAware;
14
        use Traits\CommentAware;
15

16
        private string $body = '';
17
        private bool $short = false;
18
        private bool $final = false;
19
        private bool $abstract = false;
20

21
        /** @var array<string, Parameter> */
22
        private array $parameters = [];
23
        private bool $returnReference = false;
24

25

26
        /**
27
         * Sets the hook body. When $short is true, uses arrow-function style (=> expression).
28
         * Optionally accepts Dumper-style placeholders resolved against $args.
29
         * @param  ?mixed[]  $args
30
         */
31
        public function setBody(
1✔
32
                #[Language('PHP')]
33
                string $code,
34
                ?array $args = null,
35
                bool $short = false,
36
        ): static
37
        {
38
                $this->body = $args === null
1✔
39
                        ? $code
1✔
40
                        : (new Dumper)->format($code, ...$args);
1✔
41
                $this->short = $short;
1✔
42
                return $this;
1✔
43
        }
44

45

46
        public function getBody(): string
47
        {
48
                return $this->body;
1✔
49
        }
50

51

52
        /**
53
         * Returns true if the hook uses the arrow function style (=> expression), not a block body.
54
         */
55
        public function isShort(): bool
56
        {
57
                return $this->short && trim($this->body) !== '';
1✔
58
        }
59

60

61
        public function setFinal(bool $state = true): static
1✔
62
        {
63
                $this->final = $state;
1✔
64
                return $this;
1✔
65
        }
66

67

68
        public function isFinal(): bool
69
        {
70
                return $this->final;
1✔
71
        }
72

73

74
        public function setAbstract(bool $state = true): static
1✔
75
        {
76
                $this->abstract = $state;
1✔
77
                return $this;
1✔
78
        }
79

80

81
        public function isAbstract(): bool
82
        {
83
                return $this->abstract;
1✔
84
        }
85

86

87
        /**
88
         * @param  list<Parameter>  $val
89
         * @internal
90
         */
91
        public function setParameters(array $val): static
92
        {
93
                (function (Parameter ...$val) {})(...$val);
×
94
                $this->parameters = [];
×
95
                foreach ($val as $v) {
×
96
                        $this->parameters[$v->getName()] = $v;
×
97
                }
98

99
                return $this;
×
100
        }
101

102

103
        /**
104
         * @return  array<string, Parameter>
105
         * @internal
106
         */
107
        public function getParameters(): array
108
        {
109
                return $this->parameters;
1✔
110
        }
111

112

113
        /**
114
         * Adds a parameter. If it already exists, it overwrites it.
115
         * @param  string  $name without $
116
         */
117
        public function addParameter(string $name): Parameter
1✔
118
        {
119
                return $this->parameters[$name] = new Parameter($name);
1✔
120
        }
121

122

123
        public function setReturnReference(bool $state = true): static
1✔
124
        {
125
                $this->returnReference = $state;
1✔
126
                return $this;
1✔
127
        }
128

129

130
        public function getReturnReference(): bool
131
        {
132
                return $this->returnReference;
1✔
133
        }
134
}
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