YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/WebserviceStandard/BaseModule/Privileges.php

Summary

Maintainability
A
55 mins
Test Coverage
A
100%

Function get has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function get(): array
    {
        $privileges = [];
        if (\App\User::isExists($this->getUserData('user_id'))) {
            $moduleName = $this->controller->request->getModule('module');
Severity: Minor
Found in api/webservice/WebserviceStandard/BaseModule/Privileges.php - About 55 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 static access to class '\App\User' in method 'get'.
Open

        if (\App\User::isExists($this->getUserData('user_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

Avoid using static access to class '\App\Module' in method 'get'.
Open

            $moduleId = \App\Module::getModuleId($moduleName);

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Avoid using static access to class '\App\User' in method 'get'.
Open

            $actionPermissions = \App\User::getPrivilegesFile($this->getUserData('user_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

Avoid using static access to class '\Vtiger_Action_Model' in method 'get'.
Open

                $actions = array_merge(\Vtiger_Action_Model::getAllBasic(true), \Vtiger_Action_Model::getAllUtility(true));

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_Action_Model' in method 'get'.
Open

                $actions = array_merge(\Vtiger_Action_Model::getAllBasic(true), \Vtiger_Action_Model::getAllUtility(true));

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

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

use OpenApi\Annotations as OA;

Argument 1 (raw) is 'module' but \Api\Core\Request::getModule() takes bool|true defined at /code/app/Request.php:548
Open

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

Call to method isExists from undeclared class \App\User (Did you mean class \Tests\App\User)
Open

        if (\App\User::isExists($this->getUserData('user_id'))) {

Call to method getPrivilegesFile from undeclared class \App\User (Did you mean class \Tests\App\User)
Open

            $actionPermissions = \App\User::getPrivilegesFile($this->getUserData('user_id'));

Suspicious array access to false
Open

                    $privileges[$action->getName()] = $isAdmin || (isset($permission[$action->getId()]) && \Settings_Profiles_Module_Model::IS_PERMITTED_VALUE === $permission[$action->getId()]);

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

     *         title="Base module - Privileges response 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

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

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

     *         schema="BaseModule_Privileges_ResponseBody",

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

     *         title="Base module - Privileges response schema",

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

     *        summary="Privileges for module actions",

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\Parameter(name="moduleName", in="path", @OA\Schema(type="string"), description="Module name", required=true, example="Contacts"),

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

     *         schema="BaseModule_Privileges_ResponseBody",

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

     *        description="Gets the list of actions that the user has access to in the module",

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

     *        @OA\Response(response=200, description="Privileges details",

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

     *        type="object",

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

     *        summary="Privileges for module actions",

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

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

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

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

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="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),

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

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

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

     * ),

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

     *        path="/webservice/WebserviceStandard/{moduleName}/Privileges",

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

     *        description="Gets the list of actions that the user has access to in the module",

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

     *        @OA\Response(response=200, description="Privileges details",

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\JsonContent(ref="#/components/schemas/BaseModule_Privileges_ResponseBody"),

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\Property(property="result", type="object", description="List of module privileges",

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

     *            example={"EditView" : true, "Delete" : true, "DetailView" : true, "CreateView" : true},

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="X-ENCRYPTED", in="header", @OA\Schema(ref="#/components/schemas/Header-Encrypted"), required=true),

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\Property(property="result", type="object", description="List of module privileges",

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

     *            @OA\AdditionalProperties(type="boolean", description="Action"),

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

                    $privileges[$action->getName()] = $isAdmin || (isset($permission[$action->getId()]) && \Settings_Profiles_Module_Model::IS_PERMITTED_VALUE === $permission[$action->getId()]);

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="Contacts"),

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

                foreach ($actions as $action) {

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

     *            @OA\AdditionalProperties(type="boolean", description="Action"),

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

        $privileges = [];

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

            $actionPermissions = \App\User::getPrivilegesFile($this->getUserData('user_id'));

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

     *            example={"EditView" : true, "Delete" : true, "DetailView" : true, "CreateView" : true},

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 (\App\User::isExists($this->getUserData('user_id'))) {

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

            $isAdmin = $actionPermissions['is_admin'];

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

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

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

            if ($permission || $isAdmin) {

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

        return $privileges;

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

     *         ),

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

            $permission = $actionPermissions['profile_action_permission'][$moduleId] ?? false;

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

                $actions = array_merge(\Vtiger_Action_Model::getAllBasic(true), \Vtiger_Action_Model::getAllUtility(true));

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

            $moduleId = \App\Module::getModuleId($moduleName);

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

    }

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

    public function get(): array

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 to indent lines; tabs are not allowed
Open

     * @return array

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

     *        path="/webservice/WebserviceStandard/{moduleName}/Privileges",

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

     * Get privileges for module.

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

    public $allowedMethod = ['GET'];

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\Get(

Line exceeds 120 characters; contains 145 characters
Open

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

Line exceeds 120 characters; contains 131 characters
Open

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

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

    /** {@inheritdoc}  */

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

    /**

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

     * @api

Line exceeds 120 characters; contains 194 characters
Open

                    $privileges[$action->getName()] = $isAdmin || (isset($permission[$action->getId()]) && \Settings_Profiles_Module_Model::IS_PERMITTED_VALUE === $permission[$action->getId()]);

Line exceeds 120 characters; contains 123 characters
Open

                $actions = array_merge(\Vtiger_Action_Model::getAllBasic(true), \Vtiger_Action_Model::getAllUtility(true));

There are no issues that match your filters.

Category
Status