2017-08-18 22:57:27 +02:00
|
|
|
<?php declare(strict_types=1);
|
2014-12-19 17:21:46 +01:00
|
|
|
|
|
|
|
namespace PhpParser\Builder;
|
|
|
|
|
|
|
|
use PhpParser;
|
2017-04-24 21:15:11 +02:00
|
|
|
use PhpParser\BuilderHelpers;
|
2014-12-19 17:21:46 +01:00
|
|
|
|
2022-08-28 22:57:06 +02:00
|
|
|
abstract class Declaration implements PhpParser\Builder {
|
2022-09-11 19:24:38 +02:00
|
|
|
/** @var array<string, mixed> */
|
2023-08-16 21:18:30 +02:00
|
|
|
protected array $attributes = [];
|
2014-12-19 17:21:46 +01:00
|
|
|
|
2022-09-11 15:22:23 +02:00
|
|
|
/**
|
|
|
|
* Adds a statement.
|
|
|
|
*
|
|
|
|
* @param PhpParser\Node\Stmt|PhpParser\Builder $stmt The statement to add
|
|
|
|
*
|
|
|
|
* @return $this The builder instance (for fluid interface)
|
|
|
|
*/
|
2014-12-19 17:21:46 +01:00
|
|
|
abstract public function addStmt($stmt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds multiple statements.
|
|
|
|
*
|
2022-09-11 19:24:38 +02:00
|
|
|
* @param (PhpParser\Node\Stmt|PhpParser\Builder)[] $stmts The statements to add
|
2014-12-19 17:21:46 +01:00
|
|
|
*
|
|
|
|
* @return $this The builder instance (for fluid interface)
|
|
|
|
*/
|
|
|
|
public function addStmts(array $stmts) {
|
|
|
|
foreach ($stmts as $stmt) {
|
|
|
|
$this->addStmt($stmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets doc comment for the declaration.
|
|
|
|
*
|
|
|
|
* @param PhpParser\Comment\Doc|string $docComment Doc comment to set
|
|
|
|
*
|
|
|
|
* @return $this The builder instance (for fluid interface)
|
|
|
|
*/
|
|
|
|
public function setDocComment($docComment) {
|
2017-08-13 14:06:08 +02:00
|
|
|
$this->attributes['comments'] = [
|
2017-04-24 21:15:11 +02:00
|
|
|
BuilderHelpers::normalizeDocComment($docComment)
|
2017-08-13 14:06:08 +02:00
|
|
|
];
|
2014-12-19 17:21:46 +01:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2018-01-10 15:04:06 -02:00
|
|
|
}
|