File RobotsTxtParser.php
has 353 lines of code (exceeds 250 allowed). Consider refactoring.
<?php declare(strict_types=1);
namespace t1gor\RobotsTxtParser;
use Psr\Log\LoggerAwareInterface;
RobotsTxtParser
has 27 functions (exceeds 20 allowed). Consider refactoring.
class RobotsTxtParser implements LoggerAwareInterface {
use LogsIfAvailableTrait;
Function parseURL
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
protected function parseURL($url) {
$parsed = parse_url($url);
if ($parsed === false) {
return false;
} elseif (!isset($parsed['scheme']) || !$this->isValidScheme($parsed['scheme'])) {
Function render
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
public function render($eol = "\r\n") {
$input = $this->getRules();
krsort($input);
$output = [];
foreach ($input as $userAgent => $rules) {
Function filter
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
public function filter($in, $out, &$consumed, $closing) {
while ($bucket = stream_bucket_make_writeable($in)) {
$skippedRequestRateValues = 0;
$skippedCrawlDelayValues = 0;
$skippedAllowanceValues = 0;
Method render
has 30 lines of code (exceeds 25 allowed). Consider refactoring.
public function render($eol = "\r\n") {
$input = $this->getRules();
krsort($input);
$output = [];
foreach ($input as $userAgent => $rules) {
Method process
has 30 lines of code (exceeds 25 allowed). Consider refactoring.
public function process(string $line, array &$root, string &$currentUserAgent = '*', string $prevLine = '') {
$parts = explode(':', $line);
$entry = trim($parts[1]);
$directive = $this->getDirectiveName();
Function getSitemaps
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
public function getSitemaps(?string $userAgent = null): array {
$this->buildTree();
$maps = [];
if (!is_null($userAgent)) {
Function checkRules
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
protected function checkRules(string $rule, string $path, string $userAgent = '*'): bool {
if ($this->checkHttpStatusCodeRule()) {
return ($rule === Directive::DISALLOW);
}
Function parse
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
protected function parse(string $url) {
$parsed = parse_url($url);
if ($parsed === false) {
$this->log("Failed to parse URL from {$url}");
Method __construct
has 5 arguments (exceeds 4 allowed). Consider refactoring.
$content,
string $encoding = self::DEFAULT_ENCODING,
?TreeBuilderInterface $treeBuilder = null,
?ReaderInterface $reader = null,
?UserAgentMatcherInterface $userAgentMatcher = null
Method processDirective
has 5 arguments (exceeds 4 allowed). Consider refactoring.
protected function processDirective(string $directive, string $line, &$tree, string &$userAgent, string $prevLine = '') {
Function build
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
public function build(): array {
$currentUserAgent = '*';
$tree = [];
$prevLine = '';
Function getHost
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
public function getHost(?string $userAgent = null) {
$this->buildTree();
if (!is_null($userAgent)) {
$userAgent = $this->userAgentMatcher->getMatching($userAgent, array_keys($this->tree));
Avoid too many return
statements within this method.
return $parsed;
Avoid too many return
statements within this method.
return $parsed;
Function __destruct
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
public function __destruct() {
foreach ($this->filters as $class => $instance) {
try {
if (is_resource($instance)) {
stream_filter_remove($instance);