XoopsModules25x/xoopsinfo

View on GitHub
phpsysinfo/includes/ups/class.pmset.inc.php

Summary

Maintainability
A
2 hrs
Test Coverage

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

   private function _info()
    {
        if (empty($this->_output)) {
            return;
        }
Severity: Minor
Found in phpsysinfo/includes/ups/class.pmset.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 _info has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

   private function _info()
    {
        if (empty($this->_output)) {
            return;
        }
Severity: Minor
Found in phpsysinfo/includes/ups/class.pmset.inc.php - About 1 hr to fix

    Missing class import via use statement (line '63', column '28').
    Open

                    $dev = new UPSDevice();

    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 'CommonFunctions' in method '__construct'.
    Open

            if (CommonFunctions::executeProgram('pmset', '-g batt', $temp) && !empty($temp)) {

    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 Pmset extends UPS

    The property $_output is not named in camelCase.
    Open

    class Pmset extends UPS
    {
        /**
         * internal storage for all gathered data
         *

    CamelCasePropertyName

    Since: 0.2

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

    Example

    class ClassName {
        protected $property_name;
    }

    Source

    Method name "_info" should not be prefixed with an underscore to indicate visibility
    Open

       private function _info()

    Opening brace indented incorrectly; expected 3 spaces, found 4
    Open

        {

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

        private $_output = array();

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

    Closing brace indented incorrectly; expected 3 spaces, found 4
    Open

        }

    Line indented incorrectly; expected 4 spaces, found 3
    Open

       private function _info()

    The method _info is not named in camelCase.
    Open

       private function _info()
        {
            if (empty($this->_output)) {
                return;
            }

    CamelCaseMethodName

    Since: 0.2

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

    Example

    class ClassName {
        public function get_name() {
        }
    }

    Source

    There are no issues that match your filters.

    Category
    Status