pixelfed/pixelfed

View on GitHub
app/Http/Controllers/DiscoverController.php

Summary

Maintainability
F
3 days
Test Coverage

File DiscoverController.php has 370 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace App\Http\Controllers;

use App\Hashtag;
Severity: Minor
Found in app/Http/Controllers/DiscoverController.php - About 4 hrs to fix

    Method getHashtags has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getHashtags(Request $request)
        {
            $user = $request->user();
            abort_if(! config('instance.discover.tags.is_public') && ! $user, 403);
    
    
    Severity: Major
    Found in app/Http/Controllers/DiscoverController.php - About 2 hrs to fix

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

          public function trendingApi(Request $request)
          {
              abort_if(config('instance.discover.public') == false && ! $request->user(), 403);
      
              $this->validate($request, [
      Severity: Minor
      Found in app/Http/Controllers/DiscoverController.php - About 1 hr to fix

        Method myMemories has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function myMemories(Request $request)
            {
                abort_if(! $request->user(), 404);
                $pid = $request->user()->profile_id;
                abort_if(! $this->config()['memories']['enabled'], 404);
        Severity: Minor
        Found in app/Http/Controllers/DiscoverController.php - About 1 hr to fix

          Method discoverAccountsPopular has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function discoverAccountsPopular(Request $request)
              {
                  abort_if(! $request->user(), 403);
          
                  $pid = $request->user()->profile_id;
          Severity: Minor
          Found in app/Http/Controllers/DiscoverController.php - About 1 hr to fix

            Method updateFeatures has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function updateFeatures(Request $request)
                {
                    abort_if(! $request->user(), 404);
                    abort_if(! $request->user()->is_admin, 404);
                    $pid = $request->user()->profile_id;
            Severity: Minor
            Found in app/Http/Controllers/DiscoverController.php - About 1 hr to fix

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

                  public function getHashtags(Request $request)
                  {
                      $user = $request->user();
                      abort_if(! config('instance.discover.tags.is_public') && ! $user, 403);
              
              
              Severity: Minor
              Found in app/Http/Controllers/DiscoverController.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 collect(StatusHashtagService::get($hashtag->id, $page, $end))
                                  ->filter(function ($tag) {
                                      if (! $tag['status']['local']) {
                                          return false;
                                      }
              Severity: Major
              Found in app/Http/Controllers/DiscoverController.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return ! in_array($profile['id'], $filters);
                Severity: Major
                Found in app/Http/Controllers/DiscoverController.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return $res;
                  Severity: Major
                  Found in app/Http/Controllers/DiscoverController.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return response()->json($ids, 200, [], JSON_UNESCAPED_SLASHES);
                    Severity: Major
                    Found in app/Http/Controllers/DiscoverController.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return ! in_array($profile['id'], $asf);
                      Severity: Major
                      Found in app/Http/Controllers/DiscoverController.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return $res;
                        Severity: Major
                        Found in app/Http/Controllers/DiscoverController.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return $res;
                          Severity: Major
                          Found in app/Http/Controllers/DiscoverController.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                    return false;
                            Severity: Major
                            Found in app/Http/Controllers/DiscoverController.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return ! FollowerService::follows($pid, $profile['id'], true);
                              Severity: Major
                              Found in app/Http/Controllers/DiscoverController.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                    return true;
                                Severity: Major
                                Found in app/Http/Controllers/DiscoverController.php - About 30 mins to fix

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

                                          $ids = $ids->map(function ($profile) {
                                              return AccountService::get($profile->id, true);
                                          })
                                              ->filter(function ($profile) {
                                                  return $profile && isset($profile['id'], $profile['locked']) && ! $profile['locked'];
                                  Severity: Major
                                  Found in app/Http/Controllers/DiscoverController.php and 1 other location - About 7 hrs to fix
                                  app/Http/Controllers/Api/ApiV1Controller.php on lines 4080..4099

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

                                  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

                                  There are no issues that match your filters.

                                  Category
                                  Status