1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2025-01-22 05:41:23 +01:00

Drop two more getType() usages in builders

This commit is contained in:
Nikita Popov 2017-11-13 00:24:01 +01:00
parent 8d3f48ab75
commit 0bb74e03aa
2 changed files with 16 additions and 22 deletions

View File

@ -90,18 +90,18 @@ class Class_ extends Declaration
$stmt = BuilderHelpers::normalizeNode($stmt);
$targets = [
'Stmt_TraitUse' => &$this->uses,
'Stmt_ClassConst' => &$this->constants,
'Stmt_Property' => &$this->properties,
'Stmt_ClassMethod' => &$this->methods,
Stmt\TraitUse::class => &$this->uses,
Stmt\ClassConst::class => &$this->constants,
Stmt\Property::class => &$this->properties,
Stmt\ClassMethod::class => &$this->methods,
];
$type = $stmt->getType();
if (!isset($targets[$type])) {
throw new \LogicException(sprintf('Unexpected node of type "%s"', $type));
$class = \get_class($stmt);
if (!isset($targets[$class])) {
throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
}
$targets[$type][] = $stmt;
$targets[$class][] = $stmt;
return $this;
}

View File

@ -48,20 +48,14 @@ class Interface_ extends Declaration
public function addStmt($stmt) {
$stmt = BuilderHelpers::normalizeNode($stmt);
$type = $stmt->getType();
switch ($type) {
case 'Stmt_ClassConst':
$this->constants[] = $stmt;
break;
case 'Stmt_ClassMethod':
// we erase all statements in the body of an interface method
$stmt->stmts = null;
$this->methods[] = $stmt;
break;
default:
throw new \LogicException(sprintf('Unexpected node of type "%s"', $type));
if ($stmt instanceof Stmt\ClassConst) {
$this->constants[] = $stmt;
} else if ($stmt instanceof Stmt\ClassMethod) {
// we erase all statements in the body of an interface method
$stmt->stmts = null;
$this->methods[] = $stmt;
} else {
throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
}
return $this;