t1gor/Robots.txt-Parser-Class

View on GitHub
source/Parser/DirectiveProcessors/SitemapProcessor.php

Summary

Maintainability
A
0 mins
Test Coverage

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

        } else {
            $this->log(strtr('{directive} with value {faulty} skipped as already exists for {useragent}', [
                '{directive}' => Directive::SITEMAP,
                '{faulty}'    => $entry,
                '{useragent}' => $currentUserAgent,

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 '$prevLine'.
Open

    public function process(string $line, array & $root, string & $currentUserAgent = '*', string $prevLine = '') {

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

Opening brace of a class must be on the line after the definition
Open

class SitemapProcessor extends AbstractDirectiveProcessor implements DirectiveProcessorInterface {

Spaces must be used to indent lines; tabs are not allowed
Open

        $parts = explode(':', $line);

Spaces must be used to indent lines; tabs are not allowed
Open

        if (!isset($root[$currentUserAgent][Directive::SITEMAP])) {

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

        $entry   = implode(':', $trimmed);

Spaces must be used to indent lines; tabs are not allowed
Open

            $root[$currentUserAgent][Directive::SITEMAP] = [];

Spaces must be used to indent lines; tabs are not allowed
Open

        } else {

Spaces must be used to indent lines; tabs are not allowed
Open

    public function process(string $line, array & $root, string & $currentUserAgent = '*', string $prevLine = '') {

Spaces must be used to indent lines; tabs are not allowed
Open

            $root[$currentUserAgent][Directive::SITEMAP][] = $entry;

Spaces must be used to indent lines; tabs are not allowed
Open

                '{directive}' => Directive::SITEMAP,

Spaces must be used to indent lines; tabs are not allowed
Open

        array_shift($parts);

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getDirectiveName(): string {

Spaces must be used to indent lines; tabs are not allowed
Open

        if (!in_array($entry, $root[$currentUserAgent][Directive::SITEMAP])) {

Spaces must be used to indent lines; tabs are not allowed
Open

                '{useragent}' => $currentUserAgent,

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

        return Directive::SITEMAP;

Spaces must be used to indent lines; tabs are not allowed
Open

        $trimmed = array_map('trim', $parts);

Spaces must be used to indent lines; tabs are not allowed
Open

            $this->log(strtr('{directive} with value {faulty} skipped as already exists for {useragent}', [

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Spaces must be used to indent lines; tabs are not allowed
Open

                '{faulty}'    => $entry,

Spaces must be used to indent lines; tabs are not allowed
Open

            ]));

Opening brace should be on a new line
Open

    public function process(string $line, array & $root, string & $currentUserAgent = '*', string $prevLine = '') {

Opening brace should be on a new line
Open

    public function getDirectiveName(): string {

There are no issues that match your filters.

Category
Status