]> BookStack Code Mirror - bookstack/blobdiff - app/Actions/CommentRepo.php
feat(PageContent): set unique ids on nested headers
[bookstack] / app / Actions / CommentRepo.php
index 13a83e7fdd247064983c64928811b49db2ba4ca1..8061c4542e7a86fe2f4d080677e1b1300bfd7372 100644 (file)
@@ -1,21 +1,21 @@
-<?php namespace BookStack\Actions;
+<?php
+
+namespace BookStack\Actions;
 
 use BookStack\Entities\Models\Entity;
-use League\CommonMark\CommonMarkConverter;
 use BookStack\Facades\Activity as ActivityService;
+use League\CommonMark\CommonMarkConverter;
 
 /**
- * Class CommentRepo
+ * Class CommentRepo.
  */
 class CommentRepo
 {
-
     /**
-     * @var Comment $comment
+     * @var Comment
      */
     protected $comment;
 
-
     public function __construct(Comment $comment)
     {
         $this->comment = $comment;
@@ -46,6 +46,7 @@ class CommentRepo
 
         $entity->comments()->save($comment);
         ActivityService::addForEntity($entity, ActivityType::COMMENTED_ON);
+
         return $comment;
     }
 
@@ -58,25 +59,26 @@ class CommentRepo
         $comment->text = $text;
         $comment->html = $this->commentToHtml($text);
         $comment->save();
+
         return $comment;
     }
 
     /**
      * Delete a comment from the system.
      */
-    public function delete(Comment $comment)
+    public function delete(Comment $comment): void
     {
         $comment->delete();
     }
 
     /**
-     * Convert the given comment markdown text to HTML.
+     * Convert the given comment Markdown to HTML.
      */
     public function commentToHtml(string $commentText): string
     {
         $converter = new CommonMarkConverter([
-            'html_input' => 'strip',
-            'max_nesting_level' => 10,
+            'html_input'         => 'strip',
+            'max_nesting_level'  => 10,
             'allow_unsafe_links' => false,
         ]);
 
@@ -88,7 +90,9 @@ class CommentRepo
      */
     protected function getNextLocalId(Entity $entity): int
     {
-        $comments = $entity->comments(false)->orderBy('local_id', 'desc')->first();
-        return ($comments->local_id ?? 0) + 1;
+        /** @var Comment $comment */
+        $comment = $entity->comments(false)->orderBy('local_id', 'desc')->first();
+
+        return ($comment->local_id ?? 0) + 1;
     }
 }