Function entityAfterSave
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function entityAfterSave(App\EventHandler $eventHandler)
{
$recordModel = $eventHandler->getRecordModel();
$moduleName = $eventHandler->getModuleName();
$moduleIds = Vtiger_MultiReferenceValue_UIType::getMultiReferenceModules($moduleName);
- 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 entityAfterSave() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function entityAfterSave(App\EventHandler $eventHandler)
{
$recordModel = $eventHandler->getRecordModel();
$moduleName = $eventHandler->getModuleName();
$moduleIds = Vtiger_MultiReferenceValue_UIType::getMultiReferenceModules($moduleName);
- 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
Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed. Open
public function entityAfterSave(App\EventHandler $eventHandler)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Avoid using static access to class 'Vtiger_MultiReferenceValue_UIType' in method 'entityAfterSave'. Open
Vtiger_MultiReferenceValue_UIType::setRecordToCron($module, $moduleName, $recordId);
- 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 'Vtiger_MultiReferenceValue_UIType' in method 'entityAfterLink'. Open
Vtiger_MultiReferenceValue_UIType::setRecordToCron($destinationModule, $sourceModule, $params['destinationRecordId']);
- 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\Record' in method 'entityAfterSave'. Open
$module = \App\Record::getType($recordId);
- 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\Module' in method 'entityAfterSave'. Open
if ($module && \in_array(\App\Module::getModuleId($module), $moduleIds)) {
- 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 '\Vtiger_MultiReferenceValue_UIType' in method 'entityAfterLink'. Open
if (\Vtiger_MultiReferenceValue_UIType::getFieldsByModules($sourceModule, $destinationModule)) {
- 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 'Vtiger_MultiReferenceValue_UIType' in method 'entityAfterSave'. Open
$moduleIds = Vtiger_MultiReferenceValue_UIType::getMultiReferenceModules($moduleName);
- 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\Module' in method 'entityAfterSave'. Open
if ($module && \in_array(\App\Module::getModuleId($module), $moduleIds)) {
- 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 '\Vtiger_MultiReferenceValue_UIType' in method 'entityAfterLink'. Open
if (\Vtiger_MultiReferenceValue_UIType::getFieldsByModules($destinationModule, $sourceModule)) {
- 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\Record' in method 'entityAfterSave'. Open
$module = \App\Record::getType($recordModel->get($fieldName));
- 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 'Vtiger_MultiReferenceValue_UIType' in method 'entityAfterLink'. Open
Vtiger_MultiReferenceValue_UIType::setRecordToCron($sourceModule, $destinationModule, $params['sourceRecordId']);
- 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 'Vtiger_MultiReferenceValue_UIType' in method 'entityAfterSave'. Open
Vtiger_MultiReferenceValue_UIType::setRecordToCron($module, $moduleName, $recordModel->get($fieldName));
- 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 Vtiger_MultiReferenceUpdater_Handler
- Exclude checks
The class Vtiger_MultiReferenceUpdater_Handler is not named in CamelCase. Open
class Vtiger_MultiReferenceUpdater_Handler
{
/**
* EntityAfterLink handler function.
*
- 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 for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$module = \App\Record::getType($recordId);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (\Vtiger_MultiReferenceValue_UIType::getFieldsByModules($destinationModule, $sourceModule)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$sourceModule = $params['sourceModule'];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public function entityAfterTransferUnLink(App\EventHandler $eventHandler)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ($moduleIds) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$recordId = $recordModel->getPreviousValue($fieldName);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$params = $eventHandler->getParams();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$destinationModule = $params['destinationModule'];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @param App\EventHandler $eventHandler
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public function entityAfterSave(App\EventHandler $eventHandler)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* EntityAfterUnLink handler function.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$this->entityAfterLink($eventHandler);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Vtiger_MultiReferenceValue_UIType::setRecordToCron($module, $moduleName, $recordId);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public function entityAfterUnLink(App\EventHandler $eventHandler)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$recordModel = $eventHandler->getRecordModel();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ($module && \in_array(\App\Module::getModuleId($module), $moduleIds)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Vtiger_MultiReferenceValue_UIType::setRecordToCron($destinationModule, $sourceModule, $params['destinationRecordId']);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public function entityAfterTransferLink(App\EventHandler $eventHandler)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @param App\EventHandler $eventHandler
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
foreach ($referenceFields as $fieldName => $fieldModel) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @param App\EventHandler $eventHandler
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* EntityAfterLink handler function.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Vtiger_MultiReferenceValue_UIType::setRecordToCron($sourceModule, $destinationModule, $params['sourceRecordId']);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @param App\EventHandler $eventHandler
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* EntityAfterSave function.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Vtiger_MultiReferenceValue_UIType::setRecordToCron($module, $moduleName, $recordModel->get($fieldName));
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* EntityAfterTransferUnLink handler function.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$moduleIds = Vtiger_MultiReferenceValue_UIType::getMultiReferenceModules($moduleName);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @package Handler
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (\Vtiger_MultiReferenceValue_UIType::getFieldsByModules($sourceModule, $destinationModule)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$this->entityAfterLink($eventHandler);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public function entityAfterLink(App\EventHandler $eventHandler)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ($module && \in_array(\App\Module::getModuleId($module), $moduleIds)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* EntityAfterTransferLink handler function.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$module = \App\Record::getType($recordModel->get($fieldName));
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$this->entityAfterLink($eventHandler);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$referenceFields = $recordModel->getModule()->getFieldsByReference();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (!$recordModel->isNew() && false !== $recordModel->getPreviousValue($fieldName) && $fieldModel->isActiveField()) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @param App\EventHandler $eventHandler
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$moduleName = $eventHandler->getModuleName();
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
Vtiger_MultiReferenceValue_UIType::setRecordToCron($module, $moduleName, $recordModel->get($fieldName));
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
Vtiger_MultiReferenceValue_UIType::setRecordToCron($sourceModule, $destinationModule, $params['sourceRecordId']);
- Exclude checks
Line exceeds 120 characters; contains 130 characters Open
Vtiger_MultiReferenceValue_UIType::setRecordToCron($destinationModule, $sourceModule, $params['destinationRecordId']);
- Exclude checks
Line exceeds 120 characters; contains 133 characters Open
if (!$recordModel->isNew() && false !== $recordModel->getPreviousValue($fieldName) && $fieldModel->isActiveField()) {
- Exclude checks
Class name "Vtiger_MultiReferenceUpdater_Handler" is not in camel caps format Open
class Vtiger_MultiReferenceUpdater_Handler
- Exclude checks