YetiForceCompany/YetiForceCRM

View on GitHub
app/Integrations/Wapro/Synchronizer/MultiCompany.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

Method process has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(): int
    {
        $dataReader = (new \App\Db\Query())->from('dbo.FIRMA')
            ->leftJoin('dbo.ADRESY_FIRMY', 'dbo.FIRMA.ID_ADRESU_DOMYSLNEGO = dbo.ADRESY_FIRMY.ID_ADRESY_FIRMY')
            ->where(['>', 'dbo.FIRMA.ID_FIRMY', 0])->createCommand($this->controller->getDb())->query();
Severity: Minor
Found in app/Integrations/Wapro/Synchronizer/MultiCompany.php - About 1 hr to fix

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

        public function process(): int
        {
            $dataReader = (new \App\Db\Query())->from('dbo.FIRMA')
                ->leftJoin('dbo.ADRESY_FIRMY', 'dbo.FIRMA.ID_ADRESU_DOMYSLNEGO = dbo.ADRESY_FIRMY.ID_ADRESY_FIRMY')
                ->where(['>', 'dbo.FIRMA.ID_FIRMY', 0])->createCommand($this->controller->getDb())->query();
    Severity: Minor
    Found in app/Integrations/Wapro/Synchronizer/MultiCompany.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

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

            return (new \App\Db\Query())->from('dbo.FIRMA')->count('*', $this->controller->getDb());

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

            $dataReader = (new \App\Db\Query())->from('dbo.FIRMA')

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

        public function importRecord(): int
        {
            if ($id = $this->findInMapTable($this->waproId, 'FIRMA')) {
                $this->recordModel = \Vtiger_Record_Model::getInstanceById($id, 'MultiCompany');
            } else {

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

                $this->recordModel = \Vtiger_Record_Model::getCleanInstance('MultiCompany');

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

                $this->recordModel = \Vtiger_Record_Model::getInstanceById($id, 'MultiCompany');

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

            \App\Cache::save('WaproMapTable', "{$this->waproId}|FIRMA", $this->recordModel->getId());

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

            } else {
                $this->recordModel = \Vtiger_Record_Model::getCleanInstance('MultiCompany');
                $this->recordModel->setDataForSave([\App\Integrations\Wapro::RECORDS_MAP_TABLE_NAME => [
                    'wtable' => 'FIRMA',
                ]]);

    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

    Move this "case default" clause to the end of this "switch" statement.
    Open

                        default:

    The requirement for a final case default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken. Even when the switch covers all current values of an enum, a default case should still be used because there is no guarantee that the enum won't be extended.

    Noncompliant Code Example

    switch ($param) {  //missing default clause
      case 0:
        do_something();
        break;
      case 1:
        do_something_else();
        break;
    }
    
    switch ($param) {
      default: // default clause should be the last one
        error();
        break;
      case 0:
        do_something();
        break;
      case 1:
        do_something_else();
        break;
    }
    

    Compliant Solution

    switch ($param) {
      case 0:
        do_something();
        break;
      case 1:
        do_something_else();
        break;
      default:
        error();
        break;
    }
    

    See

    • MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
    • MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
    • MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
    • MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
    • MISRA C:2012, 16.1 - All switch statements shall be well-formed
    • MISRA C:2012, 16.4 - Every switch statement shall have a default label
    • MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
    • MITRE, CWE-478 - Missing Default Case in Switch Statement
    • CERT, MSC01-C. - Strive for logical completeness
    • CERT, MSC01-CPP. - Strive for logical completeness

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

            return (new \App\Db\Query())->from('dbo.FIRMA')->count('*', $this->controller->getDb());

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

            $dataReader = (new \App\Db\Query())->from('dbo.FIRMA')

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

            while ($row = $dataReader->read()) {
                $this->waproId = $row['ID_FIRMY'];
                $this->row = $row;
                $this->skip = false;
                try {
    Severity: Major
    Found in app/Integrations/Wapro/Synchronizer/MultiCompany.php and 1 other location - About 1 hr to fix
    app/Integrations/Wapro/Synchronizer/BankAccounts.php on lines 43..64

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

    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 $s. Configured minimum length is 3.
    Open

            $s = $e = $i = $u = 0;

    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 $e. Configured minimum length is 3.
    Open

            $s = $e = $i = $u = 0;

    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 $i. Configured minimum length is 3.
    Open

            $s = $e = $i = $u = 0;

    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->findInMapTable($this->waproId, 'FIRMA')) {

    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 $u. Configured minimum length is 3.
    Open

            $s = $e = $i = $u = 0;

    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

        protected $fieldMap = [

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

            'NAZWA' => 'company_name',

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

            'ULICA' => 'addresslevel8a',

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

                ->where(['>', 'dbo.FIRMA.ID_FIRMY', 0])->createCommand($this->controller->getDb())->query();

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

                return $this->recordModel->getPreviousValue() ? 1 : 3;

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

        }

    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

            'POCZTA' => 'addresslevel6a',

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

            $dataReader = (new \App\Db\Query())->from('dbo.FIRMA')

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

                            ++$s;

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

                        case 2:

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

                $this->recordModel = \Vtiger_Record_Model::getInstanceById($id, 'MultiCompany');

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

                    'wtable' => 'FIRMA',

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

            while ($row = $dataReader->read()) {

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

            }

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

            'GMINA' => 'addresslevel4a',

    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

            'POWIAT' => 'addresslevel3a',

    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 getCounter(): int

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

            'NR_LOKALU' => 'localnumbera',

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

            $s = $e = $i = $u = 0;

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

                            ++$i;

    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

        /** {@inheritdoc} */

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

            'WOJEWODZTWO' => 'addresslevel2a',

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

            'KOD_POCZTOWY' => 'addresslevel7a',

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

            'SYM_KRAJU' => ['fieldName' => 'addresslevel1a', 'fn' => 'convertCountry'],

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

        {

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

                    ++$e;

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

            'SKRYTKA' => 'poboxa',

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

                $this->waproId = $row['ID_FIRMY'];

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

                        case 0:

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

            'REGON' => 'companyid1',

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

            'NR_DOMU' => 'buildingnumbera',

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

                            ++$u;

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

            'E_MAIL' => 'email1',

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

        ];

    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

            } else {

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

                ->leftJoin('dbo.ADRESY_FIRMY', 'dbo.FIRMA.ID_ADRESU_DOMYSLNEGO = dbo.ADRESY_FIRMY.ID_ADRESY_FIRMY')

    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

                            break;

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

                $this->recordModel->setDataForSave([\App\Integrations\Wapro::RECORDS_MAP_TABLE_NAME => [

    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

            return 2;

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

            'MIEJSCOWOSC' => 'addresslevel5a',

    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

        /** {@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

        const NAME = 'LBL_MULTI_COMPANY';

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

                $this->skip = false;

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

                    switch ($this->importRecord()) {

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

            return $i + $u;

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

        {

    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

            $this->log("Create {$i} | Update {$u} | Skipped {$s} | Error {$e}");

    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->findInMapTable($this->waproId, 'FIRMA')) {

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

                $this->recordModel = \Vtiger_Record_Model::getCleanInstance('MultiCompany');

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

            $this->recordModel->set('wapro_id', $this->waproId);

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

            $this->recordModel->save();

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

            \App\Cache::save('WaproMapTable', "{$this->waproId}|FIRMA", $this->recordModel->getId());

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

            'TELEFON' => ['fieldName' => 'phone', 'fn' => 'convertPhone'],

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

        public function process(): int

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

                $this->row = $row;

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

                    $this->logError($th);

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

        public function importRecord(): int

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

            $this->loadFromFieldMap();

    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 (new \App\Db\Query())->from('dbo.FIRMA')->count('*', $this->controller->getDb());

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

        const SEQUENCE = 0;

    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

            'NIP' => 'vat',

    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

                        case 1:

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

                } catch (\Throwable $th) {

    There are no issues that match your filters.

    Category
    Status