pixelfed/pixelfed

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

Summary

Maintainability
F
3 days
Test Coverage

File StatusController.php has 397 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace App\Http\Controllers;

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

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

        public function show(Request $request, $username, $id)
        {
            // redirect authed users to Metro 2.0
            if ($request->user()) {
                // unless they force static view
    Severity: Minor
    Found in app/Http/Controllers/StatusController.php - About 2 hrs 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 delete has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function delete(Request $request)
        {
            $this->authCheck();
    
            $this->validate($request, [
    Severity: Major
    Found in app/Http/Controllers/StatusController.php - About 2 hrs to fix

      Method showEmbed has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function showEmbed(Request $request, $username, int $id)
          {
              if (! (bool) config_cache('instance.embed.post')) {
                  $res = view('status.embed-removed');
      
      
      Severity: Major
      Found in app/Http/Controllers/StatusController.php - About 2 hrs to fix

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

            public function show(Request $request, $username, $id)
            {
                // redirect authed users to Metro 2.0
                if ($request->user()) {
                    // unless they force static view
        Severity: Minor
        Found in app/Http/Controllers/StatusController.php - About 1 hr to fix

          Function mimeTypeCheck has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function mimeTypeCheck($mimes)
              {
                  $allowed = explode(',', config_cache('pixelfed.media_types'));
                  $count = count($mimes);
                  $photos = 0;
          Severity: Minor
          Found in app/Http/Controllers/StatusController.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 storeShare has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function storeShare(Request $request)
              {
                  $this->authCheck();
          
                  $this->validate($request, [
          Severity: Minor
          Found in app/Http/Controllers/StatusController.php - About 1 hr to fix

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

                public static function mimeTypeCheck($mimes)
                {
                    $allowed = explode(',', config_cache('pixelfed.media_types'));
                    $count = count($mimes);
                    $photos = 0;
            Severity: Minor
            Found in app/Http/Controllers/StatusController.php - About 1 hr to fix

              Function delete has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function delete(Request $request)
                  {
                      $this->authCheck();
              
                      $this->validate($request, [
              Severity: Minor
              Found in app/Http/Controllers/StatusController.php - About 55 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 showEmbed has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function showEmbed(Request $request, $username, int $id)
                  {
                      if (! (bool) config_cache('instance.embed.post')) {
                          $res = view('status.embed-removed');
              
              
              Severity: Minor
              Found in app/Http/Controllers/StatusController.php - About 55 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 showObject has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function showObject(Request $request, $username, int $id)
                  {
                      $user = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
              
                      if ($user->status != null) {
              Severity: Minor
              Found in app/Http/Controllers/StatusController.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

              Consider simplifying this complex logical expression.
              Open

                      if (
                          ! $status ||
                          ! isset($status['account'], $status['account']['id']) ||
                          intval($status['account']['id']) !== intval($profile['id']) ||
                          $status['sensitive'] ||
              Severity: Major
              Found in app/Http/Controllers/StatusController.php - About 40 mins to fix

                Avoid too many return statements within this method.
                Open

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

                  Avoid too many return statements within this method.
                  Open

                              return response($content)->header('X-Frame-Options', 'ALLOWALL');
                  Severity: Major
                  Found in app/Http/Controllers/StatusController.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return 'photo:video:album';
                    Severity: Major
                    Found in app/Http/Controllers/StatusController.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

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

                        Avoid too many return statements within this method.
                        Open

                                return view($template, compact('user', 'status'));
                        Severity: Major
                        Found in app/Http/Controllers/StatusController.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return true;
                          Severity: Major
                          Found in app/Http/Controllers/StatusController.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/StatusController.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return 'text';
                              Severity: Major
                              Found in app/Http/Controllers/StatusController.php - About 30 mins to fix

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

                                    public function storeView(Request $request)
                                    {
                                        abort_if(! $request->user(), 403);
                                
                                        $views = $request->input('_v');
                                Severity: Minor
                                Found in app/Http/Controllers/StatusController.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

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

                                    public function storeShare(Request $request)
                                    {
                                        $this->authCheck();
                                
                                        $this->validate($request, [
                                Severity: Minor
                                Found in app/Http/Controllers/StatusController.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

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

                                            if ($parent && ($parent->profile_id == $user->profile_id) || ($status->profile_id == $user->profile_id) || $user->is_admin) {
                                                Cache::forget('_api:statuses:recent_9:'.$status->profile_id);
                                                Cache::forget('profile:status_count:'.$status->profile_id);
                                                Cache::forget('profile:embed:'.$status->profile_id);
                                                StatusService::del($status->id, true);
                                Severity: Major
                                Found in app/Http/Controllers/StatusController.php and 1 other location - About 1 hr to fix
                                app/Http/Controllers/StatusController.php on lines 273..280

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

                                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

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

                                        } elseif ($status->profile_id == $user->profile_id || $user->is_admin == true) {
                                            Cache::forget('_api:statuses:recent_9:'.$status->profile_id);
                                            Cache::forget('profile:status_count:'.$status->profile_id);
                                            Cache::forget('profile:embed:'.$status->profile_id);
                                            StatusService::del($status->id, true);
                                Severity: Major
                                Found in app/Http/Controllers/StatusController.php and 1 other location - About 1 hr to fix
                                app/Http/Controllers/StatusController.php on lines 265..272

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

                                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