YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/WebservicePremium/Inventory.php

Summary

Maintainability
B
5 hrs
Test Coverage
F
0%

Function getInventoryData has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    public function getInventoryData(): array
    {
        $inventoryData = [];
        foreach ($this->inventory as $inventoryKey => $inventoryItem) {
            foreach (\Vtiger_Inventory_Model::getInstance($this->moduleName)->getFields() as $columnName => $fieldModel) {
Severity: Minor
Found in api/webservice/WebservicePremium/Inventory.php - About 2 hrs 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 getProductsByInventory has 52 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function getProductsByInventory()
    {
        $isUserPermissions = \Api\WebservicePremium\Privilege::USER_PERMISSIONS === $this->permissionType;
        $this->products = [];
        $crmIds = array_keys($this->inventory);
Severity: Major
Found in api/webservice/WebservicePremium/Inventory.php - About 2 hrs to fix

    Function getProductsByInventory has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        private function getProductsByInventory()
        {
            $isUserPermissions = \Api\WebservicePremium\Privilege::USER_PERMISSIONS === $this->permissionType;
            $this->products = [];
            $crmIds = array_keys($this->inventory);
    Severity: Minor
    Found in api/webservice/WebservicePremium/Inventory.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

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

        public function validate(): bool
        {
            $inventoryErrors = [];
            foreach ($this->inventory as $inventoryKey => $inventoryItem) {
                if ('Products' === $this->products[$inventoryKey]['module']) {
    Severity: Minor
    Found in api/webservice/WebservicePremium/Inventory.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

    Avoid using undefined variables such as '$item' which will lead to PHP notices.
    Open

                    $item[$columnName] = $this->getValue($columnName, $inventoryKey) ?? $inventoryItem[$columnName] ?? $fieldModel->getDefaultValue();

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

    Source https://phpmd.org/rules/cleancode.html#undefinedvariable

    Avoid using undefined variables such as '$item' which will lead to PHP notices.
    Open

                $inventoryData[] = $item;

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

    Source https://phpmd.org/rules/cleancode.html#undefinedvariable

    Avoid using undefined variables such as '$item' which will lead to PHP notices.
    Open

                        $item['taxparam'] = \App\Json::encode(\Api\WebservicePremium\Record::getTaxParam($availableTaxes, $this->products[$inventoryKey]['taxes'], $regionalTaxes));

    UndefinedVariable

    Since: 2.8.0

    Detects when a variable is used that has not been defined before.

    Example

    class Foo
    {
        private function bar()
        {
            // $message is undefined
            echo $message;
        }
    }

    Source https://phpmd.org/rules/cleancode.html#undefinedvariable

    Missing class import via use statement (line '229', column '21').
    Open

                    'module' => new \yii\db\Expression("'Service'"), 'id' => 'serviceid', 'service_usageunit',

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

                    'module' => new \yii\db\Expression("'Products'"), 'id' => 'vtiger_products.productid', 'usageunit',

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

            $query = (new \App\Db\Query())

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

                $queryService->addSelect(['quantity' => new \yii\db\Expression('0')]);

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

                    'subunit' => new \yii\db\Expression("''"), 'description', 'unit_price', 'purchase', 'taxes',

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

            $multiCurrencyUiType = new \Vtiger_MultiCurrency_UIType();

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

            $queryService = (new \App\Db\Query())

    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

    The method getInventoryData uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                        } else {
                            $availableTaxes = $this->parentRecordModel->get('accounts_available_taxes');
                            $regionalTaxes = $this->parentRecordModel->get('taxes');
                        }

    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 '\Api\WebservicePremium\Record' in method 'getInventoryData'.
    Open

                        $item['taxparam'] = \App\Json::encode(\Api\WebservicePremium\Record::getTaxParam($availableTaxes, $this->products[$inventoryKey]['taxes'], $regionalTaxes));

    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\Fields\Currency' in method 'getInventoryCurrency'.
    Open

    }

    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_Inventory_Model' in method 'getInventoryFromRecord'.
    Open

            $inventoryData = \Vtiger_Inventory_Model::getInventoryDataById($recordId, $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

    The method getProductsByInventory uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    $row['unit_price'] = $multiCurrencyUiType->getValueForCurrency($row['unit_price'], $currencyId);
                }

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

                $this->parentRecordModel = \Vtiger_Record_Model::getInstanceById($accountId, '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\Json' in method 'getInventoryData'.
    Open

                        $item['taxparam'] = \App\Json::encode(\Api\WebservicePremium\Record::getTaxParam($availableTaxes, $this->products[$inventoryKey]['taxes'], $regionalTaxes));

    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\Fields\Currency' in method 'getProductsByInventory'.
    Open

    }

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

                    'price' => 'unit_price',

    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.

    Remove the unused function parameter "$inventoryKey".
    Open

        protected function getInventoryTaxmode(int $inventoryKey)

    Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

    Noncompliant Code Example

    function doSomething($a, $b) { // "$a" is unused
      return compute($b);
    }
    

    Compliant Solution

    function doSomething($b) {
      return compute($b);
    }
    

    Exceptions

    Functions in classes that override a class or implement interfaces are ignored.

    class C extends B {
    
      function doSomething($a, $b) {     // no issue reported on $b
        compute($a);
      }
    
    }
    

    See

    • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
    • MISRA C:2012, 2.7 - There should be no unused parameters in functions
    • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
    • CERT, MSC12-CPP. - Detect and remove code that has no effect

    Remove the unused function parameter "$inventoryKey".
    Open

        protected function getInventorySeq(int $inventoryKey): int

    Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

    Noncompliant Code Example

    function doSomething($a, $b) { // "$a" is unused
      return compute($b);
    }
    

    Compliant Solution

    function doSomething($b) {
      return compute($b);
    }
    

    Exceptions

    Functions in classes that override a class or implement interfaces are ignored.

    class C extends B {
    
      function doSomething($a, $b) {     // no issue reported on $b
        compute($a);
      }
    
    }
    

    See

    • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
    • MISRA C:2012, 2.7 - There should be no unused parameters in functions
    • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
    • CERT, MSC12-CPP. - Detect and remove code that has no effect

    Define a constant instead of duplicating this literal "description" 3 times.
    Open

                    'comment1' => 'description',

    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.

    Remove the unused function parameter "$inventoryKey".
    Open

        protected function getInventoryCurrency(int $inventoryKey): int

    Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

    Noncompliant Code Example

    function doSomething($a, $b) { // "$a" is unused
      return compute($b);
    }
    

    Compliant Solution

    function doSomething($b) {
      return compute($b);
    }
    

    Exceptions

    Functions in classes that override a class or implement interfaces are ignored.

    class C extends B {
    
      function doSomething($a, $b) {     // no issue reported on $b
        compute($a);
      }
    
    }
    

    See

    • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
    • MISRA C:2012, 2.7 - There should be no unused parameters in functions
    • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
    • CERT, MSC12-CPP. - Detect and remove code that has no effect

    Define a constant instead of duplicating this literal "taxes" 4 times.
    Open

                            $regionalTaxes = $this->parentRecordModel->get('taxes');

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

                    $quantityInStorage = $this->products[$inventoryKey]['quantity'] ?? 0.0;

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

                    'purchase' => 'purchase'

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

                if ('Products' === $this->products[$inventoryKey]['module']) {

    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.

    Avoid unused parameters such as '$inventoryKey'.
    Open

        protected function getInventoryTaxmode(int $inventoryKey)

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Avoid unused parameters such as '$inventoryKey'.
    Open

        protected function getInventorySeq(int $inventoryKey): int

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Avoid unused parameters such as '$inventoryKey'.
    Open

        protected function getInventoryCurrency(int $inventoryKey): int

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Variable $item was undeclared, but array fields are being added to it.
    Open

                        $item['taxparam'] = \App\Json::encode(\Api\WebservicePremium\Record::getTaxParam($availableTaxes, $this->products[$inventoryKey]['taxes'], $regionalTaxes));

    Call to method __construct from undeclared class \yii\db\Expression
    Open

                    'module' => new \yii\db\Expression("'Service'"), 'id' => 'serviceid', 'service_usageunit',

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

            $query = (new \App\Db\Query())

    Call to method __construct from undeclared class \yii\db\Expression
    Open

                    'subunit' => new \yii\db\Expression("''"), 'description', 'unit_price', 'purchase', 'taxes',

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

            $queryService = (new \App\Db\Query())

    Call to method __construct from undeclared class \yii\db\Expression
    Open

                    'module' => new \yii\db\Expression("'Products'"), 'id' => 'vtiger_products.productid', 'usageunit',

    Variable $item was undeclared, but array fields are being added to it.
    Open

                    $item[$columnName] = $this->getValue($columnName, $inventoryKey) ?? $inventoryItem[$columnName] ?? $fieldModel->getDefaultValue();

    Call to method __construct from undeclared class \yii\db\Expression
    Open

                $queryService->addSelect(['quantity' => new \yii\db\Expression('0')]);

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

        protected $errors = [];

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

        /** @var array Inventory items passed from request. */

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

        private $fieldMapping;

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

        /** @var int|null Price book id. */

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

        /** @var array|null Field mapping. */

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

        /** @var int Storage ID */

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

        protected $storage;

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

        protected $moduleName;

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

        protected $parentRecordModel;

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

        /** @var string Module name. */

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

        protected $inventory;

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

        /** @var array Products */

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

        protected $products = [];

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

        /** @var \Vtiger_Record_Model Parent record model */

    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 Inventory from record.

    Line exceeds 120 characters; contains 122 characters
    Open

                foreach (\Vtiger_Inventory_Model::getInstance($this->moduleName)->getFields() as $columnName => $fieldModel) {

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

                }

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

                $inventoryData[] = $item;

    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($fromRow[$columnName])) {

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

                $method = 'getInventory' . ucfirst($columnName);

    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 $this->fieldMapping;

    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

        {

    Line exceeds 120 characters; contains 176 characters
    Open

                        $item['taxparam'] = \App\Json::encode(\Api\WebservicePremium\Record::getTaxParam($availableTaxes, $this->products[$inventoryKey]['taxes'], $regionalTaxes));

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

            return $inventoryData;

    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

        public function __construct(string $moduleName, \Api\Core\BaseAction $actionModel)

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

            $this->storage = $actionModel->getUserStorageId();

    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

         * @param string $moduleName

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

                    if (\in_array($fieldModel->getColumnName(), ['total', 'margin', 'marginp', 'net', 'gross', 'discount'])) {

    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->inventory = $actionModel->controller->request->getArray('inventory');

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

            $this->permissionType = $actionModel->getPermissionType();

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

         */

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

                    'name' => 'id',

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

                    'purchase' => 'purchase'

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

                    $this->fieldMapping[$row['tofield']] = $row['field'];

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

        protected function getInventoryCurrency(int $inventoryKey): 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

                    $quantityInStorage = $this->products[$inventoryKey]['quantity'] ?? 0.0;

    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 getInventoryData(): array

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

                    if ('tax' === $columnName) {

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

         * @param string $columnName

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

        protected function getFieldMapping(): 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 ((\Vtiger_Inventory_Model::getInstance($this->moduleName)->getAutoCompleteFields()['Products'] ?? []) as $row) {

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

        public function getErrors(): array

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

            return $inventoryData;

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

         *

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

                            $availableTaxes = 'LBL_GROUP';

    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

         */

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

            }

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

        /** @var array Arrays with errors. */

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

        protected $priceBookId;

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

                $this->priceBookId = $this->parentRecordModel->get('pricebook_id');

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

        public function validate(): bool

    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

            $inventoryData = [];

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

                    }

    Line exceeds 120 characters; contains 146 characters
    Open

                    $item[$columnName] = $this->getValue($columnName, $inventoryKey) ?? $inventoryItem[$columnName] ?? $fieldModel->getDefaultValue();

    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 (!empty($accountId)) {

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

         * Validate inventory.

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

                $this->errors['inventory'] = $inventoryErrors;

    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

                foreach (\Vtiger_Inventory_Model::getInstance($this->moduleName)->getFields() as $columnName => $fieldModel) {

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

                        if (empty($this->parentRecordModel)) {

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

                        $item['taxparam'] = \App\Json::encode(\Api\WebservicePremium\Record::getTaxParam($availableTaxes, $this->products[$inventoryKey]['taxes'], $regionalTaxes));

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

            return $this->products[$inventoryKey][$fromRow[$columnName]];

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

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

        protected $permissionType;

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

            $this->moduleName = $moduleName;

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

            return $this->errors;

    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 !$inventoryErrors;

    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

            foreach ($this->inventory as $inventoryKey => $inventoryItem) {

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

                            $availableTaxes = $this->parentRecordModel->get('accounts_available_taxes');

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

                    $item[$columnName] = $this->getValue($columnName, $inventoryKey) ?? $inventoryItem[$columnName] ?? $fieldModel->getDefaultValue();

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

            if (empty($this->fieldMapping)) {

    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

                        $inventoryErrors[$inventoryKey] = ['params' => ['quantity' => $quantityInStorage]];

    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

                            $regionalTaxes = '';

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

                        continue;

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

                $this->parentRecordModel = \Vtiger_Record_Model::getInstanceById($accountId, 'Accounts');

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

            $this->getProductsByInventory();

    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

            $inventoryData = \Vtiger_Inventory_Model::getInventoryDataById($recordId, $moduleName);

    Line exceeds 120 characters; contains 122 characters
    Open

                    if (\in_array($fieldModel->getColumnName(), ['total', 'margin', 'marginp', 'net', 'gross', 'discount'])) {

    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 mixed

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

                    'comment1' => 'description',

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

                    'price' => 'unit_price',

    Line exceeds 120 characters; contains 132 characters
    Open

                foreach ((\Vtiger_Inventory_Model::getInstance($this->moduleName)->getAutoCompleteFields()['Products'] ?? []) as $row) {

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

    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 ($inventoryErrors) {

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

         * @param int    $recordId

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

         *

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

        /** @var int Sequence. */

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

        public function getInventoryFromRecord(int $recordId, string $moduleName): array

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

         * Construct.

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

            $inventoryErrors = [];

    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 ($inventoryData as &$inventoryRow) {

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

                        continue;

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

    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

                        }

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

         * Get field mapping.

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

         * @param int $inventoryKey

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

        /** @var int Permission 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

         *

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

         * @return bool

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

                $inventoryRow['qty'] = $this->inventory[$inventoryRow['name']]['qty'];

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

         * Get inventory 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

                $this->fieldMapping = [

    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 \Api\Core\BaseAction $actionModel

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

            $accountId = $actionModel->getParentCrmId();

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

            foreach ($this->inventory as $inventoryKey => $inventoryItem) {

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

                if ('Products' === $this->products[$inventoryKey]['module']) {

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

                            $regionalTaxes = $this->parentRecordModel->get('taxes');

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

            $fromRow = $this->getFieldMapping();

    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

                ->andWhere(['discontinued' => 1])

    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 (!$isUserPermissions) {

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

                    $row['unit_price'] = $row['listprice'] ?? $multiCurrencyUiType->getValueForCurrency($row['unit_price'], $currencyId);

    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

                $queryService->addSelect(['vtiger_pricebookproductrel.listprice']);

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

                ->where(['vtiger_crmentity.deleted' => 0])

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

                ->andWhere(['vtiger_products.productid' => $crmIds])

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

            }

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

            $currencyId = \App\Fields\Currency::getDefault()['id'];

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

                    'subunit' => new \yii\db\Expression("''"), 'description', 'unit_price', 'purchase', 'taxes',

    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

                ->where(['vtiger_crmentity.deleted' => 0])

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

            foreach ($dataReader as $row) {

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

    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

            $isUserPermissions = \Api\WebservicePremium\Privilege::USER_PERMISSIONS === $this->permissionType;

    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_crmentity', 'vtiger_products.productid = vtiger_crmentity.crmid')

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

                    $row['unit_price'] = $multiCurrencyUiType->getValueForCurrency($row['unit_price'], $currencyId);

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

        protected function getInventoryTaxmode(int $inventoryKey)

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

        protected function getInventorySeq(int $inventoryKey): int

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

         * Get products by inventory.

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

                ->select([

    Line exceeds 120 characters; contains 191 characters
    Open

                $query->leftJoin('vtiger_pricebookproductrel', "vtiger_pricebookproductrel.pricebookid={$this->priceBookId} AND vtiger_pricebookproductrel.productid = vtiger_products.productid");

    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

                ->from('vtiger_service')

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

            $dataReader = $query->createCommand()->query();

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

        /**

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

         * Returns sequence.

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

                ])

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

                ->andWhere(['vtiger_service.serviceid' => $crmIds]);

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

                $queryService->addSelect(['quantity' => new \yii\db\Expression('0')]);

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

                $query->leftJoin('u_#__istorages_products', "u_#__istorages_products.crmid={$this->storage} AND u_#__istorages_products.relcrmid = vtiger_products.productid");

    Line exceeds 120 characters; contains 171 characters
    Open

                $query->leftJoin('u_#__istorages_products', "u_#__istorages_products.crmid={$this->storage} AND u_#__istorages_products.relcrmid = vtiger_products.productid");

    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 1;

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

                    'module' => new \yii\db\Expression("'Products'"), 'id' => 'vtiger_products.productid', 'usageunit',

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

                $query->addSelect(['quantity' => 'u_#__istorages_products.qtyinstock']);

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

            if (!$isUserPermissions && !empty($this->priceBookId)) {

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

        protected $seq;

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

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

                    if ($quantityInStorage < (float) $inventoryItem['qty']) {

    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 the value for the column. Return null if it does not apply to this column.

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

        protected function getValue(string $columnName, int $inventoryKey)

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

                return \method_exists($this, $method) ? $this->{$method}($inventoryKey) : null;

    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) \App\Fields\Currency::getDefault()['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

                ->select([

    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($this->storage)) {

    Line exceeds 120 characters; contains 133 characters
    Open

                    $row['unit_price'] = $row['listprice'] ?? $multiCurrencyUiType->getValueForCurrency($row['unit_price'], $currencyId);

    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->products = [];

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

            $crmIds = array_keys($this->inventory);

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

            $query = (new \App\Db\Query())

    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 function getProductsByInventory()

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

                    'module' => new \yii\db\Expression("'Service'"), 'id' => 'serviceid', 'service_usageunit',

    Line exceeds 120 characters; contains 197 characters
    Open

                $queryService->leftJoin('vtiger_pricebookproductrel', "vtiger_pricebookproductrel.pricebookid={$this->priceBookId} AND vtiger_pricebookproductrel.productid = vtiger_service.serviceid");

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

                ->from('vtiger_products')

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

                ->andWhere(['discontinued' => 1])

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

                $row['purchase'] = $multiCurrencyUiType->getValueForCurrency($row['purchase'], $currencyId);

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

            $dataReader->close();

    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_crmentity', 'vtiger_service.serviceid = vtiger_crmentity.crmid')

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

                    'subunit', 'description', 'unit_price', 'purchase', 'taxes'

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

                ->union($queryService, true);

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

                $query->leftJoin('vtiger_pricebookproductrel', "vtiger_pricebookproductrel.pricebookid={$this->priceBookId} AND vtiger_pricebookproductrel.productid = vtiger_products.productid");

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

            $multiCurrencyUiType = new \Vtiger_MultiCurrency_UIType();

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

            $queryService = (new \App\Db\Query())

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

                $queryService->leftJoin('vtiger_pricebookproductrel', "vtiger_pricebookproductrel.pricebookid={$this->priceBookId} AND vtiger_pricebookproductrel.productid = vtiger_service.serviceid");

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

                $this->products[$row['id']] = $row;

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

            return ++$this->seq;

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

            if (!empty($this->storage)) {

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

            if (!$isUserPermissions && !empty($this->priceBookId)) {

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

            }

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

                $query->addSelect(['vtiger_pricebookproductrel.listprice']);

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

            }

    There are no issues that match your filters.

    Category
    Status