BookStackApp/BookStack

View on GitHub

Showing 288 of 288 total issues

File book-sort.js has 301 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Sortable, {MultiDrag} from 'sortablejs';
import {Component} from './component';
import {htmlToDom} from '../services/dom';

// Auto sort control
Severity: Minor
Found in resources/js/components/book-sort.js - About 3 hrs to fix

    User has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class User extends Model implements AuthenticatableContract, CanResetPasswordContract, Loggable, Sluggable
    {
        use HasFactory;
        use Authenticatable;
        use CanResetPassword;
    Severity: Minor
    Found in app/Users/Models/User.php - About 3 hrs to fix

      File PageController.php has 293 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      namespace BookStack\Entities\Controllers;
      
      use BookStack\Activity\Models\View;
      Severity: Minor
      Found in app/Entities/Controllers/PageController.php - About 3 hrs to fix

        File config.js has 291 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import {register as registerShortcuts} from './shortcuts';
        import {listen as listenForCommonEvents} from './common-events';
        import {scrollToQueryString} from './scrolling';
        import {listenForDragAndPaste} from './drop-paste-handling';
        import {getPrimaryToolbar, registerAdditionalToolbars} from './toolbars';
        Severity: Minor
        Found in resources/js/wysiwyg/config.js - About 3 hrs to fix

          Function register has 73 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function register(editor) {
              // Tasklist UI buttons
              editor.ui.registry.addIcon('tasklist', '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M22,8c0-0.55-0.45-1-1-1h-7c-0.55,0-1,0.45-1,1s0.45,1,1,1h7C21.55,9,22,8.55,22,8z M13,16c0,0.55,0.45,1,1,1h7 c0.55,0,1-0.45,1-1c0-0.55-0.45-1-1-1h-7C13.45,15,13,15.45,13,16z M10.47,4.63c0.39,0.39,0.39,1.02,0,1.41l-4.23,4.25 c-0.39,0.39-1.02,0.39-1.42,0L2.7,8.16c-0.39-0.39-0.39-1.02,0-1.41c0.39-0.39,1.02-0.39,1.41,0l1.42,1.42l3.54-3.54 C9.45,4.25,10.09,4.25,10.47,4.63z M10.48,12.64c0.39,0.39,0.39,1.02,0,1.41l-4.23,4.25c-0.39,0.39-1.02,0.39-1.42,0L2.7,16.16 c-0.39-0.39-0.39-1.02,0-1.41s1.02-0.39,1.41,0l1.42,1.42l3.54-3.54C9.45,12.25,10.09,12.25,10.48,12.64L10.48,12.64z"/></svg>');
              editor.ui.registry.addToggleButton('tasklist', {
                  tooltip: 'Task list',
          Severity: Major
          Found in resources/js/wysiwyg/plugins-tasklist.js - About 2 hrs to fix

            Function register has 70 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function register(editor) {
                editor.ui.registry.addIcon('details', '<svg width="24" height="24"><path d="M8.2 9a.5.5 0 0 0-.4.8l4 5.6a.5.5 0 0 0 .8 0l4-5.6a.5.5 0 0 0-.4-.8ZM20.122 18.151h-16c-.964 0-.934 2.7 0 2.7h16c1.139 0 1.173-2.7 0-2.7zM20.122 3.042h-16c-.964 0-.934 2.7 0 2.7h16c1.139 0 1.173-2.7 0-2.7z"/></svg>');
                editor.ui.registry.addIcon('togglefold', '<svg height="24"  width="24"><path d="M8.12 19.3c.39.39 1.02.39 1.41 0L12 16.83l2.47 2.47c.39.39 1.02.39 1.41 0 .39-.39.39-1.02 0-1.41l-3.17-3.17c-.39-.39-1.02-.39-1.41 0l-3.17 3.17c-.4.38-.4 1.02-.01 1.41zm7.76-14.6c-.39-.39-1.02-.39-1.41 0L12 7.17 9.53 4.7c-.39-.39-1.02-.39-1.41 0-.39.39-.39 1.03 0 1.42l3.17 3.17c.39.39 1.02.39 1.41 0l3.17-3.17c.4-.39.4-1.03.01-1.42z"/></svg>');
                editor.ui.registry.addIcon('togglelabel', '<svg height="18" width="18" viewBox="0 0 24 24"><path d="M21.41,11.41l-8.83-8.83C12.21,2.21,11.7,2,11.17,2H4C2.9,2,2,2.9,2,4v7.17c0,0.53,0.21,1.04,0.59,1.41l8.83,8.83 c0.78,0.78,2.05,0.78,2.83,0l7.17-7.17C22.2,13.46,22.2,12.2,21.41,11.41z M6.5,8C5.67,8,5,7.33,5,6.5S5.67,5,6.5,5S8,5.67,8,6.5 S7.33,8,6.5,8z"/></svg>');
            
            
            Severity: Major
            Found in resources/js/wysiwyg/plugins-details.js - About 2 hrs to fix

              Function register has 68 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function register(editor) {
                  editor.ui.registry.addIcon('tableclearformatting', '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" viewBox="0 0 24 24"><path d="M15.53088 4.64727v-.82364c0-.453-.37063-.82363-.82363-.82363H4.82363C4.37063 3 4 3.37064 4 3.82363v3.29454c0 .453.37064.82364.82363.82364h9.88362c.453 0 .82363-.37064.82363-.82364v-.82363h.82364v3.29454H8.11817v7.4127c0 .453.37064.82364.82364.82364h1.64727c.453 0 .82363-.37064.82363-.82364v-5.76544h6.58907V4.64727Z"/><path d="m18.42672 19.51563-1.54687-1.54688-1.54688 1.54688c-.26751.2675-.70124.2675-.96875 0-.26751-.26752-.26751-.70124 0-.96876L15.9111 17l-1.54688-1.54688c-.26751-.2675-.26751-.70123 0-.96875.26751-.2675.70124-.2675.96875 0l1.54688 1.54688 1.54687-1.54688c.26751-.2675.70124-.2675.96875 0 .26751.26752.26751.70124 0 .96875L17.8486 17l1.54687 1.54688c.26751.2675.26751.70123 0 .96874-.26751.26752-.70124.26752-.96875 0z"/></svg>');
              
                  const tableFirstRowContextSpec = {
                      items: ' | tablerowheader',
              Severity: Major
              Found in resources/js/wysiwyg/plugins-table-additions.js - About 2 hrs to fix

                Method index has 67 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function index(
                        Request $request,
                        ActivityQueries $activities,
                        QueryRecentlyViewed $recentlyViewed,
                        QueryTopFavourites $topFavourites,
                Severity: Major
                Found in app/App/HomeController.php - About 2 hrs to fix

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                      try {
                          const img = await DrawIO.upload(pngData, options.pageId);
                          pageEditor.undoManager.transact(() => {
                              pageEditor.dom.setAttrib(id, 'src', img.url);
                              pageEditor.dom.setAttrib(wrapId, 'drawio-diagram', img.id);
                  Severity: Major
                  Found in resources/js/wysiwyg/plugin-drawio.js and 1 other location - About 2 hrs to fix
                  resources/js/wysiwyg/plugin-drawio.js on lines 52..61

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 88.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                          try {
                              const img = await DrawIO.upload(pngData, options.pageId);
                              pageEditor.undoManager.transact(() => {
                                  pageEditor.dom.setAttrib(imgElem, 'src', img.url);
                                  pageEditor.dom.setAttrib(currentNode, 'drawio-diagram', img.id);
                  Severity: Major
                  Found in resources/js/wysiwyg/plugin-drawio.js and 1 other location - About 2 hrs to fix
                  resources/js/wysiwyg/plugin-drawio.js on lines 72..82

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 88.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Function defineCodeBlockCustomElement has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function defineCodeBlockCustomElement(editor) {
                      const doc = editor.getDoc();
                      const win = doc.defaultView;
                  
                      class CodeBlockElement extends win.HTMLElement {
                  Severity: Minor
                  Found in resources/js/wysiwyg/plugin-codeeditor.js - About 2 hrs to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function buildForEditor has 64 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export function buildForEditor(options) {
                      // Set language
                      window.tinymce.addI18n(options.language, options.translationMap);
                  
                      // BookStack Version
                  Severity: Major
                  Found in resources/js/wysiwyg/config.js - About 2 hrs to fix

                    Method formatTextUsingMatchPositions has 63 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        protected function formatTextUsingMatchPositions(array $matchPositions, string $originalText, int $targetLength): string
                        {
                            $maxEnd = mb_strlen($originalText);
                            $fetchAll = ($targetLength === 0);
                            $contextLength = ($fetchAll ? 0 : 32);
                    Severity: Major
                    Found in app/Search/SearchResultsFormatter.php - About 2 hrs to fix

                      File LdapService.php has 271 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      <?php
                      
                      namespace BookStack\Access;
                      
                      use BookStack\Exceptions\JsonDebugException;
                      Severity: Minor
                      Found in app/Access/LdapService.php - About 2 hrs to fix

                        Function formatTextUsingMatchPositions has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                        Open

                            protected function formatTextUsingMatchPositions(array $matchPositions, string $originalText, int $targetLength): string
                            {
                                $maxEnd = mb_strlen($originalText);
                                $fetchAll = ($targetLength === 0);
                                $contextLength = ($fetchAll ? 0 : 32);
                        Severity: Minor
                        Found in app/Search/SearchResultsFormatter.php - About 2 hrs to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        File web.php has 267 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        <?php
                        
                        use BookStack\Access\Controllers as AccessControllers;
                        use BookStack\Activity\Controllers as ActivityControllers;
                        use BookStack\Api\ApiDocsController;
                        Severity: Minor
                        Found in routes/web.php - About 2 hrs to fix

                          Function setupListeners has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              setupListeners() {
                                  // Filter tab click
                                  onSelect(this.filterTabs, e => {
                                      this.resetAll();
                                      this.filter = e.target.dataset.filter;
                          Severity: Major
                          Found in resources/js/components/image-manager.js - About 2 hrs to fix

                            File PageContent.php has 261 lines of code (exceeds 250 allowed). Consider refactoring.
                            Open

                            <?php
                            
                            namespace BookStack\Entities\Tools;
                            
                            use BookStack\Entities\Models\Page;
                            Severity: Minor
                            Found in app/Entities/Tools/PageContent.php - About 2 hrs to fix

                              Function isSortChangePermissible has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  protected function isSortChangePermissible(BookSortMapItem $sortMapItem, BookChild $model, ?Entity $currentParent, ?Entity $newBook, ?Entity $newChapter): bool
                                  {
                                      // Stop if we can't see the current parent or new book.
                                      if (!$currentParent || !$newBook) {
                                          return false;
                              Severity: Minor
                              Found in app/Entities/Tools/BookContents.php - About 2 hrs to fix

                              Cognitive Complexity

                              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                              A method's cognitive complexity is based on a few simple rules:

                              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                              • Code is considered more complex for each "break in the linear flow of the code"
                              • Code is considered more complex when "flow breaking structures are nested"

                              Further reading

                              Similar blocks of code found in 2 locations. Consider refactoring.
                              Open

                                  public function chapterToContainedHtml(Chapter $chapter): string
                                  {
                                      $pages = $chapter->getVisiblePages();
                                      $pages->each(function ($page) {
                                          $page->html = (new PageContent($page))->render();
                              Severity: Major
                              Found in app/Entities/Tools/ExportFormatter.php and 1 other location - About 2 hrs to fix
                              app/Entities/Tools/ExportFormatter.php on lines 108..124

                              Duplicated Code

                              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                              Tuning

                              This issue has a mass of 124.

                              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                              Refactorings

                              Further Reading

                              Severity
                              Category
                              Status
                              Source
                              Language