Skip to content

Commit 763cbbb

Browse files
committed
support both docbook:para and docbook:simpara
docs use a mixture of these...
1 parent 6e636c4 commit 763cbbb

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

generator/src/XmlDocParser/Method.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function getParams(): array
9494
$params = [];
9595
$i=1;
9696
foreach ($this->functionObject->methodparam as $param) {
97-
$notes = $this->stripReturnFalseText($this->getStringForXPath("(//docbook:refsect1[@role='parameters']//docbook:varlistentry)[$i]//docbook:note//docbook:para"));
97+
$notes = $this->stripReturnFalseText($this->getStringForXPath("(//docbook:refsect1[@role='parameters']//docbook:varlistentry)[$i]//docbook:note/"));
9898
$i++;
9999

100100
if (preg_match('/This parameter has been removed in PHP (\d+\.\d+\.\d+)/', $notes, $matches)) {
@@ -126,13 +126,13 @@ public function getPhpDoc(): string
126126

127127
private function getDocBlock(): string
128128
{
129-
$str = $this->stripReturnFalseText($this->getStringForXPath("//docbook:refsect1[@role='description']/docbook:para"));
129+
$str = $this->stripReturnFalseText($this->getStringForXPath("//docbook:refsect1[@role='description']"));
130130
$str .= "\n\n";
131131

132132
$i=1;
133133
foreach ($this->getParams() as $parameter) {
134134
$str .= '@param '.$parameter->getDocBlockType().' $'.$parameter->getParameterName().' ';
135-
$str .= $this->getStringForXPath("(//docbook:refsect1[@role='parameters']//docbook:varlistentry)[$i]//docbook:para")."\n";
135+
$str .= $this->getStringForXPath("(//docbook:refsect1[@role='parameters']//docbook:varlistentry)[$i]/")."\n";
136136
$i++;
137137
}
138138

@@ -147,7 +147,7 @@ private function getDocBlock(): string
147147

148148
public function getReturnDocBlock(): string
149149
{
150-
$returnDoc = $this->getStringForXPath("//docbook:refsect1[@role='returnvalues']/docbook:para");
150+
$returnDoc = $this->getStringForXPath("//docbook:refsect1[@role='returnvalues']");
151151
$returnDoc = $this->stripReturnFalseText($returnDoc);
152152

153153
$bestReturnType = $this->getDocBlockReturnType();
@@ -223,7 +223,11 @@ private function removeString(string $string, string $search): string
223223

224224
private function getStringForXPath(string $xpath): string
225225
{
226-
$paragraphs = $this->rootEntity->xpath($xpath);
226+
// Some doc blocks put their text inside para, some simpara
227+
$paragraphs = $this->rootEntity->xpath($xpath . "/docbook:para");
228+
if ($paragraphs === []) {
229+
$paragraphs = $this->rootEntity->xpath($xpath . "/docbook:simpara");
230+
}
227231
if ($paragraphs === false || $paragraphs === null) {
228232
throw new \RuntimeException('Error while performing Xpath request.');
229233
}

generator/tests/XmlDocParser/MethodTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function testGetReturnDocBlock(): void
123123
$docPage = new DocPage(DocPage::referenceDir() . '/sqlsrv/functions/sqlsrv-next-result.xml');
124124
$xmlObject = $docPage->getMethodSynopsis();
125125
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
126-
$this->assertEquals("@return bool|null Returns TRUE if the next result was successfully retrieved, FALSE if an error \n occurred, and NULL if there are no more results to retrieve.\n", $method->getReturnDocBlock());
126+
$this->assertEquals("@return bool|null Returns TRUE if the next result was successfully retrieved, FALSE if an error\n occurred, and NULL if there are no more results to retrieve.\n", $method->getReturnDocBlock());
127127
$this->assertEquals('?bool', $method->getSignatureReturnType());
128128
}
129129

0 commit comments

Comments
 (0)