]> BookStack Code Mirror - bookstack/commitdiff
Applied StyleCI changes
authorDan Brown <redacted>
Sat, 13 Nov 2021 13:28:17 +0000 (13:28 +0000)
committerDan Brown <redacted>
Sat, 13 Nov 2021 13:28:17 +0000 (13:28 +0000)
app/Entities/Tools/SearchIndex.php
app/Entities/Tools/SearchOptions.php
app/Entities/Tools/SearchResultsFormatter.php
app/Entities/Tools/SearchRunner.php
app/Http/Controllers/SearchController.php
tests/Entity/EntitySearchTest.php

index 3c4b5a247c75fa0f0f4096849f3cf06051e453da..702606be9640f0d528fc6d332b1102cb656610fa 100644 (file)
@@ -175,7 +175,7 @@ class SearchIndex
         $names = [];
         $values = [];
 
-        foreach($tags as $tag) {
+        foreach ($tags as $tag) {
             $names[] = $tag->name;
             $values[] = $tag->value;
         }
@@ -233,17 +233,16 @@ class SearchIndex
         $entityType = $entity->getMorphClass();
         foreach ($mergedScoreMap as $term => $score) {
             $dataArray[] = [
-                'term' => $term,
-                'score' => $score,
+                'term'        => $term,
+                'score'       => $score,
                 'entity_type' => $entityType,
-                'entity_id' => $entityId,
+                'entity_id'   => $entityId,
             ];
         }
 
         return $dataArray;
     }
 
-
     /**
      * For the given term data arrays, Merge their contents by term
      * while combining any scores.
index 9f1b9742d5a4ca773b8dccc16426528d76b7ad4b..99271058e2306412d10d14b76a888c8ecd70d371 100644 (file)
@@ -124,7 +124,6 @@ class SearchOptions
         return $terms;
     }
 
-
     /**
      * Parse a standard search term string into individual search terms and
      * extract any exact terms searches to be made.
@@ -136,7 +135,7 @@ class SearchOptions
         $terms = explode(' ', $termString);
         $indexDelimiters = SearchIndex::$delimiters;
         $parsed = [
-            'terms' => [],
+            'terms'  => [],
             'exacts' => [],
         ];
 
index 1ddee5830c53456ddf7e1c092d8359eb06ad02a5..2898520abddd5c7349abd01db7cdf6b862576411 100644 (file)
@@ -8,10 +8,10 @@ use Illuminate\Support\HtmlString;
 
 class SearchResultsFormatter
 {
-
     /**
      * For the given array of entities, Prepare the models to be shown in search result
      * output. This sets a series of additional attributes.
+     *
      * @param Entity[] $results
      */
     public function format(array $results, SearchOptions $options): void
@@ -32,7 +32,7 @@ class SearchResultsFormatter
         $terms = array_merge($options->exacts, $options->searches);
 
         $originalContentByNewAttribute = [
-            'preview_name' => $entity->name,
+            'preview_name'    => $entity->name,
             'preview_content' => $textContent,
         ];
 
@@ -49,7 +49,8 @@ class SearchResultsFormatter
 
     /**
      * Highlight tags which match the given terms.
-     * @param Tag[] $tags
+     *
+     * @param Tag[]    $tags
      * @param string[] $terms
      */
     protected function highlightTagsContainingTerms(array $tags, array $terms): void
@@ -104,6 +105,7 @@ class SearchResultsFormatter
      * adjacent or where they overlap.
      *
      * @param array<int, int> $matchPositions
+     *
      * @return array<int, int>
      */
     protected function sortAndMergeMatchPositions(array $matchPositions): array
@@ -118,7 +120,7 @@ class SearchResultsFormatter
                 $mergedRefs[$start] = $end;
                 $lastStart = $start;
                 $lastEnd = $end;
-            } else if ($end > $lastEnd) {
+            } elseif ($end > $lastEnd) {
                 $mergedRefs[$lastStart] = $end;
                 $lastEnd = $end;
             }
@@ -194,7 +196,7 @@ class SearchResultsFormatter
         $firstStart = $firstStart ?: 0;
         if ($remainder > 10 && $firstStart !== 0) {
             $padStart = max(0, $firstStart - $remainder);
-            $content = ($padStart === 0 ? '' : '...') . e(substr($originalText, $padStart,  $firstStart - $padStart)) . substr($content, 4);
+            $content = ($padStart === 0 ? '' : '...') . e(substr($originalText, $padStart, $firstStart - $padStart)) . substr($content, 4);
         }
 
         // Add ellipsis if we're not at the end
@@ -204,5 +206,4 @@ class SearchResultsFormatter
 
         return $content;
     }
-
-}
\ No newline at end of file
+}
index afe5e9f191a4b92d8895319f6d1f82266bef48b0..f6da871f49be5af2b7c664b938413c70ca302459 100644 (file)
@@ -141,13 +141,13 @@ class SearchRunner
         $relations = ['tags'];
 
         if ($entityModelInstance instanceof BookChild) {
-            $relations['book'] = function(BelongsTo $query) {
+            $relations['book'] = function (BelongsTo $query) {
                 $query->visible();
             };
         }
 
         if ($entityModelInstance instanceof Page) {
-            $relations['chapter'] = function(BelongsTo $query) {
+            $relations['chapter'] = function (BelongsTo $query) {
                 $query->visible();
             };
         }
@@ -310,7 +310,7 @@ class SearchRunner
         if (empty($termCounts)) {
             return [];
         }
-        
+
         $multipliers = [];
         $max = max(array_values($termCounts));
 
index 040c04ece0aa0125ac860ae43bfed6e174781070..6b2be5a2d77515433a2fbb4d78deedebb8bf1bda 100644 (file)
@@ -14,7 +14,8 @@ class SearchController extends Controller
     protected $searchRunner;
     protected $entityContextManager;
 
-    public function __construct(SearchRunner $searchRunner) {
+    public function __construct(SearchRunner $searchRunner)
+    {
         $this->searchRunner = $searchRunner;
     }
 
index 95d47462983dd1c1032466c6e0019d5a59301c86..f935f13317b9d5c6abd49a26dfe1e285ad07f4cf 100644 (file)
@@ -7,7 +7,6 @@ use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Bookshelf;
 use BookStack\Entities\Models\Chapter;
 use BookStack\Entities\Models\Page;
-use BookStack\Entities\Models\SearchTerm;
 use Tests\TestCase;
 
 class EntitySearchTest extends TestCase
@@ -410,5 +409,4 @@ class EntitySearchTest extends TestCase
         $search->assertSee('My &lt;cool&gt; <strong>TestPageContent</strong>', false);
         $search->assertSee('My supercool &lt;great&gt; <strong>TestPageContent</strong> page', false);
     }
-
 }