mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-06-04 02:54:51 +02:00
Add Name::getParts(), deprecate Name::$parts
In preparation for switching this to a plain string in PHP-Parser 5, deprecate direct access to the property and provide an API that will work on both versions.
This commit is contained in:
parent
ba788aa98b
commit
c9e5a13d68
@ -6,7 +6,10 @@ use PhpParser\NodeAbstract;
|
|||||||
|
|
||||||
class Name extends NodeAbstract
|
class Name extends NodeAbstract
|
||||||
{
|
{
|
||||||
/** @var string[] Parts of the name */
|
/**
|
||||||
|
* @var string[] Parts of the name
|
||||||
|
* @deprecated Use getParts() instead
|
||||||
|
*/
|
||||||
public $parts;
|
public $parts;
|
||||||
|
|
||||||
private static $specialClassNames = [
|
private static $specialClassNames = [
|
||||||
@ -30,6 +33,15 @@ class Name extends NodeAbstract
|
|||||||
return ['parts'];
|
return ['parts'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get parts of name (split by the namespace separator).
|
||||||
|
*
|
||||||
|
* @return string[] Parts of name
|
||||||
|
*/
|
||||||
|
public function getParts(): array {
|
||||||
|
return $this->parts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the first part of the name, i.e. everything before the first namespace separator.
|
* Gets the first part of the name, i.e. everything before the first namespace separator.
|
||||||
*
|
*
|
||||||
|
@ -19,10 +19,12 @@ class NameTest extends \PHPUnit\Framework\TestCase
|
|||||||
$name = new Name('foo');
|
$name = new Name('foo');
|
||||||
$this->assertSame('foo', $name->getFirst());
|
$this->assertSame('foo', $name->getFirst());
|
||||||
$this->assertSame('foo', $name->getLast());
|
$this->assertSame('foo', $name->getLast());
|
||||||
|
$this->assertSame(['foo'], $name->getParts());
|
||||||
|
|
||||||
$name = new Name('foo\bar');
|
$name = new Name('foo\bar');
|
||||||
$this->assertSame('foo', $name->getFirst());
|
$this->assertSame('foo', $name->getFirst());
|
||||||
$this->assertSame('bar', $name->getLast());
|
$this->assertSame('bar', $name->getLast());
|
||||||
|
$this->assertSame(['foo', 'bar'], $name->getParts());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testToString() {
|
public function testToString() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user