YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSMailView/models/Relation.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

Method addRelation has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function addRelation($sourceRecordId, $destinationRecordId, $params = false)
    {
        $return = false;
        if (!\is_array($destinationRecordId)) {
            $destinationRecordId = [$destinationRecordId];
Severity: Minor
Found in modules/OSSMailView/models/Relation.php - About 1 hr to fix

    Missing class import via use statement (line '28', column '49').
    Open

            $relationModel = empty($this->getData) ? (new OSSMailView_GetRecordToMails_Relation()) : $this->getTypeRelationModel();

    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 '41', column '24').
    Open

                $eventHandler = new App\EventHandler();

    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

    The method addRelation has a boolean flag argument $params, which is a certain sign of a Single Responsibility Principle violation.
    Open

        public function addRelation($sourceRecordId, $destinationRecordId, $params = false)

    BooleanArgumentFlag

    Since: 1.4.0

    A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

    Example

    class Foo {
        public function bar($flag = true) {
        }
    }

    Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

    Avoid using static access to class 'CRMEntity' in method 'addRelation'.
    Open

                    'CRMEntity' => CRMEntity::getInstance($destinationModuleName),

    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 'CRMEntity' in method 'addRelation'.
    Open

                    CRMEntity::trackLinkedInfo($crmId);

    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\Record' in method 'addRelation'.
    Open

                $destinationModuleName = \App\Record::getType($crmId);

    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 '45', column '8').
    Open

        public function addRelation($sourceRecordId, $destinationRecordId, $params = false)
        {
            $return = false;
            if (!\is_array($destinationRecordId)) {
                $destinationRecordId = [$destinationRecordId];

    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

    Reference to undeclared property \OSSMailView_Relation_Model->getData (Did you mean \OSSMailView_Relation_Model->getData())
    Open

            $relationModel = empty($this->getData) ? (new OSSMailView_GetRecordToMails_Relation()) : $this->getTypeRelationModel();

    Reference to undeclared property \OSSMailView_GetRecordToMails_Relation->date
    Open

                $relationModel->date = $params;

    Reference to undeclared property \App\Relation\RelationAbstraction->date
    Open

                $relationModel->date = $params;

    Avoid excessively long variable names like $destinationModuleName. Keep variable name length under 20.
    Open

                $destinationModuleName = \App\Record::getType($crmId);

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class OSSMailView_Relation_Model extends Vtiger_Relation_Model

    The class OSSMailView_Relation_Model is not named in CamelCase.
    Open

    class OSSMailView_Relation_Model extends Vtiger_Relation_Model
    {
        /**
         * Add relation.
         *

    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

         * @param int|int[] $destinationRecordId

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

         * @param mixed     $params

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

                $destinationModuleName = \App\Record::getType($crmId);

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

                    $eventHandler->trigger('EntityAfterLink');

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

        }

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

                    'destinationModule' => 'OSSMailView',

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

                $eventHandler->setParams($data);

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

        {

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

                    'destinationRecordId' => $sourceRecordId,

    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 (!\is_array($destinationRecordId)) {

    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 bool

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

                $relationModel->date = $params;

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

         * Add relation.

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

            $relationModel = empty($this->getData) ? (new OSSMailView_GetRecordToMails_Relation()) : $this->getTypeRelationModel();

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

            if ($params) {

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

                ];

    Line exceeds 120 characters; contains 127 characters
    Open

            $relationModel = empty($this->getData) ? (new OSSMailView_GetRecordToMails_Relation()) : $this->getTypeRelationModel();

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

            foreach ($destinationRecordId as $crmId) {

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

                    CRMEntity::trackLinkedInfo($crmId);

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

         *

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

                    'sourceModule' => $destinationModuleName,

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

                if ($return = $relationModel->create($sourceRecordId, $crmId)) {

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

                $destinationRecordId = [$destinationRecordId];

    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 int       $sourceRecordId

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

                $eventHandler = new App\EventHandler();

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

                $eventHandler->setModuleName($destinationModuleName);

    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 addRelation($sourceRecordId, $destinationRecordId, $params = false)

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

            $return = false;

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

                $data = [

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

            return $return;

    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

                    'CRMEntity' => CRMEntity::getInstance($destinationModuleName),

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

                    'sourceRecordId' => $crmId,

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

                $eventHandler->trigger('EntityBeforeLink');

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

    class OSSMailView_Relation_Model extends Vtiger_Relation_Model

    There are no issues that match your filters.

    Category
    Status