YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Companies/actions/VerifyEmail.php

Summary

Maintainability
A
3 hrs
Test Coverage

Method confirm has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function confirm(App\Request $request): void
    {
        $result = false;
        $responseType = 'error';
        $message = \App\Language::translate('LBL_INVALID_VERIFICATION_CODE', $request->getModule(false));
Severity: Minor
Found in modules/Settings/Companies/actions/VerifyEmail.php - About 1 hr to fix

    Method request has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function request(App\Request $request): void
        {
            $result = false;
            $responseType = 'error';
            $message = '';
    Severity: Minor
    Found in modules/Settings/Companies/actions/VerifyEmail.php - About 1 hr to fix

      Function request has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function request(App\Request $request): void
          {
              $result = false;
              $responseType = 'error';
              $message = '';
      Severity: Minor
      Found in modules/Settings/Companies/actions/VerifyEmail.php - About 35 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 '106', column '19').
      Open

              $response = new \Vtiger_Response();

      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 '58', column '19').
      Open

              $response = new Vtiger_Response();

      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 '49', column '16').
      Open

                          throw new \App\Exceptions\AppException($error);

      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 '80', column '15').
      Open

                      throw new \App\Exceptions\AppException(\App\Language::translate('LBL_TERMS_AGREEMENT_REQUIRED', $request->getModule(false), null, false));

      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 '99', column '15').
      Open

                      throw new \App\Exceptions\AppException($error);

      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 '48', column '9').
      Open

          public function request(App\Request $request): void
          {
              $result = false;
              $responseType = 'error';
              $message = '';

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

                  $message = \App\Language::translate('LBL_TERMS_AGREEMENT_REQUIRED', $request->getModule(false));

      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 'confirm'.
      Open

                      $message = \App\Language::translate('LBL_EMAIL_VERIFIED', $request->getModule(false));

      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 'confirm'.
      Open

              $message = \App\Language::translate('LBL_INVALID_VERIFICATION_CODE', $request->getModule(false));

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

              } else {
                  try {
                      $email = $request->getByType('email', \App\Purifier::EMAIL);
                      $registration = (new EmailVerification());
                      $result = $registration->setEmail($email)->setType(EmailVerification::PROCESS_INIT)->send();

      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

      Avoid using static access to class 'App\Process' in method 'confirm'.
      Open

                      App\Process::removeEvent(Settings_Companies_EmailVerificationModal_View::MODAL_EVENT['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 assigning values to variables in if clauses and the like (line '98', column '14').
      Open

          public function confirm(App\Request $request): void
          {
              $result = false;
              $responseType = 'error';
              $message = \App\Language::translate('LBL_INVALID_VERIFICATION_CODE', $request->getModule(false));

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

                      throw new \App\Exceptions\AppException(\App\Language::translate('LBL_TERMS_AGREEMENT_REQUIRED', $request->getModule(false), null, false));

      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 "error" 3 times.
      Open

              $responseType = 'error';

      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.

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

              if ($request->has('terms_agreement') && !$request->getBoolean('terms_agreement')) {

      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.

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

                  'success' => $result,

      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.

      @throws type of request has undeclared type \yii\db\Exception (Did you mean class \Exception)
      Open

          public function request(App\Request $request): void

      Call to method setEmail from undeclared class \App\YetiForce\EmailVerification
      Open

                      $result = $registration->setEmail($email)->setType(EmailVerification::PROCESS_INIT)->send();

      Call to method setEmail from undeclared class \App\YetiForce\EmailVerification
      Open

                  $result = $registration->setEmail($email)

      Call to method postProcess from undeclared class \App\YetiForce\EmailVerification
      Open

                      $registration->postProcess();

      Call to method __construct from undeclared class \App\YetiForce\EmailVerification
      Open

                      $registration = (new EmailVerification());

      Call to method __construct from undeclared class \App\YetiForce\EmailVerification
      Open

                  $registration = (new EmailVerification());

      Call to method getError from undeclared class \App\YetiForce\EmailVerification
      Open

                  } elseif ($error = $registration->getError()) {

      Reference to constant PROCESS_INIT from undeclared class \App\YetiForce\EmailVerification
      Open

                      $result = $registration->setEmail($email)->setType(EmailVerification::PROCESS_INIT)->send();

      Reference to constant MODAL_EVENT from undeclared class \Settings_Companies_EmailVerificationModal_View
      Open

                      App\Process::removeEvent(Settings_Companies_EmailVerificationModal_View::MODAL_EVENT['name']);

      Call to method getError from undeclared class \App\YetiForce\EmailVerification
      Open

                      if ($error = $registration->getError()) {

      Reference to constant PROCESS_REGISTER from undeclared class \App\YetiForce\EmailVerification
      Open

                      ->setType(EmailVerification::PROCESS_REGISTER)

      Each class must be in a namespace of at least one level (a top-level vendor name)
      Open

      class Settings_Companies_VerifyEmail_Action extends Settings_Vtiger_Basic_Action

      The class Settings_Companies_VerifyEmail_Action is not named in CamelCase.
      Open

      class Settings_Companies_VerifyEmail_Action extends Settings_Vtiger_Basic_Action
      {
          /** {@inheritdoc} */
          public function __construct()
          {

      CamelCaseClassName

      Since: 0.2

      It is considered best practice to use the CamelCase notation to name classes.

      Example

      class class_name {
      }

      Source

      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

              $result = false;

      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

          {

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

              $responseType = 'error';

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

                  $registration = (new EmailVerification());

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

                  $result = false;

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

          public function __construct()

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

          {

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

                  $result = $registration->setEmail($email)

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

                      ->send();

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

                      App\Process::removeEvent(Settings_Companies_EmailVerificationModal_View::MODAL_EVENT['name']);

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

                  $message = $e->getDisplayMessage();

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

                  if ($request->has('terms_agreement') && !$request->getBoolean('terms_agreement')) {

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

                  $message = \App\Language::translate('LBL_TERMS_AGREEMENT_REQUIRED', $request->getModule(false));

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

                          throw new \App\Exceptions\AppException($error);

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

                      $result = false;

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

              } catch (\App\Exceptions\AppException $e) {

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

                  'message' => $message,

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

              parent::__construct();

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

                      $result = $registration->setEmail($email)->setType(EmailVerification::PROCESS_INIT)->send();

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

                  'success' => $result,

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

                  'type' => $responseType

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

           * @param \App\Request $request

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

              $result = false;

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

                      ->setType(EmailVerification::PROCESS_REGISTER)

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

                      $registration->postProcess();

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

              $this->exposeMethod('confirm');

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

          public function request(App\Request $request): void

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

                      $registration = (new EmailVerification());

      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

              try {

      Line exceeds 120 characters; contains 154 characters
      Open

                      throw new \App\Exceptions\AppException(\App\Language::translate('LBL_TERMS_AGREEMENT_REQUIRED', $request->getModule(false), null, false));

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

                  if ($result) {

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

                      $message = \App\Language::translate('LBL_EMAIL_VERIFIED', $request->getModule(false));

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

                      throw new \App\Exceptions\AppException($error);

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

                      $email = $request->getByType('email', \App\Purifier::EMAIL);

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

          /**

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

                  $code = $request->getByType('code', \App\Purifier::TEXT);

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

                      ->setCode($code)

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

              $response->emit();

      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 function confirm(App\Request $request): void

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

                      ->setNewsletter($newsletterAgreement)

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

                      $message = $e->getDisplayMessage();

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

              $response->setResult([

      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

              ]);

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

              $message = \App\Language::translate('LBL_INVALID_VERIFICATION_CODE', $request->getModule(false));

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

                  $email = $request->getByType('email', \App\Purifier::EMAIL);

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

              $this->exposeMethod('request');

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

           * @param \App\Request $request

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

              $response = new Vtiger_Response();

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

                  }

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

              $response->setResult([

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

                  'success' => $result,

      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 email with a verification code to the given email address.

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

              } else {

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

              $responseType = '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

                  } catch (\App\Exceptions\AppException $e) {

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

           * Register an email address.

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

              $response->emit();

      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

                      $responseType = 'success';

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

                  'type' => $responseType

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

          }

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

                  } elseif ($error = $registration->getError()) {

      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

                  try {

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

                      $responseType = 'error';

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

                  $newsletterAgreement = $request->getBoolean('newsletter_agreement');

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

              $response = new \Vtiger_Response();

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

          /**

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

           * @throws \yii\db\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

              $message = '';

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

              if ($request->has('terms_agreement') && !$request->getBoolean('terms_agreement')) {

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

                      if ($error = $registration->getError()) {

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

                  'message' => $message,

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

                      throw new \App\Exceptions\AppException(\App\Language::translate('LBL_TERMS_AGREEMENT_REQUIRED', $request->getModule(false), null, false));

      Class name "Settings_Companies_VerifyEmail_Action" is not in camel caps format
      Open

      class Settings_Companies_VerifyEmail_Action extends Settings_Vtiger_Basic_Action

      There are no issues that match your filters.

      Category
      Status