YetiForceCompany/YetiForceCRM

View on GitHub
app/Integrations/Magento/Synchronizer/Record.php

Summary

Maintainability
C
1 day
Test Coverage
F
0%

Function syncAccount has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    public function syncAccount(array $data): int
    {
        $recordModel = \Vtiger_Record_Model::getCleanInstance('Accounts');
        if ($id = $this->findAccount($data, $recordModel)) {
            $recordModel = \Vtiger_Record_Model::getInstanceById($id, 'Accounts');
Severity: Minor
Found in app/Integrations/Magento/Synchronizer/Record.php - About 1 hr 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

Method syncAccount has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function syncAccount(array $data): int
    {
        $recordModel = \Vtiger_Record_Model::getCleanInstance('Accounts');
        if ($id = $this->findAccount($data, $recordModel)) {
            $recordModel = \Vtiger_Record_Model::getInstanceById($id, 'Accounts');
Severity: Minor
Found in app/Integrations/Magento/Synchronizer/Record.php - About 1 hr to fix

    Function findAccount has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public function findAccount(array $data, \Vtiger_Record_Model $recordModel): int
        {
            $vatIdField = $recordModel->getModule()->getFieldByName('vat_id');
            if ($vatIdField && $vatIdField->isActiveField() && ($vatId = $data['vat_id_a'] ?: $data['vat_id_b'] ?: false)) {
                if (\App\Cache::staticHas('MagentoFindAccount', $vatId)) {
    Severity: Minor
    Found in app/Integrations/Magento/Synchronizer/Record.php - About 35 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 syncContact has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public function syncContact(array $data): int
        {
            $recordModel = \Vtiger_Record_Model::getCleanInstance('Contacts');
            if ($id = $this->findByEmail($data, $recordModel)) {
                $recordModel = \Vtiger_Record_Model::getInstanceById($id, 'Contacts');
    Severity: Minor
    Found in app/Integrations/Magento/Synchronizer/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

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

        public function findByEmail(array $data, \Vtiger_Record_Model $recordModel): int
        {
            $email = $data['email'] ?? $data['email_a'];
            $cacheKey = 'MagentoFindByEmail' . $recordModel->getModuleName();
            if (\App\Cache::staticHas($cacheKey, $email)) {
    Severity: Minor
    Found in app/Integrations/Magento/Synchronizer/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 syncAccount() has an NPath complexity of 1248. The configured NPath complexity threshold is 200.
    Open

        public function syncAccount(array $data): int
        {
            $recordModel = \Vtiger_Record_Model::getCleanInstance('Accounts');
            if ($id = $this->findAccount($data, $recordModel)) {
                $recordModel = \Vtiger_Record_Model::getInstanceById($id, 'Accounts');

    NPathComplexity

    Since: 0.1

    The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

    Example

    class Foo {
        function bar() {
            // lots of complicated code
        }
    }

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

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

        public function syncAccount(array $data): int
        {
            $recordModel = \Vtiger_Record_Model::getCleanInstance('Accounts');
            if ($id = $this->findAccount($data, $recordModel)) {
                $recordModel = \Vtiger_Record_Model::getInstanceById($id, 'Accounts');

    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

    Refactor this function to reduce its Cognitive Complexity from 19 to the 15 allowed.
    Open

        public function syncAccount(array $data): int

    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

    Missing class import via use statement (line '165', column '26').
    Open

                $queryGenerator = new \App\QueryGenerator($recordModel->getModuleName());

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

                    $id = (new \App\Db\Query())->select(['accountid'])->from('vtiger_account')

    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 'syncAccount'.
    Open

                $recordModel = \Vtiger_Record_Model::getInstanceById($id, 'Accounts');

    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 'findByEmail'.
    Open

                $id = \App\Cache::staticGet($cacheKey, $email);

    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_Record_Model' in method 'syncContact'.
    Open

            $recordModel = \Vtiger_Record_Model::getCleanInstance('Contacts');

    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_Record_Model' in method 'syncContact'.
    Open

                $recordModel = \Vtiger_Record_Model::getInstanceById($id, 'Contacts');

    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 'syncAccount'.
    Open

                \App\Cache::staticSave('MagentoFindAccount', $recordModel->get('vat_id'), $id);

    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 'findAccount'.
    Open

                if (\App\Cache::staticHas('MagentoFindAccount', $vatId)) {

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

        public function syncAccount(array $data): int
        {
            $recordModel = \Vtiger_Record_Model::getCleanInstance('Accounts');
            if ($id = $this->findAccount($data, $recordModel)) {
                $recordModel = \Vtiger_Record_Model::getInstanceById($id, 'Accounts');

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

            if (\App\Cache::staticHas('MagentoGetFromApi|' . $type, $id)) {

    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 '135', column '55').
    Open

        public function findAccount(array $data, \Vtiger_Record_Model $recordModel): int
        {
            $vatIdField = $recordModel->getModule()->getFieldByName('vat_id');
            if ($vatIdField && $vatIdField->isActiveField() && ($vatId = $data['vat_id_a'] ?: $data['vat_id_b'] ?: false)) {
                if (\App\Cache::staticHas('MagentoFindAccount', $vatId)) {

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

                \App\Cache::staticSave('MagentoFindByEmailAccounts', $data['email'] ?? $data['email_a'], $id);

    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 findAccount uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    $id = (new \App\Db\Query())->select(['accountid'])->from('vtiger_account')
                        ->innerJoin('vtiger_crmentity', 'vtiger_account.accountid = vtiger_crmentity.crmid')
                        ->where(['vtiger_account.vat_id' => $vatId])->scalar();
                }

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

            if (\App\Cache::staticHas($cacheKey, $email)) {

    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 findByEmail uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $queryGenerator = new \App\QueryGenerator($recordModel->getModuleName());
                $queryGenerator->setStateCondition('All');
                $queryGenerator->setFields(['id'])->permissions = false;
                foreach ($recordModel->getModule()->getFieldsByType('email', true) as $fieldModel) {

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

            \App\Cache::staticSave('MagentoFindByEmailContacts', $data['email'] ?? $data['email_a'], $id);

    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 'getFromApi'.
    Open

            \App\Cache::staticSave('MagentoGetFromApi|' . $type, $id, $data);

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

        public function syncAccount(array $data): int
        {
            $recordModel = \Vtiger_Record_Model::getCleanInstance('Accounts');
            if ($id = $this->findAccount($data, $recordModel)) {
                $recordModel = \Vtiger_Record_Model::getInstanceById($id, 'Accounts');

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

                    \App\Cache::staticSave($cacheKey, $email, $id);

    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 'getFromApi'.
    Open

                return \App\Cache::staticGet('MagentoGetFromApi|' . $type, $id);

    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\Json' in method 'getFromApi'.
    Open

            $data = \App\Json::decode($this->connector->request('GET', $this->config->get('store_code') . "/V1/{$type}/$id"));

    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_Record_Model' in method 'syncAccount'.
    Open

            $recordModel = \Vtiger_Record_Model::getCleanInstance('Accounts');

    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 'findAccount'.
    Open

                    $id = \App\Cache::staticGet('MagentoFindAccount', $vatId);

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

        public function syncContact(array $data): int
        {
            $recordModel = \Vtiger_Record_Model::getCleanInstance('Contacts');
            if ($id = $this->findByEmail($data, $recordModel)) {
                $recordModel = \Vtiger_Record_Model::getInstanceById($id, 'Contacts');

    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

    Define a constant instead of duplicating this literal "email" 7 times.
    Open

            'email1' => 'email',

    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 "vat_id" 4 times.
    Open

            $recordModel->set('vat_id', $data['vat_id_a'] ?: $data['vat_id_b'] ?: '');

    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 "email_a" 5 times.
    Open

                    $companyName = $data['email'] ?? $data['email_a'];

    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 "MagentoFindAccount" 3 times.
    Open

                \App\Cache::staticSave('MagentoFindAccount', $recordModel->get('vat_id'), $id);

    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 "MagentoGetFromApi|" 3 times.
    Open

            if (\App\Cache::staticHas('MagentoGetFromApi|' . $type, $id)) {

    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 "firstname" 5 times.
    Open

                if (empty($data['firstname'])) {

    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 "lastname" 5 times.
    Open

                if (empty($data['lastname'])) {

    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.

    Call to method __construct from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

                $queryGenerator = new \App\QueryGenerator($recordModel->getModuleName());

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

                    $id = (new \App\Db\Query())->select(['accountid'])->from('vtiger_account')

    Call to method addCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

                    $queryGenerator->addCondition($fieldModel->getName(), $email, 'e', false);

    Call to method setStateCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

                $queryGenerator->setStateCondition('All');

    Call to method createQuery from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

                $id = $queryGenerator->createQuery()->scalar() ?: 0;

    Call to method setFields from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

                $queryGenerator->setFields(['id'])->permissions = false;

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

        public function getSearchCriteria(int $pageSize = 10): string
        {
            $searchCriteria = [];
            $searchCriteria[] = 'searchCriteria[filter_groups][0][filters][0][field]=entity_id';
            $searchCriteria[] = 'searchCriteria[filter_groups][0][filters][0][value]=' . $this->lastScan['id'];
    Severity: Major
    Found in app/Integrations/Magento/Synchronizer/Record.php and 2 other locations - About 5 hrs to fix
    app/Integrations/Magento/Synchronizer/Category.php on lines 164..181
    app/Integrations/Magento/Synchronizer/Product.php on lines 82..99

    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 193.

    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

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

                    $id = \App\Cache::staticGet('MagentoFindAccount', $vatId);

    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

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

                $id = \App\Cache::staticGet($cacheKey, $email);

    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

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

            if ($id = $this->findAccount($data, $recordModel)) {

    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

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

            if ($id = $this->findByEmail($data, $recordModel)) {

    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

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

        public function getFromApi(string $type, string $id): array

    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

            'fax' => 'mobile',

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

            'buildingnumberb' => 'buildingnumberb',

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

            'addresslevel6b' => 'addresslevel6b',

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

            'fax_extra' => 'mobile_extra',

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

            'buildingnumbera' => 'buildingnumbera',

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

        /**

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

            'addresslevel2b' => 'addresslevel2b',

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

            if (!empty($this->lastScan['end_date'])) {

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

         * Method to get search criteria Magento records.

    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

            $searchCriteria[] = 'searchCriteria[filter_groups][0][filters][0][field]=entity_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

         *

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

         * Account fields map .

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

            'phone' => 'phone',

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

        {

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

                $searchCriteria[] = 'searchCriteria[filter_groups][2][filters][0][condition_type]=gteq';

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

         * @param array $data

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

        public function syncAccount(array $data): int

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

         */

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

            'phone_extra' => 'phone_extra',

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

            'addresslevel8a' => 'addresslevel8a',

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

         * @param int $pageSize

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

                $searchCriteria[] = 'searchCriteria[filter_groups][2][filters][0][value]=' . $this->getFormattedTime($this->lastScan['end_date']);

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

         *

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

            'addresslevel4a' => 'addresslevel4a',

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

            'addresslevel1b' => 'addresslevel1b',

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

            'addresslevel7b' => 'addresslevel7b',

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

            'addresslevel5a' => 'addresslevel5a',

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

            'addresslevel3b' => 'addresslevel3b',

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

            'addresslevel5b' => 'addresslevel5b',

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

        /**

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

            $searchCriteria[] = 'searchCriteria[filter_groups][0][filters][0][value]=' . $this->lastScan['id'];

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

            'addresslevel2a' => 'addresslevel2a',

    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 int

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

        public function getSearchCriteria(int $pageSize = 10): string

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

        {

    Line exceeds 120 characters; contains 182 characters
    Open

     * The file is part of the paid functionality. Using the file is allowed only after purchasing a subscription. File modification allowed only with the consent of the system producer.

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

                    $data['firstname'] = $data['first_name_a'] ?? $data['first_name_b'];

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

            'addresslevel6a' => 'addresslevel6a',

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

                $companyName = $data['firstname'] . '|##|' . $data['lastname'];

    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

         * Find account record id by vat id or email fields.

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

            $searchCriteria = [];

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

            $searchCriteria[] = 'searchCriteria[pageSize]=' . $pageSize;

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

        public function findByEmail(array $data, \Vtiger_Record_Model $recordModel): int

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

         * Method to create/update account.

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

            $cacheKey = 'MagentoFindByEmail' . $recordModel->getModuleName();

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

            if ($data['email'] ?? $data['email_a']) {

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

            if (empty($data['firstname'])) {

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

                if (\App\Cache::staticHas('MagentoFindAccount', $vatId)) {

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

         * Find  record id by email fields.

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

            return $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 (empty($data['lastname'])) {

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

            $searchCriteria[] = 'searchCriteria[filter_groups][1][filters][0][condition_type]=lteq';

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

            return $searchCriteria ?? 'searchCriteria';

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

            $fields = $recordModel->getModule()->getFields();

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

                \App\Cache::staticSave('MagentoFindAccount', $recordModel->get('vat_id'), $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

         */

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

                foreach ($recordModel->getModule()->getFieldsByType('email', true) as $fieldModel) {

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

                $id = $queryGenerator->createQuery()->scalar() ?: 0;

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

                    $recordModel->set($fieldName, $value);

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

        public $accountFieldsMap = [

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

            'email1' => 'email',

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

            'addresslevel8b' => 'addresslevel8b',

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

            $searchCriteria[] = 'searchCriteria[filter_groups][1][filters][0][field]=updated_at';

    Line exceeds 120 characters; contains 140 characters
    Open

            $searchCriteria[] = 'searchCriteria[filter_groups][1][filters][0][value]=' . $this->getFormattedTime($this->lastScan['start_date']);

    Line exceeds 120 characters; contains 142 characters
    Open

                $searchCriteria[] = 'searchCriteria[filter_groups][2][filters][0][value]=' . $this->getFormattedTime($this->lastScan['end_date']);

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

            if (!($companyName = $data['company_name_a'] ?: $data['company_name_b'] ?: false)) {

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

                    $id = (new \App\Db\Query())->select(['accountid'])->from('vtiger_account')

    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

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

        public function syncContact(array $data): int

    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 string $type

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

         *

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

            'addresslevel3a' => 'addresslevel3a',

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

                if (empty($data['lastname'])) {

    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::staticSave($cacheKey, $email, $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

         *

    Line exceeds 120 characters; contains 122 characters
    Open

            $data = \App\Json::decode($this->connector->request('GET', $this->config->get('store_code') . "/V1/{$type}/$id"));

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

         * @var string[]

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

            $searchCriteria[] = 'searchCriteria[filter_groups][0][filters][0][condition_type]=gt';

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

            $searchCriteria = implode('&', $searchCriteria);

    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 = \Vtiger_Record_Model::getInstanceById($id, 'Accounts');

    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->set('accountname', $companyName);

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

            }

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

            $vatIdField = $recordModel->getModule()->getFieldByName('vat_id');

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

                if ($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

         */

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

                $recordModel = \Vtiger_Record_Model::getInstanceById($id, 'Contacts');

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

                $data['lastname'] = $data['last_name_a'] ?? $data['last_name_b'];

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

            $recordModel->save();

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

            'addresslevel1a' => 'addresslevel1a',

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

            'addresslevel7a' => 'addresslevel7a',

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

        ];

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

            'addresslevel4b' => 'addresslevel4b',

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

                if (empty($data['firstname'])) {

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

            $searchCriteria[] = 'searchCriteria[filter_groups][1][filters][0][value]=' . $this->getFormattedTime($this->lastScan['start_date']);

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

                }

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

                $searchCriteria[] = 'searchCriteria[filter_groups][2][filters][0][field]=updated_at';

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

         * @return int

    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

                if (isset($data[$source], $fields[$target])) {

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

            if (\App\Cache::staticHas($cacheKey, $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

                $queryGenerator->setFields(['id'])->permissions = false;

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

                        ->innerJoin('vtiger_crmentity', 'vtiger_account.accountid = vtiger_crmentity.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

                if ($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

        /**

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

        }

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

                $data['firstname'] = $data['first_name_a'] ?? $data['first_name_b'];

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

         * Method to create contact.

    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

            $recordModel = \Vtiger_Record_Model::getCleanInstance('Accounts');

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

            $recordModel->set('vat_id', $data['vat_id_a'] ?: $data['vat_id_b'] ?: '');

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

            return $id;

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

                $id = \App\Cache::staticGet($cacheKey, $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

            }

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

                if (isset($fields[$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

         * Get data by id from api.

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

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

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

                } else {

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

                        ->where(['vtiger_account.vat_id' => $vatId])->scalar();

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

         * @param array                $data

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

                $queryGenerator->setStateCondition('All');

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

            unset($data['attention']);

    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 ($id = $this->findAccount($data, $recordModel)) {

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

                    $companyName = $data['email'] ?? $data['email_a'];

    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 findAccount(array $data, \Vtiger_Record_Model $recordModel): int

    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

            foreach ($data as $fieldName => $value) {

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

            \App\Cache::staticSave('MagentoFindByEmailContacts', $data['email'] ?? $data['email_a'], $id);

    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

            if (\App\Cache::staticHas('MagentoGetFromApi|' . $type, $id)) {

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

                return \App\Cache::staticGet('MagentoGetFromApi|' . $type, $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

            $data = \App\Json::decode($this->connector->request('GET', $this->config->get('store_code') . "/V1/{$type}/$id"));

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

            if ($recordModel->get('vat_id')) {

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

                    $id = \App\Cache::staticGet('MagentoFindAccount', $vatId);

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

         * @return int

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

         */

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

                $queryGenerator = new \App\QueryGenerator($recordModel->getModuleName());

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

        public function getFromApi(string $type, string $id): array

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

            }

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

            foreach ($this->accountFieldsMap as $target => $source) {

    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

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

            return $this->findByEmail($data, $recordModel);

    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 ($id = $this->findByEmail($data, $recordModel)) {

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

            $fields = $recordModel->getModule()->getFields();

    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->set($target, $data[$source]);

    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 ($vatIdField && $vatIdField->isActiveField() && ($vatId = $data['vat_id_a'] ?: $data['vat_id_b'] ?: false)) {

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

                    return $id;

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

            $recordModel = \Vtiger_Record_Model::getCleanInstance('Contacts');

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

            }

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

            $id = $recordModel->getId();

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

            \App\Cache::staticSave('MagentoGetFromApi|' . $type, $id, $data);

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

                    $data['lastname'] = $data['last_name_a'] ?? $data['last_name_b'];

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

                $recordModel->set('legal_form', 'PLL_NATURAL_PERSON');

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

            $id = $recordModel->getId();

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

                \App\Cache::staticSave('MagentoFindByEmailAccounts', $data['email'] ?? $data['email_a'], $id);

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

                    $queryGenerator->addCondition($fieldModel->getName(), $email, 'e', false);

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

            return $id;

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

         * @param array $data

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

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

                }

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

                if ('|##|' === $companyName) {

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

            $email = $data['email'] ?? $data['email_a'];

    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

         * @return int

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

        {

    There are no issues that match your filters.

    Category
    Status