spiritix/html-to-pdf

View on GitHub

Showing 21 of 21 total issues

Blank line found at start of control structure
Open

        foreach ($this->options as $key => $value) {

TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE"
Open

        if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {

Blank line found at start of control structure
Open

        foreach ($options as $key => $value) {

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

    public function embed($fileName, $exit = true)

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

    public function download($fileName, $exit = true)

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

Function setOptions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function setOptions($options)
    {
        if (!is_array($options) || empty($options)) {
            throw new ConverterException('Provided options are invalid');
        }
Severity: Minor
Found in src/Spiritix/HtmlToPdf/Converter.php - About 25 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 embed() contains an exit expression.
Open

            exit;

ExitExpression

Since: 0.2

An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

Example

class Foo {
    public function bar($param)  {
        if ($param === 42) {
            exit(23);
        }
    }
}

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

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

            else {
                $key = self::SHELL_COMMAND_PREFIX_REGULAR . $key;
            }
Severity: Minor
Found in src/Spiritix/HtmlToPdf/Converter.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 download() contains an exit expression.
Open

            exit;

ExitExpression

Since: 0.2

An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

Example

class Foo {
    public function bar($param)  {
        if ($param === 42) {
            exit(23);
        }
    }
}

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

Expected 1 newline at end of file; 0 found
Open

}

Expected 1 newline at end of file; 0 found
Open

}

Expected 1 newline at end of file; 0 found
Open

}

Expected 1 newline at end of file; 0 found
Open

}

Expected 1 newline at end of file; 0 found
Open

}

Expected 1 newline at end of file; 0 found
Open

}

Expected 1 newline at end of file; 0 found
Open

}

Expected 1 newline at end of file; 0 found
Open

}

Expected 1 newline at end of file; 0 found
Open

}

Expected 1 space after closing brace; newline found
Open

            }

Expected 1 newline at end of file; 0 found
Open

}
Severity
Category
Status
Source
Language