XoopsModules25x/xoopsinfo

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

Summary

Maintainability
A
1 hr
Test Coverage

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

    private function _temperature()
    {
        foreach ($this->_lines as $line) {
            if (preg_match('/(.*):\s*(\d*)/', $line, $data)) {
                if ($data[2] > 0) {
Severity: Minor
Found in phpsysinfo/includes/mb/class.k8temp.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

Missing class import via use statement (line '57', 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

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

            if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/k8temp.txt', $lines)) {

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

            CommonFunctions::executeProgram('k8temp', '', $lines);

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

The property $_lines is not named in camelCase.
Open

class K8Temp extends Sensors
{
    /**
     * content to parse
     *

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

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

            break;

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

    private $_lines = array();

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;

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

    private function _temperature()

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

            CommonFunctions::executeProgram('k8temp', '', $lines);

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

            $lines = "";

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

            $this->error->addConfigError('__construct()', '[sensor_k8temp] ACCESS');

Line indented incorrectly; expected 12 spaces, found 8
Open

        case 'command':

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

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

Line indented incorrectly; expected 12 spaces, found 8
Open

        case 'data':

Line indented incorrectly; expected 16 spaces, found 12
Open

            if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/k8temp.txt', $lines)) {

Line indented incorrectly; expected 16 spaces, found 12
Open

            }

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

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

Line indented incorrectly; expected 12 spaces, found 8
Open

        default:

The method _temperature is not named in camelCase.
Open

    private function _temperature()
    {
        foreach ($this->_lines as $line) {
            if (preg_match('/(.*):\s*(\d*)/', $line, $data)) {
                if ($data[2] > 0) {

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