diff --git a/lib/PhpParser/Builder/Class_.php b/lib/PhpParser/Builder/Class_.php index ae6d7bf4..8d00e4d3 100644 --- a/lib/PhpParser/Builder/Class_.php +++ b/lib/PhpParser/Builder/Class_.php @@ -111,20 +111,18 @@ class Class_ extends Declaration { public function addStmt($stmt) { $stmt = BuilderHelpers::normalizeNode($stmt); - $targets = [ - Stmt\TraitUse::class => &$this->uses, - Stmt\ClassConst::class => &$this->constants, - Stmt\Property::class => &$this->properties, - Stmt\ClassMethod::class => &$this->methods, - ]; - - $class = \get_class($stmt); - if (!isset($targets[$class])) { + if ($stmt instanceof Stmt\Property) { + $this->properties[] = $stmt; + } elseif ($stmt instanceof Stmt\ClassMethod) { + $this->methods[] = $stmt; + } elseif ($stmt instanceof Stmt\TraitUse) { + $this->uses[] = $stmt; + } elseif ($stmt instanceof Stmt\ClassConst) { + $this->constants[] = $stmt; + } else { throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); } - $targets[$class][] = $stmt; - return $this; } diff --git a/lib/PhpParser/Builder/Enum_.php b/lib/PhpParser/Builder/Enum_.php index 699320d5..c9cce99b 100644 --- a/lib/PhpParser/Builder/Enum_.php +++ b/lib/PhpParser/Builder/Enum_.php @@ -74,20 +74,18 @@ class Enum_ extends Declaration { public function addStmt($stmt) { $stmt = BuilderHelpers::normalizeNode($stmt); - $targets = [ - Stmt\TraitUse::class => &$this->uses, - Stmt\EnumCase::class => &$this->enumCases, - Stmt\ClassConst::class => &$this->constants, - Stmt\ClassMethod::class => &$this->methods, - ]; - - $class = \get_class($stmt); - if (!isset($targets[$class])) { + if ($stmt instanceof Stmt\EnumCase) { + $this->enumCases[] = $stmt; + } elseif ($stmt instanceof Stmt\ClassMethod) { + $this->methods[] = $stmt; + } elseif ($stmt instanceof Stmt\TraitUse) { + $this->uses[] = $stmt; + } elseif ($stmt instanceof Stmt\ClassConst) { + $this->constants[] = $stmt; + } else { throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); } - $targets[$class][] = $stmt; - return $this; }