gdbots/common-php

View on GitHub

Showing 137 of 137 total issues

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

    public static function create($str, $camelize = true)
Severity: Minor
Found in src/Common/Util/HashtagUtils.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

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

            throw new \InvalidArgumentException(

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

Avoid using static access to class '\Gdbots\Common\Util\StringUtils' in method '__construct'.
Open

                sprintf('String expected but got [%s].', StringUtils::varToString($slug))

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 uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $slug = preg_replace("/[^a-zA-Z0-9\-\/]+/i", '-', $slug);
        }
Severity: Minor
Found in src/Common/Util/SlugUtils.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 empty try-catch blocks in testWrongValue.
Open

        } catch (\Exception $e) {
        }
Severity: Minor
Found in tests/Common/EnumTest.php by phpmd

EmptyCatchBlock

Since: 2.7.0

Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution. Occasionally this may be the right thing to do, but often it's a sign that a developer saw an exception, didn't know what to do about it, and so used an empty catch to silence the problem.

Example

class Foo {

  public function bar()
  {
      try {
          // ...
      } catch (Exception $e) {} // empty catch block
  }
}

Source https://phpmd.org/rules/design.html#emptycatchblock

Avoid using static access to class '\Gdbots\Common\Util\DateUtils' in method 'testIsValidISO8601Date'.
Open

        $this->assertFalse(DateUtils::isValidISO8601Date('cats'));
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 xmlEscape() has 102 lines of code. Current threshold is set to 100. Avoid really long methods.
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

Avoid using static access to class '\Ramsey\Uuid\Uuid' in method 'generate'.
Open

        return new static(Uuid::uuid1());

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 '\Gdbots\Common\Util\DateUtils' in method 'testIsValidISO8601Date'.
Open

        $this->assertFalse(DateUtils::isValidISO8601Date('-1 day'));
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

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

        $enum2 = 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 '\Gdbots\Common\Util\DateUtils' in method 'testIsValidISO8601Date'.
Open

        $this->assertTrue(DateUtils::isValidISO8601Date('2012-12-14T20:24:01.123456+00:00'));
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 an NPath complexity of 460. The configured NPath complexity threshold is 200.
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

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

Avoid using static access to class '\Gdbots\Common\Util\DateUtils' in method 'testIsValidISO8601Date'.
Open

        $this->assertTrue(DateUtils::isValidISO8601Date('2012-12-14T20:24:01Z'));
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

Avoid using static access to class '\DateTime' in method 'toDateTime'.
Open

        return \DateTime::createFromFormat('U.u', $this->sec . '.' . str_pad($this->usec, 6, '0', STR_PAD_LEFT));
Severity: Minor
Found in src/Common/Microtime.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 '\Gdbots\Common\Util\StringUtils' in method '__construct'.
Open

                sprintf('String expected but got [%s].', StringUtils::varToString($string))
Severity: Minor
Found in src/Identifiers/StringIdentifier.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 '\Gdbots\Common\Util\DateUtils' in method 'testIsValidISO8601Date'.
Open

        $this->assertTrue(DateUtils::isValidISO8601Date('2012-12-14T20:24:01+00:00'));
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 xmlEscape uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                // 1 char (lower ascii)
                $thisLetter = substr($str, $pos, 1);
                $pos += 1;
            }
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\Common\Util\DateUtils' in method 'testIsValidISO8601Date'.
Open

        $this->assertFalse(DateUtils::isValidISO8601Date('2012-12-14T20:24:01.123456+00:00AA'));
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

Avoid using static access to class '\DateTime' in method 'testISO8601WithMicroseconds'.
Open

        $date = \DateTime::createFromFormat(DateUtils::ISO8601, $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

Avoid using static access to class '\Gdbots\Common\Util\StringUtils' in method '__construct'.
Open

                sprintf('String expected but got [%s].', StringUtils::varToString($slug))
Severity: Minor
Found in src/Identifiers/SlugIdentifier.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

Severity
Category
Status
Source
Language