Function _parse_log_file
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private static function _parse_log_file($string)
{
global $log_file;
if (file_exists($log_file)) {
$contents = @file_get_contents($log_file);
- 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
Avoid deeply nested control flow statements. Open
while (false !== ($sentry = readdir($shandle))) {
if (($sentry!=".")&&($sentry!="..")) {
$log_file=PSI_APP_ROOT.'/sample/distrotest/'.$entry.'/'.$sentry;
echo "<tr>";
echo "<td>".$entry.'/'.$sentry."</td>";
Consider simplifying this complex logical expression. Open
if (file_exists($log_file)
&& ($lsb || $lsbfile || ($strFileName != "/etc/lsb-release"))
&& ($contents = @file_get_contents($log_file))
&& preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($strFileName, '/')."\-\-\-\-\-\-\-\-\-\-\r?\n/m", $contents)) {
return true;
Method executeProgram
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = 30)
Method rfts
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
Function rfts
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
{
global $lsb;
global $lsbfile;
if ($lsb || $lsbfile || ($strFileName != "/etc/lsb-release")) {
- 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
Remove error control operator '@' on line 47. Open
private static function _parse_log_file($string)
{
global $log_file;
if (file_exists($log_file)) {
$contents = @file_get_contents($log_file);
- 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
The method executeProgram has a boolean flag argument $booErrorRep, which is a certain sign of a Single Responsibility Principle violation. Open
public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = 30)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method rfts has a boolean flag argument $booErrorRep, which is a certain sign of a Single Responsibility Principle violation. Open
public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Remove error control operator '@' on line 101. Open
public static function fileexists($strFileName)
{
global $log_file;
global $lsb;
global $lsbfile;
- 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
The method rfts uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return false;
}
- 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
The method executeProgram uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return $strBuffer = self::_parse_log_file($strProgramname);
}
- 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
The method _parse_log_file uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return substr($contents, $startIndex);
}
- 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 assigning values to variables in if clauses and the like (line '101', column '17'). Open
public static function fileexists($strFileName)
{
global $log_file;
global $lsb;
global $lsbfile;
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid unused parameters such as '$timeout'. Open
public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = 30)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$strArgs'. Open
public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = 30)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$booErrorRep'. Open
public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$strBuffer'. Open
public static function readenv($strElem, &$strBuffer)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$strElem'. Open
public static function readenv($strElem, &$strBuffer)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$intBytes'. Open
public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$booErrorRep'. Open
public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = 30)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ($contents && preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($string, '/')."\-\-\-\-\-\-\-\-\-\-\n/m", $contents, $matches, PREG_OFFSET_CAPTURE)) {
$findIndex = $matches[0][1];
if (preg_match("/\n/m", $contents, $matches, PREG_OFFSET_CAPTURE, $findIndex)) {
$startIndex = $matches[0][1]+1;
if (preg_match("/^\-\-\-\-\-\-\-\-\-\-/m", $contents, $matches, PREG_OFFSET_CAPTURE, $startIndex)) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 185.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid using short method names like Parser::df(). The configured minimum method name length is 3. Open
public static function df()
{
return array();
}
- Read upRead up
- Exclude checks
ShortMethodName
Since: 0.2
Detects when very short method names are used.
Example
class ShortMethod {
public function a( $index ) { // Violation
}
}
Source https://phpmd.org/rules/naming.html#shortmethodname
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class CommonFunctions
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Parser
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class PSI_Error
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class _Linux extends Linux
- Exclude checks
The class PSI_Error is not named in CamelCase. Open
class PSI_Error
{
public static function singleton()
{
}
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
The class _Linux is not named in CamelCase. Open
class _Linux extends Linux
{
public function build()
{
parent::_distro();
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 9 and the first side effect is on line 2. Open
<?php
- Exclude checks
Each class must be in a file by itself Open
class CommonFunctions
- Exclude checks
Each class must be in a file by itself Open
class _Linux extends Linux
- Exclude checks
Each class must be in a file by itself Open
class Parser
- Exclude checks
Method name "CommonFunctions::_parse_log_file" is not in camel caps format Open
private static function _parse_log_file($string)
- Exclude checks
Method name "_parse_log_file" should not be prefixed with an underscore to indicate visibility Open
private static function _parse_log_file($string)
- Exclude checks
Inline control structures are not allowed Open
if ($icon != $entry.'.png')
- Exclude checks
Inline control structures are not allowed Open
else
- Exclude checks
Inline control structures are not allowed Open
if ($icon == '') $icon="unknown.png";
- Exclude checks
Inline control structures are not allowed Open
else
- Exclude checks
Inline control structures are not allowed Open
else
- Exclude checks
Inline control structures are not allowed Open
if ($icon == '') $icon="unknown.png";
- Exclude checks
Inline control structures are not allowed Open
if ($icon == '') $icon="unknown.png";
- Exclude checks
Inline control structures are not allowed Open
if ($icon != $entry.'.png')
- Exclude checks
Inline control structures are not allowed Open
else
- Exclude checks
Inline control structures are not allowed Open
if ($icon != $entry.'.png')
- Exclude checks
Inline control structures are not allowed Open
if ($icon != $entry.'.png')
- Exclude checks
Inline control structures are not allowed Open
if ($icon != $entry.'.png')
- Exclude checks
Inline control structures are not allowed Open
else
- Exclude checks
Inline control structures are not allowed Open
if ($icon != $entry.'.png')
- Exclude checks
Line exceeds 120 characters; contains 162 characters Open
if ($contents && preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($string, '/')."\-\-\-\-\-\-\-\-\-\-\n/m", $contents, $matches, PREG_OFFSET_CAPTURE)) {
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
&& preg_match("/^\-\-\-\-\-\-\-\-\-\-".preg_quote($strFileName, '/')."\-\-\-\-\-\-\-\-\-\-\r?\n/m", $contents)) {
- Exclude checks
Inline control structures are not allowed Open
else
- Exclude checks
Class name "PSI_Error" is not in camel caps format Open
class PSI_Error
- Exclude checks
Expected 1 space after ELSE keyword; newline found Open
else
- Exclude checks
Expected 1 space after ELSE keyword; newline found Open
else
- Exclude checks
Expected 1 space after ELSE keyword; newline found Open
else
- Exclude checks
Class name "_Linux" is not in camel caps format Open
class _Linux extends Linux
- Exclude checks
Expected 1 space after ELSE keyword; newline found Open
else
- Exclude checks
Expected 1 space after ELSE keyword; newline found Open
else
- Exclude checks
Expected 1 space after ELSE keyword; newline found Open
else
- Exclude checks
The variable $log_file is not named in camelCase. Open
private static function _parse_log_file($string)
{
global $log_file;
if (file_exists($log_file)) {
$contents = @file_get_contents($log_file);
- 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 $log_file is not named in camelCase. Open
public static function fileexists($strFileName)
{
global $log_file;
global $lsb;
global $lsbfile;
- 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 $log_file is not named in camelCase. Open
private static function _parse_log_file($string)
{
global $log_file;
if (file_exists($log_file)) {
$contents = @file_get_contents($log_file);
- 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 $log_file is not named in camelCase. Open
public static function fileexists($strFileName)
{
global $log_file;
global $lsb;
global $lsbfile;
- 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 $log_file is not named in camelCase. Open
public static function fileexists($strFileName)
{
global $log_file;
global $lsb;
global $lsbfile;
- 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 $log_file is not named in camelCase. Open
private static function _parse_log_file($string)
{
global $log_file;
if (file_exists($log_file)) {
$contents = @file_get_contents($log_file);
- 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 _parse_log_file is not named in camelCase. Open
private static function _parse_log_file($string)
{
global $log_file;
if (file_exists($log_file)) {
$contents = @file_get_contents($log_file);
- 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() {
}
}