BookStackApp/BookStack

View on GitHub
app/Entities/Tools/PageContent.php

Summary

Maintainability
B
5 hrs
Test Coverage

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 updateIdsRecursively has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function updateIdsRecursively(DOMNode $element, int $depth, array &$idMap, array &$changeMap): void
        {
            /* @var DOMNode $child */
            foreach ($element->childNodes as $child) {
                if ($child instanceof DOMElement && ($depth === 0 || in_array($child->nodeName, ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']) || $child->getAttribute('id'))) {
    Severity: Minor
    Found in app/Entities/Tools/PageContent.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 extractBase64ImagesFromMarkdown has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function extractBase64ImagesFromMarkdown(string $markdown, User $updater): string
        {
            $matches = [];
            $contentLength = strlen($markdown);
            $replacements = [];
    Severity: Minor
    Found in app/Entities/Tools/PageContent.php - About 55 mins 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

    Avoid too many return statements within this method.
    Open

                return '';
    Severity: Major
    Found in app/Entities/Tools/PageContent.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return $image->url;
      Severity: Major
      Found in app/Entities/Tools/PageContent.php - About 30 mins to fix

        Function base64ImageUriToUploadedImageUrl has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function base64ImageUriToUploadedImageUrl(string $uri, User $updater): string
            {
                $imageRepo = app()->make(ImageRepo::class);
                $imageInfo = $this->parseBase64ImageUri($uri);
        
        
        Severity: Minor
        Found in app/Entities/Tools/PageContent.php - About 25 mins 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

        There are no issues that match your filters.

        Category
        Status