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();
- Read upRead up
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');
- Read upRead up
- Exclude checks
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([
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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']));
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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'];
- Read upRead up
- Exclude checks
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'],
- Read upRead up
- Exclude checks
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')) {
- Read upRead up
- Exclude checks
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([
- Exclude checks
Call to method createQuery
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
return $queryGenerator->createQuery()->all();
- Exclude checks
Call to method setStateCondition
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->setStateCondition('All');
- Exclude checks
Call to method addCondition
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->addCondition('id', $this->product, 'e');
- Exclude checks
Call to method setFields
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->setFields(['id', 'qtyinstock', 'ean'])->permissions = false;
- Exclude checks
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');
- Exclude checks
Call to method __construct
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator = new \App\QueryGenerator('Products');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setFields(['id', 'qtyinstock', 'ean'])->permissions = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var int
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator = new \App\QueryGenerator('Products');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from($referenceInfo['table'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($products as $product) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return (new \App\Db\Query())->select([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->all();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$products = $this->getStockFromStorage();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$referenceInfo = \Vtiger_Relation_Model::getReferenceTableInfo('Products', 'IStorages');
- Exclude checks
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']));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->log('Update stock', $ex);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'qtyinstock' => $referenceInfo['table'] . '.qtyinstock',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $storageId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $product;
- Exclude checks
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]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
->innerJoin('vtiger_products', "{$referenceInfo['table']}.{$referenceInfo['rel']} = vtiger_products.productid")
- Exclude checks
Line exceeds 120 characters; contains 127 characters Open
\App\Log::error('Error during update stock: ' . PHP_EOL . $ex->__toString() . PHP_EOL, 'Integrations/Magento');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setStateCondition('All');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
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.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Product id.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
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)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getStockFromProducts()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var int
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
} elseif ('IStorages' === $this->config->get('storage_quantity_location') && ((int) $this->config->get('storage_id') === $this->storageId)) {
- Exclude checks
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]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data['qty'] = $product['qtyinstock'];
- Exclude checks
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');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->addCondition('id', $this->product, 'e');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $queryGenerator->createQuery()->all();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'ean' => 'vtiger_products.ean', ])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'id' => $referenceInfo['table'] . '.' . $referenceInfo['rel'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where([$referenceInfo['base'] => $this->storageId, $referenceInfo['rel'] => $this->product])
- Exclude checks
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']));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (\Throwable $ex) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get stock from products.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getStockFromStorage()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('Products' === $this->config->get('storage_quantity_location')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get stock from storage.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Storage id.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$products = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$products = $this->getStockFromProducts();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->innerJoin('vtiger_products', "{$referenceInfo['table']}.{$referenceInfo['rel']} = vtiger_products.productid")
- Exclude checks