Function getStructure
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function getStructure()
{
if (!empty($this->structuredValues)) {
return $this->structuredValues;
}
- 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
Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed. Open
public function getStructure()
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Avoid using static access to class 'Vtiger_Loader' in method 'getInstanceFromRecordModel'. Open
$className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->getName(true));
- 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_Loader' in method 'getInstanceForModule'. Open
$className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->get('name'));
- 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
Saw unextractable annotation for comment '* @param <type> $module - module model'</type>
Open
* @param <type> $module - module model
- Exclude checks
Returning type false
but getRecord()
is declared to return \Vtiger_Record_Model
Open
return $this->record;
- Exclude checks
Argument 3 (moduleName)
is false
but \Vtiger_Loader::getComponentClassName()
takes string
defined at /code/include/Loader.php:149
Open
$className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->getName(true));
- Exclude checks
Saw unextractable annotation for comment '* @param <type> $record - record instance'</type>
Open
* @param <type> $record - record instance
- Exclude checks
Call with 1 arg(s) to \Vtiger_Module_Model::getName()
which only takes 0 arg(s) defined at /code/modules/Vtiger/models/Module.php:42
Open
$className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->getName(true));
- Exclude checks
Returning type false
but getModule()
is declared to return \Vtiger_Module_Model
Open
return $this->module;
- Exclude checks
Call to method getName
on non-class type false
Open
return $this->record->getName();
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Vtiger_RecordStructure_Model extends \App\Base
- Exclude checks
The class Vtiger_RecordStructure_Model is not named in CamelCase. Open
class Vtiger_RecordStructure_Model extends \App\Base
{
protected $record = false;
protected $module = false;
protected $structuredValues = [];
- 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
protected $module = 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
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->record;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getRecordName()
- 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
$recordExists = !empty($recordModel);
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
$className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->getName(true));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to retieve the instance from module model.
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
$className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->get('name'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Vtiger_Record_Model
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to set the module.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param <type> $module - module 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
$recordModel = $this->getRecord();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to retieve the instance from record model.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Vtiger_RecordStructure_Model
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->record = $record;
- 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 getStructure()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel = $this->getModule();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModelList = $blockModel->getFields();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModel->set('fieldvalue', $recordModel->get($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
const RECORD_STRUCTURE_MODE_MASSEDIT = 'MassEdit';
- 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->record->getName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->module;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$blockModelList = $moduleModel->getBlocks();
- 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
$instance->setModule($moduleModel)->setRecord($recordModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getInstanceForModule($moduleModel, $mode = self::RECORD_STRUCTURE_MODE_DEFAULT)
- 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
$instance->setModule($moduleModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const RECORD_STRUCTURE_MODE_EDIT = 'Edit';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to set the record Model.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Vtiger_Module_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
$this->module = $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
*
- 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
const RECORD_STRUCTURE_MODE_DETAIL = 'Detail';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param <type> $record - record instance
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Vtiger_RecordStructure_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
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Vtiger_Module_Model $moduleModel - module instance
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $mode
- 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
$this->structuredValues[$blockLabel][$fieldName] = $fieldModel;
- 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 Vtiger_Record_Model $recordModel - record instance
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->getName(true));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $structuredValues = [];
- 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 - values in structure array('block'=>array(fieldinfo));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($blockModelList as $blockLabel => $blockModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->structuredValues[$blockLabel] = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($fieldModel->isViewable()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->structuredValues;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getInstanceFromRecordModel($recordModel, $mode = self::RECORD_STRUCTURE_MODE_DEFAULT)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getRecord()
- 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
public function setModule($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
$className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->get('name'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const RECORD_STRUCTURE_MODE_DEFAULT = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const RECORD_STRUCTURE_MODE_SUMMARY = 'Summary';
- 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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Vtiger_RecordStructure_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
if (!empty($this->structuredValues)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $record = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const RECORD_STRUCTURE_MODE_QUICKCREATE = 'QuickCreate';
- 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 values in stuctured format.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance = new $className();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $instance;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setRecord($record)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getModule()
- 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->structuredValues;
- 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
if ($recordExists) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $mode
- 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 record.
- 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 (!empty($fieldModelList)) {
- 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 Vtiger_RecordStructure_Model
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel = $recordModel->getModule();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance = new $className();
- Exclude checks
Class name "Vtiger_RecordStructure_Model" is not in camel caps format Open
class Vtiger_RecordStructure_Model extends \App\Base
- Exclude checks