pixelfed/pixelfed

View on GitHub
app/Services/MediaStorageService.php

Summary

Maintainability
C
1 day
Test Coverage

Method fetchAvatar has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function fetchAvatar($avatar, $local = false, $skipRecentCheck = false)
    {
        $queue = random_int(1, 15) > 5 ? 'mmo' : 'low';
        $url = $avatar->remote_url;
        $driver = $local ? 'local' : config('filesystems.cloud');
Severity: Major
Found in app/Services/MediaStorageService.php - About 2 hrs to fix

    Method remoteToCloud has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function remoteToCloud($media)
        {
            $url = $media->remote_url;
    
            if (! Helpers::validateUrl($url)) {
    Severity: Major
    Found in app/Services/MediaStorageService.php - About 2 hrs to fix

      File MediaStorageService.php has 260 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      namespace App\Services;
      
      use App\Jobs\AvatarPipeline\AvatarStorageCleanup;
      Severity: Minor
      Found in app/Services/MediaStorageService.php - About 2 hrs to fix

        Function fetchAvatar has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function fetchAvatar($avatar, $local = false, $skipRecentCheck = false)
            {
                $queue = random_int(1, 15) > 5 ? 'mmo' : 'low';
                $url = $avatar->remote_url;
                $driver = $local ? 'local' : config('filesystems.cloud');
        Severity: Minor
        Found in app/Services/MediaStorageService.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

        Method cloudMove has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function cloudMove($media)
            {
                if (! Storage::exists($media->media_path)) {
                    return 'invalid file';
                }
        Severity: Minor
        Found in app/Services/MediaStorageService.php - About 1 hr to fix

          Function remoteToCloud has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function remoteToCloud($media)
              {
                  $url = $media->remote_url;
          
                  if (! Helpers::validateUrl($url)) {
          Severity: Minor
          Found in app/Services/MediaStorageService.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

          Avoid too many return statements within this method.
          Open

                      return;
          Severity: Major
          Found in app/Services/MediaStorageService.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return;
            Severity: Major
            Found in app/Services/MediaStorageService.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return;
              Severity: Major
              Found in app/Services/MediaStorageService.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return [
                            'length' => $len,
                            'mime' => $mime,
                        ];
                Severity: Major
                Found in app/Services/MediaStorageService.php - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status