Function doTask
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function doTask($recordModel = null)
{
$users = [];
foreach ($this->members as $member) {
$users = array_merge($users, \App\PrivilegeUtil::getUserByMember($member));
- 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 '46', column '10'). Open
(new \App\BatchMethod(['method' => '\App\Mailer::sendFromTemplate', 'params' => ['params' => [
- 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 assigning values to variables in if clauses and the like (line '45', column '63'). Open
public function doTask($recordModel = null)
{
$users = [];
foreach ($this->members as $member) {
$users = array_merge($users, \App\PrivilegeUtil::getUserByMember($member));
- 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_Record_Model' in method 'doTask'. Open
$userRecordModel = \Vtiger_Record_Model::getInstanceById($user, '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 = array_merge($users, \App\PrivilegeUtil::getUserByMember($member));
- 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 unused parameters such as '$recordModel'. Open
public function doTask($recordModel = null)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Reference to undeclared property \VTEmailReport->emailoptout
Open
$checkApproval = (bool) ($this->emailoptout ?? null);
- Exclude checks
Reference to undeclared property \VTEmailReport->members
(Did you mean $member) Open
foreach ($this->members as $member) {
- Exclude checks
Reference to undeclared property \VTEmailReport->template
Open
'template' => $this->template,
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class VTEmailReport extends VTTask
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
foreach ($this->members as $member) {
- 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 getFieldNames()
- 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
foreach (array_unique($users) as $user) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* Get field names.
- 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
(new \App\BatchMethod(['method' => '\App\Mailer::sendFromTemplate', 'params' => ['params' => [
- 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 $recordEventState = self::RECORD_EVENT_INACTIVE;
- 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
]]]))->save();
- 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 doTask($recordModel = null)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @package App
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @param Vtiger_Record_Model $recordModel
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'textParserParams' => [
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'userId' => $user
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/** {@inheritdoc} */
- 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 ('Active' === $userRecordModel->get('status') && !empty($userEmail = $userRecordModel->get('email1')) && (!$checkApproval || $userRecordModel->get('emailoptout'))) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$checkApproval = (bool) ($this->emailoptout ?? 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
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* Execute task.
- 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
$users = [];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$userRecordModel = \Vtiger_Record_Model::getInstanceById($user, 'Users');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'to' => $userEmail,
- 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
$users = array_merge($users, \App\PrivilegeUtil::getUserByMember($member));
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @return string[]
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return ['template', 'members', 'emailoptout'];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'template' => $this->template,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
]
- Exclude checks
Line exceeds 120 characters; contains 180 characters Open
if ('Active' === $userRecordModel->get('status') && !empty($userEmail = $userRecordModel->get('email1')) && (!$checkApproval || $userRecordModel->get('emailoptout'))) {
- Exclude checks