gdbots/common-php

View on GitHub

Showing 137 of 137 total issues

Function create has a Cognitive Complexity of 272 (exceeds 5 allowed). Consider refactoring.
Open

    public static function create($string, $allowSlashes = false)
    {
        $slug = '';
        $string = html_entity_decode($string, ENT_QUOTES);

Severity: Minor
Found in src/Common/Util/SlugUtils.php - About 5 days 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 xmlEscape has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

    public static function xmlEscape($str)
    {
        // array used to figure what number to decrement from character order value
        // according to number of characters used to map unicode to ascii by utf-8
        $decrement = [];
Severity: Minor
Found in src/Common/Util/StringUtils.php - About 5 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

File URLUtils.php has 310 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Gdbots\Common\Util;

final class URLUtils
Severity: Minor
Found in src/Common/Util/URLUtils.php - About 3 hrs to fix

    The class SlugUtils has an overall complexity of 71 which is very high. The configured complexity threshold is 50.
    Open

    final class SlugUtils
    {
        const VALID_SLUG_PATTERN = '/^[a-z0-9-]+$/';
        const VALID_DATED_SLUG_PATTERN = '/^([a-z0-9-]|[a-z0-9-][a-z0-9-\/]*[a-z0-9-])$/';
    
    
    Severity: Minor
    Found in src/Common/Util/SlugUtils.php by phpmd

    The class StringUtils has 11 public methods. Consider refactoring StringUtils to keep number of public methods under 10.
    Open

    final class StringUtils
    {
        // todo: memoize inflectors and maybe move inflectors to own class
    
        /**
    Severity: Minor
    Found in src/Common/Util/StringUtils.php by phpmd

    TooManyPublicMethods

    Since: 0.1

    A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

    By default it ignores methods starting with 'get' or 'set'.

    Example

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

    Method xmlEscape has 79 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function xmlEscape($str)
        {
            // array used to figure what number to decrement from character order value
            // according to number of characters used to map unicode to ascii by utf-8
            $decrement = [];
    Severity: Major
    Found in src/Common/Util/StringUtils.php - About 3 hrs to fix

      Method create has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function create($string, $allowSlashes = false)
          {
              $slug = '';
              $string = html_entity_decode($string, ENT_QUOTES);
      
      
      Severity: Major
      Found in src/Common/Util/SlugUtils.php - About 3 hrs to fix

        Consider simplifying this complex logical expression.
        Open

                    } else if (($c >= 8219 && $c <= 8223) || $c == 8242 || $c == 8243 || $c == 8216 || $c == 8217 || $c == 168 || $c == 180 || $c == 729 || $c == 733) {
                        //all the strange curly single and double quotes
                        // Ignore them
                    } else if ($c == 188) {
                        $slug .= '-one-quarter-';
        Severity: Critical
        Found in src/Common/Util/SlugUtils.php - About 2 hrs to fix

          Avoid excessively long variable names like $crazyInsaneRegexThatSomehowDetectsIso8601. Keep variable name length under 20.
          Open

                  $crazyInsaneRegexThatSomehowDetectsIso8601 = '/^([\+-]?\d{4}(?!\d{2}\b))'
          Severity: Minor
          Found in src/Common/Util/DateUtils.php by phpmd

          LongVariable

          Since: 0.2

          Detects when a field, formal or local variable is declared with a long name.

          Example

          class Something {
              protected $reallyLongIntName = -3; // VIOLATION - Field
              public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                  $otherReallyLongName = -5; // VIOLATION - Local
                  for ($interestingIntIndex = 0; // VIOLATION - For
                       $interestingIntIndex < 10;
                       $interestingIntIndex++ ) {
                  }
              }
          }

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

          Method create has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function create($str, $camelize = true)
              {
                  // remove special chars (accents, etc.)
                  $str = trim(self::normalize($str));
                  $str = ltrim($str, '#_ ');
          Severity: Minor
          Found in src/Common/Util/HashtagUtils.php - About 1 hr to fix

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

                    $m = new self();
            Severity: Minor
            Found in src/Common/Microtime.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

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

                        $a = [];
            Severity: Minor
            Found in src/Common/Util/StringUtils.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

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

                    while (preg_match('/^\d{4}\/\d{2}\/\d{2}\/?(\S+)?/', $slug, $m)) {
            Severity: Minor
            Found in src/Common/Util/SlugUtils.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

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

                    $m = new self();
            Severity: Minor
            Found in src/Common/Microtime.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

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

                    $b = 'AAAAAAACEEEEIIIIDNOOOOOOOUUUUUYbsaaaaaaaceeeeiiiidnooooooouuuuuyybyRr';
            Severity: Minor
            Found in src/Common/Util/HashtagUtils.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

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

                        $c = ord(substr($string, $i, 1));
            Severity: Minor
            Found in src/Common/Util/SlugUtils.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

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

                    $m = new self();
            Severity: Minor
            Found in src/Common/Microtime.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

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

                    $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖŐØÙÚÛÜŰÝÞßàáâãäåæçèéêëìíîïðñòóôõöőøùúûűüýýþÿŔŕ';
            Severity: Minor
            Found in src/Common/Util/HashtagUtils.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

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

                    $m = new self();
            Severity: Minor
            Found in src/Common/Microtime.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

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

                        $c = $decimalCode;
            Severity: Minor
            Found in src/Common/Util/StringUtils.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

            Severity
            Category
            Status
            Source
            Language