Function getRecordModelsFromRequest
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function getRecordModelsFromRequest(App\Request $request)
{
$moduleName = $request->getModule();
$moduleModel = Vtiger_Module_Model::getInstance($moduleName);
$recordIds = self::getRecordsListFromRequest($request);
- 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 '34', column '19'). Open
$response = new Vtiger_Response();
- 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 '52', column '22'). Open
$recordIds = (new \App\Db\Query())->select(['id'])->from('vtiger_users')->column();
- 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 '19', column '14'). Open
throw new \App\Exceptions\NoPermitted('LBL_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
Avoid using static access to class 'Users_Record_Model' in method 'checkPermission'. Open
$currentUserModel = Users_Record_Model::getCurrentUserModel();
- 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 'getRecordModelsFromRequest'. 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
Avoid using static access to class '\App\Privilege' in method 'process'. Open
if (\App\Privilege::isPermitted($moduleName, 'Save', $recordId)) {
- 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 'getRecordModelsFromRequest'. Open
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleModel);
- 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
Declaration of function getRecordModelsFromRequest(\App\Request $request) : \Vtiger_Record_Model
should be compatible with function getRecordModelsFromRequest(\App\Request $request) : \Vtiger_Record_Model[]
defined in /code/modules/Vtiger/actions/MassSave.php:53
Open
public function getRecordModelsFromRequest(App\Request $request)
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$recordIds = (new \App\Db\Query())->select(['id'])->from('vtiger_users')->column();
- Exclude checks
Argument 2 (module)
is \Vtiger_Module_Model|\vtlib\Module|\vtlib\ModuleBasic
but \Vtiger_Record_Model::getInstanceById()
takes string
defined at /code/modules/Vtiger/models/Record.php:763
Open
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleModel);
- Exclude checks
Returning type array<int>|array{}</int>
but getRecordModelsFromRequest()
is declared to return \Vtiger_Record_Model
Open
return $recordModels;
- Exclude checks
Class \Vtiger_Record_Model
was passed to foreach, but it does not extend Traversable. This may be intentional, because some of that class's declared properties are accessible from this context. (This check excludes dynamic properties) Open
foreach ($recordModels as $recordId => $recordModel) {
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Users_MassSave_Action extends Vtiger_MassSave_Action
- Exclude checks
The class Users_MassSave_Action is not named in CamelCase. Open
class Users_MassSave_Action extends Vtiger_MassSave_Action
{
/** {@inheritdoc} */
public function checkPermission(App\Request $request)
{
- 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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Vtiger_Record_Model or Module specific Record Model instance
- 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
continue;
- 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 (!$currentUserModel->isAdminUser()) {
- 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
$recordModels[$recordId] = $recordModel;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setResult(true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($recordIds) && 'all' === $request->getRaw('selected_ids')) {
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModels = [];
- 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
$recordModels = $this->getRecordModelsFromRequest($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get the record model based on the request parameters.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getRecordModelsFromRequest(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$recordModel->isEditable()) {
- 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 \App\Request $request
- 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
$recordModels[$recordId] = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModel->getUITypeModel()->setValueFromRequest($request, $recordModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $recordModels;
- 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
$recordIds = self::getRecordsListFromRequest($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($recordModels as $recordId => $recordModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModelList = $moduleModel->getFields();
- 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 ($recordIds as $recordId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fieldModelList as $fieldName => $fieldModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function checkPermission(App\Request $request)
- 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
$recordIds = (new \App\Db\Query())->select(['id'])->from('vtiger_users')->column();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($fieldModel->isWritable() && $request->has($fieldName)) {
- 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
$response->emit();
- 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->setId($recordId);
- 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 = $request->getModule();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response = new Vtiger_Response();
- 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
$currentUserModel = Users_Record_Model::getCurrentUserModel();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\App\Privilege::isPermitted($moduleName, 'Save', $recordId)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = $request->getModule();
- Exclude checks
Class name "Users_MassSave_Action" is not in camel caps format Open
class Users_MassSave_Action extends Vtiger_MassSave_Action
- Exclude checks