Function getOpenTicketStatus
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public static function getOpenTicketStatus()
{
$getTicketStatusClosed = self::getTicketStatusNotModify();
\App\Log::trace(__METHOD__);
if (empty($getTicketStatusClosed)) {
- 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
Missing class import via use statement (line '42', column '24'). Open
$ticketStatus = (new App\Db\Query())->select(['ticket_status_indicate_closing'])
- 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
Avoid using static access to class '\App\Log' in method 'updateTicketStatusNotModify'. Open
\App\Log::trace('Entering Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');
- 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 'App\Fields\Picklist' in method 'getAllTicketStatus'. Open
return App\Fields\Picklist::getValuesName('ticketstatus');
- 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 '\App\Log' in method 'getTicketStatus'. Open
\App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');
- 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 '\App\Log' in method 'getAllTicketStatus'. Open
\App\Log::trace(__METHOD__);
- 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 '\App\Log' in method 'updateTicketStatusNotModify'. Open
\App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');
- 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 '\App\Log' in method 'getOpenTicketStatus'. Open
\App\Log::trace(__METHOD__);
- 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 'App\Fields\Picklist' in method 'getTicketStatus'. Open
$return = App\Fields\Picklist::getValuesName('ticketstatus');
- 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 getOpenTicketStatus uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$getAllTicketStatus = self::getAllTicketStatus();
foreach ($getTicketStatusClosed as $key => $closedStatus) {
foreach ($getAllTicketStatus as $key => $status) {
if ($closedStatus == $status) {
- 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 '\App\Log' in method 'getTicketStatus'. Open
\App\Log::trace('Entering Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');
- 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
Define a constant instead of duplicating this literal "vtiger_support_processes" 3 times. Open
->from('vtiger_support_processes')
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "ticket_status_indicate_closing" 3 times. Open
$ticketStatus = (new App\Db\Query())->select(['ticket_status_indicate_closing'])
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Call to undeclared method \App\Db\Query::select
Open
$ticketStatus = (new App\Db\Query())->select(['ticket_status_indicate_closing'])
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace(__METHOD__);
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
\App\Db::getInstance()->createCommand()->update('vtiger_support_processes', [
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('Entering Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('Entering Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
\App\Db::getInstance()->createCommand()->update('vtiger_support_processes', [
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace(__METHOD__);
- Exclude checks
Returning type true
but updateTicketStatusNotModify()
is declared to return array
Open
return true;
- Exclude checks
Avoid excessively long variable names like $ticketStatusNotModify. Keep variable name length under 20. Open
protected static $ticketStatusNotModify;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $getTicketStatusClosed. Keep variable name length under 20. Open
$getTicketStatusClosed = self::getTicketStatusNotModify();
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_SupportProcesses_Module_Model extends Settings_Vtiger_Module_Model
- Exclude checks
The class Settings_SupportProcesses_Module_Model is not named in CamelCase. Open
class Settings_SupportProcesses_Module_Model extends Settings_Vtiger_Module_Model
{
public static function getCleanInstance()
{
return new self();
- 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
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
], ['id' => 1])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getTicketStatusNotModify()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = $getAllTicketStatus;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getTicketStatus()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Update ticket status for support processes from support_processes.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Db::getInstance()->createCommand()->update('vtiger_support_processes', [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($getTicketStatusClosed as $key => $closedStatus) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace('Entering Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
], ['id' => 1])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$getAllTicketStatus = self::getAllTicketStatus();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return new self();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = App\Fields\Picklist::getValuesName('ticketstatus');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (self::$ticketStatusNotModify) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($getTicketStatusClosed)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getCleanInstance()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$getTicketStatusClosed = self::getTicketStatusNotModify();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace(__METHOD__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$ticketStatus = (new App\Db\Query())->select(['ticket_status_indicate_closing'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array - array of ticket status
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($closedStatus == $status) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::$ticketStatusNotModify = $return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function updateTicketStatusNotModify($data)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return App\Fields\Picklist::getValuesName('ticketstatus');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($ticketStatus)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Db::getInstance()->createCommand()->update('vtiger_support_processes', [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($data['val'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace('Exiting Settings_SupportProcesses_Module_Model::updateTicketStatusNotModify() method ...');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Gets ticket status for support processes from support_processes.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $result;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Gets ticket status for support processes.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace('Entering Settings_SupportProcesses_Module_Model::getTicketStatus() method ...');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return self::$ticketStatusNotModify;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->scalar();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace(__METHOD__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getOpenTicketStatus()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = explode(',', $ticketStatus);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'ticket_status_indicate_closing' => '',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data = implode(',', \is_array($data['val']) ? $data['val'] : [$data['val']]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($getAllTicketStatus as $key => $status) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($getAllTicketStatus[$key]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected static $ticketStatusNotModify;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array - array of ticket status
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'ticket_status_indicate_closing' => $data,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getAllTicketStatus()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array - array of ticket status
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_support_processes')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $data
- Exclude checks
Class name "Settings_SupportProcesses_Module_Model" is not in camel caps format Open
class Settings_SupportProcesses_Module_Model extends Settings_Vtiger_Module_Model
- Exclude checks