Declaration.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Builder;
  3. use PhpParser;
  4. use PhpParser\BuilderHelpers;
  5. abstract class Declaration implements PhpParser\Builder {
  6. /** @var array<string, mixed> */
  7. protected array $attributes = [];
  8. /**
  9. * Adds a statement.
  10. *
  11. * @param PhpParser\Node\Stmt|PhpParser\Builder $stmt The statement to add
  12. *
  13. * @return $this The builder instance (for fluid interface)
  14. */
  15. abstract public function addStmt($stmt);
  16. /**
  17. * Adds multiple statements.
  18. *
  19. * @param (PhpParser\Node\Stmt|PhpParser\Builder)[] $stmts The statements to add
  20. *
  21. * @return $this The builder instance (for fluid interface)
  22. */
  23. public function addStmts(array $stmts) {
  24. foreach ($stmts as $stmt) {
  25. $this->addStmt($stmt);
  26. }
  27. return $this;
  28. }
  29. /**
  30. * Sets doc comment for the declaration.
  31. *
  32. * @param PhpParser\Comment\Doc|string $docComment Doc comment to set
  33. *
  34. * @return $this The builder instance (for fluid interface)
  35. */
  36. public function setDocComment($docComment) {
  37. $this->attributes['comments'] = [
  38. BuilderHelpers::normalizeDocComment($docComment)
  39. ];
  40. return $this;
  41. }
  42. }