Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Fixer / Notify.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer\Notify.
6  */
7
8 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer;
9
10 use Drupal\drupalmoduleupgrader\FixerBase;
11 use Pharborist\DocCommentNode;
12 use Pharborist\LineCommentBlockNode;
13 use Pharborist\NodeInterface;
14
15 /**
16  * @Fixer(
17  *  id = "notify"
18  * )
19  */
20 class Notify extends FixerBase {
21
22   use NodeCollectorTrait;
23
24   /**
25    * {@inheritdoc}
26    */
27   public function execute() {
28     foreach ($this->getObjects() as $node) {
29       $comment = $this->getComment($node);
30       if ($comment) {
31         $comment .= "\n\n";
32       }
33       $this->setComment($node, $comment . $this->configuration['note']);
34     }
35
36     $this->target->save();
37   }
38
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();
44     }
45     else {
46       return '';
47     }
48   }
49
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));
54     }
55     else {
56       LineCommentBlockNode::create($comment_text)->insertBefore($node->getStatement());
57     }
58   }
59
60   /**
61    * Returns if a node supports doc comments by importing DocCommentTrait
62    * anywhere in its lineage.
63    *
64    * @param \Pharborist\NodeInterface $node
65    *
66    * @return boolean
67    */
68   protected function supportsDocComments(NodeInterface $node) {
69     return $this->usesTrait('Pharborist\DocCommentTrait', $node);
70   }
71
72 }