YetiForceCompany/YetiForceCRM

View on GitHub
app/TextParser/RelatedRecordsDataFromField.php

Summary

Maintainability
A
40 mins
Test Coverage
F
0%

Consider simplifying this complex logical expression.
Open

        if (!$sourceFieldName || !$this->textParser->recordModel || empty($sourceRecordId = $this->textParser->recordModel->get($sourceFieldName))
            || !\App\Record::isExists($sourceRecordId) || !($recordModel = \Vtiger_Record_Model::getInstanceById($sourceRecordId)) || !$recordModel->isViewable()
        ) {
            return [];
        }
Severity: Major
Found in app/TextParser/RelatedRecordsDataFromField.php - About 40 mins to fix

    Missing class import via use statement (line '43', column '19').
    Open

            $instance = new \App\TextParser\RelatedRecordsData($textParser, $this->params);

    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 '\Vtiger_Record_Model' in method 'process'.
    Open

                || !\App\Record::isExists($sourceRecordId) || !($recordModel = \Vtiger_Record_Model::getInstanceById($sourceRecordId)) || !$recordModel->isViewable()

    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 assigning values to variables in if clauses and the like (line '36', column '69').
    Open

        public function process()
        {
            $sourceFieldName = array_shift($this->params);
            if (!$sourceFieldName || !$this->textParser->recordModel || empty($sourceRecordId = $this->textParser->recordModel->get($sourceFieldName))
                || !\App\Record::isExists($sourceRecordId) || !($recordModel = \Vtiger_Record_Model::getInstanceById($sourceRecordId)) || !$recordModel->isViewable()

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid using static access to class '\App\Record' in method 'process'.
    Open

                || !\App\Record::isExists($sourceRecordId) || !($recordModel = \Vtiger_Record_Model::getInstanceById($sourceRecordId)) || !$recordModel->isViewable()

    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 assigning values to variables in if clauses and the like (line '37', column '52').
    Open

        public function process()
        {
            $sourceFieldName = array_shift($this->params);
            if (!$sourceFieldName || !$this->textParser->recordModel || empty($sourceRecordId = $this->textParser->recordModel->get($sourceFieldName))
                || !\App\Record::isExists($sourceRecordId) || !($recordModel = \Vtiger_Record_Model::getInstanceById($sourceRecordId)) || !$recordModel->isViewable()

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Argument 1 (recordId) is null but \Vtiger_Record_Model::getInstanceById() takes int defined at /code/modules/Vtiger/models/Record.php:763
    Open

                || !\App\Record::isExists($sourceRecordId) || !($recordModel = \Vtiger_Record_Model::getInstanceById($sourceRecordId)) || !$recordModel->isViewable()

    Call to method getInstanceByModel from undeclared class \App\TextParser (Did you mean class \Tests\App\TextParser)
    Open

            $textParser = \App\TextParser::getInstanceByModel($recordModel)->setExtensionState($this->textParser->useExtension);

    Argument 1 (recordId) is null but \App\Record::isExists() takes int defined at /code/app/Record.php:266
    Open

                || !\App\Record::isExists($sourceRecordId) || !($recordModel = \Vtiger_Record_Model::getInstanceById($sourceRecordId)) || !$recordModel->isViewable()

    Reference to instance property useExtension from undeclared class \App\TextParser
    Open

            $textParser = \App\TextParser::getInstanceByModel($recordModel)->setExtensionState($this->textParser->useExtension);

    Variable $sourceRecordId is undeclared
    Open

                || !\App\Record::isExists($sourceRecordId) || !($recordModel = \Vtiger_Record_Model::getInstanceById($sourceRecordId)) || !$recordModel->isViewable()

    Reference to instance property recordModel from undeclared class \App\TextParser
    Open

            if (!$sourceFieldName || !$this->textParser->recordModel || empty($sourceRecordId = $this->textParser->recordModel->get($sourceFieldName))

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

        }

    Line exceeds 120 characters; contains 161 characters
    Open

                || !\App\Record::isExists($sourceRecordId) || !($recordModel = \Vtiger_Record_Model::getInstanceById($sourceRecordId)) || !$recordModel->isViewable()

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

            $instance = new \App\TextParser\RelatedRecordsData($textParser, $this->params);

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

            return $instance->process();

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

        /** @var mixed Parser type */

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

        /** @var string Default template */

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

        public $default = "YFParser('\$(custom : RelatedRecordsDataFromField|__SOURCE_FIELD_NAME__|__RELATION_MODULE_OR_RELATION_ID__|__FIELDS__|__CONDITIONS__|__LIMIT__|__ORDER_BY__|__RELATION_CONDITION__)\$')";

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

            if (!$sourceFieldName || !$this->textParser->recordModel || empty($sourceRecordId = $this->textParser->recordModel->get($sourceFieldName))

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

            ) {

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

        /** @var string Class name */

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

        public $type = 'pdf';

    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

        public function process()

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

            $textParser = \App\TextParser::getInstanceByModel($recordModel)->setExtensionState($this->textParser->useExtension);

    Line exceeds 120 characters; contains 124 characters
    Open

            $textParser = \App\TextParser::getInstanceByModel($recordModel)->setExtensionState($this->textParser->useExtension);

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

         * @return array

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

         * Process.

    Line exceeds 120 characters; contains 146 characters
    Open

            if (!$sourceFieldName || !$this->textParser->recordModel || empty($sourceRecordId = $this->textParser->recordModel->get($sourceFieldName))

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

        public $name = 'LBL_RECORDS_LIST_DATA_FROM_FIELD_TEMPLATE';

    Line exceeds 120 characters; contains 208 characters
    Open

        public $default = "YFParser('\$(custom : RelatedRecordsDataFromField|__SOURCE_FIELD_NAME__|__RELATION_MODULE_OR_RELATION_ID__|__FIELDS__|__CONDITIONS__|__LIMIT__|__ORDER_BY__|__RELATION_CONDITION__)\$')";

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

         */

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

                || !\App\Record::isExists($sourceRecordId) || !($recordModel = \Vtiger_Record_Model::getInstanceById($sourceRecordId)) || !$recordModel->isViewable()

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

            $sourceFieldName = array_shift($this->params);

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

                return [];

    There are no issues that match your filters.

    Category
    Status