pixelfed/pixelfed

View on GitHub
app/Http/Controllers/Api/AdminApiController.php

Summary

Maintainability
F
1 wk
Test Coverage

File AdminApiController.php has 726 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
Severity: Major
Found in app/Http/Controllers/Api/AdminApiController.php - About 1 day to fix

    Method userAdminAction has 154 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function userAdminAction(Request $request)
        {
            abort_if(!$request->user() || !$request->user()->token(), 404);
    
            abort_unless($request->user()->is_admin == 1, 404);
    Severity: Major
    Found in app/Http/Controllers/Api/AdminApiController.php - About 6 hrs to fix

      Method autospamHandle has 126 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function autospamHandle(Request $request)
          {
              abort_if(!$request->user() || !$request->user()->token(), 404);
      
              abort_unless($request->user()->is_admin == 1, 404);
      Severity: Major
      Found in app/Http/Controllers/Api/AdminApiController.php - About 5 hrs to fix

        Function userAdminAction has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
        Open

            public function userAdminAction(Request $request)
            {
                abort_if(!$request->user() || !$request->user()->token(), 404);
        
                abort_unless($request->user()->is_admin == 1, 404);
        Severity: Minor
        Found in app/Http/Controllers/Api/AdminApiController.php - About 4 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 updateConfiguration has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function updateConfiguration(Request $request)
            {
                abort_if(!$request->user() || !$request->user()->token(), 404);
        
                abort_unless($request->user()->is_admin == 1, 404);
        Severity: Minor
        Found in app/Http/Controllers/Api/AdminApiController.php - About 2 hrs to fix

          Method getAllStats has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getAllStats(Request $request)
              {
                  abort_if(!$request->user() || !$request->user()->token(), 404);
          
                  abort_unless($request->user()->is_admin === 1, 404);
          Severity: Minor
          Found in app/Http/Controllers/Api/AdminApiController.php - About 1 hr to fix

            Method modReportHandle has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function modReportHandle(Request $request)
                {
                    abort_if(!$request->user() || !$request->user()->token(), 404);
            
                    abort_unless($request->user()->is_admin == 1, 404);
            Severity: Minor
            Found in app/Http/Controllers/Api/AdminApiController.php - About 1 hr to fix

              Method modReports has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function modReports(Request $request)
                  {
                      abort_if(!$request->user() || !$request->user()->token(), 404);
              
                      abort_unless($request->user()->is_admin == 1, 404);
              Severity: Minor
              Found in app/Http/Controllers/Api/AdminApiController.php - About 1 hr to fix

                Method getConfiguration has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function getConfiguration(Request $request)
                    {
                        abort_if(!$request->user() || !$request->user()->token(), 404);
                
                        abort_unless($request->user()->is_admin == 1, 404);
                Severity: Minor
                Found in app/Http/Controllers/Api/AdminApiController.php - About 1 hr to fix

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

                      public function instances(Request $request)
                      {
                          abort_if(!$request->user() || !$request->user()->token(), 404);
                  
                          abort_unless($request->user()->is_admin == 1, 404);
                  Severity: Minor
                  Found in app/Http/Controllers/Api/AdminApiController.php - About 1 hr to fix

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

                        public function autospam(Request $request)
                        {
                            abort_if(!$request->user() || !$request->user()->token(), 404);
                    
                            abort_unless($request->user()->is_admin == 1, 404);
                    Severity: Minor
                    Found in app/Http/Controllers/Api/AdminApiController.php - About 1 hr to fix

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

                          public function getUser(Request $request)
                          {
                              abort_if(!$request->user() || !$request->user()->token(), 404);
                      
                              abort_unless($request->user()->is_admin == 1, 404);
                      Severity: Minor
                      Found in app/Http/Controllers/Api/AdminApiController.php - About 1 hr to fix

                        Avoid too many return statements within this method.
                        Open

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

                          Avoid too many return statements within this method.
                          Open

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

                            Avoid too many return statements within this method.
                            Open

                                    return AdminInstance::collection($res);
                            Severity: Major
                            Found in app/Http/Controllers/Api/AdminApiController.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

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

                                Avoid too many return statements within this method.
                                Open

                                                return $query->orderBy('id', 'desc');
                                Severity: Major
                                Found in app/Http/Controllers/Api/AdminApiController.php - About 30 mins to fix

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

                                      public function modReportHandle(Request $request)
                                      {
                                          abort_if(!$request->user() || !$request->user()->token(), 404);
                                  
                                          abort_unless($request->user()->is_admin == 1, 404);
                                  Severity: Minor
                                  Found in app/Http/Controllers/Api/AdminApiController.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 autospamHandle has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public function autospamHandle(Request $request)
                                      {
                                          abort_if(!$request->user() || !$request->user()->token(), 404);
                                  
                                          abort_unless($request->user()->is_admin == 1, 404);
                                  Severity: Minor
                                  Found in app/Http/Controllers/Api/AdminApiController.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($profile->user_id) {
                                                  DB::table('oauth_access_tokens')->whereUserId($user->id)->delete();
                                                  DB::table('oauth_auth_codes')->whereUserId($user->id)->delete();
                                                  $user->email = $user->id;
                                                  $user->password = '';
                                  Severity: Major
                                  Found in app/Http/Controllers/Api/AdminApiController.php and 1 other location - About 6 hrs to fix
                                  app/Http/Controllers/Admin/AdminReportController.php on lines 1012..1030

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

                                  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

                                          return collect([
                                              [
                                                  'name' => 'ActivityPub Federation',
                                                  'description' => 'Enable activitypub federation support, compatible with Pixelfed, Mastodon and other platforms.',
                                                  'key' => 'federation.activitypub.enabled'
                                  Severity: Major
                                  Found in app/Http/Controllers/Api/AdminApiController.php and 1 other location - About 3 hrs to fix
                                  app/Http/Controllers/Api/AdminApiController.php on lines 430..464

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

                                  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

                                                  return collect([
                                              [
                                                  'name' => 'ActivityPub Federation',
                                                  'description' => 'Enable activitypub federation support, compatible with Pixelfed, Mastodon and other platforms.',
                                                  'key' => 'federation.activitypub.enabled'
                                  Severity: Major
                                  Found in app/Http/Controllers/Api/AdminApiController.php and 1 other location - About 3 hrs to fix
                                  app/Http/Controllers/Api/AdminApiController.php on lines 365..399

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

                                  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

                                          if($action == 'dismiss-all') {
                                              AccountInterstitial::whereType('post.autospam')
                                                  ->whereItemType('App\Status')
                                                  ->whereNull('appeal_handled_at')
                                                  ->whereUserId($appeal->user_id)
                                  Severity: Major
                                  Found in app/Http/Controllers/Api/AdminApiController.php and 1 other location - About 1 hr to fix
                                  app/Http/Controllers/Admin/AdminReportController.php on lines 330..341

                                  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

                                  Similar blocks of code found in 3 locations. Consider refactoring.
                                  Open

                                          } else if($action === 'cw') {
                                              ModLogService::boot()
                                                  ->objectUid($profile->id)
                                                  ->objectId($profile->id)
                                                  ->objectType('App\Profile::class')
                                  Severity: Minor
                                  Found in app/Http/Controllers/Api/AdminApiController.php and 2 other locations - About 30 mins to fix
                                  app/Http/Controllers/Api/AdminApiController.php on lines 619..680
                                  app/Http/Controllers/Api/AdminApiController.php on lines 649..680

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

                                  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

                                  Similar blocks of code found in 3 locations. Consider refactoring.
                                  Open

                                          } else if($action === 'unlisted') {
                                              ModLogService::boot()
                                                  ->objectUid($profile->id)
                                                  ->objectId($profile->id)
                                                  ->objectType('App\Profile::class')
                                  Severity: Minor
                                  Found in app/Http/Controllers/Api/AdminApiController.php and 2 other locations - About 30 mins to fix
                                  app/Http/Controllers/Api/AdminApiController.php on lines 634..680
                                  app/Http/Controllers/Api/AdminApiController.php on lines 649..680

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

                                  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

                                  Similar blocks of code found in 3 locations. Consider refactoring.
                                  Open

                                          } else if($action === 'no_autolink') {
                                              ModLogService::boot()
                                                  ->objectUid($profile->id)
                                                  ->objectId($profile->id)
                                                  ->objectType('App\Profile::class')
                                  Severity: Minor
                                  Found in app/Http/Controllers/Api/AdminApiController.php and 2 other locations - About 30 mins to fix
                                  app/Http/Controllers/Api/AdminApiController.php on lines 619..680
                                  app/Http/Controllers/Api/AdminApiController.php on lines 634..680

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

                                  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