BookStackApp/BookStack

View on GitHub
app/Uploads/ImageService.php

Summary

Maintainability
B
5 hrs
Test Coverage

Method saveNew has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function saveNew(string $imageName, string $imageData, string $type, int $uploadedTo = 0): Image
    {
        $disk = $this->storage->getDisk($type);
        $secureUploads = setting('app-secure-images');
        $fileName = $this->storage->cleanImageFileName($imageName);
Severity: Minor
Found in app/Uploads/ImageService.php - About 1 hr to fix

    Method checkUserHasAccessToRelationOfImageAtPath has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function checkUserHasAccessToRelationOfImageAtPath(string $path): bool
        {
            if (str_starts_with($path, 'uploads/images/')) {
                $path = substr($path, 15);
            }
    Severity: Minor
    Found in app/Uploads/ImageService.php - About 1 hr to fix

      Method saveNewFromUpload has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

              UploadedFile $uploadedFile,
              string $type,
              int $uploadedTo = 0,
              int $resizeWidth = null,
              int $resizeHeight = null,
      Severity: Minor
      Found in app/Uploads/ImageService.php - About 45 mins to fix

        Function imageUrlToBase64 has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            public function imageUrlToBase64(string $url): ?string
            {
                $storagePath = $this->storage->urlToPath($url);
                if (empty($url) || is_null($storagePath)) {
                    return null;
        Severity: Minor
        Found in app/Uploads/ImageService.php - About 45 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

        Function checkUserHasAccessToRelationOfImageAtPath has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function checkUserHasAccessToRelationOfImageAtPath(string $path): bool
            {
                if (str_starts_with($path, 'uploads/images/')) {
                    $path = substr($path, 15);
                }
        Severity: Minor
        Found in app/Uploads/ImageService.php - About 35 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 false;
        Severity: Major
        Found in app/Uploads/ImageService.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                      return $this->queries->shelves->visibleForList()->where('id', '=', $image->uploaded_to)->exists();
          Severity: Major
          Found in app/Uploads/ImageService.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return $this->queries->books->visibleForList()->where('id', '=', $image->uploaded_to)->exists();
            Severity: Major
            Found in app/Uploads/ImageService.php - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status