t1gor/Robots.txt-Parser-Class

View on GitHub

Showing 17 of 1,364 total issues

File RobotsTxtParser.php has 353 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php declare(strict_types=1);

namespace t1gor\RobotsTxtParser;

use Psr\Log\LoggerAwareInterface;
Severity: Minor
Found in source/RobotsTxtParser.php - About 4 hrs to fix

    RobotsTxtParser has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class RobotsTxtParser implements LoggerAwareInterface {
    
        use LogsIfAvailableTrait;
    
        // default encoding
    Severity: Minor
    Found in source/RobotsTxtParser.php - About 3 hrs to fix

      Function parseURL has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function parseURL($url) {
              $parsed = parse_url($url);
              if ($parsed === false) {
                  return false;
              } elseif (!isset($parsed['scheme']) || !$this->isValidScheme($parsed['scheme'])) {
      Severity: Minor
      Found in source/RobotsTxtParser.php - About 1 hr 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

      Function render has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function render($eol = "\r\n") {
              $input = $this->getRules();
              krsort($input);
              $output = [];
              foreach ($input as $userAgent => $rules) {
      Severity: Minor
      Found in source/RobotsTxtParser.php - About 1 hr 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

      Function filter has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function filter($in, $out, &$consumed, $closing) {
              while ($bucket = stream_bucket_make_writeable($in)) {
                  $skippedRequestRateValues = 0;
                  $skippedCrawlDelayValues = 0;
                  $skippedAllowanceValues = 0;
      Severity: Minor
      Found in source/Stream/Filters/SkipDirectivesWithInvalidValuesFilter.php - About 1 hr 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

      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

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

            public function render($eol = "\r\n") {
                $input = $this->getRules();
                krsort($input);
                $output = [];
                foreach ($input as $userAgent => $rules) {
        Severity: Minor
        Found in source/RobotsTxtParser.php - About 1 hr to fix

          Function getSitemaps has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getSitemaps(?string $userAgent = null): array {
                  $this->buildTree();
                  $maps = [];
          
                  if (!is_null($userAgent)) {
          Severity: Minor
          Found in source/RobotsTxtParser.php - About 1 hr 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

          Function checkRules has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function checkRules(string $rule, string $path, string $userAgent = '*'): bool {
                  // check for disallowed http status code
                  if ($this->checkHttpStatusCodeRule()) {
                      return ($rule === Directive::DISALLOW);
                  }
          Severity: Minor
          Found in source/RobotsTxtParser.php - About 1 hr 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

          Function parse has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function parse(string $url) {
                  $parsed = parse_url($url);
          
                  if ($parsed === false) {
                      $this->log("Failed to parse URL from {$url}");
          Severity: Minor
          Found in source/Parser/Url.php - About 45 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

          Method __construct has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  $content,
                  string $encoding = self::DEFAULT_ENCODING,
                  ?TreeBuilderInterface $treeBuilder = null,
                  ?ReaderInterface $reader = null,
                  ?UserAgentMatcherInterface $userAgentMatcher = null
          Severity: Minor
          Found in source/RobotsTxtParser.php - About 35 mins to fix

            Method processDirective has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                protected function processDirective(string $directive, string $line, &$tree, string &$userAgent, string $prevLine = '') {
            Severity: Minor
            Found in source/Parser/TreeBuilder.php - About 35 mins to fix

              Function build has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function build(): array {
                      $currentUserAgent = '*';
                      $tree             = [];
                      $prevLine         = '';
              
              
              Severity: Minor
              Found in source/Parser/TreeBuilder.php - About 35 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

              Function getHost has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function getHost(?string $userAgent = null) {
                      $this->buildTree();
              
                      if (!is_null($userAgent)) {
                          $userAgent = $this->userAgentMatcher->getMatching($userAgent, array_keys($this->tree));
              Severity: Minor
              Found in source/RobotsTxtParser.php - About 35 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 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

                  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

                  Severity
                  Category
                  Status
                  Source
                  Language