Skip to content
Merged
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: 9 additions & 5 deletions generator/src/XmlDocParser/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getParams(): array
$params = [];
$i=1;
foreach ($this->functionObject->methodparam as $param) {
$notes = $this->stripReturnFalseText($this->getStringForXPath("(//docbook:refsect1[@role='parameters']//docbook:varlistentry)[$i]//docbook:note//docbook:para"));
$notes = $this->stripReturnFalseText($this->getStringForXPath("(//docbook:refsect1[@role='parameters']//docbook:varlistentry)[$i]//docbook:note/"));
$i++;

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

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

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

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

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

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

private function getStringForXPath(string $xpath): string
{
$paragraphs = $this->rootEntity->xpath($xpath);
// Some doc blocks put their text inside para, some simpara
$paragraphs = $this->rootEntity->xpath($xpath . "/docbook:para");
if ($paragraphs === []) {
$paragraphs = $this->rootEntity->xpath($xpath . "/docbook:simpara");
}
if ($paragraphs === false || $paragraphs === null) {
throw new \RuntimeException('Error while performing Xpath request.');
}
Expand Down
2 changes: 1 addition & 1 deletion generator/tests/XmlDocParser/MethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function testGetReturnDocBlock(): void
$docPage = new DocPage(DocPage::referenceDir() . '/sqlsrv/functions/sqlsrv-next-result.xml');
$xmlObject = $docPage->getMethodSynopsis();
$method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), ErrorType::FALSY);
$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());
$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());
$this->assertEquals('?bool', $method->getSignatureReturnType());
}

Expand Down
Loading