mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-17 15:18:17 +01:00
Rewrote overly magic code to make it readable (#906)
New code inspired by 950bf8f1d1/lib/PhpParser/Builder/Trait_.php (L43)
This commit is contained in:
parent
21a3e8cac5
commit
4c4af21df8
@ -111,20 +111,18 @@ class Class_ extends Declaration {
|
|||||||
public function addStmt($stmt) {
|
public function addStmt($stmt) {
|
||||||
$stmt = BuilderHelpers::normalizeNode($stmt);
|
$stmt = BuilderHelpers::normalizeNode($stmt);
|
||||||
|
|
||||||
$targets = [
|
if ($stmt instanceof Stmt\Property) {
|
||||||
Stmt\TraitUse::class => &$this->uses,
|
$this->properties[] = $stmt;
|
||||||
Stmt\ClassConst::class => &$this->constants,
|
} elseif ($stmt instanceof Stmt\ClassMethod) {
|
||||||
Stmt\Property::class => &$this->properties,
|
$this->methods[] = $stmt;
|
||||||
Stmt\ClassMethod::class => &$this->methods,
|
} elseif ($stmt instanceof Stmt\TraitUse) {
|
||||||
];
|
$this->uses[] = $stmt;
|
||||||
|
} elseif ($stmt instanceof Stmt\ClassConst) {
|
||||||
$class = \get_class($stmt);
|
$this->constants[] = $stmt;
|
||||||
if (!isset($targets[$class])) {
|
} else {
|
||||||
throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
|
throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$targets[$class][] = $stmt;
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,20 +74,18 @@ class Enum_ extends Declaration {
|
|||||||
public function addStmt($stmt) {
|
public function addStmt($stmt) {
|
||||||
$stmt = BuilderHelpers::normalizeNode($stmt);
|
$stmt = BuilderHelpers::normalizeNode($stmt);
|
||||||
|
|
||||||
$targets = [
|
if ($stmt instanceof Stmt\EnumCase) {
|
||||||
Stmt\TraitUse::class => &$this->uses,
|
$this->enumCases[] = $stmt;
|
||||||
Stmt\EnumCase::class => &$this->enumCases,
|
} elseif ($stmt instanceof Stmt\ClassMethod) {
|
||||||
Stmt\ClassConst::class => &$this->constants,
|
$this->methods[] = $stmt;
|
||||||
Stmt\ClassMethod::class => &$this->methods,
|
} elseif ($stmt instanceof Stmt\TraitUse) {
|
||||||
];
|
$this->uses[] = $stmt;
|
||||||
|
} elseif ($stmt instanceof Stmt\ClassConst) {
|
||||||
$class = \get_class($stmt);
|
$this->constants[] = $stmt;
|
||||||
if (!isset($targets[$class])) {
|
} else {
|
||||||
throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
|
throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
$targets[$class][] = $stmt;
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user