pixelfed/pixelfed

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

Summary

Maintainability
D
2 days
Test Coverage

File ProfileController.php has 314 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace App\Http\Controllers;

use App\AccountInterstitial;
Severity: Minor
Found in app/Http/Controllers/ProfileController.php - About 3 hrs to fix

    Method showAtomFeed has 63 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function showAtomFeed(Request $request, $user)
        {
            abort_if(! config('federation.atom.enabled'), 404);
    
            $pid = AccountService::usernameToId($user);
    Severity: Major
    Found in app/Http/Controllers/ProfileController.php - About 2 hrs to fix

      Method buildProfile has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function buildProfile(Request $request, $user)
          {
              $username = $user->username;
              $loggedIn = Auth::check();
              $isPrivate = false;
      Severity: Major
      Found in app/Http/Controllers/ProfileController.php - About 2 hrs to fix

        Function show has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            public function show(Request $request, $username)
            {
                if ($request->wantsJson() && (bool) config_cache('federation.activitypub.enabled')) {
                    $user = $this->getCachedUser($username, true);
                    abort_if(! $user, 404, 'Not found');
        Severity: Minor
        Found in app/Http/Controllers/ProfileController.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 buildProfile has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function buildProfile(Request $request, $user)
            {
                $username = $user->username;
                $loggedIn = Auth::check();
                $isPrivate = false;
        Severity: Minor
        Found in app/Http/Controllers/ProfileController.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 embed has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function embed(Request $request, $username)
            {
                $res = view('profile.embed-removed');
        
                if (! (bool) config_cache('instance.embed.profile')) {
        Severity: Minor
        Found in app/Http/Controllers/ProfileController.php - About 1 hr to fix

          Method show has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function show(Request $request, $username)
              {
                  if ($request->wantsJson() && (bool) config_cache('federation.activitypub.enabled')) {
                      $user = $this->getCachedUser($username, true);
                      abort_if(! $user, 404, 'Not found');
          Severity: Minor
          Found in app/Http/Controllers/ProfileController.php - About 1 hr to fix

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

                public function embed(Request $request, $username)
                {
                    $res = view('profile.embed-removed');
            
                    if (! (bool) config_cache('instance.embed.profile')) {
            Severity: Minor
            Found in app/Http/Controllers/ProfileController.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 response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
            Severity: Major
            Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return view('profile.show', compact('profile', 'settings'));
              Severity: Major
              Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
                Severity: Major
                Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return $settings->show_atom;
                  Severity: Major
                  Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                        return StatusService::get($status->id, true);
                    Severity: Major
                    Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return response()
                                  ->view('atom.user',
                                      [
                                          'profile' => $profile,
                                          'items' => $data['items'],
                      Severity: Major
                      Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

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

                          Avoid too many return statements within this method.
                          Open

                                      return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
                          Severity: Major
                          Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

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

                              Avoid too many return statements within this method.
                              Open

                                          return redirect('/login');
                              Severity: Major
                              Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return compact('items', 'permalink', 'headers');
                                Severity: Major
                                Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return $this->buildProfile($request, $user);
                                  Severity: Major
                                  Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return view('profile.private', compact('user', 'is_following', 'requested'));
                                    Severity: Major
                                    Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                          return $status &&
                                                              isset($status['account']) &&
                                                              isset($status['media_attachments']) &&
                                                              count($status['media_attachments']);
                                      Severity: Major
                                      Found in app/Http/Controllers/ProfileController.php - About 30 mins to fix

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

                                            public function showAtomFeed(Request $request, $user)
                                            {
                                                abort_if(! config('federation.atom.enabled'), 404);
                                        
                                                $pid = AccountService::usernameToId($user);
                                        Severity: Minor
                                        Found in app/Http/Controllers/ProfileController.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