YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

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

    public function process()
    {
        $products = [];
        if ('Products' === $this->config->get('storage_quantity_location')) {
            $products = $this->getStockFromProducts();
Severity: Minor
Found in app/Integrations/Magento/Synchronizer/InventoryStock.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

Missing class import via use statement (line '63', column '25').
Open

        $queryGenerator = new \App\QueryGenerator('Products');

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

        return (new \App\Db\Query())->select([

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

                \App\Log::error('Error during update stock: ' . PHP_EOL . $ex->__toString() . PHP_EOL, 'Integrations/Magento');

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

                $data = \App\Json::decode($this->connector->request('GET', $this->config->get('store_code') . '/V1/stockItems/' . $product['ean']));

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_Relation_Model' in method 'getStockFromStorage'.
Open

        $referenceInfo = \Vtiger_Relation_Model::getReferenceTableInfo('Products', 'IStorages');

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

                $data['qty'] = $product['qtyinstock'];

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

            'id' => $referenceInfo['table'] . '.' . $referenceInfo['rel'],

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

        if ('Products' === $this->config->get('storage_quantity_location')) {

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 undeclared method \App\Db\Query::select
Open

        return (new \App\Db\Query())->select([

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

        return $queryGenerator->createQuery()->all();

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

        $queryGenerator->setStateCondition('All');

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

        $queryGenerator->addCondition('id', $this->product, 'e');

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

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

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

                \App\Log::error('Error during update stock: ' . PHP_EOL . $ex->__toString() . PHP_EOL, 'Integrations/Magento');

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

        $queryGenerator = new \App\QueryGenerator('Products');

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

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

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

    /**

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 array

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

     * @var int

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

        $queryGenerator = new \App\QueryGenerator('Products');

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

            ->from($referenceInfo['table'])

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

        foreach ($products as $product) {

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

        return (new \App\Db\Query())->select([

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

            ->all();

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

            $products = $this->getStockFromStorage();

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

    {

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

        $referenceInfo = \Vtiger_Relation_Model::getReferenceTableInfo('Products', 'IStorages');

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/stockItems/' . $product['ean']));

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

                $this->log('Update stock', $ex);

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

            'qtyinstock' => $referenceInfo['table'] . '.qtyinstock',

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

    public $storageId;

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

    public $product;

Line exceeds 120 characters; contains 171 characters
Open

                $this->connector->request('PUT', "{$this->config->get('store_code')}/V1/products/{$product['ean']}/stockItems/{$data['item_id']}", ['stockItem' => $data]);

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

     */

Line exceeds 120 characters; contains 123 characters
Open

            ->innerJoin('vtiger_products', "{$referenceInfo['table']}.{$referenceInfo['rel']} = vtiger_products.productid")

Line exceeds 120 characters; contains 127 characters
Open

                \App\Log::error('Error during update stock: ' . PHP_EOL . $ex->__toString() . PHP_EOL, 'Integrations/Magento');

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->setStateCondition('All');

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

     * Product 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

        } elseif ('IStorages' === $this->config->get('storage_quantity_location') && ((int) $this->config->get('storage_id') === $this->storageId)) {

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

    public function getStockFromProducts()

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

     * @var int

Line exceeds 120 characters; contains 149 characters
Open

        } elseif ('IStorages' === $this->config->get('storage_quantity_location') && ((int) $this->config->get('storage_id') === $this->storageId)) {

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

                $this->connector->request('PUT', "{$this->config->get('store_code')}/V1/products/{$product['ean']}/stockItems/{$data['item_id']}", ['stockItem' => $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

    public function process()

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

                $data['qty'] = $product['qtyinstock'];

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

                \App\Log::error('Error during update stock: ' . PHP_EOL . $ex->__toString() . PHP_EOL, 'Integrations/Magento');

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

        $queryGenerator->addCondition('id', $this->product, 'e');

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

        return $queryGenerator->createQuery()->all();

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

            'ean' => 'vtiger_products.ean', ])

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

            'id' => $referenceInfo['table'] . '.' . $referenceInfo['rel'],

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

            ->where([$referenceInfo['base'] => $this->storageId, $referenceInfo['rel'] => $this->product])

Line exceeds 120 characters; contains 148 characters
Open

                $data = \App\Json::decode($this->connector->request('GET', $this->config->get('store_code') . '/V1/stockItems/' . $product['ean']));

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

            } catch (\Throwable $ex) {

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

     * Get stock from products.

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

    public function getStockFromStorage()

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 ('Products' === $this->config->get('storage_quantity_location')) {

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

     * Get stock from storage.

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

     * Storage id.

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

        $products = [];

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

            $products = $this->getStockFromProducts();

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

            ->innerJoin('vtiger_products', "{$referenceInfo['table']}.{$referenceInfo['rel']} = vtiger_products.productid")

There are no issues that match your filters.

Category
Status