YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/models/RecordStructure.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
35%

Function getStructure has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    public function getStructure()
    {
        if (!empty($this->structuredValues)) {
            return $this->structuredValues;
        }
Severity: Minor
Found in modules/Vtiger/models/RecordStructure.php - About 2 hrs to fix

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()

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));

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'));

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

Returning type false but getRecord() is declared to return \Vtiger_Record_Model
Open

        return $this->record;

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));

Saw unextractable annotation for comment '* @param <type> $record - record instance'</type>
Open

     * @param <type> $record - record instance

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));

Returning type false but getModule() is declared to return \Vtiger_Module_Model
Open

        return $this->module;

Call to method getName on non-class type false
Open

        return $this->record->getName();
Severity: Critical
Found in modules/Vtiger/models/RecordStructure.php by phan

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

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 = [];

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;

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this;

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->record;

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getRecordName()

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        $recordExists = !empty($recordModel);

Line exceeds 120 characters; contains 123 characters
Open

        $className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->getName(true));

Spaces must be used to indent lines; tabs are not allowed
Open

     * Function to retieve the instance from module model.

Line exceeds 120 characters; contains 121 characters
Open

        $className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->get('name'));

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return Vtiger_Record_Model

Spaces must be used to indent lines; tabs are not allowed
Open

     * Function to set the module.

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param <type> $module - module model

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        $recordModel = $this->getRecord();

Spaces must be used to indent lines; tabs are not allowed
Open

     * Function to retieve the instance from record model.

Spaces must be used to indent lines; tabs are not allowed
Open

     * Function to get the module.

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return Vtiger_RecordStructure_Model

Spaces must be used to indent lines; tabs are not allowed
Open

        $this->record = $record;

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getStructure()

Spaces must be used to indent lines; tabs are not allowed
Open

        $moduleModel = $this->getModule();

Spaces must be used to indent lines; tabs are not allowed
Open

            $fieldModelList = $blockModel->getFields();

Spaces must be used to indent lines; tabs are not allowed
Open

                            $fieldModel->set('fieldvalue', $recordModel->get($fieldName));

Spaces must be used to indent lines; tabs are not allowed
Open

            }

Spaces must be used to indent lines; tabs are not allowed
Open

    const RECORD_STRUCTURE_MODE_MASSEDIT = 'MassEdit';

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->record->getName();

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->module;

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this;

Spaces must be used to indent lines; tabs are not allowed
Open

        $blockModelList = $moduleModel->getBlocks();

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        $instance->setModule($moduleModel)->setRecord($recordModel);

Spaces must be used to indent lines; tabs are not allowed
Open

    public static function getInstanceForModule($moduleModel, $mode = self::RECORD_STRUCTURE_MODE_DEFAULT)

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        $instance->setModule($moduleModel);

Spaces must be used to indent lines; tabs are not allowed
Open

    const RECORD_STRUCTURE_MODE_EDIT = 'Edit';

Spaces must be used to indent lines; tabs are not allowed
Open

     * Function to set the record Model.

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return Vtiger_Module_Model

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        $this->module = $module;

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    const RECORD_STRUCTURE_MODE_DETAIL = 'Detail';

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param <type> $record - record instance

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return Vtiger_RecordStructure_Model

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param Vtiger_Module_Model $moduleModel - module instance

Spaces must be used to indent lines; tabs are not allowed
Open

        return $instance;

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param mixed               $mode

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

                        $this->structuredValues[$blockLabel][$fieldName] = $fieldModel;

Spaces must be used to indent lines; tabs are not allowed
Open

                }

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param Vtiger_Record_Model $recordModel - record instance

Spaces must be used to indent lines; tabs are not allowed
Open

        $className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->getName(true));

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $structuredValues = [];

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array - values in structure array('block'=>array(fieldinfo));

Spaces must be used to indent lines; tabs are not allowed
Open

        foreach ($blockModelList as $blockLabel => $blockModel) {

Spaces must be used to indent lines; tabs are not allowed
Open

                $this->structuredValues[$blockLabel] = [];

Spaces must be used to indent lines; tabs are not allowed
Open

                    if ($fieldModel->isViewable()) {

Spaces must be used to indent lines; tabs are not allowed
Open

        return $this->structuredValues;

Spaces must be used to indent lines; tabs are not allowed
Open

    public static function getInstanceFromRecordModel($recordModel, $mode = self::RECORD_STRUCTURE_MODE_DEFAULT)

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getRecord()

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    public function setModule($module)

Spaces must be used to indent lines; tabs are not allowed
Open

                    }

Spaces must be used to indent lines; tabs are not allowed
Open

        $className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->get('name'));

Spaces must be used to indent lines; tabs are not allowed
Open

    const RECORD_STRUCTURE_MODE_DEFAULT = '';

Spaces must be used to indent lines; tabs are not allowed
Open

    const RECORD_STRUCTURE_MODE_SUMMARY = 'Summary';

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return Vtiger_RecordStructure_Model

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

        if (!empty($this->structuredValues)) {

Spaces must be used to indent lines; tabs are not allowed
Open

    protected $record = false;

Spaces must be used to indent lines; tabs are not allowed
Open

    const RECORD_STRUCTURE_MODE_QUICKCREATE = 'QuickCreate';

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * Function to get the values in stuctured format.

Spaces must be used to indent lines; tabs are not allowed
Open

        $instance = new $className();

Spaces must be used to indent lines; tabs are not allowed
Open

        return $instance;

Spaces must be used to indent lines; tabs are not allowed
Open

    public function setRecord($record)

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getModule()

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

            return $this->structuredValues;

Spaces must be used to indent lines; tabs are not allowed
Open

                foreach ($fieldModelList as $fieldName => $fieldModel) {

Spaces must be used to indent lines; tabs are not allowed
Open

                        if ($recordExists) {

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param mixed               $mode

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

     * Function to get the record.

Spaces must be used to indent lines; tabs are not allowed
Open

     *

Spaces must be used to indent lines; tabs are not allowed
Open

            if (!empty($fieldModelList)) {

Spaces must be used to indent lines; tabs are not allowed
Open

                        }

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return Vtiger_RecordStructure_Model

Spaces must be used to indent lines; tabs are not allowed
Open

        $moduleModel = $recordModel->getModule();

Spaces must be used to indent lines; tabs are not allowed
Open

        $instance = new $className();

Class name "Vtiger_RecordStructure_Model" is not in camel caps format
Open

class Vtiger_RecordStructure_Model extends \App\Base

There are no issues that match your filters.

Category
Status