keboola/php-utils

View on GitHub

Showing 61 of 61 total issues

Missing class import via use statement (line '21', column '17').
Open

            new \DateTimeZone($timezone)

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 jsonDecode has a boolean flag argument $logJson, which is a certain sign of a Single Responsibility Principle violation.
Open

function jsonDecode($json, $assoc = false, $depth = 512, $options = 0, $logJson = false, $lint = false)
Severity: Minor
Found in src/Keboola/Utils/jsonDecode.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 getDataFromPath has a boolean flag argument $ignoreEmpty, which is a certain sign of a Single Responsibility Principle violation.
Open

function getDataFromPath($path, $data, $separator = "/", $ignoreEmpty = true)
Severity: Minor
Found in src/Keboola/Utils/getDataFromPath.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 '\Keboola\Utils\Sanitizer\ColumnNameSanitizer' in method 'sanitizeColumnName'.
Open

    return ColumnNameSanitizer::sanitize($s, $charlist, $lower);

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

            } else {
                if ($ignoreEmpty == true) { // return if empty and ignore == true
                    $data = null;
                    break;
                } else {
Severity: Minor
Found in src/Keboola/Utils/getDataFromPath.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 '\Keboola\Utils\Sanitizer\ColumnNameSanitizer' in method 'toAscii'.
Open

    return ColumnNameSanitizer::toAscii($s);
Severity: Minor
Found in src/Keboola/Utils/toAscii.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 function httpBuildUrl() has an NPath complexity of 208. The configured NPath complexity threshold is 200.
Open

function httpBuildUrl(array $parse_url)
{
    // Skip if the URL is relative
    if (!empty($parse_url["scheme"]) && !empty($parse_url["host"])) {
        // scheme - e.g. http
Severity: Minor
Found in src/Keboola/Utils/httpBuildUrl.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 '\DateTime' in method 'isValidDateTimeString'.
Open

}

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 'isValidDateTimeString'.
Open

        $date = \DateTime::createFromFormat(
            $dateFormat,
            $dateStr,
            new \DateTimeZone($timezone)
        );

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

    } else {
        $date = \DateTime::createFromFormat($dateFormat, $dateStr);
    }

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 '\DateTime' in method 'isValidDateTimeString'.
Open

        $date = \DateTime::createFromFormat($dateFormat, $dateStr);

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

    } else {
        foreach ($vars as $var) {
            if (!is_object($var)) {
                return false;
            } else {
Severity: Minor
Found in src/Keboola/Utils/isEmptyObject.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 unused local variables such as '$v'.
Open

        foreach ($query as $k => $v) {
Severity: Minor
Found in src/Keboola/Utils/buildUrl.php by phpmd

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

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

        } else {
            $result[$prefix . $key] = $value;
        }
Severity: Minor
Found in src/Keboola/Utils/flattenArray.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

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

    } else {
        $url = "";
    }
Severity: Minor
Found in src/Keboola/Utils/httpBuildUrl.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 unused parameters such as '$key'.
Open

    array_walk_recursive($array, function (&$string, $key, $settings) {

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

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

            } else {
                return isEmptyObject((object) $var);
            }
Severity: Minor
Found in src/Keboola/Utils/isEmptyObject.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 '\DateTime' in method 'isValidDateTimeString'.
Open

}

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

        } else {
            $newQuery = $query;
        }
Severity: Minor
Found in src/Keboola/Utils/buildUrl.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

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

                } else {
                    throw new Exception\NoDataFoundException("Error parsing data. {$path} not found.");
                }
Severity: Minor
Found in src/Keboola/Utils/getDataFromPath.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

Severity
Category
Status
Source
Language