Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Fixer / Notify.php
diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Fixer/Notify.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Fixer/Notify.php
new file mode 100644 (file)
index 0000000..44f8db4
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer\Notify.
+ */
+
+namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer;
+
+use Drupal\drupalmoduleupgrader\FixerBase;
+use Pharborist\DocCommentNode;
+use Pharborist\LineCommentBlockNode;
+use Pharborist\NodeInterface;
+
+/**
+ * @Fixer(
+ *  id = "notify"
+ * )
+ */
+class Notify extends FixerBase {
+
+  use NodeCollectorTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function execute() {
+    foreach ($this->getObjects() as $node) {
+      $comment = $this->getComment($node);
+      if ($comment) {
+        $comment .= "\n\n";
+      }
+      $this->setComment($node, $comment . $this->configuration['note']);
+    }
+
+    $this->target->save();
+  }
+
+  protected function getComment(NodeInterface $node) {
+    if ($this->supportsDocComments($node)) {
+      /** @var \Pharborist\DocCommentTrait $node */
+      $comment = $node->getDocComment() ?: DocCommentNode::create('');
+      return $comment->getCommentText();
+    }
+    else {
+      return '';
+    }
+  }
+
+  protected function setComment(NodeInterface $node, $comment_text) {
+    if ($this->supportsDocComments($node)) {
+      /** @var \Pharborist\DocCommentTrait $node */
+      $node->setDocComment(DocCommentNode::create($comment_text));
+    }
+    else {
+      LineCommentBlockNode::create($comment_text)->insertBefore($node->getStatement());
+    }
+  }
+
+  /**
+   * Returns if a node supports doc comments by importing DocCommentTrait
+   * anywhere in its lineage.
+   *
+   * @param \Pharborist\NodeInterface $node
+   *
+   * @return boolean
+   */
+  protected function supportsDocComments(NodeInterface $node) {
+    return $this->usesTrait('Pharborist\DocCommentTrait', $node);
+  }
+
+}