voyager-admin/voyager

View on GitHub
src/Http/Controllers/MediaController.php

Summary

Maintainability
D
2 days
Test Coverage
F
0%

File MediaController.php has 369 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Voyager\Admin\Http\Controllers;

use Illuminate\Http\Request;
Severity: Minor
Found in src/Http/Controllers/MediaController.php - About 4 hrs to fix

    Method listFiles has 93 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function listFiles(Request $request)
        {
            $hide_thumbnails = VoyagerFacade::setting('media.hide-thumbnails', true);
            $thumbnail_names = $this->getThumbnailDefinitions()->pluck('name')->transform(function ($name) {
                return '_'.$name;
    Severity: Major
    Found in src/Http/Controllers/MediaController.php - About 3 hrs to fix

      Method processUploadedFile has 68 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function processUploadedFile($file, $path)
          {
              $name = '';
              $count = 0;
              $thumbnails = 0;
      Severity: Major
      Found in src/Http/Controllers/MediaController.php - About 2 hrs to fix

        Method getThumbnailDefinitions has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function getThumbnailDefinitions()
            {
                $thumbs = collect(VoyagerFacade::setting('thumbnails'));
        
                return $thumbs->map(function ($thumb, $name) {
        Severity: Minor
        Found in src/Http/Controllers/MediaController.php - About 1 hr to fix

          Function processUploadedFile has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function processUploadedFile($file, $path)
              {
                  $name = '';
                  $count = 0;
                  $thumbnails = 0;
          Severity: Minor
          Found in src/Http/Controllers/MediaController.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 delete has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              public function delete(Request $request)
              {
                  $storage = Storage::disk($this->disk);
                  $files_deleted = 0;
                  $dirs_deleted = 0;
          Severity: Minor
          Found in src/Http/Controllers/MediaController.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 download has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function download(Request $request)
              {
                  $files = $request->get('files', []);
                  if (count($files) == 1 && $files[0]['file']['type'] !== 'directory') {
                      return Storage::disk($this->disk)->get($files[0]['file']['relative_path'].$files[0]['file']['name']);
          Severity: Minor
          Found in src/Http/Controllers/MediaController.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

          Avoid too many return statements within this method.
          Open

                  return response()->json($files->values());
          Severity: Major
          Found in src/Http/Controllers/MediaController.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return !Str::contains(Str::lower($file['file']['url']), $exclude);
            Severity: Major
            Found in src/Http/Controllers/MediaController.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return $file;
              Severity: Major
              Found in src/Http/Controllers/MediaController.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return $file['file']['type'] == 'directory' ? 0 : 99999999;
                Severity: Major
                Found in src/Http/Controllers/MediaController.php - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status