jidaikobo-shibata/a11yc

View on GitHub
classes/Element.php

Summary

Maintainability
C
1 day
Test Coverage

Function explodeStrings has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

    public static function explodeStrings($str)
    {
        $attrs = array();
        foreach (explode(' ', $str) as $k => $v)
        {
Severity: Minor
Found in classes/Element.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

Function prepareStrings has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    public static function prepareStrings($str)
    {
        // escaped quote
        $str = str_replace(
            array("\\'", '\\"'),
Severity: Minor
Found in classes/Element.php - About 2 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

Method prepareStrings has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function prepareStrings($str)
    {
        // escaped quote
        $str = str_replace(
            array("\\'", '\\"'),
Severity: Major
Found in classes/Element.php - About 2 hrs to fix

    Method explodeStrings has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function explodeStrings($str)
        {
            $attrs = array();
            foreach (explode(' ', $str) as $k => $v)
            {
    Severity: Minor
    Found in classes/Element.php - About 1 hr to fix

      The class Element has 16 fields. Consider redesigning Element to keep the number of fields under 15.
      Open

      class Element
      {
          public static $ignores = array(
              "/\<script.+?\<\/script\>/si",
              "/\<style.+?\<\/style\>/si",
      Severity: Minor
      Found in classes/Element.php by phpmd

      TooManyFields

      Since: 0.1

      Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

      Example

      class Person {
         protected $one;
         private $two;
         private $three;
         [... many more fields ...]
      }

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

      Method recoverStr has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function recoverStr($val)
          {
              return str_replace(
                  array(
                      self::$quoted_double,
      Severity: Minor
      Found in classes/Element.php - About 1 hr to fix

        Function isIgnorable has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function isIgnorable($str)
            {
                $attrs = Element\Get::attributes($str);
        
                // Strictly this is not so correct. but it seems be considered.
        Severity: Minor
        Found in classes/Element.php - About 45 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 false;
        Severity: Major
        Found in classes/Element.php - About 30 mins to fix

          Avoid assigning values to variables in if clauses and the like (line '179', column '8').
          Open

              public static function prepareStrings($str)
              {
                  // escaped quote
                  $str = str_replace(
                      array("\\'", '\\"'),
          Severity: Minor
          Found in classes/Element.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

          Avoid assigning values to variables in if clauses and the like (line '86', column '34').
          Open

              public static function isIgnorable($str)
              {
                  $attrs = Element\Get::attributes($str);
          
                  // Strictly this is not so correct. but it seems be considered.
          Severity: Minor
          Found in classes/Element.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

          Avoid assigning values to variables in if clauses and the like (line '87', column '37').
          Open

              public static function isIgnorable($str)
              {
                  $attrs = Element\Get::attributes($str);
          
                  // Strictly this is not so correct. but it seems be considered.
          Severity: Minor
          Found in classes/Element.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

          TODO found
          Open

                      // exclude JavaScript TODO
          Severity: Minor
          Found in classes/Element.php by fixme

          There are no issues that match your filters.

          Category
          Status