Function reloadApprovals
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function reloadApprovals(int $approvalId): void
{
$moduleName = 'Approvals';
if (\App\Record::isExists($approvalId, $moduleName)) {
$contactModal = \Vtiger_Module_Model::getInstance('Contacts');
- 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 '56', column '12'). Open
(new \App\BatchMethod([
- 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
Missing class import via use statement (line '51', column '25'). Open
$dataReader = (new \App\QueryGenerator('ApprovalsRegister'))
- 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
Missing class import via use statement (line '30', column '9'). Open
(new \App\BatchMethod([
- 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 '\Vtiger_Module_Model' in method 'reloadApprovals'. Open
$contactModal = \Vtiger_Module_Model::getInstance('Contacts');
- 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 'reloadApprovals'. Open
if (\App\Record::isExists($approvalId, $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
Call to method __construct
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$dataReader = (new \App\QueryGenerator('ApprovalsRegister'))
- Exclude checks
Call to method setFields
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$dataReader = (new \App\QueryGenerator('ApprovalsRegister'))
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Approvals_Approvals_Handler
- Exclude checks
The class Approvals_Approvals_Handler is not named in CamelCase. Open
class Approvals_Approvals_Handler
{
/**
* EntityAfterSave 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 to indent lines; tabs are not allowed Open
'params' => [$recordModel->getId()]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param App\EventHandler $eventHandler
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* EntityAfterSave handler function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModel = $recordModel->getField('approvals_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
$contactModal = \Vtiger_Module_Model::getInstance('Contacts');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'method' => 'ApprovalsRegister_Module_Model::reloadApprovals',
- 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
->createQuery()->createCommand()->query();
- 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
$moduleName = 'Approvals';
- Exclude checks
Line exceeds 120 characters; contains 150 characters Open
&& ($recordModel->get($fieldModel->getName()) === $acceptValue || $acceptValue === $recordModel->getPreviousValue($fieldModel->getName()))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $approvalId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->setFields(['contactid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
]))->save();
- 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
&& $fieldModel->isActiveField()
- 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
->addCondition('approvalsid', $approvalId, 'eid')->setDistinct('contactid')
- 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 entityAfterSave(App\EventHandler $eventHandler)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$acceptValue = 'PLL_ACTIVE';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
&& ($recordModel->get($fieldModel->getName()) === $acceptValue || $acceptValue === $recordModel->getPreviousValue($fieldModel->getName()))
- 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
$recordModel = $eventHandler->getRecordModel();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Reload approvals.
- 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
foreach ($contactModal->getFieldsByType('multiReference', true) as $fieldModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
]))->save();
- 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
while ($contactId = $dataReader->readColumn(0)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'params' => [$contactId]
- 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
(new \App\BatchMethod([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'method' => 'Approvals_Approvals_Handler::reloadApprovals',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($fieldModel
- 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
}
- 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 reloadApprovals(int $approvalId): void
- 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 ($fieldModel->getReferenceList() === [$moduleName]) {
- 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 (\App\Record::isExists($approvalId, $moduleName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new \App\QueryGenerator('ApprovalsRegister'))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
(new \App\BatchMethod([
- Exclude checks
Class name "Approvals_Approvals_Handler" is not in camel caps format Open
class Approvals_Approvals_Handler
- Exclude checks