YetiForceCompany/YetiForceCRM

View on GitHub
app/TextUtils.php

Summary

Maintainability
D
2 days
Test Coverage
A
90%

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

    public static function htmlTruncateByWords(string $html, int $length = 0, string $ending = '...'): string
    {
        if (!$length) {
            $length = Config::main('listview_max_textlength');
        }
Severity: Minor
Found in app/TextUtils.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

Function htmlTruncate has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    public static function htmlTruncate(string $html, int $length = 255, string $ending = '...'): string
    {
        if (\strlen($html) <= $length) {
            return $html;
        }
Severity: Minor
Found in app/TextUtils.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 htmlTruncateByWords has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function htmlTruncateByWords(string $html, int $length = 0, string $ending = '...'): string
    {
        if (!$length) {
            $length = Config::main('listview_max_textlength');
        }
Severity: Minor
Found in app/TextUtils.php - About 1 hr to fix

    Method htmlTruncate has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function htmlTruncate(string $html, int $length = 255, string $ending = '...'): string
        {
            if (\strlen($html) <= $length) {
                return $html;
            }
    Severity: Minor
    Found in app/TextUtils.php - About 1 hr to fix

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

          public static function textTruncate($text, $length = false, $addDots = true)
          {
              if (!$length) {
                  $length = Config::main('listview_max_textlength');
              }
      Severity: Minor
      Found in app/TextUtils.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

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

          public static function htmlTruncate(string $html, int $length = 255, string $ending = '...'): string
          {
              if (\strlen($html) <= $length) {
                  return $html;
              }
      Severity: Minor
      Found in app/TextUtils.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

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

          public static function htmlTruncateByWords(string $html, int $length = 0, string $ending = '...'): string
          {
              if (!$length) {
                  $length = Config::main('listview_max_textlength');
              }
      Severity: Minor
      Found in app/TextUtils.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

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

          public static function htmlTruncate(string $html, int $length = 255, string $ending = '...'): string
      Severity: Critical
      Found in app/TextUtils.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

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

          public static function htmlTruncateByWords(string $html, int $length = 0, string $ending = '...'): string
      Severity: Critical
      Found in app/TextUtils.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

      Missing class import via use statement (line '176', column '14').
      Open

              $dom = new \DOMDocument('1.0', 'UTF-8');
      Severity: Minor
      Found in app/TextUtils.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

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

          public static function textTruncate($text, $length = false, $addDots = true)
      Severity: Minor
      Found in app/TextUtils.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

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

          public static function textTruncate($text, $length = false, $addDots = true)
      Severity: Minor
      Found in app/TextUtils.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 using static access to class 'App\Config' in method 'htmlTruncateByWords'.
      Open

                  $length = Config::main('listview_max_textlength');
      Severity: Minor
      Found in app/TextUtils.php by phpmd

      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 'App\Config' in method 'textTruncate'.
      Open

                  $length = Config::main('listview_max_textlength');
      Severity: Minor
      Found in app/TextUtils.php by phpmd

      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 'App\Config' in method 'textTruncate'.
      Open

                  $text = mb_substr($text, 0, $length, Config::main('default_charset'));
      Severity: Minor
      Found in app/TextUtils.php by phpmd

      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

      Define a constant instead of duplicating this literal "/^<\s*([^\s>!]+).*?>$/s" 4 times.
      Open

                          preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName);
      Severity: Critical
      Found in app/TextUtils.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.

      Returning type ?string but textTruncate() is declared to return string
      Open

              return $text;
      Severity: Minor
      Found in app/TextUtils.php by phan

      Argument 1 (str) is ?string but \mb_substr() takes string
      Open

                  $text = mb_substr($text, 0, $length, Config::main('default_charset'));
      Severity: Minor
      Found in app/TextUtils.php by phan

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

                  if (!empty($tag[1])) {
                      if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
                          // if tag is a closing tag
                      } elseif (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $tag[1], $tagName)) {
                          $pos = array_search(strtolower($tagName[1]), $openTags);
      Severity: Major
      Found in app/TextUtils.php and 1 other location - About 5 hrs to fix
      app/TextUtils.php on lines 90..103

      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 190.

      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 (!empty($tag[1])) {
                      if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
                          // if tag is a closing tag
                      } elseif (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $tag[1], $tagName)) {
                          $pos = array_search(strtolower($tagName[1]), $openTags);
      Severity: Major
      Found in app/TextUtils.php and 1 other location - About 5 hrs to fix
      app/TextUtils.php on lines 143..156

      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 190.

      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

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

                  if (($totalLength + $tagLength + $openTagsLength) >= $length) {
                      if (empty($html)) {
                          preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName);
                          $openTags[] = $tagName[1];
                          $html = $tag[1] . self::textTruncate($tag[2], $length - 3, false);
      Severity: Minor
      Found in app/TextUtils.php and 1 other location - About 50 mins to fix
      app/TextUtils.php on lines 82..89

      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 97.

      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

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

                  if (($totalLength + $tagLength + $openTagsLength) >= $length) {
                      if (empty($html)) {
                          preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName);
                          $openTags[] = $tagName[1];
                          $html = $tag[1] . self::textTruncate($tag[2], $length - 3, false);
      Severity: Minor
      Found in app/TextUtils.php and 1 other location - About 50 mins to fix
      app/TextUtils.php on lines 135..142

      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 97.

      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

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if ($addDots) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Truncating HTML.
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string $html
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  return $html;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $html = $tag[1] . self::textTruncate($tag[2], $length - 3, false);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param bool|int $length
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $html .= $tag[0];
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $totalLength += $tagLength;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $html .= '</' . implode('></', $openTags) . '>';
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $openTagsLength = 0;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $textLength = mb_strlen($text);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $text .= '...';
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          // if tag is a closing tag
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          if (false !== $pos) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $openTagsLength += \mb_strlen("</{$tagName[1]}>");
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if ($openTags) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string   $text
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              foreach ($tags as $tag) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $html = $tag[1] . self::textTruncate($tag[2], $length - 3, false);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              unset($openTags[$pos]);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public static function htmlTruncate(string $html, int $length = 255, string $ending = '...'): string
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param bool     $addDots
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public static function getTextLength($text)
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Truncating text.
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return $text;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return string
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string $ending
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if ((!$addDots && $textLength > $length) || ($addDots && $textLength > $length + 2)) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param int    $length
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if (($totalLength + $tagLength + $openTagsLength) >= $length) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $tagLength = \mb_strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $tag[2]));
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $openTags[] = $tagName[1];
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $openTags[] = $tagName[1];
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      break;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param int    $length
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Truncating HTML by words.
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string $html
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (!$length) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $tagLength = \mb_strlen($tag[0]);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      if (empty($html)) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $openTags = [];
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public static function textTruncate($text, $length = false, $addDots = true)
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (!$length) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              preg_match_all('/(<.+?>)?([^<>]*)/s', $html, $tags, PREG_SET_ORDER);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $html .= $ending;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              preg_match_all('/(<.+?>)?([^<>]*)/s', $html, $tags, PREG_SET_ORDER);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      } elseif (preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName)) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          array_unshift($openTags, strtolower($tagName[1]));
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Get text length.
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $length = Config::main('listview_max_textlength');
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $totalLength = \mb_strlen($ending);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $html = '';
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $pos = array_search(strtolower($tagName[1]), $openTags);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return $html;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (\strlen($html) <= $length) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string $text
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $length = Config::main('listview_max_textlength');
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $openTagsLength = 0;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      if (empty($html)) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $textLength = 0;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  return $html;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $html = '';
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return null !== $text ? mb_strlen($text) : 0;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (null !== $text) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $text = mb_substr($text, 0, $length, Config::main('default_charset'));
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return string
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public static function htmlTruncateByWords(string $html, int $length = 0, string $ending = '...'): string
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if (\strlen(strip_tags($html)) <= $length) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      } elseif (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $tag[1], $tagName)) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if (!empty($tag[1])) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Line exceeds 120 characters; contains 149 characters
      Open

                      if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string $ending
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $totalLength = \mb_strlen($ending);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              foreach ($tags as $tag) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if (($totalLength + $tagLength + $openTagsLength) >= $length) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $html .= $tag[0];
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      } elseif (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $tag[1], $tagName)) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              unset($openTags[$pos]);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $html .= $ending;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @param string $tag
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              $openTagsLength -= \mb_strlen("</{$tagName[1]}>");
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          public static function getTagAttributes(string $tag): array
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          // if tag is a closing tag
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $openTagsLength += \mb_strlen("</{$tagName[1]}>");
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return int
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $openTags = [];
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                              $openTagsLength -= \mb_strlen("</{$tagName[1]}>");
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return string
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $dom = new \DOMDocument('1.0', 'UTF-8');
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if ($tag->hasAttributes()) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * @return string[]
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $attributes = [];
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Line exceeds 120 characters; contains 149 characters
      Open

                      if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $tag[1])) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $html .= '</' . implode('></', $openTags) . '>';
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          $pos = array_search(strtolower($tagName[1]), $openTags);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          array_unshift($openTags, strtolower($tagName[1]));
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              if ($openTags) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  foreach ($tag->attributes as $attr) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      $attributes[$attr->name] = $attr->value;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  if (!empty($tag[1])) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           *
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  $totalLength += $tagLength;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $tag = $dom->getElementsByTagName('*')->item(2);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              libxml_use_internal_errors($previousValue);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      break;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      } elseif (preg_match('/^<\s*([^\s>!]+).*?>$/s', $tag[1], $tagName)) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          /**
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                          if (false !== $pos) {
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                      }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

          }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           * Get all attributes of a tag.
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              libxml_clear_errors();
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

                  }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return $attributes;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              return $html;
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

           */
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $previousValue = libxml_use_internal_errors(true);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              $dom->loadHTML('<?xml encoding="utf-8"?>' . $tag);
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      Spaces must be used to indent lines; tabs are not allowed
      Open

              }
      Severity: Minor
      Found in app/TextUtils.php by phpcodesniffer

      There are no issues that match your filters.

      Category
      Status