mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2025-01-22 05:11:39 +01:00
Drop two more getType() usages in builders
This commit is contained in:
parent
8d3f48ab75
commit
0bb74e03aa
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user