dadajuice/zephyrus

View on GitHub
src/Zephyrus/Security/CsrfGuard.php

Summary

Maintainability
B
6 hrs
Test Coverage
A
100%

CsrfGuard has 24 functions (exceeds 20 allowed). Consider refactoring.
Open

class CsrfGuard
{
    public const HEADER_TOKEN = 'HTTP_X_CSRF_TOKEN';
    public const REQUEST_TOKEN_VALUE = 'CSRFToken';
    public const TOKEN_LENGTH = 48;
Severity: Minor
Found in src/Zephyrus/Security/CsrfGuard.php - About 2 hrs to fix

    Consider simplifying this complex logical expression.
    Open

            if ($this->isGetSecured() && $method == "GET") {
                return true;
            } elseif ($this->isPostSecured() && $method == "POST") {
                return true;
            } elseif ($this->isPutSecured() && $method == "PUT") {
    Severity: Major
    Found in src/Zephyrus/Security/CsrfGuard.php - About 40 mins to fix

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

          public function injectForms(string $html): string
          {
              preg_match_all("/<form(.*?)>(.*?)<\\/form>/is", $html, $matches, PREG_SET_ORDER);
              if (is_array($matches)) {
                  foreach ($matches as $match) {
      Severity: Minor
      Found in src/Zephyrus/Security/CsrfGuard.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

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

          public function run(): void
          {
              if (!$this->isExempt()) {
                  $providedToken = $this->getProvidedCsrfToken();
                  if (is_null($providedToken)) {
      Severity: Minor
      Found in src/Zephyrus/Security/CsrfGuard.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

      Avoid too many return statements within this method.
      Open

                  return true;
      Severity: Major
      Found in src/Zephyrus/Security/CsrfGuard.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                return false;
        Severity: Major
        Found in src/Zephyrus/Security/CsrfGuard.php - About 30 mins to fix

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

              private function isExempt(): bool
              {
                  if (!$this->isHttpMethodFiltered($this->request->getMethod()->value)) {
                      return true;
                  }
          Severity: Minor
          Found in src/Zephyrus/Security/CsrfGuard.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

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

              private function isHttpMethodFiltered(string $method): bool
              {
                  if ($this->isGetSecured() && $method == "GET") {
                      return true;
                  } elseif ($this->isPostSecured() && $method == "POST") {
          Severity: Minor
          Found in src/Zephyrus/Security/CsrfGuard.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

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

              private function initializeGuardedMethods(): void
              {
                  if (isset($this->configurations['guard_methods'])) {
                      foreach ($this->configurations['guard_methods'] as $method) {
                          if (!in_array($method, ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])) {
          Severity: Minor
          Found in src/Zephyrus/Security/CsrfGuard.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

          There are no issues that match your filters.

          Category
          Status