Method doTask
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function doTask($recordModel)
{
$moduleName = $recordModel->getModuleName();
$recordId = $recordModel->getId();
switch ($this->recipients) {
Function doTask
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function doTask($recordModel)
{
$moduleName = $recordModel->getModuleName();
$recordId = $recordModel->getId();
switch ($this->recipients) {
- 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 using static access to class '\App\User' in method 'doTask'. Open
if (!empty($this->skipCurrentUser) && false !== ($key = array_search(\App\User::getCurrentUserId(), $users))) {
- 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\PrivilegeUtil' in method 'doTask'. Open
$users = \App\PrivilegeUtil::getUserByMember($this->recipients);
- 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 '60', column '52'). Open
public function doTask($recordModel)
{
$moduleName = $recordModel->getModuleName();
$recordId = $recordModel->getId();
switch ($this->recipients) {
- 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 'Vtiger_Watchdog_Model' in method 'doTask'. Open
$watchdog = Vtiger_Watchdog_Model::getInstanceById($recordId, $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 'Vtiger_Record_Model' in method 'doTask'. Open
$notification = Vtiger_Record_Model::getCleanInstance('Notification');
- 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\ModuleHierarchy' in method 'doTask'. Open
$relatedField = \App\ModuleHierarchy::getMappingRelatedField($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\TextParser' in method 'doTask'. Open
$textParser = \App\TextParser::getInstanceByModel($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 "shownerid" 3 times. Open
$users = array_merge([$recordModel->get('assigned_user_id')], explode(',', $recordModel->get('shownerid')));
- 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 with 3 arg(s) to \Vtiger_Record_Model::set()
which only takes 2 arg(s) defined at /code/modules/Vtiger/models/Record.php:88
Open
$notification->set('title', $textParser->setContent($this->title)->parse()->getContent(), 'Text');
- Exclude checks
Reference to undeclared property \VTWatchdog->type
Open
$notification->set('notification_type', $this->type);
- Exclude checks
Reference to undeclared property \VTWatchdog->recipients
Open
switch ($this->recipients) {
- Exclude checks
Reference to undeclared property \VTWatchdog->skipCurrentUser
Open
if (!empty($this->skipCurrentUser) && false !== ($key = array_search(\App\User::getCurrentUserId(), $users))) {
- Exclude checks
Reference to undeclared property \VTWatchdog->recipients
Open
$users = \App\PrivilegeUtil::getUserByMember($this->recipients);
- Exclude checks
Reference to undeclared property \VTWatchdog->title
Open
$notification->set('title', $textParser->setContent($this->title)->parse()->getContent(), 'Text');
- Exclude checks
Call to method getCurrentUserId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
if (!empty($this->skipCurrentUser) && false !== ($key = array_search(\App\User::getCurrentUserId(), $users))) {
- Exclude checks
Call to method getInstanceByModel
from undeclared class \App\TextParser
(Did you mean class \Tests\App\TextParser) Open
$textParser = \App\TextParser::getInstanceByModel($recordModel);
- Exclude checks
Call with 3 arg(s) to \Vtiger_Record_Model::set()
which only takes 2 arg(s) defined at /code/modules/Vtiger/models/Record.php:88
Open
$notification->set('description', $textParser->setContent($this->message)->parse()->getContent(), 'Text');
- Exclude checks
Reference to undeclared property \VTWatchdog->message
Open
$notification->set('description', $textParser->setContent($this->message)->parse()->getContent(), 'Text');
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class VTWatchdog extends VTTask
- Exclude checks
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 12 and the first side effect is on line 10. Open
<?php
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getFieldNames()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get request method name for field name.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Execute task.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Vtiger_Record_Model $recordModel
- 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
case 'showner':
- 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
case 'owner_and_showner':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $executeImmediately = 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
public function doTask($recordModel)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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
$users = explode(',', $recordModel->get('shownerid'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return ['type', 'message', 'recipients', 'title', 'skipCurrentUser'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$notification->setHandlerExceptions(['disableHandlers' => true]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($this->recipients) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$users = \App\PrivilegeUtil::getUserByMember($this->recipients);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$users = array_filter($users);
- 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 getFieldsNamesRequestMethod(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'watchdog':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$watchdog = Vtiger_Watchdog_Model::getInstanceById($recordId, $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'owner':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($this->skipCurrentUser) && false !== ($key = array_search(\App\User::getCurrentUserId(), $users))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$textParser = \App\TextParser::getInstanceByModel($recordModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$notification->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
$users = [$recordModel->get('assigned_user_id')];
- 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
$moduleName = $recordModel->getModuleName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedField = \App\ModuleHierarchy::getMappingRelatedField($moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $srcWatchdogModule = 'Notification';
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
$users = array_merge([$recordModel->get('assigned_user_id')], explode(',', $recordModel->get('shownerid')));
- 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
$recordId = $recordModel->getId();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$users = array_merge([$recordModel->get('assigned_user_id')], explode(',', $recordModel->get('shownerid')));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return ['message' => 'getForHtml'];
- 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
$users = $watchdog->getWatchingUsers();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$notification->set('notification_status', 'PLL_UNREAD');
- 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
$notification->set('title', $textParser->setContent($this->title)->parse()->getContent(), 'Text');
- 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
$notification->set('shownerid', implode(',', $users));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($users[$key]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$notification = Vtiger_Record_Model::getCleanInstance('Notification');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$notification->set('description', $textParser->setContent($this->message)->parse()->getContent(), 'Text');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($users)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$notification->set($relatedField, $recordId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$notification->set('notification_type', $this->type);
- Exclude checks