Function addDetail
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function addDetail($prev, $post)
{
if (self::$lockTrack) {
return true;
}
- 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 addBasic
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function addBasic(string $type): void
{
$db = App\Db::getInstance('log');
if ('view' == $type && App\Request::_isAjax()) {
self::lockTracking();
- 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
The method lockTracking has a boolean flag argument $lock, which is a certain sign of a Single Responsibility Principle violation. Open
public static function lockTracking($lock = 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
Avoid using static access to class '\App\Request' in method 'addBasic'. Open
'module_name' => \App\Request::_get('module'),
- 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\Db' in method 'addDetail'. Open
$db = App\Db::getInstance('log');
- 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 assigning values to variables in if clauses and the like (line '42', column '7'). Open
public static function addBasic(string $type): void
{
$db = App\Db::getInstance('log');
if ('view' == $type && App\Request::_isAjax()) {
self::lockTracking();
- 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 using static access to class 'App\Db' in method 'addBasic'. Open
$db = App\Db::getInstance('log');
- 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\Request' in method 'addBasic'. Open
if ($mode = \App\Request::_getMode()) {
- 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\Request' in method 'addBasic'. Open
if ('view' == $type && App\Request::_isAjax()) {
- 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\User' in method 'addBasic'. Open
'user_id' => \App\User::getCurrentUserId(),
- 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
Call to method getCurrentUserId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
'user_id' => \App\User::getCurrentUserId(),
- Exclude checks
Assigning int
to property but \Settings_Vtiger_Tracker_Model::$recordId
is string
Open
self::$recordId = $record;
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$insertedInfo = $db->createCommand()->insert('l_#__settings_tracker_basic', [
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$db->createCommand()->insert('l_#__settings_tracker_detail', [
- Exclude checks
Assigning string
to property but \Settings_Vtiger_Tracker_Model::$id
is false
Open
self::$id = $db->getLastInsertID('l_#__settings_tracker_basic_id_seq');
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
App\Db::getInstance('log')->createCommand()
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_Vtiger_Tracker_Model
- Exclude checks
The class Settings_Vtiger_Tracker_Model is not named in CamelCase. Open
class Settings_Vtiger_Tracker_Model
{
private static $recordId = '';
private static $lockTrack = false;
private static $id = false;
- 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
Avoid variables with short names like $id. Configured minimum length is 3. Open
private static $id = false;
- 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
Avoid variables with short names like $db. Configured minimum length is 3. Open
$db = App\Db::getInstance('log');
- 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
Avoid variables with short names like $db. Configured minimum length is 3. Open
$db = App\Db::getInstance('log');
- 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
Spaces must be used to indent lines; tabs are not allowed Open
private static $id = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== self::$id || self::$lockTrack) {
- 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
'user_id' => \App\User::getCurrentUserId(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'record_id' => self::$recordId ? self::$recordId : 0,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($post as $key => $value) {
- 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
private static $recordId = '';
- 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
'module_name' => \App\Request::_get('module'),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
App\Db::getInstance('log')->createCommand()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'prev_value' => $prev[$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
];
- 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 lockTracking($lock = true)
- 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 void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$action = \App\Process::$processType . ':' . \App\Process::$processName;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'date' => date('Y-m-d H:i:s'),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::$id = $db->getLastInsertID('l_#__settings_tracker_basic_id_seq');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function changeType($type)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- 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
'save' => 2,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::lockTracking();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => self::$types[$type],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (self::$lockTrack) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::$lockTrack = $lock;
- 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
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->execute();
- 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
])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::$recordId = $record;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'view' => 1,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('view' == $type && App\Request::_isAjax()) {
- 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
if (false !== self::$id) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'post_value' => null === $value ? '' : $value,
- 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
])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function addDetail($prev, $post)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'field' => $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
'id' => self::$id,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($mode = \App\Request::_getMode()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$insertedInfo = $db->createCommand()->insert('l_#__settings_tracker_basic', [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'action' => $action,
- 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 (isset($prev[$key]) && $value == $prev[$key]) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private static $lockTrack = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private static $types = [
- 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 (1 === $insertedInfo) {
- 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
$db->createCommand()->insert('l_#__settings_tracker_detail', [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'delete' => 3,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $type
- 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
$db = App\Db::getInstance('log');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::addBasic('save');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Adding basic information about tracking.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db = App\Db::getInstance('log');
- 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('l_#__settings_tracker_basic', ['type' => self::$types[$type]], ['id' => [self::$id]])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function addBasic(string $type): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$action .= ':' . $mode;
- 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 setRecordId($record)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty(self::$recordId)) {
- Exclude checks
Class name "Settings_Vtiger_Tracker_Model" is not in camel caps format Open
class Settings_Vtiger_Tracker_Model
- Exclude checks