-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from phpDocumentor/fix/modified-backtrace-arg…
…uments Fix issue with modified backtrace
- Loading branch information
Showing
3 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Reflection; | ||
|
||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @coversNothing | ||
*/ | ||
class ModifyBackTraceSafeTest extends TestCase | ||
{ | ||
public function testBackTraceModificationDoesNotImpactFunctionArguments() | ||
{ | ||
$traverser = new Traverser(); | ||
$node1 = new Node(); | ||
$node1->children[] = new Node(); | ||
$node1->children[] = new Node(); | ||
|
||
$traverser->traverse([new Node(), $node1]); | ||
} | ||
} | ||
|
||
|
||
class Node { | ||
public $children = []; | ||
} | ||
|
||
class Traverser | ||
{ | ||
public function traverse(array $nodes) | ||
{ | ||
$this->traverseArray($nodes); | ||
} | ||
|
||
public function traverseArray(array $nodes): array | ||
{ | ||
$doNodes = []; | ||
|
||
foreach ($nodes as &$node) { | ||
$node = $this->callback($node); | ||
$node = $this->traverseNode($node); | ||
|
||
$doNodes[] = $node; | ||
} | ||
|
||
return $doNodes; | ||
} | ||
|
||
public function callback(Node $class) : Node | ||
{ | ||
$docblock = <<<DOCBLOCK | ||
/** | ||
* @see sql.php | ||
*/ | ||
DOCBLOCK; | ||
|
||
$factor = DocBlockFactory::createInstance(); | ||
|
||
$factor->create($docblock); | ||
|
||
return $class; | ||
} | ||
|
||
private function traverseNode(Node $node) : Node | ||
{ | ||
if ($node->children) { | ||
$this->traverseArray($node->children); | ||
} | ||
|
||
return $node; | ||
} | ||
} |