mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-17 23:28:15 +01:00
Ensure names are not empty
This commit is contained in:
parent
336a49b428
commit
b507fa43da
@ -218,8 +218,16 @@ class Name extends NodeAbstract
|
||||
*/
|
||||
private static function prepareName($name) : array {
|
||||
if (\is_string($name)) {
|
||||
if ('' === $name) {
|
||||
throw new \InvalidArgumentException('Name cannot be empty');
|
||||
}
|
||||
|
||||
return explode('\\', $name);
|
||||
} elseif (\is_array($name)) {
|
||||
if (empty($name)) {
|
||||
throw new \InvalidArgumentException('Name cannot be empty');
|
||||
}
|
||||
|
||||
return $name;
|
||||
} elseif ($name instanceof self) {
|
||||
return $name->parts;
|
||||
|
@ -132,13 +132,29 @@ class NameTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Expected string, array of parts or Name instance
|
||||
*/
|
||||
public function testInvalidArg() {
|
||||
Name::concat('foo', new \stdClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Name cannot be empty
|
||||
*/
|
||||
public function testInvalidEmptyString() {
|
||||
new Name('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Name cannot be empty
|
||||
*/
|
||||
public function testInvalidEmptyArray() {
|
||||
new Name([]);
|
||||
}
|
||||
|
||||
/** @dataProvider provideTestIsSpecialClassName */
|
||||
public function testIsSpecialClassName($name, $expected) {
|
||||
$name = new Name($name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user