Function editViewPreSave
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function editViewPreSave(App\EventHandler $eventHandler)
{
$recordModel = $eventHandler->getRecordModel();
$response = ['result' => true];
$fieldsDependency = \App\FieldsDependency::getByRecordModel(\App\Request::_getByType('fromView'), $recordModel);
- 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 assigning values to variables in if clauses and the like (line '48', column '50'). Open
public function editViewPreSave(App\EventHandler $eventHandler)
{
$recordModel = $eventHandler->getRecordModel();
$response = ['result' => true];
$fieldsDependency = \App\FieldsDependency::getByRecordModel(\App\Request::_getByType('fromView'), $recordModel);
- 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\FieldsDependency' in method 'editViewPreSave'. Open
$fieldsDependency = \App\FieldsDependency::getByRecordModel(\App\Request::_getByType('fromView'), $recordModel);
- 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\FieldsDependency' in method 'editViewChangeValue'. Open
$fieldsDependency = \App\FieldsDependency::getByRecordModel(\App\Request::_getByType('fromView'), $recordModel);
- 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_Record_Model' in method 'vars'. Open
$recordModel = Vtiger_Record_Model::getCleanInstance($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\FieldsDependency' in method 'vars'. Open
}
- 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 'editViewChangeValue'. Open
$fieldsDependency = \App\FieldsDependency::getByRecordModel(\App\Request::_getByType('fromView'), $recordModel);
- 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\Language' in method 'editViewPreSave'. Open
'message' => \App\Language::translate('LBL_NOT_FILLED_MANDATORY_FIELDS') . ': <br /> - ' . implode('<br /> - ', $mandatoryFields),
- 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 'editViewPreSave'. Open
$fieldsDependency = \App\FieldsDependency::getByRecordModel(\App\Request::_getByType('fromView'), $recordModel);
- 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 "mandatory" 3 times. Open
if ($fieldsDependency['show']['mandatory']) {
- 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 "frontend" 4 times. Open
if ($fieldsDependency['show']['frontend']) {
- 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.
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Vtiger_FieldsDependency_Handler
- Exclude checks
The class Vtiger_FieldsDependency_Handler is not named in CamelCase. Open
class Vtiger_FieldsDependency_Handler
{
/**
* EditViewChangeValue 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
if ($fieldsDependency['show']['mandatory']) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$mandatoryFields = [];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'result' => false,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'message' => \App\Language::translate('LBL_NOT_FILLED_MANDATORY_FIELDS') . ': <br /> - ' . implode('<br /> - ', $mandatoryFields),
- 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 (empty($recordModel)) {
- 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
return null;
- 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
$mandatoryFields[] = $fieldModel->getFullLabelTranslation();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @param string $moduleName
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @license YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$return['showFields'] = $fieldsDependency['show']['frontend'];
- 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
return $response;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @return array|null
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
- 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
$return['hideFields'] = $fieldsDependency['hide']['frontend'];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$fieldsDependency = \App\FieldsDependency::getByRecordModel(\App\Request::_getByType('fromView'), $recordModel);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return \App\FieldsDependency::getByRecordModel($view, $recordModel)['conditionsFields'];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @copyright YetiForce S.A.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* EditViewChangeValue handler function.
- 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
if ($fieldsDependency['hide']['frontend']) {
- 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
$response = [
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'hoverField' => reset($fieldsDependency['show']['mandatory']),
- 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
if (\App\EventHandler::EDIT_VIEW_CHANGE_VALUE === $name) {
- 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
$return = [];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return $return;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public function editViewPreSave(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
* @param array $params
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$fieldsDependency = \App\FieldsDependency::getByRecordModel(\App\Request::_getByType('fromView'), $recordModel);
- 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
{
- 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
$response = ['result' => true];
- 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 editViewChangeValue(App\EventHandler $eventHandler)
- 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
* @param string $name
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ($fieldsDependency['show']['frontend']) {
- 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 vars(string $name, array $params, string $moduleName): ?array
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* EditViewPreSave handler function.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ('' === $recordModel->get($fieldName) && ($fieldModel = $recordModel->getField($fieldName)) && $fieldModel->isActiveField()) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ($mandatoryFields) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
foreach ($fieldsDependency['show']['mandatory'] as $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
* @package Handler
- 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
* Get variables for the current event.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
[$recordModel,$view] = $params;
- Exclude checks
Line exceeds 120 characters; contains 145 characters Open
if ('' === $recordModel->get($fieldName) && ($fieldModel = $recordModel->getField($fieldName)) && $fieldModel->isActiveField()) {
- Exclude checks
Line exceeds 120 characters; contains 150 characters Open
'message' => \App\Language::translate('LBL_NOT_FILLED_MANDATORY_FIELDS') . ': <br /> - ' . implode('<br /> - ', $mandatoryFields),
- Exclude checks
Class name "Vtiger_FieldsDependency_Handler" is not in camel caps format Open
class Vtiger_FieldsDependency_Handler
- Exclude checks