YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
0 mins
Test Coverage
B
87%

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

            throw new \Api\Core\Exception('No permissions to view 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 '34', column '14').
Open

            throw new \Api\Core\Exception("No permissions for action ExportPdf in {$moduleName} module", 405);

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 '31', column '14').
Open

            throw new \Api\Core\Exception('Record doesn\'t exist', 404);

MissingImport

Since: 2.7.0

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

Example

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

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

Avoid using static access to class '\Api\WebservicePremium\Privilege' in method 'checkPermission'.
Open

        if (!\Api\WebservicePremium\Privilege::isPermitted($moduleName, 'ExportPdf')) {

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

                'second_name' => \App\Language::translate($template->get('secondary_name'), $template->get('module_name')),

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

        $handlerClass = \Vtiger_Loader::getComponentClassName('Model', 'PDF', $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\Language' in method 'get'.
Open

                'name' => \App\Language::translate($template->getName(), $template->get('module_name')),

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\Record' in method 'checkPermission'.
Open

        if (!\App\Record::isExists($this->controller->request->getInteger('record'), $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_Record_Model' in method 'checkPermission'.
Open

        $recordModel = \Vtiger_Record_Model::getInstanceById($this->controller->request->getInteger('record'), $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

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

        if (!\App\Record::isExists($this->controller->request->getInteger('record'), $moduleName)) {

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.

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

     * ),

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

     *            @OA\AdditionalProperties(

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

        $templates = $pdfModel->getActiveTemplatesForRecord($recordId, 'Detail', $moduleName);

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

     *        summary="Gets a list of  PDF templates",

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(property="second_name", type="string", example="order"),

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

        foreach ($templates as $template) {

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

                'name' => \App\Language::translate($template->getName(), $template->get('module_name')),

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

     *        description="PDF templates",

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

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

     *        @OA\Response(

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

     *            description="Gets a list of  PDF templates",

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

     *            response=404,

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

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

     *        title="Base module - Get PDF templates list response schema",

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

     *            title="Pdf templates",

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

     *        path="/webservice/WebservicePremium/{moduleName}/PdfTemplates/{recordId}",

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

     *        description="PDF templates",

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

     *        @OA\Response(

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

     *            response=405,

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

     *            description="No permissions for action ExportPdf in {moduleName} module",

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

            $templatesData[$template->getId()] = [

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/BaseModule_Get_PdfTemplates_Response"),

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

     *        ),

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

    {

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

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

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

     *        summary="Gets a list of  PDF templates",

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

     *        @OA\Response(

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

     *            description="No record id",

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

     *            response=405,

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

     *            type="object",

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

     *                title="Pdf template detail",

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

     *                type="object",

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

        $recordId = $this->controller->request->getInteger('record');

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="recordId", in="path", @OA\Schema(type="integer"), description="Record id", required=true, example=116),

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

     *        schema="BaseModule_Get_PdfTemplates_Response",

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

     *                 @OA\Property(property="name", type="string", example="order"),

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

     *                 @OA\Property(property="default", type="integer", example=1),

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

     *            response=403,

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

     *            type="object",

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

     *        tags={"BaseModule"},

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

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

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

     *            response=403,

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

     *            description="No permissions to view record",

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

     *            description="No record id",

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

     *        ),

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

     *        schema="BaseModule_Get_PdfTemplates_Response",

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

     *        title="Base module - Get PDF templates list response schema",

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

     *            title="Pdf templates",

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

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

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

        $handlerClass = \Vtiger_Loader::getComponentClassName('Model', 'PDF', $moduleName);

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

        }

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

     *            description="Gets a list of  PDF templates",

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

     *        @OA\Response(

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

     *                title="Pdf template detail",

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

     *                 @OA\Property(property="name", type="string", example="order"),

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

                'id' => $template->getId(),

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

     *            description="No permissions to view record",

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

     *        @OA\Response(

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

     *            @OA\AdditionalProperties(

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

        $templatesData = [];

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

                'default' => $template->get('default'),

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

        return $templatesData;

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\XmlContent(ref="#/components/schemas/BaseModule_Get_PdfTemplates_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

     *            response=404,

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

     *            property="result",

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

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

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

        $pdfModel = new $handlerClass();

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

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

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

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

     *        ),

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

     *        @OA\Property(

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

     *        ),

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

     *        tags={"BaseModule"},

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

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="second_name", type="string", example="order"),

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

     *                 @OA\Property(property="default", type="integer", example=1),

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

     *        @OA\Parameter(name="recordId", in="path", @OA\Schema(type="integer"), description="Record id", required=true, example=116),

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

     *            description="No permissions for action ExportPdf in {moduleName} module",

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

                'second_name' => \App\Language::translate($template->get('secondary_name'), $template->get('module_name')),

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

    {

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

            throw new \Api\Core\Exception("No permissions for action ExportPdf in {$moduleName} module", 405);

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

        }

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

            throw new \Api\Core\Exception('Record doesn\'t exist', 404);

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

        if (!\Api\WebservicePremium\Privilege::isPermitted($moduleName, 'ExportPdf')) {

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

        parent::checkPermission();

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 method - Gets a list of  PDF templates.

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(

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

    public $allowedMethod = ['GET'];

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

    /** {@inheritdoc}  */

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

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

Line exceeds 120 characters; contains 123 characters
Open

                'second_name' => \App\Language::translate($template->get('secondary_name'), $template->get('module_name')),

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

    /**

Line exceeds 120 characters; contains 135 characters
Open

     *        @OA\Parameter(name="recordId", in="path", @OA\Schema(type="integer"), description="Record id", required=true, example=116),

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

        if (!\App\Record::isExists($this->controller->request->getInteger('record'), $moduleName)) {

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

        $recordModel = \Vtiger_Record_Model::getInstanceById($this->controller->request->getInteger('record'), $moduleName);

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

    protected function checkPermission(): void

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

        }

Line exceeds 120 characters; contains 124 characters
Open

        $recordModel = \Vtiger_Record_Model::getInstanceById($this->controller->request->getInteger('record'), $moduleName);

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

        if (!$recordModel->isViewable()) {

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

     *        path="/webservice/WebservicePremium/{moduleName}/PdfTemplates/{recordId}",

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

There are no issues that match your filters.

Category
Status