t1gor/Robots.txt-Parser-Class

View on GitHub

Showing 1,364 of 1,364 total issues

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

class SkipDirectivesWithInvalidValuesFilter extends \php_user_filter implements CustomFilterInterface {

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

class SkipEmptyLinesFilter extends \php_user_filter implements CustomFilterInterface {

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

class SkipUnsupportedDirectivesFilter extends \php_user_filter implements CustomFilterInterface {

CASE statements must be defined using a colon
Open

            case Directive::HOST;
Severity: Minor
Found in source/RobotsTxtParser.php by phpcodesniffer

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

abstract class WarmingMessages {
Severity: Minor
Found in source/WarmingMessages.php by phpcodesniffer

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

interface ReaderInterface extends LoggerAwareInterface {

Avoid too many return statements within this method.
Open

        return $parsed;
Severity: Major
Found in source/Parser/Url.php - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

            return $parsed;
    Severity: Major
    Found in source/RobotsTxtParser.php - About 30 mins to fix

      Missing class import via use statement (line '236', column '13').
      Open

              throw new \RuntimeException(WarmingMessages::SET_UA_DEPRECATED);
      Severity: Minor
      Found in source/RobotsTxtParser.php by phpmd

      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

      Missing class import via use statement (line '81', column '14').
      Open

                  throw new \InvalidArgumentException($error);

      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

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

          public function __destruct() {
              foreach ($this->filters as $class => $instance) {
                  try {
                      if (is_resource($instance)) {
                          stream_filter_remove($instance);
      Severity: Minor
      Found in source/Stream/GeneratorBasedReader.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

      Avoid unused parameters such as '$currentUserAgent'.
      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

      Avoid using static access to class '\t1gor\RobotsTxtParser\Parser\HostName' in method 'isValidHostName'.
      Open

              return HostName::isValid($host);
      Severity: Minor
      Found in source/RobotsTxtParser.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 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 using static access to class 't1gor\RobotsTxtParser\Parser\HostName' in method 'parse'.
      Open

              if (!isset($parsed['host']) || !HostName::isValid($parsed['host'])) {
      Severity: Minor
      Found in source/Parser/Url.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 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

      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

      Avoid using static access to class 't1gor\RobotsTxtParser\Directive' in method 'checkRuleSwitch'.
      Open

              switch (Directive::attemptGetInline($rule)) {
      Severity: Minor
      Found in source/RobotsTxtParser.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 't1gor\RobotsTxtParser\Directive' in method 'checkRuleSwitch'.
      Open

                      if ($this->checkHostRule(Directive::stripInline($rule))) {
      Severity: Minor
      Found in source/RobotsTxtParser.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 getSitemaps uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  foreach ($this->tree as $userAgentBased) {
                      if (isset($userAgentBased[Directive::SITEMAP]) && !empty($userAgentBased[Directive::SITEMAP])) {
                          $maps = array_merge($maps, $userAgentBased[Directive::SITEMAP]);
                      }
      Severity: Minor
      Found in source/RobotsTxtParser.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