YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/crons/IntegrationPLGusRegon.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

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

    public function process()
    {
        $this->loadConfig();
        $recordCollector = \App\RecordCollector::getInstance('App\RecordCollectors\Gus', $this->config['moduleName']);
        if (!$recordCollector->isActive()) {
Severity: Minor
Found in modules/Vtiger/crons/IntegrationPLGusRegon.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 process has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process()
    {
        $this->loadConfig();
        $recordCollector = \App\RecordCollector::getInstance('App\RecordCollectors\Gus', $this->config['moduleName']);
        if (!$recordCollector->isActive()) {
Severity: Minor
Found in modules/Vtiger/crons/IntegrationPLGusRegon.php - About 1 hr to fix

    Missing class import via use statement (line '79', column '52').
    Open

                $this->config = array_merge($this->config, (new \ReflectionClass($class))->getStaticProperties());

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

                    $recordCollector->setRequest(new \App\Request(['module' => $this->config['moduleName'], 'taxNumber' => $value], false));

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

                $recordId = (new \App\QueryGenerator($this->config['moduleName']))->setFields(['id'])->addCondition($this->config['fieldName'], $value, 'e')->createQuery()->scalar();

    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\RecordCollectors\Helper\GusClient' in method 'process'.
    Open

            $client = \App\RecordCollectors\Helper\GusClient::getInstance();

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

                    $recordModel = \Vtiger_Record_Model::getCleanInstance($this->config['moduleName']);

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

                \App\Log::warning('GUS record collector is not active', __CLASS__);

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

                \App\Log::warning('The cron job was skipped because the field is not active', __CLASS__);

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

            $recordCollector = \App\RecordCollector::getInstance('App\RecordCollectors\Gus', $this->config['moduleName']);

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

                            \App\Log::error("[taxNumber => $value]Error during data validation: \n{$th->__toString()}\n", __CLASS__);

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

            'defaultValues' => [],

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

            'fieldName' => 'registration_number_2',

    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 "moduleName" 6 times.
    Open

            'moduleName' => 'Leads',

    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

                $recordId = (new \App\QueryGenerator($this->config['moduleName']))->setFields(['id'])->addCondition($this->config['fieldName'], $value, 'e')->createQuery()->scalar();

    Assigning 0 to property but \Vtiger_IntegrationPLGusRegon_Cron->logs is string
    Open

            $this->logs = $i;

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

                $recordId = (new \App\QueryGenerator($this->config['moduleName']))->setFields(['id'])->addCondition($this->config['fieldName'], $value, 'e')->createQuery()->scalar();

    Call to undeclared function \array_key_first()
    Open

                    $key = array_key_first($response['dataCounter']);

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

                \App\Log::warning('GUS record collector is not active', __CLASS__);

    Reference to undeclared class \Config\Components\RecordCollectors\Gus
    Open

                $this->config = array_merge($this->config, (new \ReflectionClass($class))->getStaticProperties());

    Call to method search from undeclared class \App\RecordCollectors\Base (Did you mean class \App\Base or class \App\Cache\Base or class \App\Cli\Base or class \App\Controller\Base or class \App\Controller\View\Base or class \App\Db\Importers\Base or class \Tests\Base)
    Open

                    $response = $recordCollector->search();

    Call to method isActive from undeclared class \App\RecordCollectors\Base (Did you mean class \App\Base or class \App\Cache\Base or class \App\Cli\Base or class \App\Controller\Base or class \App\Controller\View\Base or class \App\Db\Importers\Base or class \Tests\Base)
    Open

            if (!$recordCollector->isActive()) {

    Call to method setRequest from undeclared class \App\RecordCollectors\Base (Did you mean class \App\Base or class \App\Cache\Base or class \App\Cli\Base or class \App\Controller\Base or class \App\Controller\View\Base or class \App\Db\Importers\Base or class \Tests\Base)
    Open

                    $recordCollector->setRequest(new \App\Request(['module' => $this->config['moduleName'], 'taxNumber' => $value], false));

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

                \App\Log::warning('The cron job was skipped because the field is not active', __CLASS__);

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

                            \App\Log::error("[taxNumber => $value]Error during data validation: \n{$th->__toString()}\n", __CLASS__);

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

    class Vtiger_IntegrationPLGusRegon_Cron extends \App\CronHandler

    The class Vtiger_IntegrationPLGusRegon_Cron is not named in CamelCase.
    Open

    class Vtiger_IntegrationPLGusRegon_Cron extends \App\CronHandler
    {
        /** @var array Default configuration for data download */
        private $config = [
            'moduleName' => 'Leads',

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

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

        /** @var array Default configuration for data download */

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

            $recordCollector = \App\RecordCollector::getInstance('App\RecordCollectors\Gus', $this->config['moduleName']);

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

                        }

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

            'fieldName' => 'registration_number_2',

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

            if (!Vtiger_Module_Model::getInstance($this->config['moduleName'])->getFieldByName($this->config['fieldName'])->isActiveField()) {

    Line exceeds 120 characters; contains 196 characters
    Open

            $response = $client->getData('DanePobierzRaportZbiorczy', ['pDataRaportu' => date('Y-m-d', strtotime('-1 day')), 'pNazwaRaportu' => 'BIR11NowePodmiotyPrawneOrazDzialalnosciOsFizycznych']);

    Line exceeds 120 characters; contains 136 characters
    Open

                    $recordCollector->setRequest(new \App\Request(['module' => $this->config['moduleName'], 'taxNumber' => $value], false));

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

                    foreach ($response['fields'] as $fieldName => $values) {

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

            $client->endSession();

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

        public function loadConfig(): void

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

            $class = '\\Config\\Components\\RecordCollectors\\Gus';

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

            'moduleName' => 'Leads',

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

                return;

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

            $response = $client->getData('DanePobierzRaportZbiorczy', ['pDataRaportu' => date('Y-m-d', strtotime('-1 day')), 'pNazwaRaportu' => 'BIR11NowePodmiotyPrawneOrazDzialalnosciOsFizycznych']);

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

            foreach ($response as $value) {

    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

        /**

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

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

            if (!$recordCollector->isActive()) {

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

                \App\Log::warning('GUS record collector is not active', __CLASS__);

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

                        $recordModel->setData(array_merge($recordModel->getData(), $this->config['defaultValues']));

    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($this->config['moduleName']);

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

                            $recordModel->getField($fieldName)->getUITypeModel()->validate($values['data'][$key]['raw']);

    Line exceeds 120 characters; contains 129 characters
    Open

                            \App\Log::error("[taxNumber => $value]Error during data validation: \n{$th->__toString()}\n", __CLASS__);

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

                if (empty($recordId)) {

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

                    if (!empty($this->config['defaultValues'])) {

    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

                    $recordCollector->setRequest(new \App\Request(['module' => $this->config['moduleName'], 'taxNumber' => $value], false));

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

            $this->logs = $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

        private $config = [

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

                    $response = $recordCollector->search();

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

                    $key = array_key_first($response['dataCounter']);

    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

        public function process()

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

            }

    Line exceeds 120 characters; contains 178 characters
    Open

                $recordId = (new \App\QueryGenerator($this->config['moduleName']))->setFields(['id'])->addCondition($this->config['fieldName'], $value, 'e')->createQuery()->scalar();

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

                            \App\Log::error("[taxNumber => $value]Error during data validation: \n{$th->__toString()}\n", __CLASS__);

    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 void

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

                        } catch (\Throwable $th) {

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

                $recordId = (new \App\QueryGenerator($this->config['moduleName']))->setFields(['id'])->addCondition($this->config['fieldName'], $value, 'e')->createQuery()->scalar();

    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;

    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

            'defaultValues' => [],

    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 = $value['regon'];

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

         * Load cron configuration.

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

            if (\class_exists($class)) {

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

            $client = \App\RecordCollectors\Helper\GusClient::getInstance();

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

                    arsort($response['dataCounter']);

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

                }

    Line exceeds 120 characters; contains 138 characters
    Open

            if (!Vtiger_Module_Model::getInstance($this->config['moduleName'])->getFieldByName($this->config['fieldName'])->isActiveField()) {

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

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

                $this->config = array_merge($this->config, (new \ReflectionClass($class))->getStaticProperties());

    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\Log::warning('The cron job was skipped because the field is not active', __CLASS__);

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

                            $recordModel->set($fieldName, $values['data'][$key]['raw']);

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

    class Vtiger_IntegrationPLGusRegon_Cron extends \App\CronHandler

    There are no issues that match your filters.

    Category
    Status