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');
- Read upRead up
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));
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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,
- Read upRead up
- Exclude checks
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)) {
- Read upRead up
- Exclude checks
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;
- Exclude checks
Call to method addCondition
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->addCondition($fieldModel->getName(), $email, 'e', false);
- Exclude checks
Returning type bool
but post()
is declared to return array
Open
return \App\Mailer::sendFromTemplate([
- Exclude checks
Call to method getModuleModel
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$emailFields = $queryGenerator->getModuleModel()->getFieldsByType('email', true);
- Exclude checks
Call to method __construct
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator = (new \App\QueryGenerator($moduleName));
- Exclude checks
Call to method setFields
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$recordId = $queryGenerator->setFields(['id'])->createQuery()->scalar();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\JsonContent(ref="#/components/schemas/BaseModule_Post_SendEmail_Request"),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\MediaType(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Response(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\JsonContent(ref="#/components/schemas/BaseModule_Post_SendEmail_Response"),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Response(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* response=401,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Method Not Allowed",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Schema(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Schema(
- Exclude checks
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"),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* type="boolean",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* mediaType="application/x-www-form-urlencoded",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Response(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* schema="BaseModule_Post_SendEmail_Response",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* tags={"BaseModule"},
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\RequestBody(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* response=405,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* mediaType="multipart/form-data",
- Exclude checks
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"),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* response=200,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\JsonContent(ref="#/components/schemas/BaseModule_Post_SendEmail_Response"),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Response(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Not Found",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* schema="BaseModule_Post_SendEmail_Request",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* title="Request body for SendEmail",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* schema="BaseModule_Post_SendEmail_Response",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* type="boolean",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* response=404,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* schema="BaseModule_Post_SendEmail_Request",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Specific ID of the email template",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* type="integer"
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* type="object",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* summary="Send e-mail",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* mediaType="multipart/form-data",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Schema(ref="#/components/schemas/BaseModule_Post_SendEmail_Request")
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Response(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="No permissions for module",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* property="e-mail",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="E-mail address (Token type field in the module is required)",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Property(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$moduleName = $this->controller->request->getModule();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* },
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Required data for communication",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* mediaType="application/x-www-form-urlencoded",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* type="object",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Property(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* example=true
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* tags={"BaseModule"},
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Schema(ref="#/components/schemas/BaseModule_Post_SendEmail_Request")
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Response(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Not Found",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Property(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* type="string"
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* property="templateId",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* property="result",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* {"basicAuth" : {}, "ApiKeyAuth" : {}, "token" : {}}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\RequestBody(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Schema(ref="#/components/schemas/BaseModule_Post_SendEmail_Request")
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\JsonContent(ref="#/components/schemas/BaseModule_Post_SendEmail_Request"),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\MediaType(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Schema(ref="#/components/schemas/BaseModule_Post_SendEmail_Request")
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* response=401,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="No permissions for module",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* property="result",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* title="Request body for SendEmail",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Property(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* property="templateId",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Added mail to quote for send: true - success , false - fail",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Required data for communication",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Added mail to quote for send: true - success , false - fail",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\MediaType(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Status of adding an email to the queue",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="`No sent token` OR `Invalid token`",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* type="object",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Property(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* required=true,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* required=true,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
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"),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* response=403,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* response=403,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Response(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* title="Response body for SendEmail",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* path="/webservice/ManageConsents/{moduleName}/SendEmail",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* summary="Send e-mail",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* security={
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\MediaType(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* response=404,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Response(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Method Not Allowed",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* example=true
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$templateId = $this->controller->request->getInteger('templateId');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* {"basicAuth" : {}, "ApiKeyAuth" : {}, "token" : {}}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Status of adding an email to the queue",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="`No sent token` OR `Invalid token`",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Response(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* type="string"
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* type="integer"
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* type="object",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* response=200,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Property(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* property="e-mail",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="E-mail address (Token type field in the module is required)",
- Exclude checks
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"),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @OA\Response(
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ),
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* response=405,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* description="Specific ID of the email template",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* title="Response body for SendEmail",
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public function post()
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return \App\Mailer::sendFromTemplate([
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'recordId' => $recordId,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$recordId = $queryGenerator->setFields(['id'])->createQuery()->scalar();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$email = $this->controller->request->getByType('e-mail', 'Email');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$recordId = '';
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'to' => $email,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
foreach ($emailFields as $fieldModel) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'moduleName' => $moduleName,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$queryGenerator = (new \App\QueryGenerator($moduleName));
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ($emailFields && $email) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
throw new \Api\Core\Exception('No permissions for email template: ' . $templateId, 403);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
]);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
'template' => $templateId,
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (!\App\Privilege::isPermitted('EmailTemplates', 'DetailView', $templateId)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$emailFields = $queryGenerator->getModuleModel()->getFieldsByType('email', true);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$queryGenerator->addCondition($fieldModel->getName(), $email, 'e', false);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (!$recordId) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
throw new \Api\Core\Exception('Not Found', 404);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* path="/webservice/ManageConsents/{moduleName}/SendEmail",
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $allowedMethod = ['POST'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
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"),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Send e-mail.
- Exclude checks
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"),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \Api\Core\Exception
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @OA\Post(
- Exclude checks