gdbots/common-php

View on GitHub

Showing 137 of 137 total issues

The method xmlEscape uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $xml .= $encodedLetter;
            }
Severity: Minor
Found in src/Common/Util/StringUtils.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

Source https://phpmd.org/rules/cleancode.html#elseexpression

Avoid using static access to class 'Gdbots\Tests\Common\TestEnum' in method 'testEquals'.
Open

        $enum1 = TestEnum::CONST1();
Severity: Minor
Found in tests/Common/EnumTest.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 '\DateTime' in method 'testUtcZuluWithMicroseconds'.
Open

        $date = \DateTime::createFromFormat(DateUtils::ISO8601_ZULU, $expected);
Severity: Minor
Found in tests/Common/Util/DateUtilsTest.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

The method create() has a Cyclomatic Complexity of 61. The configured cyclomatic complexity threshold is 10.
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 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 xmlEscape() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10.
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 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

Line exceeds 120 characters; contains 160 characters
Open

            } else if (($c >= 8219 && $c <= 8223) || $c == 8242 || $c == 8243 || $c == 8216 || $c == 8217 || $c == 168 || $c == 180 || $c == 729 || $c == 733) {

Line exceeds 120 characters; contains 176 characters
Open

        @trigger_error(sprintf('"%s" is deprecated.  Use "Gdbots\Pbj\WellKnown\[Time]UuidIdentifier" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);

Line exceeds 120 characters; contains 164 characters
Open

        @trigger_error(sprintf('"%s" is deprecated.  Use "Gdbots\Pbj\WellKnown\GeoPoint" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);
Severity: Minor
Found in src/Common/GeoPoint.php by phpcodesniffer

Inline control structures are not allowed
Open

        if (!preg_match("/^(https?):\/\//", $url))
Severity: Minor
Found in src/Common/Util/URLUtils.php by phpcodesniffer

Line exceeds 120 characters; contains 165 characters
Open

        @trigger_error(sprintf('"%s" is deprecated.  Use "Gdbots\Pbj\WellKnown\Microtime" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);
Severity: Minor
Found in src/Common/Microtime.php by phpcodesniffer

Line exceeds 120 characters; contains 170 characters
Open

        @trigger_error(sprintf('"%s" is deprecated.  Use "Gdbots\Pbj\WellKnown\SlugIdentifier" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);

Line exceeds 120 characters; contains 165 characters
Open

        @trigger_error(sprintf('"%s" is deprecated.  Use "Gdbots\Pbj\WellKnown\BigNumber" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);
Severity: Minor
Found in src/Common/BigNumber.php by phpcodesniffer

Line exceeds 120 characters; contains 154 characters
Open

        $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖŐØÙÚÛÜŰÝÞßàáâãäåæçèéêëìíîïðñòóôõöőøùúûűüýýþÿŔŕ';

Line exceeds 120 characters; contains 175 characters
Open

        @trigger_error(sprintf('"%s" is deprecated.  Use "Gdbots\Pbj\WellKnown\DatedSlugIdentifier" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);

Line exceeds 120 characters; contains 172 characters
Open

        @trigger_error(sprintf('"%s" is deprecated.  Use "Gdbots\Pbj\WellKnown\StringIdentifier" from "gdbots/pbj" 1.1.x or later instead.', __CLASS__), E_USER_DEPRECATED);

Usage of ELSE IF is discouraged; use ELSEIF instead
Open

            } else if ($c == 199 || $c == 231 || $c == 162) {

Usage of ELSE IF is discouraged; use ELSEIF instead
Open

            } else if ($c == 253 || $c == 255 || $c == 221 || $c == 376) {

Usage of ELSE IF is discouraged; use ELSEIF instead
Open

            } else if ($c == 188) {

Usage of ELSE IF is discouraged; use ELSEIF instead
Open

            } else if (($c >= 249 && $c <= 252) || ($c >= 217 && $c <= 220)) {

Usage of ELSE IF is discouraged; use ELSEIF instead
Open

            } else if (($c >= 236 && $c <= 239) || ($c >= 204 && $c <= 207)) {
Severity
Category
Status
Source
Language