Function getListFields
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getListFields(): array
{
if (!isset($this->listFieldModels)) {
$fieldObjects = [];
$service = $this->getService();
- 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 '55', column '38'). Open
$fieldObjects[$fieldName] = new \App\Base(['name' => $fieldName, 'label' => $fieldLabel]);
- 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
Define a constant instead of duplicating this literal "index.php?module=" 3 times. Open
return 'index.php?module=' . $this->getName() . '&parent=Settings&view=Edit&typeApi=' . $this->typeApi;
- 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.
Reference to undeclared property \Settings_WebserviceUsers_Module_Model->listFieldModels
Open
return $this->listFieldModels;
- Exclude checks
Reference to undeclared property \Settings_WebserviceUsers_Module_Model->listFieldModels
Open
$this->listFieldModels = $fieldObjects;
- Exclude checks
Reference to undeclared property \Settings_WebserviceUsers_Module_Model->listFieldModels
Open
if (!isset($this->listFieldModels)) {
- Exclude checks
Returning type string
but getBaseTable()
is declared to return \type
Open
return $this->getService()->baseTable;
- Exclude checks
Returning type ?object
but getService()
is declared to return \Settings_WebserviceUsers_Record_Model
Open
return $recordService;
- Exclude checks
Return type of getBaseTable()
is undeclared type \type
Open
public function getBaseTable()
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_WebserviceUsers_Module_Model extends Settings_Vtiger_Module_Model
- Exclude checks
The class Settings_WebserviceUsers_Module_Model is not named in CamelCase. Open
class Settings_WebserviceUsers_Module_Model extends Settings_Vtiger_Module_Model
{
/** @var string Api type. */
public $typeApi;
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldObjects[$fieldName] = new \App\Base(['name' => $fieldName, 'label' => $fieldLabel]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $name = 'WebserviceUsers';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $recordService;
- 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
$fieldObjects = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$service = $this->getService();
- 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
* @return type
- 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 'index.php?module=' . $this->getName() . '&parent=Settings&view=Edit&typeApi=' . $this->typeApi;
- 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 getService()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordService->typeApi = $this->typeApi;
- 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 $this->getService()->baseTable;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getTableIndex()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
return 'index.php?module=' . $this->getName() . '&parent=Settings&view=ListViewSession&typeApi=' . $this->typeApi;
- 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
$recordService = new $class();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->listFieldModels = $fieldObjects;
- 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
* Function to get the url for edit view of the module.
- 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
* Gets service record instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getNameFields()
- 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
* @return string - url
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getHistoryAccessActivityUrl(): 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
return 'index.php?module=' . $this->getName() . '&parent=Settings&view=HistoryAccessActivity&typeApi=' . $this->typeApi;
- 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 getBaseTable()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get table primary key.
- 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
* @return array - array which contains fields which together construct name fields
- 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
$recordService = null;
- 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
* Function returns name of table in database.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string URL
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getSessionViewUrl(): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return \Settings_WebserviceUsers_Record_Model
- 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
return $this->getService()->baseIndex;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
return 'index.php?module=' . $this->getName() . '&parent=Settings&view=HistoryAccessActivity&typeApi=' . $this->typeApi;
- 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 'index.php?module=' . $this->getName() . '&parent=Settings&view=ListViewSession&typeApi=' . $this->typeApi;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get the url for history activity view of the user.
- 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 $typeApi;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Module Name. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getListFields(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!isset($this->listFieldModels)) {
- 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
if (class_exists($class)) {
- 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 ($service->listFields as $fieldName => $fieldLabel) {
- 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
/** @var string Api type. */
- 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
* Function to retrieve name fields of a module.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [];
- 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 getEditViewUrl()
- 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 string URL
- 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
$class = "Settings_WebserviceUsers_{$this->typeApi}_Service";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($service) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->listFieldModels;
- 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
* Function to get the url for session view of the user.
- Exclude checks
Class name "Settings_WebserviceUsers_Module_Model" is not in camel caps format Open
class Settings_WebserviceUsers_Module_Model extends Settings_Vtiger_Module_Model
- Exclude checks