bizley/yii2-podium

View on GitHub
src/controllers/ForumController.php

Summary

Maintainability
F
4 days
Test Coverage

File ForumController.php has 516 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace bizley\podium\controllers;

use bizley\podium\db\Query;
Severity: Major
Found in src/controllers/ForumController.php - About 1 day to fix

    Function actionAdvancedSearch has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
    Open

        public function actionAdvancedSearch()
        {
            $dataProvider = null;
            $list = [];
    
    Severity: Minor
    Found in src/controllers/ForumController.php - About 6 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 actionPoll has 90 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function actionPoll()
        {
            if (!Yii::$app->request->isAjax) {
                return $this->redirect(['forum/index']);
            }
    Severity: Major
    Found in src/controllers/ForumController.php - About 3 hrs to fix

      The class ForumController has an overall complexity of 88 which is very high. The configured complexity threshold is 50.
      Open

      class ForumController extends ForumPostController
      {
          /**
           * @inheritdoc
           */
      Severity: Minor
      Found in src/controllers/ForumController.php by phpmd

      The class ForumController has 15 public methods. Consider refactoring ForumController to keep number of public methods under 10.
      Open

      class ForumController extends ForumPostController
      {
          /**
           * @inheritdoc
           */
      Severity: Minor
      Found in src/controllers/ForumController.php by phpmd

      TooManyPublicMethods

      Since: 0.1

      A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

      By default it ignores methods starting with 'get' or 'set'.

      Example

      Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

      Function actionPoll has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public function actionPoll()
          {
              if (!Yii::$app->request->isAjax) {
                  return $this->redirect(['forum/index']);
              }
      Severity: Minor
      Found in src/controllers/ForumController.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 actionEditpoll has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function actionEditpoll($cid = null, $fid = null, $tid = null, $pid = null)
          {
              $poll = Poll::find()->joinWith('thread')->where([
                  Poll::tableName() . '.id' => $pid,
                  Poll::tableName() . '.thread_id' => $tid,
      Severity: Major
      Found in src/controllers/ForumController.php - About 2 hrs to fix

        Method behaviors has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function behaviors()
            {
                return [
                    'access' => [
                        'class' => AccessControl::className(),
        Severity: Major
        Found in src/controllers/ForumController.php - About 2 hrs to fix

          Method actionAdvancedSearch has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function actionAdvancedSearch()
              {
                  $dataProvider = null;
                  $list = [];
          
          Severity: Minor
          Found in src/controllers/ForumController.php - About 2 hrs to fix

            Method actionDeletepoll has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function actionDeletepoll($cid = null, $fid = null, $tid = null, $pid = null)
                {
                    $poll = Poll::find()->joinWith('thread')->where([
                        Poll::tableName() . '.id' => $pid,
                        Poll::tableName() . '.thread_id' => $tid,
            Severity: Minor
            Found in src/controllers/ForumController.php - About 1 hr to fix

              Function actionEditpoll has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function actionEditpoll($cid = null, $fid = null, $tid = null, $pid = null)
                  {
                      $poll = Poll::find()->joinWith('thread')->where([
                          Poll::tableName() . '.id' => $pid,
                          Poll::tableName() . '.thread_id' => $tid,
              Severity: Minor
              Found in src/controllers/ForumController.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 actionShow has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function actionShow($id = null)
                  {
                      if (!is_numeric($id) || $id < 1) {
                          $this->error(Yii::t('podium/flash', 'Sorry! We can not find the post you are looking for.'));
                          return $this->redirect(['forum/index']);
              Severity: Minor
              Found in src/controllers/ForumController.php - About 1 hr to fix

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

                    public function actionDeletepoll($cid = null, $fid = null, $tid = null, $pid = null)
                    {
                        $poll = Poll::find()->joinWith('thread')->where([
                            Poll::tableName() . '.id' => $pid,
                            Poll::tableName() . '.thread_id' => $tid,
                Severity: Minor
                Found in src/controllers/ForumController.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 actionForum has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function actionForum($cid = null, $id = null, $slug = null, $toggle = null)
                    {
                        $filters = Yii::$app->session->get('forum-filters');
                        if (in_array(strtolower($toggle), ['new', 'edit', 'hot', 'pin', 'lock', 'all'])) {
                            if (strtolower($toggle) == 'all') {
                Severity: Minor
                Found in src/controllers/ForumController.php - About 1 hr to fix

                  Avoid too many return statements within this method.
                  Open

                          return $this->render('deletepoll', ['model' => $poll]);
                  Severity: Major
                  Found in src/controllers/ForumController.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                        return Json::encode($data);
                    Severity: Major
                    Found in src/controllers/ForumController.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return Json::encode($data);
                      Severity: Major
                      Found in src/controllers/ForumController.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return $this->render('editpoll', ['model' => $poll]);
                        Severity: Major
                        Found in src/controllers/ForumController.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return Json::encode($data);
                          Severity: Major
                          Found in src/controllers/ForumController.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return Json::encode($data);
                            Severity: Major
                            Found in src/controllers/ForumController.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                                  return $this->redirect(['forum/thread',
                                                      'cid' => $poll->thread->forum->category->id,
                                                      'fid' => $poll->thread->forum->id,
                                                      'id' => $poll->thread->id,
                                                      'slug' => $poll->thread->slug
                              Severity: Major
                              Found in src/controllers/ForumController.php - About 30 mins to fix

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

                                    public function actionForum($cid = null, $id = null, $slug = null, $toggle = null)
                                    {
                                        $filters = Yii::$app->session->get('forum-filters');
                                        if (in_array(strtolower($toggle), ['new', 'edit', 'hot', 'pin', 'lock', 'all'])) {
                                            if (strtolower($toggle) == 'all') {
                                Severity: Minor
                                Found in src/controllers/ForumController.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

                                The method actionEditpoll() has an NPath complexity of 288. The configured NPath complexity threshold is 200.
                                Open

                                    public function actionEditpoll($cid = null, $fid = null, $tid = null, $pid = null)
                                    {
                                        $poll = Poll::find()->joinWith('thread')->where([
                                            Poll::tableName() . '.id' => $pid,
                                            Poll::tableName() . '.thread_id' => $tid,
                                Severity: Minor
                                Found in src/controllers/ForumController.php by phpmd

                                NPathComplexity

                                Since: 0.1

                                The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                Example

                                class Foo {
                                    function bar() {
                                        // lots of complicated code
                                    }
                                }

                                Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                The method actionPoll() has 101 lines of code. Current threshold is set to 100. Avoid really long methods.
                                Open

                                    public function actionPoll()
                                    {
                                        if (!Yii::$app->request->isAjax) {
                                            return $this->redirect(['forum/index']);
                                        }
                                Severity: Minor
                                Found in src/controllers/ForumController.php by phpmd

                                The method actionPoll() has an NPath complexity of 396. The configured NPath complexity threshold is 200.
                                Open

                                    public function actionPoll()
                                    {
                                        if (!Yii::$app->request->isAjax) {
                                            return $this->redirect(['forum/index']);
                                        }
                                Severity: Minor
                                Found in src/controllers/ForumController.php by phpmd

                                NPathComplexity

                                Since: 0.1

                                The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                Example

                                class Foo {
                                    function bar() {
                                        // lots of complicated code
                                    }
                                }

                                Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                The method actionAdvancedSearch() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
                                Open

                                    public function actionAdvancedSearch()
                                    {
                                        $dataProvider = null;
                                        $list = [];
                                
                                Severity: Minor
                                Found in src/controllers/ForumController.php by phpmd

                                CyclomaticComplexity

                                Since: 0.1

                                Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                Example

                                // Cyclomatic Complexity = 11
                                class Foo {
                                1   public function example() {
                                2       if ($a == $b) {
                                3           if ($a1 == $b1) {
                                                fiddle();
                                4           } elseif ($a2 == $b2) {
                                                fiddle();
                                            } else {
                                                fiddle();
                                            }
                                5       } elseif ($c == $d) {
                                6           while ($c == $d) {
                                                fiddle();
                                            }
                                7        } elseif ($e == $f) {
                                8           for ($n = 0; $n < $h; $n++) {
                                                fiddle();
                                            }
                                        } else {
                                            switch ($z) {
                                9               case 1:
                                                    fiddle();
                                                    break;
                                10              case 2:
                                                    fiddle();
                                                    break;
                                11              case 3:
                                                    fiddle();
                                                    break;
                                                default:
                                                    fiddle();
                                                    break;
                                            }
                                        }
                                    }
                                }

                                Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                The method actionEditpoll() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
                                Open

                                    public function actionEditpoll($cid = null, $fid = null, $tid = null, $pid = null)
                                    {
                                        $poll = Poll::find()->joinWith('thread')->where([
                                            Poll::tableName() . '.id' => $pid,
                                            Poll::tableName() . '.thread_id' => $tid,
                                Severity: Minor
                                Found in src/controllers/ForumController.php by phpmd

                                CyclomaticComplexity

                                Since: 0.1

                                Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                Example

                                // Cyclomatic Complexity = 11
                                class Foo {
                                1   public function example() {
                                2       if ($a == $b) {
                                3           if ($a1 == $b1) {
                                                fiddle();
                                4           } elseif ($a2 == $b2) {
                                                fiddle();
                                            } else {
                                                fiddle();
                                            }
                                5       } elseif ($c == $d) {
                                6           while ($c == $d) {
                                                fiddle();
                                            }
                                7        } elseif ($e == $f) {
                                8           for ($n = 0; $n < $h; $n++) {
                                                fiddle();
                                            }
                                        } else {
                                            switch ($z) {
                                9               case 1:
                                                    fiddle();
                                                    break;
                                10              case 2:
                                                    fiddle();
                                                    break;
                                11              case 3:
                                                    fiddle();
                                                    break;
                                                default:
                                                    fiddle();
                                                    break;
                                            }
                                        }
                                    }
                                }

                                Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                The method actionPoll() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
                                Open

                                    public function actionPoll()
                                    {
                                        if (!Yii::$app->request->isAjax) {
                                            return $this->redirect(['forum/index']);
                                        }
                                Severity: Minor
                                Found in src/controllers/ForumController.php by phpmd

                                CyclomaticComplexity

                                Since: 0.1

                                Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                Example

                                // Cyclomatic Complexity = 11
                                class Foo {
                                1   public function example() {
                                2       if ($a == $b) {
                                3           if ($a1 == $b1) {
                                                fiddle();
                                4           } elseif ($a2 == $b2) {
                                                fiddle();
                                            } else {
                                                fiddle();
                                            }
                                5       } elseif ($c == $d) {
                                6           while ($c == $d) {
                                                fiddle();
                                            }
                                7        } elseif ($e == $f) {
                                8           for ($n = 0; $n < $h; $n++) {
                                                fiddle();
                                            }
                                        } else {
                                            switch ($z) {
                                9               case 1:
                                                    fiddle();
                                                    break;
                                10              case 2:
                                                    fiddle();
                                                    break;
                                11              case 3:
                                                    fiddle();
                                                    break;
                                                default:
                                                    fiddle();
                                                    break;
                                            }
                                        }
                                    }
                                }

                                Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                The class ForumController has a coupling between objects value of 17. Consider to reduce the number of dependencies under 13.
                                Open

                                class ForumController extends ForumPostController
                                {
                                    /**
                                     * @inheritdoc
                                     */
                                Severity: Minor
                                Found in src/controllers/ForumController.php by phpmd

                                CouplingBetweenObjects

                                Since: 1.1.0

                                A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

                                Example

                                class Foo {
                                    /**
                                     * @var \foo\bar\X
                                     */
                                    private $x = null;
                                
                                    /**
                                     * @var \foo\bar\Y
                                     */
                                    private $y = null;
                                
                                    /**
                                     * @var \foo\bar\Z
                                     */
                                    private $z = null;
                                
                                    public function setFoo(\Foo $foo) {}
                                    public function setBar(\Bar $bar) {}
                                    public function setBaz(\Baz $baz) {}
                                
                                    /**
                                     * @return \SplObjectStorage
                                     * @throws \OutOfRangeException
                                     * @throws \InvalidArgumentException
                                     * @throws \ErrorException
                                     */
                                    public function process(\Iterator $it) {}
                                
                                    // ...
                                }

                                Source https://phpmd.org/rules/design.html#couplingbetweenobjects

                                There are no issues that match your filters.

                                Category
                                Status