YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/WebservicePremium/BaseModule/SaveInventory.php

Summary

Maintainability
B
6 hrs
Test Coverage
F
0%

Function post has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    public function post(): array
    {
        if ($result = $this->checkBeforeSave()) {
            return $result;
        }
Severity: Minor
Found in api/webservice/WebservicePremium/BaseModule/SaveInventory.php - About 3 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 post has 61 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function post(): array
    {
        if ($result = $this->checkBeforeSave()) {
            return $result;
        }
Severity: Major
Found in api/webservice/WebservicePremium/BaseModule/SaveInventory.php - About 2 hrs to fix

    The method post() has an NPath complexity of 7560. The configured NPath complexity threshold is 200.
    Open

        public function post(): array
        {
            if ($result = $this->checkBeforeSave()) {
                return $result;
            }

    NPathComplexity

    Since: 0.1

    The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

    Example

    class Foo {
        function bar() {
            // lots of complicated code
        }
    }

    Source https://phpmd.org/rules/codesize.html#npathcomplexity

    The method post() has a Cyclomatic Complexity of 18. The configured cyclomatic complexity threshold is 10.
    Open

        public function post(): array
        {
            if ($result = $this->checkBeforeSave()) {
                return $result;
            }

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

    Refactor this function to reduce its Cognitive Complexity from 26 to the 15 allowed.
    Open

        public function post(): array

    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

    See

    Reduce the number of returns of this function 4, down to the maximum allowed 3.
    Open

        private function checkBeforeSave(): array

    Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

    Noncompliant Code Example

    With the default threshold of 3:

    function myFunction(){ // Noncompliant as there are 4 return statements
      if (condition1) {
        return true;
      } else {
        if (condition2) {
          return false;
        } else {
          return true;
        }
      }
      return false;
    }
    

    Missing class import via use statement (line '45', column '14').
    Open

                throw new \Api\Core\Exception('No permissions to create record', 403);

    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 '191', column '26').
    Open

            $this->inventory = new \Api\WebservicePremium\Inventory($this->moduleName, $this);

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Avoid assigning values to variables in if clauses and the like (line '105', column '7').
    Open

        public function post(): array
        {
            if ($result = $this->checkBeforeSave()) {
                return $result;
            }

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid using static access to class '\Vtiger_Record_Model' in method 'checkPermission'.
    Open

            $this->recordModel = \Vtiger_Record_Model::getCleanInstance($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 '\Vtiger_InventoryLimit_UIType' in method 'post'.
    Open

                    $limits = \Vtiger_InventoryLimit_UIType::getLimits();

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

        public function getCheckStockLevels(): bool
        {
            if (\Api\WebservicePremium\Privilege::USER_PERMISSIONS !== $this->getPermissionType() && ($parentId = $this->getParentCrmId())) {
                return (bool) \Vtiger_Record_Model::getInstanceById($parentId)->get('check_stock_levels');
            }

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid using static access to class '\Vtiger_Record_Model' in method 'post'.
    Open

                $parentRecordModel = \Vtiger_Record_Model::getInstanceById($parentRecordId, '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 '\Api\Core\Module' in method 'post'.
    Open

            $fieldPermission = \Api\Core\Module::getApiFieldPermission($this->moduleName, (int) $this->controller->app['id']);

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

            } else {
                $inventoryData = $this->inventory->getInventoryData();
            }

    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

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

                            'errors' => [

    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.

    Rename "$moduleName" which has the same name as the field declared at line 27.
    Open

            $moduleName = $this->controller->request->getModule();

    Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.

    Noncompliant Code Example

    class Foo {
      public $myField;
    
      public function doSomething() {
        $myField = 0;
        ...
      }
    }
    

    See

    Possibly zero references to use statement for classlike/namespace OA (\OpenApi\Annotations)
    Open

    use OpenApi\Annotations as OA;

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Response(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            description="No permissions to create record",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        schema="BaseAction_SaveInventory_ResponseBodyError",

    Spaces must be used for alignment; tabs are not allowed
    Open

                }

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    @OA\Post(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        summary="A store functionality - creates a record in an advanced module (orders)",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\XmlContent(ref="#/components/schemas/Exception"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Schema(ref="#/components/schemas/BaseAction_SaveInventory_ResponseBodyError"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(property="id", description="Record Id", type="integer", example=38),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

                    continue;

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        tags={"BaseModule"},

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        security={{"basicAuth" : {}, "ApiKeyAuth" : {}, "token" : {}}},

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            description="Contents of the response contains only id nd module name",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        security={{"basicAuth" : {}, "ApiKeyAuth" : {}, "token" : {}}},

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            response=403,

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\JsonContent(ref="#/components/schemas/BaseAction_SaveInventory_ResponseBody"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            response=403,

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(property="status", type="integer", enum={0, 1}, description="A numeric value of 0 or 1 that indicates whether the communication is valid. 1 - success , 0 - error"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\JsonContent(ref="#/components/schemas/Exception"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        schema="BaseAction_SaveInventory_ResponseBodySuccess",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        title="Base module - Create inventory record response success schema",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    @OA\Schema(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(property="errors", description="Error details", type="object"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    @OA\Schema(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        description="Creating inventory records for the functionality of the store",

    Spaces must be used for alignment; tabs are not allowed
    Open

            foreach ($this->moduleModel->getFields() as $fieldName => $fieldModel) {

    Spaces must be used for alignment; tabs are not allowed
    Open

        {

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\XmlContent(ref="#/components/schemas/BaseAction_SaveInventory_ResponseBody"),

    Spaces must be used for alignment; tabs are not allowed
    Open

                return $result;

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(property="status", type="integer", enum={0, 1}, description="A numeric value of 0 or 1 that indicates whether the communication is valid. 1 - success , 0 - error"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            property="result",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            description="Create result",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        path="/webservice/WebservicePremium/{moduleName}/SaveInventory",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        schema="BaseAction_SaveInventory_ResponseBody",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Schema(ref="#/components/schemas/BaseAction_SaveInventory_ResponseBodySuccess"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(property="moduleName", type="string", example="SSingleOrders"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            response=200,

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    @OA\Schema(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            }

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        description="Creating inventory records for the functionality of the store",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\JsonContent(ref="#/components/schemas/Exception"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    @OA\Schema(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        title="Base module - Create inventory record response error schema",

    Spaces must be used for alignment; tabs are not allowed
    Open

         */

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        path="/webservice/WebservicePremium/{moduleName}/SaveInventory",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="moduleName", in="path", @OA\Schema(type="string"), description="Module name", required=true, example="Accounts"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            description="No permissions to create record",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Schema(ref="#/components/schemas/BaseAction_SaveInventory_ResponseBodyError"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Response(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Response(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            property="result",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

                if ($this->controller->request->has($fieldName)) {

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Response(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            type="object",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            }

    Spaces must be used for alignment; tabs are not allowed
    Open

            if ($result = $this->checkBeforeSave()) {

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            response=200,

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\JsonContent(ref="#/components/schemas/BaseAction_SaveInventory_ResponseBody"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            description="Contents of the response contains only id nd module name",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            oneOf={

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        schema="BaseAction_SaveInventory_ResponseBody",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(property="moduleName", type="string", example="SSingleOrders"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    @OA\Schema(

    Spaces must be used for alignment; tabs are not allowed
    Open

                if (!$fieldModel->isWritable()) {

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        tags={"BaseModule"},

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\XmlContent(ref="#/components/schemas/BaseAction_SaveInventory_ResponseBody"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        summary="A store functionality - creates a record in an advanced module (orders)",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Parameter(name="moduleName", in="path", @OA\Schema(type="string"), description="Module name", required=true, example="Accounts"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    @OA\Schema(

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        title="Base module - Create inventory record response schema",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            description="Create result",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        title="Base module - Create inventory record response schema",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *                @OA\Schema(ref="#/components/schemas/BaseAction_SaveInventory_ResponseBodySuccess"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        title="Base module - Create inventory record response error schema",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *    ),

    Spaces must be used for alignment; tabs are not allowed
    Open

        public function post(): array

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            @OA\XmlContent(ref="#/components/schemas/Exception"),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        ),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *            oneOf={

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        schema="BaseAction_SaveInventory_ResponseBodySuccess",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        title="Base module - Create inventory record response success schema",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(property="id", description="Record Id", type="integer", example=38),

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        schema="BaseAction_SaveInventory_ResponseBodyError",

    Spaces must be used for alignment; tabs are not allowed
    Open

         *        @OA\Property(property="errors", description="Error details", type="object"),

    Spaces must be used for alignment; tabs are not allowed
    Open

                }

    Spaces must be used for alignment; tabs are not allowed
    Open

                $this->recordModel->set($fieldModel->getFieldName(), $this->getUserStorageId());

    Spaces must be used for alignment; tabs are not allowed
    Open

            if ($fieldPermission) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                return [

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

            $this->inventory = new \Api\WebservicePremium\Inventory($this->moduleName, $this);

    Spaces must be used for alignment; tabs are not allowed
    Open

        /**

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

            if (\Api\WebservicePremium\Privilege::USER_PERMISSIONS !== $this->getPermissionType()) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                if (!empty($creditLimitId)) {

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

                    if ($grossFieldModel && $grossFieldModel->getSummaryValuesFromData($inventoryData) > (($limits[$creditLimitId]['value'] ?? 0) - $parentRecordModel->get('sum_open_orders'))) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                    $grossFieldModel = \Vtiger_Inventory_Model::getInstance($this->moduleName)->getField('gross');

    Spaces must be used for alignment; tabs are not allowed
    Open

                        return [

    Spaces must be used for alignment; tabs are not allowed
    Open

            return [

    Spaces must be used for alignment; tabs are not allowed
    Open

         *

    Spaces must be used for alignment; tabs are not allowed
    Open

                        'record' => 'There are no inventory records',

    Spaces must be used for alignment; tabs are not allowed
    Open

                return [

    Spaces must be used for alignment; tabs are not allowed
    Open

            $this->moduleModel = $this->recordModel->getModule();

    Spaces must be used for alignment; tabs are not allowed
    Open

            if (!$this->moduleModel->isInventory()) {

    Spaces must be used for alignment; tabs are not allowed
    Open

            $parentRecordId = $this->getParentCrmId();

    Spaces must be used for alignment; tabs are not allowed
    Open

                    $this->recordModel->set($fieldModel->getFieldName(), $this->getUserCrmId());

    Spaces must be used for alignment; tabs are not allowed
    Open

            $fieldPermission = \Api\Core\Module::getApiFieldPermission($this->moduleName, (int) $this->controller->app['id']);

    Spaces must be used for alignment; tabs are not allowed
    Open

            $inventoryData = [];

    Spaces must be used for alignment; tabs are not allowed
    Open

                }

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

            ];

    Spaces must be used for alignment; tabs are not allowed
    Open

                ];

    Spaces must be used for alignment; tabs are not allowed
    Open

            if ($this->getCheckStockLevels() && !$this->inventory->validate()) {

    Spaces must be used for alignment; tabs are not allowed
    Open

         */

    Spaces must be used for alignment; tabs are not allowed
    Open

                if ($fieldModel && !$this->controller->request->has($fieldModel->getFieldName())) {

    Spaces must be used for alignment; tabs are not allowed
    Open

            if (!empty($parentRecordId)) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                    $this->recordModel->set($fieldName, $parentRecordModel->get($fieldName));

    Spaces must be used for alignment; tabs are not allowed
    Open

                            'errors' => [

    Spaces must be used for alignment; tabs are not allowed
    Open

        private function checkBeforeSave(): array

    Spaces must be used for alignment; tabs are not allowed
    Open

                    ],

    Spaces must be used for alignment; tabs are not allowed
    Open

                $fieldModel = current($this->moduleModel->getReferenceFieldsForModule('Contacts'));

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

                                'limit' => 'Merchant limit was exceeded',

    Spaces must be used for alignment; tabs are not allowed
    Open

                    }

    Spaces must be used for alignment; tabs are not allowed
    Open

         * Get information, whether to check inventory levels.

    Spaces must be used for alignment; tabs are not allowed
    Open

                }

    Spaces must be used for alignment; tabs are not allowed
    Open

            } else {

    Spaces must be used for alignment; tabs are not allowed
    Open

                $creditLimitId = $parentRecordModel->get('creditlimit');

    Spaces must be used for alignment; tabs are not allowed
    Open

            if (!$this->controller->request->has('inventory')) {

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

                        'record' => 'This is not an inventory module',

    Spaces must be used for alignment; tabs are not allowed
    Open

         * @return bool

    Spaces must be used for alignment; tabs are not allowed
    Open

            $fieldModel = current($this->moduleModel->getReferenceFieldsForModule('IStorages'));

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

                ];

    Spaces must be used for alignment; tabs are not allowed
    Open

            return [];

    Spaces must be used for alignment; tabs are not allowed
    Open

        }

    Spaces must be used for alignment; tabs are not allowed
    Open

        {

    Spaces must be used for alignment; tabs are not allowed
    Open

                    $fieldModel->getUITypeModel()->setValueFromRequest($this->controller->request, $this->recordModel);

    Spaces must be used for alignment; tabs are not allowed
    Open

                }

    Spaces must be used for alignment; tabs are not allowed
    Open

            $this->recordModel->initInventoryData($inventoryData, false);

    Spaces must be used for alignment; tabs are not allowed
    Open

                    $limits = \Vtiger_InventoryLimit_UIType::getLimits();

    Spaces must be used for alignment; tabs are not allowed
    Open

                'id' => $this->recordModel->getId(),

    Spaces must be used for alignment; tabs are not allowed
    Open

        }

    Spaces must be used for alignment; tabs are not allowed
    Open

                if ($fieldModel) {

    Spaces must be used for alignment; tabs are not allowed
    Open

            if ($fieldModel) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                $parentRecordModel = \Vtiger_Record_Model::getInstanceById($parentRecordId, 'Accounts');

    Spaces must be used for alignment; tabs are not allowed
    Open

                        ];

    Spaces must be used for alignment; tabs are not allowed
    Open

            $this->recordModel->save();

    Spaces must be used for alignment; tabs are not allowed
    Open

         * @return array

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

                'moduleName' => $this->moduleName,

    Spaces must be used for alignment; tabs are not allowed
    Open

            if (\Api\WebservicePremium\Privilege::USER_PERMISSIONS !== $this->getPermissionType() && ($parentId = $this->getParentCrmId())) {

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

                $fieldModel = current($this->moduleModel->getReferenceFieldsForModule('Accounts'));

    Spaces must be used for alignment; tabs are not allowed
    Open

                $inventoryData = $this->inventory->getInventoryFromRecord($this->controller->request->getInteger('reference_id'), $this->controller->request->getByType('reference_module', 'Alnum'));

    Spaces must be used for alignment; tabs are not allowed
    Open

                if (!$this->controller->request->has($fieldName)) {

    Spaces must be used for alignment; tabs are not allowed
    Open

         * Check the request before the save.

    Spaces must be used for alignment; tabs are not allowed
    Open

                    'errors' => [

    Spaces must be used for alignment; tabs are not allowed
    Open

                return (bool) \Vtiger_Record_Model::getInstanceById($parentId)->get('check_stock_levels');

    Spaces must be used for alignment; tabs are not allowed
    Open

            return false;

    Spaces must be used for alignment; tabs are not allowed
    Open

            }

    Spaces must be used for alignment; tabs are not allowed
    Open

                $this->recordModel->setDataForSave([$fieldPermission['tablename'] => [$fieldPermission['columnname'] => 1]]);

    Spaces must be used for alignment; tabs are not allowed
    Open

                $inventoryData = $this->inventory->getInventoryData();

    Spaces must be used for alignment; tabs are not allowed
    Open

                            ],

    Spaces must be used for alignment; tabs are not allowed
    Open

                }

    Spaces must be used for alignment; tabs are not allowed
    Open

        }

    Spaces must be used for alignment; tabs are not allowed
    Open

            $this->moduleName = $this->controller->request->getModule();

    Spaces must be used for alignment; tabs are not allowed
    Open

                    'errors' => [

    Spaces must be used for alignment; tabs are not allowed
    Open

         *

    Spaces must be used for alignment; tabs are not allowed
    Open

            if ($this->controller->request->has('reference_id') && $this->controller->request->has('reference_module')) {

    Spaces must be used for alignment; tabs are not allowed
    Open

                $fieldName = 'assigned_user_id';

    Spaces must be used for alignment; tabs are not allowed
    Open

                    $this->recordModel->set($fieldModel->getFieldName(), $parentRecordId);

    Spaces must be used for alignment; tabs are not allowed
    Open

         */

    Spaces must be used for alignment; tabs are not allowed
    Open

        {

    Spaces must be used for alignment; tabs are not allowed
    Open

                    ],

    Spaces must be used for alignment; tabs are not allowed
    Open

        public function getCheckStockLevels(): bool

    Spaces must be used for alignment; tabs are not allowed
    Open

        /**

    Spaces must be used for alignment; tabs are not allowed
    Open

                ];

    Spaces must be used for alignment; tabs are not allowed
    Open

                return [

    Spaces must be used for alignment; tabs are not allowed
    Open

                    'errors' => $this->inventory->getErrors(),

    The 'getCheckStockLevels()' method which returns a boolean should be named 'is...()' or 'has...()'
    Open

        public function getCheckStockLevels(): bool
        {
            if (\Api\WebservicePremium\Privilege::USER_PERMISSIONS !== $this->getPermissionType() && ($parentId = $this->getParentCrmId())) {
                return (bool) \Vtiger_Record_Model::getInstanceById($parentId)->get('check_stock_levels');
            }

    BooleanGetMethodName

    Since: 0.2

    Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

    Example

    class Foo {
        /**
         * @return boolean
         */
        public function getFoo() {} // bad
        /**
         * @return bool
         */
        public function isFoo(); // ok
        /**
         * @return boolean
         */
        public function getFoo($bar); // ok, unless checkParameterizedMethods=true
    }

    Source https://phpmd.org/rules/naming.html#booleangetmethodname

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

        protected function checkPermission(): void

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

            parent::checkPermission();

    Line exceeds 120 characters; contains 145 characters
    Open

         *        @OA\Parameter(name="moduleName", in="path", @OA\Schema(type="string"), description="Module name", required=true, example="Accounts"),

    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

        private $recordModel;

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

            $moduleName = $this->controller->request->getModule();

    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 $allowedMethod = ['POST'];

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

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

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

            if (!$this->recordModel->isCreateable()) {

    Line exceeds 120 characters; contains 189 characters
    Open

         *        @OA\Property(property="status", type="integer", enum={0, 1}, description="A numeric value of 0 or 1 that indicates whether the communication is valid. 1 - success , 0 - error"),

    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 \Api\WebservicePremium\Inventory Inventory object. */

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

        private $inventory;

    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 \Vtiger_Module_Model Module model. */

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

        private $moduleModel;

    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

         * Put method - A store functionality - creates a record in an advanced module (orders).

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

         *

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

         *    @OA\Post(

    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

        private $moduleName;

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

        /** @var \Vtiger_Record_Model Record model. */

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

                throw new \Api\Core\Exception('No permissions to create record', 403);

    Line exceeds 120 characters; contains 131 characters
    Open

         *        @OA\Parameter(name="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),

    Line exceeds 120 characters; contains 194 characters
    Open

                $inventoryData = $this->inventory->getInventoryFromRecord($this->controller->request->getInteger('reference_id'), $this->controller->request->getByType('reference_module', 'Alnum'));

    Line exceeds 120 characters; contains 121 characters
    Open

                $this->recordModel->setDataForSave([$fieldPermission['tablename'] => [$fieldPermission['columnname'] => 1]]);

    Line exceeds 120 characters; contains 137 characters
    Open

            if (\Api\WebservicePremium\Privilege::USER_PERMISSIONS !== $this->getPermissionType() && ($parentId = $this->getParentCrmId())) {

    Line exceeds 120 characters; contains 190 characters
    Open

                    if ($grossFieldModel && $grossFieldModel->getSummaryValuesFromData($inventoryData) > (($limits[$creditLimitId]['value'] ?? 0) - $parentRecordModel->get('sum_open_orders'))) {

    Line exceeds 120 characters; contains 122 characters
    Open

            $fieldPermission = \Api\Core\Module::getApiFieldPermission($this->moduleName, (int) $this->controller->app['id']);

    There are no issues that match your filters.

    Category
    Status