5 * Contains \Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer\Notify.
8 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer;
10 use Drupal\drupalmoduleupgrader\FixerBase;
11 use Pharborist\DocCommentNode;
12 use Pharborist\LineCommentBlockNode;
13 use Pharborist\NodeInterface;
20 class Notify extends FixerBase {
22 use NodeCollectorTrait;
27 public function execute() {
28 foreach ($this->getObjects() as $node) {
29 $comment = $this->getComment($node);
33 $this->setComment($node, $comment . $this->configuration['note']);
36 $this->target->save();
39 protected function getComment(NodeInterface $node) {
40 if ($this->supportsDocComments($node)) {
41 /** @var \Pharborist\DocCommentTrait $node */
42 $comment = $node->getDocComment() ?: DocCommentNode::create('');
43 return $comment->getCommentText();
50 protected function setComment(NodeInterface $node, $comment_text) {
51 if ($this->supportsDocComments($node)) {
52 /** @var \Pharborist\DocCommentTrait $node */
53 $node->setDocComment(DocCommentNode::create($comment_text));
56 LineCommentBlockNode::create($comment_text)->insertBefore($node->getStatement());
61 * Returns if a node supports doc comments by importing DocCommentTrait
62 * anywhere in its lineage.
64 * @param \Pharborist\NodeInterface $node
68 protected function supportsDocComments(NodeInterface $node) {
69 return $this->usesTrait('Pharborist\DocCommentTrait', $node);