Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion phpdotnet/phd/Package/PHP/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,19 @@ public function format_function_text($value, $tag, $display_value = null) {
$filename = "function." . str_replace("_", "-", $value);
} else {
$ref = $this->normalizeFQN($value);
$filename = $this->getRefnameLink($ref);
$filename = null;
/* A bare methodname may collide with a global function
* (e.g. Serializable::serialize vs serialize), so prefer
* a method of the class currently being documented */
if ($tag === "methodname"
&& !str_contains($ref, "::")
&& $this->cchunk["class_name_ref"] !== null
) {
$filename = $this->getRefnameLink($this->cchunk["class_name_ref"] . "::" . $ref);
}
if ($filename === null) {
$filename = $this->getRefnameLink($ref);
}
}
if ($filename !== null) {
if ($this->CURRENT_ID !== $filename) {
Expand Down
79 changes: 79 additions & 0 deletions tests/package/php/class_and_method_link_rendering_002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
--TEST--
Class and method link rendering 002: bare methodname colliding with a global function
--FILE--
<?php
namespace phpdotnet\phd;

require_once __DIR__ . "/../../setup.php";

$config->xmlFile = __DIR__ . "/data/class_and_method_link_rendering_002.xml";

$indices = [
[
"docbook_id" => "function.conflictingname",
"filename" => "function.conflictingname",
],
[
"docbook_id" => "myclass.conflictingname",
"filename" => "myclass.conflictingname",
],
[
"docbook_id" => "function.onlyfunction",
"filename" => "function.onlyfunction",
],
];

$format = new TestPHPChunkedXHTML($config, $outputHandler);

foreach ($indices as $index) {
$format->SQLiteIndex(
null, // $context,
null, // $index,
$index["docbook_id"] ?? "", // $id,
$index["filename"] ?? "", // $filename,
$index["parent_id"] ?? "", // $parent,
$index["sdesc"] ?? "", // $sdesc,
$index["ldesc"] ?? "", // $ldesc,
$index["element"] ?? "", // $element,
$index["previous"] ?? "", // $previous,
$index["next"] ?? "", // $next,
$index["chunk"] ?? 0, // $chunk
);
}

$format->addRefname("function.conflictingname", "conflictingname");
$format->addRefname("myclass.conflictingname", "myclass::conflictingname");
$format->addRefname("function.onlyfunction", "onlyfunction");

$render = new TestRender(new Reader($outputHandler), $config, $format);

$render->run();
?>
--EXPECTF--
Filename: class.myclass.html
Content:
<div id="class.myclass" class="reference">

<h1 class="title">The MyClass class</h1>


<div class="partintro"><p class="verinfo">(No version information available, might only be in Git)</p>

<div class="section">
<p class="simpara">1. Bare methodname colliding with a global function links to the method of the current class</p>
<span class="methodname"><a href="myclass.conflictingname.html" class="methodname">conflictingName()</a></span>
</div>

<div class="section">
<p class="simpara">2. Function with the same name still links to the global function</p>
<span class="function"><a href="function.conflictingname.html" class="function">conflictingName()</a></span>
</div>

<div class="section">
<p class="simpara">3. Bare methodname without a matching method falls back to the global function</p>
<span class="methodname"><a href="function.onlyfunction.html" class="methodname">onlyFunction()</a></span>
</div>

</div>

</div>
26 changes: 26 additions & 0 deletions tests/package/php/data/class_and_method_link_rendering_002.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<reference xml:id="class.myclass" role="class" xmlns="http://docbook.org/ns/docbook">

<title>The MyClass class</title>
<titleabbrev>MyClass</titleabbrev>

<partintro>

<section>
<simpara>1. Bare methodname colliding with a global function links to the method of the current class</simpara>
<methodname>conflictingName</methodname>
</section>

<section>
<simpara>2. Function with the same name still links to the global function</simpara>
<function>conflictingName</function>
</section>

<section>
<simpara>3. Bare methodname without a matching method falls back to the global function</simpara>
<methodname>onlyFunction</methodname>
</section>

</partintro>

</reference>