1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-30 04:19:30 +01:00

Don't return by ref from getAttribute()

This is not worth the few times where it might be useful.
This commit is contained in:
Nikita Popov 2017-09-29 17:14:27 +02:00
parent d8f9173390
commit 3d4621bbea
3 changed files with 10 additions and 5 deletions

View File

@ -77,7 +77,7 @@ interface Node
*
* @return mixed
*/
public function &getAttribute(string $key, $default = null);
public function getAttribute(string $key, $default = null);
/**
* Returns all the attributes of this node.

View File

@ -30,7 +30,7 @@ abstract class NodeAbstract implements Node, \JsonSerializable
* @return int Line
*/
public function getLine() : int {
return $this->getAttribute('startLine', -1);
return $this->attributes['startLine'] ?? -1;
}
/**
@ -95,7 +95,7 @@ abstract class NodeAbstract implements Node, \JsonSerializable
return array_key_exists($key, $this->attributes);
}
public function &getAttribute(string $key, $default = null) {
public function getAttribute(string $key, $default = null) {
if (!array_key_exists($key, $this->attributes)) {
return $default;
} else {

View File

@ -67,9 +67,14 @@ class NodeAbstractTest extends TestCase
*/
public function testGetDocComment(array $attributes, Node $node) {
$this->assertSame('/** doc comment */', $node->getDocComment()->getText());
array_pop($node->getAttribute('comments')); // remove doc comment
$comments = $node->getComments();
array_pop($comments); // remove doc comment
$node->setAttribute('comments', $comments);
$this->assertNull($node->getDocComment());
array_pop($node->getAttribute('comments')); // remove comment
array_pop($comments); // remove comment
$node->setAttribute('comments', $comments);
$this->assertNull($node->getDocComment());
}