Function setTokens
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function setTokens(string $fieldName, string $moduleName)
{
$moduleModel = \Vtiger_Module_Model::getInstance($moduleName);
$fieldModel = $moduleModel->getFieldByName($fieldName);
if ($fieldModel && $fieldModel->isActiveField()) {
- 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 '31', column '23'). Open
$dataReader = (new \App\QueryGenerator($moduleName))
- 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 '46', column '9'). Open
(new \App\BatchMethod(['method' => __METHOD__, 'params' => [$fieldName, $moduleName, time()]]))->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
Avoid using static access to class '\App\Encryption' in method 'generateToken'. Open
return hash('sha256', microtime(true) . \App\Encryption::generatePassword(20));
- 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 'setTokens'. Open
$recordModel = \Vtiger_Record_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_Module_Model' in method 'setTokens'. Open
$moduleModel = \Vtiger_Module_Model::getInstance($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 generatePassword
from undeclared class \App\Encryption
(Did you mean class \Tests\App\Encryption) Open
return hash('sha256', microtime(true) . \App\Encryption::generatePassword(20));
- Exclude checks
Call to method addCondition
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$dataReader = (new \App\QueryGenerator($moduleName))
- Exclude checks
Call to method __construct
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$dataReader = (new \App\QueryGenerator($moduleName))
- Exclude checks
Call to undeclared method \Vtiger_Base_UIType::generateToken
Open
$token = $fieldModel->getUITypeModel()->generateToken();
- 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
* Sets token data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($fieldModel && $fieldModel->isActiveField()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new \App\QueryGenerator($moduleName))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $fieldName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set($fieldModel->getName(), $token)->setDataForSave([$fieldModel->getTableName() => [$fieldModel->getColumnName() => $token]])->save();
- Exclude checks
Line exceeds 120 characters; contains 165 characters Open
$recordModel->set($fieldModel->getName(), $token)->setDataForSave([$fieldModel->getTableName() => [$fieldModel->getColumnName() => $token]])->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
* @param string $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
->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Generate token.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$limit) {
- 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
$moduleModel = \Vtiger_Module_Model::getInstance($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
return hash('sha256', microtime(true) . \App\Encryption::generatePassword(20));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->addCondition($fieldModel->getName(), '', 'y')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function setTokens(string $fieldName, string $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
(new \App\BatchMethod(['method' => __METHOD__, 'params' => [$fieldName, $moduleName, time()]]))->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- 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 generateToken(): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$limit = 5000;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->createQuery()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->createCommand()
- 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
->setFields(['id'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = \Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
- 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
$fieldModel = $moduleModel->getFieldByName($fieldName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$token = $fieldModel->getUITypeModel()->generateToken();
- 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 ($recordId = $dataReader->readColumn(0)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
--$limit;
- Exclude checks