XoopsModules25x/xoopsinfo

View on GitHub
phpsysinfo/includes/mb/class.hddtemp.inc.php

Summary

Maintainability
C
1 day
Test Coverage

Function _temperature has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
Open

    private function _temperature()
    {
        $ar_buf = array();
        switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
        case 'tcp':
Severity: Minor
Found in phpsysinfo/includes/mb/class.hddtemp.inc.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 _temperature has 80 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function _temperature()
    {
        $ar_buf = array();
        switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
        case 'tcp':
Severity: Major
Found in phpsysinfo/includes/mb/class.hddtemp.inc.php - About 3 hrs to fix

    The method _temperature() has an NPath complexity of 882. The configured NPath complexity threshold is 200.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    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 _temperature() has a Cyclomatic Complexity of 25. The configured cyclomatic complexity threshold is 10.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    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

    Remove error control operator '@' on line 31.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    ErrorControlOperator

    Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

    Example

    function foo($filePath) {
        $file = @fopen($filPath); // hides exceptions
        $key = @$array[$notExistingKey]; // assigns null to $key
    }

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

    Missing class import via use statement (line '101', column '32').
    Open

                        $dev = new SensorDevice();

    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

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

                } else {
                    if (CommonFunctions::rfts("/proc/partitions", $strContent, 0, 4096, false)) {
                        $arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
                        foreach ($arrContent as $strLine) {
                            if (!preg_match("/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit)) {

    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 '_temperature'.
    Open

                if (CommonFunctions::rfts("/proc/diskstats", $strContent, 0, 4096, false)) {

    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 _temperature uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    $this->error->addError("HDDTemp error", $errno.", ".$errstr);
                }

    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 '_temperature'.
    Open

                if (CommonFunctions::executeProgram("hddtemp", $strDrives, $hddtemp_value, 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

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

                    if (CommonFunctions::rfts("/proc/partitions", $strContent, 0, 4096, false)) {

    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 HDDTemp extends Sensors

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

                $fp = @fsockopen('localhost', 7634, $errno, $errstr, 5);

    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;

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

        private function _temperature()

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

                break;

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

                break;

    Line exceeds 120 characters; contains 137 characters
    Open

                        $dev->setName($data[1] . ' (' . (strpos($data[2], "  ")?substr($data[2], 0, strpos($data[2], "  ")):$data[2]) . ')');

    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 indented incorrectly; expected at least 16 spaces, found 12
    Open

                $lines = '';

    Line indented incorrectly; expected 16 spaces, found 12
    Open

                } else {

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

                $ar_buf = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);

    Line indented incorrectly; expected 20 spaces, found 16
    Open

                    foreach ($arrContent as $strLine) {

    Line indented incorrectly; expected 32 spaces, found 28
    Open

                                if (file_exists($strDrive)) {

    Line indented incorrectly; expected 16 spaces, found 12
    Open

                }

    Line indented incorrectly; expected at least 24 spaces, found 20
    Open

                        $arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);

    Line indented incorrectly; expected 28 spaces, found 24
    Open

                            }

    Line indented incorrectly; expected 20 spaces, found 16
    Open

                    while (!feof($fp)) {

    Line indented incorrectly; expected 20 spaces, found 16
    Open

                    }

    Line indented incorrectly; expected 24 spaces, found 20
    Open

                        }

    Line indented incorrectly; expected 20 spaces, found 16
    Open

                    if (CommonFunctions::rfts("/proc/partitions", $strContent, 0, 4096, false)) {

    Line indented incorrectly; expected 24 spaces, found 20
    Open

                        foreach ($arrContent as $strLine) {

    Line indented incorrectly; expected at least 32 spaces, found 28
    Open

                                $strDrive = '/dev/'.$arrSplit[2];

    Line indented incorrectly; expected at least 28 spaces, found 24
    Open

                            array_push($ar_buf, "|".implode("|", $temp)."|");

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

                $strDrives = "";

    Line indented incorrectly; expected 28 spaces, found 24
    Open

                            if (!preg_match("/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit)) {

    Line indented incorrectly; expected 24 spaces, found 20
    Open

                        }

    Line indented incorrectly; expected 12 spaces, found 8
    Open

            case 'tcp':

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

                $hddtemp_value = "";

    Line indented incorrectly; expected 28 spaces, found 24
    Open

                            if (! empty($arrSplit[2])) {

    Line indented incorrectly; expected 20 spaces, found 16
    Open

                    }

    Line indented incorrectly; expected 16 spaces, found 12
    Open

                }

    Line indented incorrectly; expected 20 spaces, found 16
    Open

                    foreach ($hddtemp_value as $line) {

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

                $fp = @fsockopen('localhost', 7634, $errno, $errstr, 5);

    Line indented incorrectly; expected at least 24 spaces, found 20
    Open

                        $lines .= fread($fp, 1024);

    Line indented incorrectly; expected 28 spaces, found 24
    Open

                            }

    Line indented incorrectly; expected 20 spaces, found 16
    Open

                    }

    Line indented incorrectly; expected 16 spaces, found 12
    Open

                if (trim($strDrives) == "") {

    Line indented incorrectly; expected 24 spaces, found 20
    Open

                        if (count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) {

    Line indented incorrectly; expected 12 spaces, found 8
    Open

            default:

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

                    $arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);

    Line indented incorrectly; expected 24 spaces, found 20
    Open

                        if (! empty($arrSplit[2])) {

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

                    break;

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

                $lines = str_replace("||", "|\n|", $lines);

    Line indented incorrectly; expected 28 spaces, found 24
    Open

                            if (file_exists($strDrive)) {

    Line indented incorrectly; expected 28 spaces, found 24
    Open

                            }

    Line indented incorrectly; expected 16 spaces, found 12
    Open

                if (CommonFunctions::executeProgram("hddtemp", $strDrives, $hddtemp_value, PSI_DEBUG)) {

    Line indented incorrectly; expected at least 28 spaces, found 24
    Open

                            $temp[2] = trim($ar_temp[1]);

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

                $this->error->addConfigError("temperature()", "[sensor_hddtemp] ACCESS");

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

                    $this->error->addError("HDDTemp error", $errno.", ".$errstr);

    Line indented incorrectly; expected 12 spaces, found 8
    Open

            case 'command':

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

                $strContent = "";

    Line indented incorrectly; expected at least 24 spaces, found 20
    Open

                        preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);

    Line indented incorrectly; expected at least 32 spaces, found 28
    Open

                                $strDrives = $strDrives.$strDrive.' ';

    Line indented incorrectly; expected at least 32 spaces, found 28
    Open

                                preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);

    Line indented incorrectly; expected at least 28 spaces, found 24
    Open

                            preg_match("/^([0-9]*)(.*)/", $temp[2], $ar_temp);

    Line indented incorrectly; expected 16 spaces, found 12
    Open

                if ($fp) {

    Line indented incorrectly; expected at least 36 spaces, found 32
    Open

                                    $strDrives = $strDrives.$strDrive.' ';

    Line indented incorrectly; expected 24 spaces, found 20
    Open

                        }

    Line indented incorrectly; expected 16 spaces, found 12
    Open

                }

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

                    $hddtemp_value = preg_split("/\n/", $hddtemp_value, -1, PREG_SPLIT_NO_EMPTY);

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

                    fclose($fp);

    Line indented incorrectly; expected at least 28 spaces, found 24
    Open

                            $strDrive = '/dev/'.$arrSplit[2];

    Line indented incorrectly; expected 32 spaces, found 28
    Open

                                }

    Line indented incorrectly; expected 16 spaces, found 12
    Open

                }

    Line indented incorrectly; expected at least 28 spaces, found 24
    Open

                            $temp[3] = trim($ar_temp[2]);

    Line indented incorrectly; expected 20 spaces, found 16
    Open

                    }

    Line indented incorrectly; expected 16 spaces, found 12
    Open

                if (CommonFunctions::rfts("/proc/diskstats", $strContent, 0, 4096, false)) {

    Line indented incorrectly; expected 16 spaces, found 12
    Open

                } else {

    Line indented incorrectly; expected at least 24 spaces, found 20
    Open

                        $temp = preg_split("/:\s/", $line, 3);

    The variable $hddtemp_value is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $hddtemp_value is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $ar_temp is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $ar_temp is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $ar_buf is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $ar_buf is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $hddtemp_value is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $ar_temp is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $ar_buf is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $hddtemp_value is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $ar_buf is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $hddtemp_value is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The method _temperature is not named in camelCase.
    Open

        private function _temperature()
        {
            $ar_buf = array();
            switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
            case 'tcp':

    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