YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/ManageConsents/BaseModule/SendEmail.php

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

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

    public function post()
    {
        $moduleName = $this->controller->request->getModule();
        $templateId = $this->controller->request->getInteger('templateId');
        $email = $this->controller->request->getByType('e-mail', 'Email');
Severity: Minor
Found in api/webservice/ManageConsents/BaseModule/SendEmail.php - About 25 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

Missing class import via use statement (line '113', column '26').
Open

        $queryGenerator = (new \App\QueryGenerator($moduleName));

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

            throw new \Api\Core\Exception('No permissions for email template: ' . $templateId, 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 '122', column '14').
Open

            throw new \Api\Core\Exception('Not Found', 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 '\App\Mailer' in method 'post'.
Open

        return \App\Mailer::sendFromTemplate([
            'moduleName' => $moduleName,
            'template' => $templateId,
            'to' => $email,
            'recordId' => $recordId,

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\Privilege' in method 'post'.
Open

        if (!\App\Privilege::isPermitted('EmailTemplates', 'DetailView', $templateId)) {

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;

Call to method addCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

                $queryGenerator->addCondition($fieldModel->getName(), $email, 'e', false);

Returning type bool but post() is declared to return array
Open

        return \App\Mailer::sendFromTemplate([

Call to method getModuleModel from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

        $emailFields = $queryGenerator->getModuleModel()->getFieldsByType('email', true);

Call to method __construct from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

        $queryGenerator = (new \App\QueryGenerator($moduleName));

Call to method setFields from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
Open

            $recordId = $queryGenerator->setFields(['id'])->createQuery()->scalar();

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

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

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

     *             @OA\MediaType(

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/BaseModule_Post_SendEmail_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=401,

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

     *                description="Method Not Allowed",

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

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

     *                type="boolean",

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

     *                 mediaType="application/x-www-form-urlencoded",

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

     *        ),

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

     *        schema="BaseModule_Post_SendEmail_Response",

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

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

     *                response=405,

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

     */

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

     *                 mediaType="multipart/form-data",

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

     *                response=200,

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

     *                @OA\JsonContent(ref="#/components/schemas/BaseModule_Post_SendEmail_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

     *                description="Not Found",

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

     *        ),

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

     *        schema="BaseModule_Post_SendEmail_Request",

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

     *        title="Request body for SendEmail",

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

     *        schema="BaseModule_Post_SendEmail_Response",

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

     *                type="boolean",

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

     *        ),

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

     *                response=404,

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

     *        schema="BaseModule_Post_SendEmail_Request",

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

     *                description="Specific ID of the email template",

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

     *                type="integer"

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

     *        summary="Send e-mail",

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

     *                 mediaType="multipart/form-data",

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

     *             ),

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

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

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 for module",

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

     *        ),

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

     *                property="e-mail",

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

     *                description="E-mail address (Token type field in the module is required)",

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

     *        @OA\Property(

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

     *    },

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

     *                description="Required data for communication",

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

     *                 mediaType="application/x-www-form-urlencoded",

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

     *                 example=true

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

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

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

     *                description="Not Found",

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="string"

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

     *        ),

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

     *                property="templateId",

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

     *                property="result",

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

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

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

     *        @OA\RequestBody(

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

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

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

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

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

     *             @OA\MediaType(

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

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

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

     *             ),

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

     *                response=401,

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

     *        ),

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

     *                description="No permissions for module",

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

     *                property="result",

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

     *        title="Request body for SendEmail",

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

     *        @OA\Property(

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

     *                property="templateId",

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

     *                description="Added mail to quote for send: true - success , false - fail",

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

     *                description="Required data for communication",

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

     *                description="Added mail to quote for send: true - success , false - fail",

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

     *         ),

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

     *             @OA\MediaType(

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

     *                description="Status of adding an email to the queue",

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

     *                description="`No sent token` OR `Invalid token`",

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

     *                required=true,

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

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

     *                response=403,

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

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="Response body for SendEmail",

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

     *        path="/webservice/ManageConsents/{moduleName}/SendEmail",

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

     *        summary="Send e-mail",

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

     *    security={

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

     *             @OA\MediaType(

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

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

     *                description="Method Not Allowed",

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

     *        ),

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

     *                 example=true

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

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

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

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

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

     *                description="Status of adding an email to the queue",

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

     *                description="`No sent token` OR `Invalid token`",

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

     *                type="string"

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

     *                type="integer"

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

     *             ),

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

     *                response=200,

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

     *                property="e-mail",

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

     *                description="E-mail address (Token type field in the module is required)",

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

     *        @OA\Response(

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

     *        ),

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="Specific ID of the email template",

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

     *        title="Response body for SendEmail",

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

    public function post()

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

        }

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

        return \App\Mailer::sendFromTemplate([

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

            'recordId' => $recordId,

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

            $recordId = $queryGenerator->setFields(['id'])->createQuery()->scalar();

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

        $email = $this->controller->request->getByType('e-mail', 'Email');

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

        $recordId = '';

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

            'to' => $email,

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

    }

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

            foreach ($emailFields as $fieldModel) {

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

            'moduleName' => $moduleName,

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

        $queryGenerator = (new \App\QueryGenerator($moduleName));

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

        if ($emailFields && $email) {

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

        }

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

            throw new \Api\Core\Exception('No permissions for email template: ' . $templateId, 403);

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

        ]);

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

            'template' => $templateId,

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

        if (!\App\Privilege::isPermitted('EmailTemplates', 'DetailView', $templateId)) {

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

        $emailFields = $queryGenerator->getModuleModel()->getFieldsByType('email', true);

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

                $queryGenerator->addCondition($fieldModel->getName(), $email, 'e', false);

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

        if (!$recordId) {

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

            throw new \Api\Core\Exception('Not Found', 404);

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

     *        path="/webservice/ManageConsents/{moduleName}/SendEmail",

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

    public $allowedMethod = ['POST'];

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

     *

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

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

     *

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

     * Send e-mail.

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

     * @return array

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

     * @throws \Api\Core\Exception

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(

There are no issues that match your filters.

Category
Status