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':
- Read upRead up
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':
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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();
- Read upRead up
- Exclude checks
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)) {
- Read upRead up
- Exclude checks
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)) {
- Read upRead up
- Exclude checks
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);
}
- Read upRead up
- Exclude checks
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)) {
- Read upRead up
- Exclude checks
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)) {
- Read upRead up
- Exclude checks
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
- Exclude checks
Avoid variables with short names like $fp. Configured minimum length is 3. Open
$fp = @fsockopen('localhost', 7634, $errno, $errstr, 5);
- Read upRead up
- Exclude checks
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;
- Exclude checks
Method name "_temperature" should not be prefixed with an underscore to indicate visibility Open
private function _temperature()
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Line exceeds 120 characters; contains 137 characters Open
$dev->setName($data[1] . ' (' . (strpos($data[2], " ")?substr($data[2], 0, strpos($data[2], " ")):$data[2]) . ')');
- Exclude checks
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
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 12 Open
$lines = '';
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
} else {
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 12 Open
$ar_buf = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
- Exclude checks
Line indented incorrectly; expected 20 spaces, found 16 Open
foreach ($arrContent as $strLine) {
- Exclude checks
Line indented incorrectly; expected 32 spaces, found 28 Open
if (file_exists($strDrive)) {
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected at least 24 spaces, found 20 Open
$arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
- Exclude checks
Line indented incorrectly; expected 28 spaces, found 24 Open
}
- Exclude checks
Line indented incorrectly; expected 20 spaces, found 16 Open
while (!feof($fp)) {
- Exclude checks
Line indented incorrectly; expected 20 spaces, found 16 Open
}
- Exclude checks
Line indented incorrectly; expected 24 spaces, found 20 Open
}
- Exclude checks
Line indented incorrectly; expected 20 spaces, found 16 Open
if (CommonFunctions::rfts("/proc/partitions", $strContent, 0, 4096, false)) {
- Exclude checks
Line indented incorrectly; expected 24 spaces, found 20 Open
foreach ($arrContent as $strLine) {
- Exclude checks
Line indented incorrectly; expected at least 32 spaces, found 28 Open
$strDrive = '/dev/'.$arrSplit[2];
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 24 Open
array_push($ar_buf, "|".implode("|", $temp)."|");
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 12 Open
$strDrives = "";
- Exclude checks
Line indented incorrectly; expected 28 spaces, found 24 Open
if (!preg_match("/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit)) {
- Exclude checks
Line indented incorrectly; expected 24 spaces, found 20 Open
}
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 8 Open
case 'tcp':
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 12 Open
$hddtemp_value = "";
- Exclude checks
Line indented incorrectly; expected 28 spaces, found 24 Open
if (! empty($arrSplit[2])) {
- Exclude checks
Line indented incorrectly; expected 20 spaces, found 16 Open
}
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected 20 spaces, found 16 Open
foreach ($hddtemp_value as $line) {
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 12 Open
$fp = @fsockopen('localhost', 7634, $errno, $errstr, 5);
- Exclude checks
Line indented incorrectly; expected at least 24 spaces, found 20 Open
$lines .= fread($fp, 1024);
- Exclude checks
Line indented incorrectly; expected 28 spaces, found 24 Open
}
- Exclude checks
Line indented incorrectly; expected 20 spaces, found 16 Open
}
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
if (trim($strDrives) == "") {
- Exclude checks
Line indented incorrectly; expected 24 spaces, found 20 Open
if (count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) {
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 8 Open
default:
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 16 Open
$arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
- Exclude checks
Line indented incorrectly; expected 24 spaces, found 20 Open
if (! empty($arrSplit[2])) {
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 16 Open
break;
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 12 Open
$lines = str_replace("||", "|\n|", $lines);
- Exclude checks
Line indented incorrectly; expected 28 spaces, found 24 Open
if (file_exists($strDrive)) {
- Exclude checks
Line indented incorrectly; expected 28 spaces, found 24 Open
}
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
if (CommonFunctions::executeProgram("hddtemp", $strDrives, $hddtemp_value, PSI_DEBUG)) {
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 24 Open
$temp[2] = trim($ar_temp[1]);
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 12 Open
$this->error->addConfigError("temperature()", "[sensor_hddtemp] ACCESS");
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 16 Open
$this->error->addError("HDDTemp error", $errno.", ".$errstr);
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 8 Open
case 'command':
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 12 Open
$strContent = "";
- Exclude checks
Line indented incorrectly; expected at least 24 spaces, found 20 Open
preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
- Exclude checks
Line indented incorrectly; expected at least 32 spaces, found 28 Open
$strDrives = $strDrives.$strDrive.' ';
- Exclude checks
Line indented incorrectly; expected at least 32 spaces, found 28 Open
preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 24 Open
preg_match("/^([0-9]*)(.*)/", $temp[2], $ar_temp);
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
if ($fp) {
- Exclude checks
Line indented incorrectly; expected at least 36 spaces, found 32 Open
$strDrives = $strDrives.$strDrive.' ';
- Exclude checks
Line indented incorrectly; expected 24 spaces, found 20 Open
}
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 16 Open
$hddtemp_value = preg_split("/\n/", $hddtemp_value, -1, PREG_SPLIT_NO_EMPTY);
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 16 Open
fclose($fp);
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 24 Open
$strDrive = '/dev/'.$arrSplit[2];
- Exclude checks
Line indented incorrectly; expected 32 spaces, found 28 Open
}
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 24 Open
$temp[3] = trim($ar_temp[2]);
- Exclude checks
Line indented incorrectly; expected 20 spaces, found 16 Open
}
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
if (CommonFunctions::rfts("/proc/diskstats", $strContent, 0, 4096, false)) {
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
} else {
- Exclude checks
Line indented incorrectly; expected at least 24 spaces, found 20 Open
$temp = preg_split("/:\s/", $line, 3);
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
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':
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}