Function execute
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function execute()
{
if (empty($this->_filecontent)) {
return;
}
- 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
Function __construct
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function __construct($enc)
{
parent::__construct(__CLASS__, $enc);
switch (strtolower(PSI_PLUGIN_UPDATENOTIFIER_ACCESS)) {
case 'command':
- 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 using undefined variables such as '$buffer_info' which will lead to PHP notices. Open
CommonFunctions::executeProgram("/usr/lib/update-notifier/apt-check", "--human-readable", $buffer_info);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$buffer_info' which will lead to PHP notices. Open
CommonFunctions::executeProgram("/usr/lib/update-notifier/apt-check", "2>&1", $buffer_info);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$buffer_info' which will lead to PHP notices. Open
CommonFunctions::rfts("/var/lib/update-notifier/updates-available", $buffer_info);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$buffer_info' which will lead to PHP notices. Open
$this->_filecontent = preg_split("/\r?\n/", $buffer_info, -1, PREG_SPLIT_NO_EMPTY);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$buffer_info' which will lead to PHP notices. Open
CommonFunctions::rfts(PSI_PLUGIN_UPDATENOTIFIER_FILE, $buffer_info);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using static access to class 'CommonFunctions' in method '__construct'. Open
CommonFunctions::executeProgram("/usr/lib/update-notifier/apt-check", "2>&1", $buffer_info);
- 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 '__construct'. Open
CommonFunctions::rfts(PSI_PLUGIN_UPDATENOTIFIER_FILE, $buffer_info);
- 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 __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
CommonFunctions::rfts("/var/lib/update-notifier/updates-available", $buffer_info);
}
- 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 execute uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
/*
Universal format: A;B
- A: packages to update
- B: security packages to update
- 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 __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
CommonFunctions::executeProgram("/usr/lib/update-notifier/apt-check", "2>&1", $buffer_info);
}
- 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 '__construct'. Open
CommonFunctions::executeProgram("/usr/lib/update-notifier/apt-check", "--human-readable", $buffer_info);
- 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 execute uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->global_error->addWarning("Unable to parse UpdateNotifier file");
}
- 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 '__construct'. Open
CommonFunctions::rfts("/var/lib/update-notifier/updates-available", $buffer_info);
- 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 execute uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->global_error->addWarning("Unable to parse UpdateNotifier file");
}
- 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 unused local variables such as '$text'. Open
list($num, $text) = explode(" ", $line, 2);
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class UpdateNotifier extends PSI_Plugin
- Exclude checks
The property $_result is not named in camelCase. Open
class UpdateNotifier extends PSI_Plugin
{
/**
* variable, which holds the content of the command
* @var array
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_filecontent is not named in camelCase. Open
class UpdateNotifier extends PSI_Plugin
{
/**
* variable, which holds the content of the command
* @var array
- Read upRead up
- Exclude checks
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;
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Property name "$_filecontent" should not be prefixed with an underscore to indicate visibility Open
private $_filecontent = array();
- Exclude checks
Property name "$_result" should not be prefixed with an underscore to indicate visibility Open
private $_result = array();
- Exclude checks
Terminating statement must be indented to the same level as the CASE body Open
break;
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
if (defined('PSI_PLUGIN_UPDATENOTIFIER_UBUNTU_LANDSCAPE_FORMAT') && (PSI_PLUGIN_UPDATENOTIFIER_UBUNTU_LANDSCAPE_FORMAT === true)) {
- 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 exceeds 120 characters; contains 139 characters Open
if (defined('PSI_PLUGIN_UPDATENOTIFIER_UBUNTU_LANDSCAPE_FORMAT') && (PSI_PLUGIN_UPDATENOTIFIER_UBUNTU_LANDSCAPE_FORMAT === true)) {
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 12 Open
$this->global_error->addConfigError("__construct()", "[updatenotifier] ACCESS");
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
if (defined('PSI_PLUGIN_UPDATENOTIFIER_UBUNTU_LANDSCAPE_FORMAT') && (PSI_PLUGIN_UPDATENOTIFIER_UBUNTU_LANDSCAPE_FORMAT === true)) {
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 8 Open
case 'data':
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 16 Open
CommonFunctions::rfts(PSI_PLUGIN_UPDATENOTIFIER_FILE, $buffer_info);
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
} else {
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 16 Open
CommonFunctions::rfts("/var/lib/update-notifier/updates-available", $buffer_info);
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
} else {
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 12 Open
if (defined('PSI_PLUGIN_UPDATENOTIFIER_FILE') && is_string(PSI_PLUGIN_UPDATENOTIFIER_FILE)) {
- 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
CommonFunctions::executeProgram("/usr/lib/update-notifier/apt-check", "--human-readable", $buffer_info);
- Exclude checks
Line indented incorrectly; expected at least 20 spaces, found 16 Open
CommonFunctions::executeProgram("/usr/lib/update-notifier/apt-check", "2>&1", $buffer_info);
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 8 Open
case 'command':
- Exclude checks
The variable $buffer_info is not named in camelCase. Open
public function __construct($enc)
{
parent::__construct(__CLASS__, $enc);
switch (strtolower(PSI_PLUGIN_UPDATENOTIFIER_ACCESS)) {
case 'command':
- 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 $buffer_info is not named in camelCase. Open
public function __construct($enc)
{
parent::__construct(__CLASS__, $enc);
switch (strtolower(PSI_PLUGIN_UPDATENOTIFIER_ACCESS)) {
case 'command':
- 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 $buffer_info is not named in camelCase. Open
public function __construct($enc)
{
parent::__construct(__CLASS__, $enc);
switch (strtolower(PSI_PLUGIN_UPDATENOTIFIER_ACCESS)) {
case 'command':
- 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 $buffer_info is not named in camelCase. Open
public function __construct($enc)
{
parent::__construct(__CLASS__, $enc);
switch (strtolower(PSI_PLUGIN_UPDATENOTIFIER_ACCESS)) {
case 'command':
- 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 $buffer_info is not named in camelCase. Open
public function __construct($enc)
{
parent::__construct(__CLASS__, $enc);
switch (strtolower(PSI_PLUGIN_UPDATENOTIFIER_ACCESS)) {
case 'command':
- 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();
}
}