PrivateBin/PrivateBin

View on GitHub
lib/FormatV2.php

Summary

Maintainability
C
7 hrs
Test Coverage

Avoid too many return statements within this method.
Open

            return false;
Severity: Major
Found in lib/FormatV2.php - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

                return false;
    Severity: Major
    Found in lib/FormatV2.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                  return false;
      Severity: Major
      Found in lib/FormatV2.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                return true;
        Severity: Major
        Found in lib/FormatV2.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                      return false;
          Severity: Major
          Found in lib/FormatV2.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return false;
            Severity: Major
            Found in lib/FormatV2.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return false;
              Severity: Major
              Found in lib/FormatV2.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return false;
                Severity: Major
                Found in lib/FormatV2.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return false;
                  Severity: Major
                  Found in lib/FormatV2.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return false;
                    Severity: Major
                    Found in lib/FormatV2.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return false;
                      Severity: Major
                      Found in lib/FormatV2.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return false;
                        Severity: Major
                        Found in lib/FormatV2.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return false;
                          Severity: Major
                          Found in lib/FormatV2.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return false;
                            Severity: Major
                            Found in lib/FormatV2.php - About 30 mins to fix

                              The method isValid() has an NPath complexity of 5898240. The configured NPath complexity threshold is 200.
                              Open

                                  public static function isValid($message, $isComment = false)
                                  {
                                      $required_keys = array('adata', 'v', 'ct');
                                      if ($isComment) {
                                          $required_keys[] = 'pasteid';
                              Severity: Minor
                              Found in lib/FormatV2.php by phpmd

                              NPathComplexity

                              Since: 0.1

                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                              Example

                              class Foo {
                                  function bar() {
                                      // lots of complicated code
                                  }
                              }

                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                              The method isValid() has a Cyclomatic Complexity of 27. The configured cyclomatic complexity threshold is 10.
                              Open

                                  public static function isValid($message, $isComment = false)
                                  {
                                      $required_keys = array('adata', 'v', 'ct');
                                      if ($isComment) {
                                          $required_keys[] = 'pasteid';
                              Severity: Minor
                              Found in lib/FormatV2.php by phpmd

                              CyclomaticComplexity

                              Since: 0.1

                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                              Example

                              // Cyclomatic Complexity = 11
                              class Foo {
                              1   public function example() {
                              2       if ($a == $b) {
                              3           if ($a1 == $b1) {
                                              fiddle();
                              4           } elseif ($a2 == $b2) {
                                              fiddle();
                                          } else {
                                              fiddle();
                                          }
                              5       } elseif ($c == $d) {
                              6           while ($c == $d) {
                                              fiddle();
                                          }
                              7        } elseif ($e == $f) {
                              8           for ($n = 0; $n < $h; $n++) {
                                              fiddle();
                                          }
                                      } else {
                                          switch ($z) {
                              9               case 1:
                                                  fiddle();
                                                  break;
                              10              case 2:
                                                  fiddle();
                                                  break;
                              11              case 3:
                                                  fiddle();
                                                  break;
                                              default:
                                                  fiddle();
                                                  break;
                                          }
                                      }
                                  }
                              }

                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                              Reduce the number of returns of this function 18, down to the maximum allowed 3.
                              Open

                                  public static function isValid($message, $isComment = false)
                              Severity: Major
                              Found in lib/FormatV2.php by sonar-php

                              Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

                              Noncompliant Code Example

                              With the default threshold of 3:

                              function myFunction(){ // Noncompliant as there are 4 return statements
                                if (condition1) {
                                  return true;
                                } else {
                                  if (condition2) {
                                    return false;
                                  } else {
                                    return true;
                                  }
                                }
                                return false;
                              }
                              

                              Refactor this function to reduce its Cognitive Complexity from 27 to the 15 allowed.
                              Open

                                  public static function isValid($message, $isComment = false)
                              Severity: Critical
                              Found in lib/FormatV2.php by sonar-php

                              Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

                              See

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

                                  public static function isValid($message, $isComment = false)
                              Severity: Minor
                              Found in lib/FormatV2.php by phpmd

                              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 assigning values to variables in if clauses and the like (line '72', column '15').
                              Open

                                  public static function isValid($message, $isComment = false)
                                  {
                                      $required_keys = array('adata', 'v', 'ct');
                                      if ($isComment) {
                                          $required_keys[] = 'pasteid';
                              Severity: Minor
                              Found in lib/FormatV2.php by phpmd

                              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

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

                                      $required_keys = array('adata', 'v', 'ct');
                              Severity: Critical
                              Found in lib/FormatV2.php by sonar-php

                              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.

                              Avoid variables with short names like $ct. Configured minimum length is 3.
                              Open

                                      if (!($ct = base64_decode($message['ct'], true))) {
                              Severity: Minor
                              Found in lib/FormatV2.php by phpmd

                              ShortVariable

                              Since: 0.2

                              Detects when a field, local, or parameter has a very short name.

                              Example

                              class Something {
                                  private $q = 15; // VIOLATION - Field
                                  public static function main( array $as ) { // VIOLATION - Formal
                                      $r = 20 + $this->q; // VIOLATION - Local
                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                          $r += $this->q;
                                      }
                                  }
                              }

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

                              There are no issues that match your filters.

                              Category
                              Status