Method deleteAllRecords
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function deleteAllRecords(string $untilModifiedTime, int $userId)
{
$actualUserId = App\User::getCurrentUserId();
try {
if (!App\User::isExists($userId)) {
Function deleteAllRecords
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function deleteAllRecords(string $untilModifiedTime, int $userId)
{
$actualUserId = App\User::getCurrentUserId();
try {
if (!App\User::isExists($userId)) {
- 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 '75', column '11'). Open
(new App\BatchMethod(['method' => 'RecycleBin_Module_Model::deleteAllRecords', 'params' => [$untilModifiedTime, $userId]]))->save();
- 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 '61', column '15'). Open
throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);
- 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 '66', column '23'). Open
$dataReader = (new \App\Db\Query())->select(['crmid', 'setype'])->from('vtiger_crmentity')
- 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 'App\User' in method 'deleteAllRecords'. Open
App\User::setCurrentUserId($userId);
- 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 '\vtlib\Functions' in method 'deleteAllRecords'. Open
$modulesList = \vtlib\Functions::getAllModules(true, false, 0);
- 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\Config' in method 'deleteAllRecords'. Open
$deleteMaxCount = App\Config::module('RecycleBin', 'DELETE_MAX_COUNT');
- 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\User' in method 'deleteAllRecords'. Open
App\User::setCurrentUserId($actualUserId);
- 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\User' in method 'deleteAllRecords'. Open
App\User::setCurrentUserId($actualUserId);
- 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 '\vtlib\Functions' in method 'getAllModuleList'. Open
return \vtlib\Functions::getAllModules(true, false, 0);
- 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\Log' in method 'deleteAllRecords'. Open
\App\Log::error($ex->__toString());
- 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 'deleteAllRecords'. Open
$recordModel = Vtiger_Record_Model::getInstanceById($row['crmid'], $row['setype']);
- 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\User' in method 'deleteAllRecords'. Open
$actualUserId = App\User::getCurrentUserId();
- 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\User' in method 'deleteAllRecords'. Open
if (!App\User::isExists($userId)) {
- 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 "setype" 3 times. Open
$dataReader = (new \App\Db\Query())->select(['crmid', 'setype'])->from('vtiger_crmentity')
- 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 to method setCurrentUserId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
App\User::setCurrentUserId($userId);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$dataReader = (new \App\Db\Query())->select(['crmid', 'setype'])->from('vtiger_crmentity')
- Exclude checks
Call to method setCurrentUserId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
App\User::setCurrentUserId($actualUserId);
- Exclude checks
Call to method error
from undeclared class \App\Log
Open
\App\Log::error($ex->__toString());
- Exclude checks
Call to method setCurrentUserId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
App\User::setCurrentUserId($actualUserId);
- Exclude checks
Call to method getCurrentUserId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$actualUserId = App\User::getCurrentUserId();
- Exclude checks
Call to method isExists
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
if (!App\User::isExists($userId)) {
- Exclude checks
Saw an @param annotation for recordsToDelete,
but it was not found in the param list of function deleteAllRecords(string $untilModifiedTime, int $userId)
Open
* @param int[] $recordsToDelete
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class RecycleBin_Module_Model extends Vtiger_Module_Model
- Exclude checks
The class RecycleBin_Module_Model is not named in CamelCase. Open
class RecycleBin_Module_Model extends Vtiger_Module_Model
{
/**
* Function to get all available modules for list.
*
- 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
Only one argument is allowed per line in a multi-line function call Open
['<=', 'modifiedtime', $untilModifiedTime], ])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function isQuickSearchEnabled(): bool
- 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 false;
- 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
/** {@inheritdoc} */
- 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 false;
- 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 function getAllModuleList()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return \vtlib\Functions::getAllModules(true, false, 0);
- 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
$dataReader = (new \App\Db\Query())->select(['crmid', 'setype'])->from('vtiger_crmentity')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->delete();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
--$deleteMaxCount;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
App\User::setCurrentUserId($actualUserId);
- 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 isAdvSortEnabled(): bool
- 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
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modulesList = \vtlib\Functions::getAllModules(true, false, 0);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::error($ex->__toString());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\NoPermitted('ERR_PERMISSION_DENIED', 406);
- 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
['<=', 'modifiedtime', $untilModifiedTime], ])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array|mixed
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function isCustomViewAdvCondEnabled(): bool
- 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
/** {@inheritdoc} */
- 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\User::isExists($userId)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int[] $recordsToDelete
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$actualUserId = App\User::getCurrentUserId();
- 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
* @throws \App\Exceptions\NoPermitted
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function deleteAllRecords(string $untilModifiedTime, int $userId)
- Exclude checks
Line exceeds 120 characters; contains 152 characters Open
(new App\BatchMethod(['method' => 'RecycleBin_Module_Model::deleteAllRecords', 'params' => [$untilModifiedTime, $userId]]))->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get all available modules for list.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['vtiger_crmentity.deleted' => 1],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (\Throwable $ex) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
App\User::setCurrentUserId($actualUserId);
- 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
* Delete all records from recycle to given date and module.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $untilModifiedTime
- 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(['method' => 'RecycleBin_Module_Model::deleteAllRecords', 'params' => [$untilModifiedTime, $userId]]))->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($recordModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- 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 (0 >= $deleteMaxCount) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $userId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$deleteMaxCount = App\Config::module('RecycleBin', 'DELETE_MAX_COUNT');
- 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
/**
- 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
->createCommand()->query();
- 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
if (!$recordModel->privilegeToDelete()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['and',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
App\User::setCurrentUserId($userId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['in', 'setype', array_column($modulesList, 'name')],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = Vtiger_Record_Model::getInstanceById($row['crmid'], $row['setype']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Multi-line function call not indented correctly; expected 16 spaces but found 24 Open
['<=', 'modifiedtime', $untilModifiedTime], ])
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
['<=', 'modifiedtime', $untilModifiedTime], ])
- Exclude checks
Class name "RecycleBin_Module_Model" is not in camel caps format Open
class RecycleBin_Module_Model extends Vtiger_Module_Model
- Exclude checks