XoopsModules25x/xoopsinfo

View on GitHub
phpsysinfo/plugins/quotas/class.quotas.inc.php

Summary

Maintainability
A
2 hrs
Test Coverage

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

    public function execute()
    {
        $i = 0;
        $quotas = array();
        foreach ($this->_filecontent as $thisline) {
Severity: Minor
Found in phpsysinfo/plugins/quotas/class.quotas.inc.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 execute has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function execute()
    {
        $i = 0;
        $quotas = array();
        foreach ($this->_filecontent as $thisline) {
Severity: Minor
Found in phpsysinfo/plugins/quotas/class.quotas.inc.php - About 1 hr to fix

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

        public function __construct($enc)
        {
            parent::__construct(__CLASS__, $enc);
            switch (strtolower(PSI_PLUGIN_QUOTAS_ACCESS)) {
            case 'command':
    Severity: Minor
    Found in phpsysinfo/plugins/quotas/class.quotas.inc.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

    Avoid using undefined variables such as '$buffer' which will lead to PHP notices.
    Open

            if (trim($buffer) != "") {

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$buffer' which will lead to PHP notices.
    Open

                CommonFunctions::executeProgram("repquota", "-au", $buffer, PSI_DEBUG);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$buffer' which will lead to PHP notices.
    Open

                $this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    Avoid using undefined variables such as '$buffer' which will lead to PHP notices.
    Open

                CommonFunctions::rfts(PSI_APP_ROOT."/data/quotas.txt", $buffer);

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

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

    The method __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $this->_filecontent = array();
            }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

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

    The method execute uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                    } else {
                        $quotas[$i]['byte_percent_used'] = 0;
                    }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

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

    Avoid using static access to class 'CommonFunctions' in method '__construct'.
    Open

                CommonFunctions::rfts(PSI_APP_ROOT."/data/quotas.txt", $buffer);

    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

    The method execute uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                    } else {
                        $quotas[$i]['file_percent_used'] = 0;
                    }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

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

    Avoid using static access to class 'CommonFunctions' in method '__construct'.
    Open

                CommonFunctions::executeProgram("repquota", "-au", $buffer, PSI_DEBUG);

    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

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class Quotas extends PSI_Plugin

    The property $_filecontent is not named in camelCase.
    Open

    class Quotas extends PSI_Plugin
    {
        /**
         * variable, which holds the content of the command
         * @var array

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    The property $_result is not named in camelCase.
    Open

    class Quotas extends PSI_Plugin
    {
        /**
         * variable, which holds the content of the command
         * @var array

    CamelCasePropertyName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name attributes.

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    Avoid variables with short names like $i. Configured minimum length is 3.
    Open

            $i = 0;

    ShortVariable

    Since: 0.2

    Detects when a field, local, or parameter has a very short name.

    Example

    class Something {
        private $q = 15; // VIOLATION - Field
        public static function main( array $as ) { // VIOLATION - Formal
            $r = 20 + $this->q; // VIOLATION - Local
            for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                $r += $this->q;
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#shortvariable

    Terminating statement must be indented to the same level as the CASE body
    Open

                break;

    Property name "$_filecontent" should not be prefixed with an underscore to indicate visibility
    Open

        private $_filecontent = array();

    Terminating statement must be indented to the same level as the CASE body
    Open

                break;

    Property name "$_result" should not be prefixed with an underscore to indicate visibility
    Open

        private $_result = array();

    Terminating statement must be indented to the same level as the CASE body
    Open

                break;

    Line exceeds 120 characters; contains 127 characters
    Open

                        $quotas[$i]['file_percent_used'] = round((($quotas[$i]['file_used'] / $quotas[$i]['file_hard']) * 100), 1);

    Line exceeds 120 characters; contains 132 characters
    Open

     * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version

    Line exceeds 120 characters; contains 127 characters
    Open

                        $quotas[$i]['byte_percent_used'] = round((($quotas[$i]['byte_used'] / $quotas[$i]['byte_hard']) * 100), 1);

    Line indented incorrectly; expected at least 16 spaces, found 12
    Open

                CommonFunctions::rfts(PSI_APP_ROOT."/data/quotas.txt", $buffer);

    Line indented incorrectly; expected 12 spaces, found 8
    Open

            case 'command':

    Line indented incorrectly; expected at least 16 spaces, found 12
    Open

                $this->global_error->addConfigError("__construct()", "[quotas] ACCESS");

    Line indented incorrectly; expected at least 16 spaces, found 12
    Open

                CommonFunctions::executeProgram("repquota", "-au", $buffer, PSI_DEBUG);

    Line indented incorrectly; expected 12 spaces, found 8
    Open

            case 'data':

    Line indented incorrectly; expected 12 spaces, found 8
    Open

            default:

    There are no issues that match your filters.

    Category
    Status