YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Companies/models/Record.php

Summary

Maintainability
B
4 hrs
Test Coverage
F
27%

Method getFieldInstanceByName has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getFieldInstanceByName(string $name, string $label = ''): Vtiger_Field_Model
    {
        $moduleName = $this->getModule()->getName(true);
        $labels = $this->getModule()->getFormFields();
        $label = $label ?: ($labels[$name]['label'] ?? '');
Severity: Major
Found in modules/Settings/Companies/models/Record.php - About 2 hrs to fix

    Function getFieldInstanceByName has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getFieldInstanceByName(string $name, string $label = ''): Vtiger_Field_Model
        {
            $moduleName = $this->getModule()->getName(true);
            $labels = $this->getModule()->getFormFields();
            $label = $label ?: ($labels[$name]['label'] ?? '');
    Severity: Minor
    Found in modules/Settings/Companies/models/Record.php - About 55 mins 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

    Function save has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public function save(): void
        {
            $db = App\Db::getInstance('admin');
            $transaction = $db->beginTransaction();
    
    
    Severity: Minor
    Found in modules/Settings/Companies/models/Record.php - About 25 mins 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

    The method getFieldInstanceByName() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
    Open

        public function getFieldInstanceByName(string $name, string $label = ''): Vtiger_Field_Model
        {
            $moduleName = $this->getModule()->getName(true);
            $labels = $this->getModule()->getFormFields();
            $label = $label ?: ($labels[$name]['label'] ?? '');

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

    The class Settings_Companies_Record_Model has a coupling between objects value of 19. Consider to reduce the number of dependencies under 13.
    Open

    class Settings_Companies_Record_Model extends Settings_Vtiger_Record_Model
    {
        public $module;
        /** @var array Record changes */
        protected $changes = [];

    CouplingBetweenObjects

    Since: 1.1.0

    A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

    Example

    class Foo {
        /**
         * @var \foo\bar\X
         */
        private $x = null;
    
        /**
         * @var \foo\bar\Y
         */
        private $y = null;
    
        /**
         * @var \foo\bar\Z
         */
        private $z = null;
    
        public function setFoo(\Foo $foo) {}
        public function setBar(\Bar $bar) {}
        public function setBaz(\Baz $baz) {}
    
        /**
         * @return \SplObjectStorage
         * @throws \OutOfRangeException
         * @throws \InvalidArgumentException
         * @throws \ErrorException
         */
        public function process(\Iterator $it) {}
    
        // ...
    }

    Source https://phpmd.org/rules/design.html#couplingbetweenobjects

    Missing class import via use statement (line '57', column '15').
    Open

            $row = (new \App\Db\Query())->from('s_#__companies')->one($db);

    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 '174', column '13').
    Open

            throw new \App\Exceptions\NoPermitted('LBL_OPERATION_NOT_PERMITTED');

    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 '115', column '26').
    Open

                    $registration = (new \App\YetiForce\Register());

    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 '118', column '16').
    Open

                        throw new \App\Exceptions\AppException($error);

    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 '64', column '14').
    Open

                throw new \App\Exceptions\DbException('LBL_RECORD_NOT_FOUND');

    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 '\App\Cache' in method 'save'.
    Open

            \App\Cache::clear();

    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\Purifier' in method 'getDisplayValue'.
    Open

                    $value =\App\Purifier::encodeHtml($value);

    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

    The method getInstance uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                throw new \App\Exceptions\DbException('LBL_RECORD_NOT_FOUND');
            }

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

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

    Avoid using static access to class '\App\Fields\Country' in method 'getFieldInstanceByName'.
    Open

                    foreach (\App\Fields\Country::getAll() as $country) {

    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 'Settings_Vtiger_Module_Model' in method 'getModule'.
    Open

                $module = Settings_Vtiger_Module_Model::getInstance('Settings:Companies');

    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\Cache' in method 'save'.
    Open

            \App\Cache::staticDelete('CompanyGet', '');

    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\Language' in method 'getFieldInstanceByName'.
    Open

                        $params['picklistValues'][$industry] = \App\Language::translate($industry, $moduleName, null, false);

    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 '114', column '9').
    Open

        public function save(): void
        {
            $db = App\Db::getInstance('admin');
            $transaction = $db->beginTransaction();
    
    

    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\Language' in method 'getDisplayValue'.
    Open

                    $value =\App\Language::translateSingleMod($value, 'Other.Country');

    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\Module' in method 'getDisplayValue'.
    Open

                    $value = \App\Module::getModuleName((int) $value);

    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\Language' in method 'getDisplayValue'.
    Open

                    $value = App\Language::translate($value);

    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\Log' in method 'save'.
    Open

                \App\Log::error($ex->__toString());

    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\Language' in method 'getFieldInstanceByName'.
    Open

                        $params['picklistValues'][$country['name']] = \App\Language::translateSingleMod($country['name'], 'Other.Country', null, false);

    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 'Settings_Vtiger_Field_Model' in method 'getFieldInstanceByName'.
    Open

            return Settings_Vtiger_Field_Model::init($moduleName, $params);

    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 '117', column '9').
    Open

        public function save(): void
        {
            $db = App\Db::getInstance('admin');
            $transaction = $db->beginTransaction();
    
    

    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\Db' in method 'save'.
    Open

            $db = App\Db::getInstance('admin');

    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 'Settings_Companies_Module_Model' in method 'getFieldInstanceByName'.
    Open

                    foreach (Settings_Companies_Module_Model::getIndustryList() as $industry) {

    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\Db' in method 'getInstance'.
    Open

            $db = \App\Db::getInstance('admin');

    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\Process' in method 'save'.
    Open

                    \App\Process::removeEvent(\Settings_Companies_EditModal_View::MODAL_EVENT['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

    Define a constant instead of duplicating this literal "uitype" 5 times.
    Open

                'uitype' => 1,

    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.

    Define a constant instead of duplicating this literal "maximumlength" 3 times.
    Open

                'maximumlength' => '255',

    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.

    Rename "$module" which has the same name as the field declared at line 13.
    Open

                $module = Settings_Vtiger_Module_Model::getInstance('Settings:Companies');

    Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

    Noncompliant Code Example

    class Foo {
      public $myField;
    
      public function doSomething() {
        $myField = 0;
        ...
      }
    }
    

    See

    Define a constant instead of duplicating this literal "purifyType" 3 times.
    Open

                'purifyType' => \App\Purifier::TEXT

    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.

    Rename "$changes" which has the same name as the field declared at line 15.
    Open

                if (($changes = $this->getPreviousValue()) && (\count($changes) > 1) || false === $this->getPreviousValue('email')) {

    Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

    Noncompliant Code Example

    class Foo {
      public $myField;
    
      public function doSomething() {
        $myField = 0;
        ...
      }
    }
    

    See

    Define a constant instead of duplicating this literal "picklistValues" 4 times.
    Open

                    $params['picklistValues'] = [];

    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.

    Argument 3 (language) is null but \App\Language::translateSingleMod() takes bool|false|string defined at /code/app/Language.php:308
    Open

                        $params['picklistValues'][$country['name']] = \App\Language::translateSingleMod($country['name'], 'Other.Country', null, false);

    Call to method getName from undeclared class \Settings_Companies_Module_Model
    Open

            $moduleName = $this->getModule()->getName(true);

    Call to undeclared method \App\Db\Query::from
    Open

            $row = (new \App\Db\Query())->from('s_#__companies')->one($db);

    Return type of getModule() is undeclared type \Settings_Companies_Module_Model
    Open

        public function getModule(): Settings_Companies_Module_Model

    Call to method setRawCompanyData from undeclared class \App\YetiForce\Register
    Open

                    $registration->setRawCompanyData($this->getData())->register();

    Call to method getNameFields from undeclared class \Settings_Companies_Module_Model
    Open

                $fields = $this->getModule()->getNameFields();

    Call to method error from undeclared class \App\Log
    Open

                \App\Log::error($ex->__toString());

    Call to method __construct from undeclared class \App\YetiForce\Register
    Open

                    $registration = (new \App\YetiForce\Register());

    Call to method getIndustryList from undeclared class \Settings_Companies_Module_Model
    Open

                    foreach (Settings_Companies_Module_Model::getIndustryList() as $industry) {

    Returning type \Settings_Vtiger_Module_Model but getModule() is declared to return \Settings_Companies_Module_Model
    Open

            return $this->module;

    Reference to constant MODAL_EVENT from undeclared class \Settings_Companies_EditModal_View
    Open

                    \App\Process::removeEvent(\Settings_Companies_EditModal_View::MODAL_EVENT['name']);

    Call to undeclared method \App\Db::createCommand
    Open

                $db->createCommand()->update('s_#__companies', $params, ['id' => $this->getId()])->execute();

    Call to undeclared method \App\Db::beginTransaction
    Open

            $transaction = $db->beginTransaction();

    Call to method getError from undeclared class \App\YetiForce\Register
    Open

                    if ($error = $registration->getError()) {

    Call to method getFormFields from undeclared class \Settings_Companies_Module_Model
    Open

            $labels = $this->getModule()->getFormFields();

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

        public function set($key, $value)
        {
            if ($this->getId() && !\in_array($key, ['id']) && (\array_key_exists($key, $this->value) && $this->value[$key] != $value)) {
                $this->changes[$key] = $this->get($key);
            }
    Severity: Major
    Found in modules/Settings/Companies/models/Record.php and 2 other locations - About 1 hr to fix
    modules/Settings/AutomaticAssignment/models/Record.php on lines 204..210
    modules/Settings/PickListDependency/models/Record.php on lines 234..240

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 102.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    class Settings_Companies_Record_Model extends Settings_Vtiger_Record_Model

    Avoid variables with short names like $db. Configured minimum length is 3.
    Open

            $db = App\Db::getInstance('admin');

    ShortVariable

    Since: 0.2

    Detects when a field, local, or parameter has a very short name.

    Example

    class Something {
        private $q = 15; // VIOLATION - Field
        public static function main( array $as ) { // VIOLATION - Formal
            $r = 20 + $this->q; // VIOLATION - Local
            for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                $r += $this->q;
            }
        }
    }

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

    The class Settings_Companies_Record_Model is not named in CamelCase.
    Open

    class Settings_Companies_Record_Model extends Settings_Vtiger_Record_Model
    {
        public $module;
        /** @var array Record changes */
        protected $changes = [];

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

    Avoid variables with short names like $db. Configured minimum length is 3.
    Open

            $db = \App\Db::getInstance('admin');

    ShortVariable

    Since: 0.2

    Detects when a field, local, or parameter has a very short name.

    Example

    class Something {
        private $q = 15; // VIOLATION - Field
        public static function main( array $as ) { // VIOLATION - Formal
            $r = 20 + $this->q; // VIOLATION - Local
            for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                $r += $this->q;
            }
        }
    }

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

    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

                    $registration->setRawCompanyData($this->getData())->register();

    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 $fieldName ? (array_key_exists($fieldName, $this->changes) ? $this->changes[$fieldName] : false) : $this->changes;

    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 getModule(): Settings_Companies_Module_Model

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

                /** @var Settings_Companies_Module_Model $module */

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

            try {

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

                    }

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

                $transaction->commit();

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

         * @return int Id

    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 ($row) {

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

                $instance->setData($row);

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

            } else {

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

        }

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

        protected $changes = [];

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

         * Function to get the Name.

    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

         * Function to save.

    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 Display Value, for the current field type with given DB Insert Value.

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

         * @param string $key

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

                    break;

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

                case 'country':

    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

            $labels = $this->getModule()->getFormFields();

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

                'name' => $fieldName,

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

                    $params['uitype'] = 16;

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

        public function getId(): int

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

         * Function to get the Edit View Url.

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

         */

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

         * @throws \App\Exceptions\DbException

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

         * Function to get Module 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

                if (($changes = $this->getPreviousValue()) && (\count($changes) > 1) || false === $this->getPreviousValue('email')) {

    Line exceeds 120 characters; contains 129 characters
    Open

                if (($changes = $this->getPreviousValue()) && (\count($changes) > 1) || false === $this->getPreviousValue('email')) {

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

                }

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

                $fields = $this->getModule()->getNameFields();

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

            } catch (\Throwable $ex) {

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

        {

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

                        $params['picklistValues'][$industry] = \App\Language::translate($industry, $moduleName, null, false);

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

            return $this->get('id');

    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->get('name');

    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->changes[$key] = $this->get($key);

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

            return parent::set($key, $value);

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

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

            $db = App\Db::getInstance('admin');

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

                $transaction->rollBack();

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

            $value = $this->get($key) ?? '';

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

            return $value;

    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

         * @param string $name

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

            $companyId = $this->getId();

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

            $fieldName = 'YetiForce' === $sourceModule ? "companies[$companyId][$name]" : $name;

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

            ];

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

                case 'name':

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

                    $params['maximumlength'] = '50';

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

                    foreach (\App\Fields\Country::getAll() as $country) {

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

                        $params['picklistValues'][$country['name']] = \App\Language::translateSingleMod($country['name'], 'Other.Country', null, 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

                    $params['uitype'] = 17;

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

                    unset($params['validator']);

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

        /** @var array Record changes */

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

        }

    Line exceeds 120 characters; contains 132 characters
    Open

            if ($this->getId() && !\in_array($key, ['id']) && (\array_key_exists($key, $this->value) && $this->value[$key] != $value)) {

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

                    $registration = (new \App\YetiForce\Register());

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

                $params = array_intersect_key($this->getData(), array_flip($fields));

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

                $db->createCommand()->update('s_#__companies', $params, ['id' => $this->getId()])->execute();

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

         * @return string

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

                case 'tabid':

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

            throw new \App\Exceptions\NoPermitted('LBL_OPERATION_NOT_PERMITTED');

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

                    $params['uitype'] = 13;

    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 static function getInstance()

    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

                $module = Settings_Vtiger_Module_Model::getInstance('Settings:Companies');

    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

            $label = $label ?: ($labels[$name]['label'] ?? '');

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

                'column' => $name,

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

                'typeofdata' => 'V~M',

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

                    foreach (Settings_Companies_Module_Model::getIndustryList() as $industry) {

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

                case 'country':

    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|Settings_Companies_Record_Model instance, if exists

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

         * @param string $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

        /**

    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\Process::removeEvent(\Settings_Companies_EditModal_View::MODAL_EVENT['name']);

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

                \App\Log::error($ex->__toString());

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

            \App\Cache::clear();

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

            switch ($key) {

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

                case 'industry':

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

                    $value = App\Language::translate($value);

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

            $moduleName = $this->getModule()->getName(true);

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

                case 'email':

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

                    $params['isEditableReadOnly'] = true;

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

                    break;

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

        public function getEditViewUrl(): string

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

            return '?module=Companies&parent=Settings&view=Edit';

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

                $instance = new self();

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

         * Get pervious value by field.

    Line exceeds 120 characters; contains 129 characters
    Open

            return $fieldName ? (array_key_exists($fieldName, $this->changes) ? $this->changes[$fieldName] : false) : $this->changes;

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

        public function save(): void

    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 determines fields available in edition view.

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

            $sourceModule = $this->get('source');

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

                'displaytype' => 1,

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

                'presence' => '',

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

                'maximumlength' => '255',

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

                'purifyType' => \App\Purifier::TEXT

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

                    break;

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

         * Function to get the Id.

    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 getPreviousValue(string $fieldName = '')

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

         * @param string $label

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

                'label' => $label,

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

                    $params['picklistValues'] = [];

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

                    }

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

                    $params['purifyType'] = \App\Purifier::EMAIL;

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

        public $module;

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

        public function getName(): string

    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

            \App\Cache::staticDelete('CompanyGet', '');

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

         */

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

                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

         * @return \Vtiger_Field_Model

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

                    break;

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

                    $params['maximumlength'] = '100';

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

            return Settings_Vtiger_Field_Model::init($moduleName, $params);

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

         * @return string URL

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

         * Function to get the instance of companies record model.

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

        /** {@inheritdoc} */

    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

                'value' => '',

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

                'isEditableReadOnly' => false,

    Line exceeds 120 characters; contains 148 characters
    Open

                        $params['picklistValues'][$country['name']] = \App\Language::translateSingleMod($country['name'], 'Other.Country', null, false);

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

                    break;

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

                    break;

    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 string

    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

            $row = (new \App\Db\Query())->from('s_#__companies')->one($db);

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

         *

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

                        throw new \App\Exceptions\AppException($error);

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

        }

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

                    $value =\App\Language::translateSingleMod($value, 'Other.Country');

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

        }

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

                case 'industry':

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

                    $params['picklistValues'] = [];

    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

            $db = \App\Db::getInstance('admin');

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

                throw new \App\Exceptions\DbException('LBL_RECORD_NOT_FOUND');

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

            if ($this->getId() && !\in_array($key, ['id']) && (\array_key_exists($key, $this->value) && $this->value[$key] != $value)) {

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

         * @return mixed

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

            if (!isset($this->module)) {

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

            $transaction = $db->beginTransaction();

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

                    if ($error = $registration->getError()) {

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

                    break;

    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 delete(): bool

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

            $params = [

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

                    $params['uitype'] = 16;

    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 set($key, $value)

    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 Settings_Companies_Module_Model

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

                    break;

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

         * @throws \App\Exceptions\NoPermitted

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

        {

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

                    unset($params['validator']);

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

                    $params['purifyType'] = \App\Purifier::URL;

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

                throw $ex;

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

        public function getDisplayValue(string $key): string

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

                    $value = \App\Module::getModuleName((int) $value);

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

                    break;

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

            switch ($name) {

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

                    break;

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

                    $params['typeofdata'] = 'V~O';

    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 delete the current Record 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

                'uitype' => 1,

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

                case 'website':

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

                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

                    $value =\App\Purifier::encodeHtml($value);

    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 getFieldInstanceByName(string $name, string $label = ''): Vtiger_Field_Model

    Line exceeds 120 characters; contains 121 characters
    Open

                        $params['picklistValues'][$industry] = \App\Language::translate($industry, $moduleName, null, false);

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

    class Settings_Companies_Record_Model extends Settings_Vtiger_Record_Model

    There are no issues that match your filters.

    Category
    Status