shieldfy/normalizer

View on GitHub

Showing 18 of 18 total issues

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

    public function run()
    {
        $matches = [];

        // check if value matches typical charCode pattern
Severity: Minor
Found in src/Normalizers/NormalizeJSCharcode.php - About 3 hrs 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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        if (preg_match_all('/(?:(?:[\\\]+\w+\s*){8,})/ims', $this->value, $matches)) {
            $converted = '';
            $charcode  = explode('\\', preg_replace('/[ux]/', '', implode(',', $matches[0])));

            foreach (array_map('hexdec', array_filter($charcode)) as $char) {
Severity: Major
Found in src/Normalizers/NormalizeJSCharcode.php and 1 other location - About 2 hrs to fix
src/Normalizers/NormalizeJSCharcode.php on lines 73..83

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 138.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        if (preg_match_all('/(?:(?:[\\\]+\d+[ \t]*){8,})/ims', $this->value, $matches)) {
            $converted = '';
            $charcode  = explode('\\', preg_replace('/\s/', '', implode(',', $matches[0])));

            foreach (array_map('octdec', array_filter($charcode)) as $char) {
Severity: Major
Found in src/Normalizers/NormalizeJSCharcode.php and 1 other location - About 2 hrs to fix
src/Normalizers/NormalizeJSCharcode.php on lines 86..96

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 138.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method run has 58 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function run()
    {

        // critical ctrl values
        $search = [
Severity: Major
Found in src/Normalizers/NormalizeControlChars.php - About 2 hrs to fix

    Method run has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function run()
        {
            $matches = [];
    
            // check if value matches typical charCode pattern
    Severity: Minor
    Found in src/Normalizers/NormalizeJSCharcode.php - About 1 hr to fix

      Method run has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function run()
          {
              if (! $this->runPreSearch()) {
                  return $this->value;
              }
      Severity: Minor
      Found in src/Normalizers/NormalizeUTF7.php - About 1 hr to fix

        Method run has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function run()
            {
                //normalize remaining backslashes
                if ($this->value != preg_replace('/(\w)\\\/', '$1', $this->value)) {
                    $this->value .= preg_replace('/(\w)\\\/', '$1', $this->value);
        Severity: Minor
        Found in src/Normalizers/NormalizeConcatenated.php - About 1 hr to fix

          Method run has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function run()
              {
                  if (! $this->runPreSearch()) {
                      return $this->value;
                  }
          Severity: Minor
          Found in src/Normalizers/NormalizeSerialize.php - About 1 hr to fix

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

                public function run()
                {
                    if (! $this->runPreSearch()) {
                        return $this->value;
                    }
            Severity: Minor
            Found in src/Normalizers/NormalizeSQLHex.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

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

                public function run()
                {
                    if (! $this->runPreSearch()) {
                        return $this->value;
                    }
            Severity: Minor
            Found in src/Normalizers/NormalizeSerialize.php - About 55 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 $this->value;
            Severity: Major
            Found in src/Normalizers/NormalizeSerialize.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return $this->value;
              Severity: Major
              Found in src/Normalizers/NormalizeSerialize.php - About 30 mins to fix

                Missing class import via use statement (line '66', column '23').
                Open

                            throw new \Exception('Normalizer Not found use one of supported normalizers ( '.implode(' , ', array_keys($this->normalizers)).' )');
                Severity: Minor
                Found in src/Normalizer.php by phpmd

                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

                Remove error control operator '@' on line 65.
                Open

                    public function run()
                    {
                        if (! $this->runPreSearch()) {
                            return $this->value;
                        }

                ErrorControlOperator

                Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

                Example

                function foo($filePath) {
                    $file = @fopen($filPath); // hides exceptions
                    $key = @$array[$notExistingKey]; // assigns null to $key
                }

                Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

                Avoid too many return statements within this method.
                Open

                        return $decoded;
                Severity: Major
                Found in src/Normalizers/NormalizeSerialize.php - About 30 mins to fix

                  The method run() has an NPath complexity of 256. The configured NPath complexity threshold is 200.
                  Open

                      public function run()
                      {
                          if (! $this->runPreSearch()) {
                              return $this->value;
                          }

                  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 run() has an NPath complexity of 225. The configured NPath complexity threshold is 200.
                  Open

                      public function run()
                      {
                          $matches = [];
                  
                          // check if value matches typical charCode pattern

                  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 run() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10.
                  Open

                      public function run()
                      {
                          $matches = [];
                  
                          // check if value matches typical charCode pattern

                  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

                  Severity
                  Category
                  Status
                  Source
                  Language