pixelfed/pixelfed

View on GitHub
app/Http/Controllers/Admin/AdminReportController.php

Summary

Maintainability
F
1 wk
Test Coverage

File AdminReportController.php has 1282 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace App\Http\Controllers\Admin;

use App\AccountInterstitial;
Severity: Major
Found in app/Http/Controllers/Admin/AdminReportController.php - About 3 days to fix

    Function reportsApiRemoteHandle has a Cognitive Complexity of 65 (exceeds 5 allowed). Consider refactoring.
    Open

        public function reportsApiRemoteHandle(Request $request)
        {
            $this->validate($request, [
                'id' => 'required|exists:remote_reports,id',
                'action' => 'required|in:mark-read,cw-posts,unlist-posts,delete-posts,private-posts,mark-all-read-by-domain,mark-all-read-by-username,cw-all-posts,private-all-posts,unlist-all-posts'
    Severity: Minor
    Found in app/Http/Controllers/Admin/AdminReportController.php - About 1 day 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 reportsHandleProfileAction has 198 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function reportsHandleProfileAction($report, $action)
        {
            switch ($action) {
                case 'ignore':
                    Report::whereObjectId($report->object_id)
    Severity: Major
    Found in app/Http/Controllers/Admin/AdminReportController.php - About 7 hrs to fix

      Method reportsApiRemoteHandle has 157 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function reportsApiRemoteHandle(Request $request)
          {
              $this->validate($request, [
                  'id' => 'required|exists:remote_reports,id',
                  'action' => 'required|in:mark-read,cw-posts,unlist-posts,delete-posts,private-posts,mark-all-read-by-domain,mark-all-read-by-username,cw-all-posts,private-all-posts,unlist-all-posts'
      Severity: Major
      Found in app/Http/Controllers/Admin/AdminReportController.php - About 6 hrs to fix

        Method updateSpam has 124 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function updateSpam(Request $request, $id)
            {
                $this->validate($request, [
                    'action' => 'required|in:dismiss,approve,dismiss-all,approve-all,delete-account,mark-spammer',
                ]);
        Severity: Major
        Found in app/Http/Controllers/Admin/AdminReportController.php - About 4 hrs to fix

          Method reportsHandleStatusAction has 123 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function reportsHandleStatusAction($report, $action)
              {
                  switch ($action) {
                      case 'ignore':
                          Report::whereObjectId($report->object_id)
          Severity: Major
          Found in app/Http/Controllers/Admin/AdminReportController.php - About 4 hrs to fix

            Function reportsHandleProfileAction has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function reportsHandleProfileAction($report, $action)
                {
                    switch ($action) {
                        case 'ignore':
                            Report::whereObjectId($report->object_id)
            Severity: Minor
            Found in app/Http/Controllers/Admin/AdminReportController.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 reportsHandleSpamAction has 92 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function reportsHandleSpamAction($appeal, $action)
                {
                    $meta = json_decode($appeal->meta);
            
                    if ($action == 'mark-read') {
            Severity: Major
            Found in app/Http/Controllers/Admin/AdminReportController.php - About 3 hrs to fix

              Method spam has 84 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function spam(Request $request)
                  {
                      $this->validate($request, [
                          'tab' => 'sometimes|in:home,not-spam,spam,settings,custom,exemptions',
                      ]);
              Severity: Major
              Found in app/Http/Controllers/Admin/AdminReportController.php - About 3 hrs to fix

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

                    protected function reportsHandleStoryAction($report, $action)
                    {
                        switch ($action) {
                            case 'ignore':
                                Report::whereObjectId($report->object_id)
                Severity: Major
                Found in app/Http/Controllers/Admin/AdminReportController.php - About 2 hrs to fix

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

                      protected function reportsHandleStatusAction($report, $action)
                      {
                          switch ($action) {
                              case 'ignore':
                                  Report::whereObjectId($report->object_id)
                  Severity: Minor
                  Found in app/Http/Controllers/Admin/AdminReportController.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 fixUncategorizedSpam has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function fixUncategorizedSpam(Request $request)
                      {
                          if (Cache::get('admin-dash:reports:spam-sync-active')) {
                              return redirect('/i/admin/reports/autospam');
                          }
                  Severity: Minor
                  Found in app/Http/Controllers/Admin/AdminReportController.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 handleReportAction has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function handleReportAction(Report $report, $action)
                      {
                          $item = $report->reported();
                          $report->admin_seen = Carbon::now();
                  
                  
                  Severity: Minor
                  Found in app/Http/Controllers/Admin/AdminReportController.php - About 1 hr to fix

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

                        public function reports(Request $request)
                        {
                            $filter = $request->input('filter') == 'closed' ? 'closed' : 'open';
                            $page = $request->input('page') ?? 1;
                    
                    
                    Severity: Minor
                    Found in app/Http/Controllers/Admin/AdminReportController.php - About 1 hr to fix

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

                          public function updateAppeal(Request $request, $id)
                          {
                              $this->validate($request, [
                                  'action' => 'required|in:dismiss,approve',
                              ]);
                      Severity: Minor
                      Found in app/Http/Controllers/Admin/AdminReportController.php - About 1 hr to fix

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

                            public function fixUncategorizedSpam(Request $request)
                            {
                                if (Cache::get('admin-dash:reports:spam-sync-active')) {
                                    return redirect('/i/admin/reports/autospam');
                                }
                        Severity: Minor
                        Found in app/Http/Controllers/Admin/AdminReportController.php - About 1 hr to fix

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

                              public function reportsHandleSpamAction($appeal, $action)
                              {
                                  $meta = json_decode($appeal->meta);
                          
                                  if ($action == 'mark-read') {
                          Severity: Minor
                          Found in app/Http/Controllers/Admin/AdminReportController.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 spam has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function spam(Request $request)
                              {
                                  $this->validate($request, [
                                      'tab' => 'sometimes|in:home,not-spam,spam,settings,custom,exemptions',
                                  ]);
                          Severity: Minor
                          Found in app/Http/Controllers/Admin/AdminReportController.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 reportMailVerifications has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public function reportMailVerifications(Request $request)
                              {
                                  $ids = Redis::smembers('email:manual');
                                  $ignored = Redis::smembers('email:manual-ignored');
                                  $reports = [];
                          Severity: Minor
                          Found in app/Http/Controllers/Admin/AdminReportController.php - About 1 hr to fix

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

                                public function updateSpam(Request $request, $id)
                                {
                                    $this->validate($request, [
                                        'action' => 'required|in:dismiss,approve,dismiss-all,approve-all,delete-account,mark-spammer',
                                    ]);
                            Severity: Minor
                            Found in app/Http/Controllers/Admin/AdminReportController.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 handleReportAction has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public function handleReportAction(Report $report, $action)
                                {
                                    $item = $report->reported();
                                    $report->admin_seen = Carbon::now();
                            
                            
                            Severity: Minor
                            Found in app/Http/Controllers/Admin/AdminReportController.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 $mins.' min(s)';
                            Severity: Major
                            Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                                          return $q->whereNull('appeal_handled_at');
                              Severity: Major
                              Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                    return $res && isset($res['id']);
                                Severity: Major
                                Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                              return $q->whereIsSpam(false);
                                  Severity: Major
                                  Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

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

                                      Avoid too many return statements within this method.
                                      Open

                                                      return floor($mins / 60).' hour(s)';
                                      Severity: Major
                                      Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                    return AccountInterstitial::selectRaw('*, count(id) as counter')
                                                        ->whereType('post.autospam')
                                                        ->groupBy('user_id')
                                                        ->get()
                                                        ->avg('counter');
                                        Severity: Major
                                        Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

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

                                            Avoid too many return statements within this method.
                                            Open

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

                                              Avoid too many return statements within this method.
                                              Open

                                                              return 0;
                                              Severity: Major
                                              Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                            return floor($mins / 60 / 24).' day(s)';
                                                Severity: Major
                                                Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

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

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                                return $q->whereIsSpam(true);
                                                    Severity: Major
                                                    Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                              return view('admin.reports.spam', compact('tab', 'appeals', 'openCount', 'monthlyCount', 'totalCount', 'avgCount', 'avgOpen', 'uncategorized'));
                                                      Severity: Major
                                                      Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                return view('admin.reports.home', compact('reports', 'ai', 'spam', 'mailVerifications'));
                                                        Severity: Major
                                                        Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

                                                                                  return [200];
                                                          Severity: Major
                                                          Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                    return view('admin.reports.mail_verification', compact('reports', 'ignored'));
                                                            Severity: Major
                                                            Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                              return [200];
                                                              Severity: Major
                                                              Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                                    return [200];
                                                                Severity: Major
                                                                Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                                  Avoid too many return statements within this method.
                                                                  Open

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

                                                                    Avoid too many return statements within this method.
                                                                    Open

                                                                                    return [200];
                                                                    Severity: Major
                                                                    Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                                      Avoid too many return statements within this method.
                                                                      Open

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

                                                                        Avoid too many return statements within this method.
                                                                        Open

                                                                                            return [200];
                                                                        Severity: Major
                                                                        Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                                          Avoid too many return statements within this method.
                                                                          Open

                                                                                          return [200];
                                                                          Severity: Major
                                                                          Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                                            Avoid too many return statements within this method.
                                                                            Open

                                                                                            return [200];
                                                                            Severity: Major
                                                                            Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                                              Avoid too many return statements within this method.
                                                                              Open

                                                                                              return [200];
                                                                              Severity: Major
                                                                              Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                                                Avoid too many return statements within this method.
                                                                                Open

                                                                                                        return [200];
                                                                                Severity: Major
                                                                                Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                                                  Avoid too many return statements within this method.
                                                                                  Open

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

                                                                                    Avoid too many return statements within this method.
                                                                                    Open

                                                                                                    return [200];
                                                                                    Severity: Major
                                                                                    Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                                                      Avoid too many return statements within this method.
                                                                                      Open

                                                                                                              return [200];
                                                                                      Severity: Major
                                                                                      Found in app/Http/Controllers/Admin/AdminReportController.php - About 30 mins to fix

                                                                                        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/Admin/AdminReportController.php and 1 other location - About 6 hrs to fix
                                                                                        app/Http/Controllers/Api/AdminApiController.php on lines 570..588

                                                                                        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

                                                                                                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/Admin/AdminReportController.php and 1 other location - About 1 hr to fix
                                                                                        app/Http/Controllers/Api/AdminApiController.php on lines 173..183

                                                                                        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