Skip to content

Commit e546e7b

Browse files
authored
Fix rendering of attribute constants (#249)
$this->cchunk["fieldsynopsis"]["modifier"] was not set for atrributes due to the early return, but this value is needed in order to be able to decide if the fieldsynopsis refers to a constant or a property at https://github.com/php/phd/blob/d7f700463918a466705e92b4bfd4df0afa39d944/phpdotnet/phd/Package/Generic/XHTML.php#L1608
1 parent 0e43594 commit e546e7b

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

phpdotnet/phd/Package/Generic/XHTML.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,7 @@ public function format_fieldsynopsis($open, $name, $attrs) {
14271427
}
14281428

14291429
public function format_fieldsynopsis_modifier_text($value, $tag) {
1430+
$this->cchunk["fieldsynopsis"]["modifier"] = trim($value);
14301431
if ($this->getRole() === "attribute") {
14311432
$attribute = trim(strtolower($value), "#[]\\");
14321433
$href = Format::getFilename("class.$attribute");
@@ -1435,7 +1436,6 @@ public function format_fieldsynopsis_modifier_text($value, $tag) {
14351436
}
14361437
return false;
14371438
}
1438-
$this->cchunk["fieldsynopsis"]["modifier"] = trim($value);
14391439
return $this->TEXT($value);
14401440
}
14411441

tests/package/generic/attribute_formatting_003.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,21 @@ Content:
8585
}</div>
8686
</div>
8787

88+
<div class="section">
89+
<p class="para">3. Constant of a class with attribute</p>
90+
<div class="classsynopsis"><div class="classsynopsisinfo">
91+
92+
<span class="attribute">#[\UnknownAttribute]</span><br>
93+
<span class="modifier">class</span> <strong class="classname">ClassName</strong>
94+
{</div>
95+
<div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
96+
<div class="fieldsynopsis">
97+
<span class="modifier">public</span>
98+
<span class="modifier">const</span>
99+
<span class="type">string</span>
100+
<var class="fieldsynopsis_varname">CONSTANT_NAME</var>;</div>
101+
102+
}</div>
103+
</div>
104+
88105
</div>

tests/package/generic/data/attribute_formatting_003.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,21 @@
3535
</classsynopsis>
3636
</section>
3737

38+
<section>
39+
<para>3. Constant of a class with attribute</para>
40+
<classsynopsis class="class">
41+
<ooclass>
42+
<modifier role="attribute">#[\UnknownAttribute]</modifier>
43+
<classname>ClassName</classname>
44+
</ooclass>
45+
<classsynopsisinfo role="comment">Constants</classsynopsisinfo>
46+
<fieldsynopsis>
47+
<modifier>public</modifier>
48+
<modifier>const</modifier>
49+
<type>string</type>
50+
<varname>CONSTANT_NAME</varname>
51+
</fieldsynopsis>
52+
</classsynopsis>
53+
</section>
54+
3855
</chapter>

0 commit comments

Comments
 (0)