]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Tools/SlugGenerator.php
respective book and chapter structure added.
[bookstack] / app / Entities / Tools / SlugGenerator.php
index 4501279f2a31d3c367e6a2ce34be9f1afedaf639..5df300bb04c8f14c135979f99d0b325272c78806 100644 (file)
@@ -1,15 +1,17 @@
-<?php namespace BookStack\Entities\Tools;
+<?php
 
+namespace BookStack\Entities\Tools;
+
+use BookStack\App\Model;
+use BookStack\App\Sluggable;
 use BookStack\Entities\Models\BookChild;
-use BookStack\Interfaces\Sluggable;
 use Illuminate\Support\Str;
 
 class SlugGenerator
 {
-
     /**
      * Generate a fresh slug for the given entity.
-     * The slug will generated so it does not conflict within the same parent item.
+     * The slug will be generated so that it doesn't conflict within the same parent item.
      */
     public function generate(Sluggable $model): string
     {
@@ -17,6 +19,7 @@ class SlugGenerator
         while ($this->slugInUse($slug, $model)) {
             $slug .= '-' . Str::random(3);
         }
+
         return $slug;
     }
 
@@ -26,15 +29,18 @@ class SlugGenerator
     protected function formatNameAsSlug(string $name): string
     {
         $slug = Str::slug($name);
-        if ($slug === "") {
+        if ($slug === '') {
             $slug = substr(md5(rand(1, 500)), 0, 5);
         }
+
         return $slug;
     }
 
     /**
      * Check if a slug is already in-use for this
      * type of model within the same parent.
+     *
+     * @param Sluggable&Model $model
      */
     protected function slugInUse(string $slug, Sluggable $model): bool
     {