t1gor/Robots.txt-Parser-Class

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

Summary

Maintainability
A
1 hr
Test Coverage

Method process has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(string $line, array &$root, string &$currentUserAgent = '*', string $prevLine = '') {
        $parts     = explode(':', $line);
        $entry     = trim($parts[1]);
        $directive = $this->getDirectiveName();

Severity: Minor
Found in source/Parser/DirectiveProcessors/AbstractAllowanceProcessor.php - About 1 hr to fix

    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

    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,
                    '{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

    Define a constant instead of duplicating this literal "{useragent}" 3 times.
    Open

                    '{useragent}' => $currentUserAgent,

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define a constant instead of duplicating this literal "{directive}" 3 times.
    Open

                    '{directive}' => $directive,

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

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

    abstract class AbstractAllowanceProcessor extends AbstractDirectiveProcessor implements DirectiveProcessorInterface {

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

                ]));

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

                $this->log(strtr('{directive} with invalid value "{faulty}" found for {useragent}, skipping', [

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

        }

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

                $this->log(strtr('{directive} with empty value found for {useragent}, skipping', [

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

                ]));

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

                $root[$currentUserAgent][$directive] = [];

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

            }

    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

            if (!in_array($entry, $root[$currentUserAgent][$directive])) {

    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;

    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

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

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

                $root[$currentUserAgent][$directive][] = $entry;

    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

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

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

            $entry     = trim($parts[1]);

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

            if (!preg_match("/^\//", $entry)) {

    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

                return;

    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

                    '{faulty}'    => $entry,

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

                    '{directive}' => $directive,

    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

                    '{directive}' => $directive,

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

            $directive = $this->getDirectiveName();

    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

            if (!isset($root[$currentUserAgent][$directive])) {

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

            if (empty($entry)) {

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

                    '{directive}' => $directive,

    Opening brace should be on a new line
    Open

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

    There are no issues that match your filters.

    Category
    Status