BookStackApp/BookStack

View on GitHub

Showing 288 of 288 total issues

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

    public function chapterToPdf(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 49..64

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

Function parsePlural has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    parsePlural(translation, count, replacements) {
        const splitText = translation.split('|');
        const exactCountRegex = /^{([0-9]+)}/;
        const rangeRegex = /^\[([0-9]+),([0-9*]+)]/;
        let result = null;
Severity: Minor
Found in resources/js/services/translations.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

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

    public function findVisibleBySlugsOrFail(string $bookSlug, string $pageSlug): Page
    {
        /** @var ?Page $page */
        $page = $this->start()->with('book')
            ->scopes('visible')
Severity: Major
Found in app/Entities/Queries/PageQueries.php and 1 other location - About 2 hrs to fix
app/Entities/Queries/ChapterQueries.php on lines 31..48

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 122.

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

    public function findVisibleBySlugsOrFail(string $bookSlug, string $chapterSlug): Chapter
    {
        /** @var ?Chapter $chapter */
        $chapter = $this->start()
            ->scopes('visible')
Severity: Major
Found in app/Entities/Queries/ChapterQueries.php and 1 other location - About 2 hrs to fix
app/Entities/Queries/PageQueries.php on lines 42..58

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 122.

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

File TrashCan.php has 251 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace BookStack\Entities\Tools;

use BookStack\Entities\EntityProvider;
Severity: Minor
Found in app/Entities/Tools/TrashCan.php - About 2 hrs to fix

    Consider simplifying this complex logical expression.
    Open

            if ($model instanceof Page) {
                $parentPermission = ($currentParent instanceof Chapter) ? 'chapter-update' : 'book-update';
                $hasCurrentParentPermission = userCan($parentPermission, $currentParent);
    
                // This needs to check if there was an intended chapter location in the original sort map
    Severity: Critical
    Found in app/Entities/Tools/BookContents.php - About 2 hrs to fix

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

              const config = buildForInput({
                  language: this.wysiwygLanguage,
                  containerElement: this.formInput,
                  darkMode: document.documentElement.classList.contains('dark-mode'),
                  textDirection: this.wysiwygTextDirection,
      Severity: Major
      Found in resources/js/components/page-comments.js and 1 other location - About 2 hrs to fix
      resources/js/components/page-comment.js on lines 65..72

      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 75.

      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

              const config = buildForInput({
                  language: this.wysiwygLanguage,
                  containerElement: this.input,
                  darkMode: document.documentElement.classList.contains('dark-mode'),
                  textDirection: this.wysiwygTextDirection,
      Severity: Major
      Found in resources/js/components/page-comment.js and 1 other location - About 2 hrs to fix
      resources/js/components/page-comments.js on lines 126..133

      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 75.

      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

      Method processAccessTokenCallback has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function processAccessTokenCallback(OidcAccessToken $accessToken, OidcProviderSettings $settings): User
          {
              $idTokenText = $accessToken->getIdToken();
              $idToken = new OidcIdToken(
                  $idTokenText,
      Severity: Minor
      Found in app/Access/Oidc/OidcService.php - About 1 hr to fix

        Function init has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export async function init(editor) {
            const Code = await window.importVersioned('code');
        
            /**
             * @param {ViewUpdate} v
        Severity: Minor
        Found in resources/js/markdown/codemirror.js - About 1 hr to fix

          Method build has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function build(): array
              {
                  // Note, while we attempt to use the user's preference here, the request to the manifest
                  // does not start a session, so we won't have current user context.
                  // This was attempted but removed since manifest calls could affect user session
          Severity: Minor
          Found in app/App/PwaManifestBuilder.php - About 1 hr to fix

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

            export function register(editor) {
                // Headers
                for (let i = 1; i < 5; i++) {
                    editor.shortcuts.add(`meta+${i}`, '', ['FormatBlock', false, `h${i + 1}`]);
                }
            Severity: Minor
            Found in resources/js/wysiwyg/shortcuts.js - About 1 hr to fix

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

                  up: {
                      active(elem, parent) {
                          return !(elem.previousElementSibling === null && !parent);
                      },
                      run(elem, parent) {
              Severity: Major
              Found in resources/js/components/book-sort.js and 1 other location - About 1 hr to fix
              resources/js/components/book-sort.js on lines 56..64

              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 72.

              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

                  down: {
                      active(elem, parent) {
                          return !(elem.nextElementSibling === null && !parent);
                      },
                      run(elem, parent) {
              Severity: Major
              Found in resources/js/components/book-sort.js and 1 other location - About 1 hr to fix
              resources/js/components/book-sort.js on lines 47..55

              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 72.

              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

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

                  public function index(Request $request)
                  {
                      $this->checkPermission('settings-manage');
                      $this->checkPermission('users-manage');
              
              
              Severity: Minor
              Found in app/Activity/Controllers/AuditLogController.php - About 1 hr to fix

                Function show has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    show(event = null) {
                        this.hideAll();
                
                        this.menu.style.display = 'block';
                        this.menu.classList.add('anim', 'menuIn');
                Severity: Minor
                Found in resources/js/components/dropdown.js - About 1 hr to fix

                  Function containHtml has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                  Open

                      protected function containHtml(string $htmlContent): string
                      {
                          $imageTagsOutput = [];
                          preg_match_all("/\<img.*?src\=(\'|\")(.*?)(\'|\").*?\>/i", $htmlContent, $imageTagsOutput);
                  
                  
                  Severity: Minor
                  Found in app/Entities/Tools/ExportFormatter.php - About 1 hr 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 drop has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function drop(editor, options, event) {
                      const {dom} = editor;
                      const rng = window.tinymce.dom.RangeUtils.getCaretRangeFromPoint(
                          event.clientX,
                          event.clientY,
                  Severity: Minor
                  Found in resources/js/wysiwyg/drop-paste-handling.js - About 1 hr to fix

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

                        prev_book: {
                            active(elem, parent, book) {
                                return book.previousElementSibling !== null;
                            },
                            run(elem, parent, book) {
                    Severity: Major
                    Found in resources/js/components/book-sort.js and 1 other location - About 1 hr to fix
                    resources/js/components/book-sort.js on lines 65..73

                    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 69.

                    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

                        next_book: {
                            active(elem, parent, book) {
                                return book.nextElementSibling !== null;
                            },
                            run(elem, parent, book) {
                    Severity: Major
                    Found in resources/js/components/book-sort.js and 1 other location - About 1 hr to fix
                    resources/js/components/book-sort.js on lines 74..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 69.

                    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