rugk/xenforo-threema-gateway

View on GitHub
src/library/ThreemaGateway/Handler/Action/TfaCallback/Abstract.php

Summary

Maintainability
C
1 day
Test Coverage

The class ThreemaGateway_Handler_Action_TfaCallback_Abstract has an overall complexity of 56 which is very high. The configured complexity threshold is 50.
Open

abstract class ThreemaGateway_Handler_Action_TfaCallback_Abstract extends ThreemaGateway_Handler_Action_Abstract
{
    /**
     * @var array Cache of models
     */

File Abstract.php has 287 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * 2FA callback actions.
 *
 * @package ThreemaGateway
Severity: Minor
Found in src/library/ThreemaGateway/Handler/Action/TfaCallback/Abstract.php - About 2 hrs to fix

    ThreemaGateway_Handler_Action_TfaCallback_Abstract has 25 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class ThreemaGateway_Handler_Action_TfaCallback_Abstract extends ThreemaGateway_Handler_Action_Abstract
    {
        /**
         * @var array Cache of models
         */
    Severity: Minor
    Found in src/library/ThreemaGateway/Handler/Action/TfaCallback/Abstract.php - About 2 hrs to fix

      Method setDataForRequest has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function setDataForRequest(
              array $confirmRequest,
              array $setData,
              array $processOptions = []
          ) {
      Severity: Major
      Found in src/library/ThreemaGateway/Handler/Action/TfaCallback/Abstract.php - About 2 hrs to fix

        Function processPending has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            public function processPending(array $processOptions = [])
            {
                if (!$this->pendingRequests) {
                    $this->preProcessPending();
                }
        Severity: Minor
        Found in src/library/ThreemaGateway/Handler/Action/TfaCallback/Abstract.php - About 1 hr 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

        Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            public function __construct(ThreemaGateway_Handler_Action_Callback $handler,
                                        Threema\MsgApi\Helpers\ReceiveMessageResult $receiveResult,
                                        Threema\MsgApi\Messages\ThreemaMessage $threemaMsg,
                                        &$output,
                                        &$saveMessage,
        Severity: Minor
        Found in src/library/ThreemaGateway/Handler/Action/TfaCallback/Abstract.php - About 45 mins to fix

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

              protected function setDataForRequest(
                  array $confirmRequest,
                  array $setData,
                  array $processOptions = []
              ) {
          Severity: Minor
          Found in src/library/ThreemaGateway/Handler/Action/TfaCallback/Abstract.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 '546', column '23').
          Open

                      throw new XenForo_Exception('Could not get provider data from session using key ' . $sessionKey . '.');

          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 '496', column '23').
          Open

                      throw new Exception('preSaveData() returned an error and prevented data saving.');

          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 '568', column '23').
          Open

                      throw new XenForo_Exception('Could not get user 2FA data.');

          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 '575', column '23').
          Open

                      throw new XenForo_Exception('Could not get provider data. (error: ' . $e->getMessage() . ')');

          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

          The method addFilter has a boolean flag argument $failOnError, which is a certain sign of a Single Responsibility Principle violation.
          Open

              public function addFilter($filterType, $filterData, $failOnError = true)

          BooleanArgumentFlag

          Since: 1.4.0

          A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

          Example

          class Foo {
              public function bar($flag = true) {
              }
          }

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

          Missing class import via use statement (line '677', column '27').
          Open

                          throw new XenForo_Exception('Could not get user data data.');

          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 '579', column '23').
          Open

                      throw new XenForo_Exception('Could not get provider data.');

          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 '616', column '27').
          Open

                          throw new XenForo_Exception('Invalid provider data fetch method: ' . $this->dataFetchMode);

          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 '523', column '23').
          Open

                      throw new Exception('postSaveData() returned an 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 '170', column '27').
          Open

                          throw new XenForo_Exception('preProcessPending() could not get any pending request data.');

          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 '503', column '23').
          Open

                      throw new Exception('preSaveDataMerged() returned an error and prevented data saving.');

          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

          The method applyFilter has a boolean flag argument $failOnError, which is a certain sign of a Single Responsibility Principle violation.
          Open

              abstract protected function applyFilter($filterType, $filterData, $failOnError = true);

          BooleanArgumentFlag

          Since: 1.4.0

          A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

          Example

          class Foo {
              public function bar($flag = true) {
              }
          }

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

          Avoid using static access to class 'XenForo_Application' in method 'getSession'.
          Open

                      $class         = XenForo_Application::resolveDynamicClass('XenForo_Session');

          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 'XenForo_Model' in method 'getModelFromCache'.
          Open

                      $this->modelCache[$class] = XenForo_Model::create($class);

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

              protected function preProcessPending()
              {
                  // check whether message has already been saved to prevent replay attacks
                  $this->callback->assertNoReplayAttack($this->receiveResult->getMessageId());
          
          

          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 unused parameters such as '$confirmRequest'.
          Open

              protected function postSaveData(array $confirmRequest, array &$providerData, array $processOptions = [])

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Avoid unused parameters such as '$confirmRequest'.
          Open

              protected function preSaveDataMerged(array $confirmRequest, array &$providerData, array $processOptions = [])

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Avoid unused parameters such as '$processOptions'.
          Open

              protected function preSaveData(array $confirmRequest, array &$oldProviderData, array &$setData, array $processOptions = [])

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Avoid unused parameters such as '$setData'.
          Open

              protected function preSaveData(array $confirmRequest, array &$oldProviderData, array &$setData, array $processOptions = [])

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Avoid unused parameters such as '$oldProviderData'.
          Open

              protected function preSaveData(array $confirmRequest, array &$oldProviderData, array &$setData, array $processOptions = [])

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Avoid unused parameters such as '$processOptions'.
          Open

              protected function preSaveDataMerged(array $confirmRequest, array &$providerData, array $processOptions = [])

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Avoid unused parameters such as '$providerData'.
          Open

              protected function preSaveDataMerged(array $confirmRequest, array &$providerData, array $processOptions = [])

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Avoid unused parameters such as '$processOptions'.
          Open

              protected function postSaveData(array $confirmRequest, array &$providerData, array $processOptions = [])

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Avoid unused parameters such as '$providerData'.
          Open

              protected function postSaveData(array $confirmRequest, array &$providerData, array $processOptions = [])

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Avoid unused parameters such as '$confirmRequest'.
          Open

              protected function preSaveData(array $confirmRequest, array &$oldProviderData, array &$setData, array $processOptions = [])

          UnusedFormalParameter

          Since: 0.2

          Avoid passing parameters to methods or constructors and then not using those parameters.

          Example

          class Foo
          {
              private function bar($howdy)
              {
                  // $howdy is not used
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

          Avoid excessively long class names like ThreemaGateway_Handler_Action_TfaCallback_Abstract. Keep class name length under 40.
          Open

          abstract class ThreemaGateway_Handler_Action_TfaCallback_Abstract extends ThreemaGateway_Handler_Action_Abstract
          {
              /**
               * @var array Cache of models
               */

          LongClassName

          Since: 2.9

          Detects when classes or interfaces are declared with excessively long names.

          Example

          class ATooLongClassNameThatHintsAtADesignProblem {
          
          }
          
          interface ATooLongInterfaceNameThatHintsAtADesignProblem {
          
          }

          Source https://phpmd.org/rules/naming.html#longclassname

          There are no issues that match your filters.

          Category
          Status