core/modules/node/NodeController.php

Summary

Maintainability
D
2 days
Test Coverage

Method getNodeOptions has 238 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function getNodeOptions()
    {
        // show only
        $showOnlyWhenFields = [
            'title',
Severity: Major
Found in core/modules/node/NodeController.php - About 1 day to fix

    File NodeController.php has 300 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    class NodeController extends Ajde_Controller
    {
        /**
    Severity: Minor
    Found in core/modules/node/NodeController.php - About 3 hrs to fix

      Function getNodeOptions has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function getNodeOptions()
          {
              // show only
              $showOnlyWhenFields = [
                  'title',
      Severity: Minor
      Found in core/modules/node/NodeController.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 view has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function view()
          {
              // we want to display published nodes only
              if (!(UserModel::getLoggedIn() && UserModel::getLoggedIn()->isAdmin())) {
                  Ajde::app()->getRequest()->set('filterPublished', true);
      Severity: Minor
      Found in core/modules/node/NodeController.php - About 1 hr to fix

        Function view has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            public function view()
            {
                // we want to display published nodes only
                if (!(UserModel::getLoggedIn() && UserModel::getLoggedIn()->isAdmin())) {
                    Ajde::app()->getRequest()->set('filterPublished', true);
        Severity: Minor
        Found in core/modules/node/NodeController.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

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

            public static function getNodeOptions()
            {
                // show only
                $showOnlyWhenFields = [
                    'title',
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

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

        class NodeController extends Ajde_Controller
        {
            /**
             * @var NodeModel
             */
        Severity: Minor
        Found in core/modules/node/NodeController.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

        Missing class import via use statement (line '109', column '26').
        Open

                $nodetypes = new NodetypeCollection();
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        Missing class import via use statement (line '315', column '17').
        Open

                    new Ajde_Filter_Where('target', Ajde_Filter::FILTER_EQUALS, 'node'),
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        Missing class import via use statement (line '328', column '25').
        Open

                            new Ajde_Filter_Where('user.id', Ajde_Filter::FILTER_IN, new Ajde_Db_Function($subquery)),
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        Missing class import via use statement (line '328', column '82').
        Open

                            new Ajde_Filter_Where('user.id', Ajde_Filter::FILTER_IN, new Ajde_Db_Function($subquery)),
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        Missing class import via use statement (line '311', column '26').
        Open

                $decorator = new Ajde_Crud_Cms_Meta_Decorator();
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        Missing class import via use statement (line '36', column '21').
        Open

                $node = new NodeModel();
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        Missing class import via use statement (line '121', column '24').
        Open

                $options = new Ajde_Crud_Options();
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

        Source http://phpmd.org/rules/cleancode.html#MissingImport

        Avoid using static access to class 'Ajde_Event' in method 'view'.
        Open

                Ajde_Event::trigger($this, 'onAfterNodeLoaded', [$node]);
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

        Source https://phpmd.org/rules/cleancode.html#staticaccess

        Avoid using static access to class 'UserModel' in method 'view'.
        Open

                if (!(UserModel::getLoggedIn() && UserModel::getLoggedIn()->isAdmin())) {
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

        Source https://phpmd.org/rules/cleancode.html#staticaccess

        Avoid using static access to class 'UserModel' in method 'getNodeOptions'.
        Open

                    $user = UserModel::getLoggedIn();
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

        Source https://phpmd.org/rules/cleancode.html#staticaccess

        Avoid using static access to class 'UserModel' in method 'getNodeOptions'.
        Open

                    if (!UserModel::isAdmin()) {
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

        Source https://phpmd.org/rules/cleancode.html#staticaccess

        Avoid using static access to class 'UserModel' in method 'getNodeOptions'.
        Open

                    if (!UserModel::isAdmin()) {
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

        Source https://phpmd.org/rules/cleancode.html#staticaccess

        Avoid using static access to class 'Ajde_Dump' in method 'view'.
        Open

                    Ajde_Dump::warn('Previewing unpublished node');
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

        Source https://phpmd.org/rules/cleancode.html#staticaccess

        Avoid assigning values to variables in if clauses and the like (line '76', column '13').
        Open

            public function view()
            {
                // we want to display published nodes only
                if (!(UserModel::getLoggedIn() && UserModel::getLoggedIn()->isAdmin())) {
                    Ajde::app()->getRequest()->set('filterPublished', true);
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

        Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

        Avoid using static access to class 'UserModel' in method 'getNodeOptions'.
        Open

                        $currentUser = UserModel::getLoggedIn();
        Severity: Minor
        Found in core/modules/node/NodeController.php by phpmd

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

        Source https://phpmd.org/rules/cleancode.html#staticaccess

        There are no issues that match your filters.

        Category
        Status