t1gor/Robots.txt-Parser-Class

View on GitHub
source/Stream/Filters/SkipDirectivesWithInvalidValuesFilter.php

Summary

Maintainability
A
1 hr
Test Coverage

Showing 43 of 43 total issues

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

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

$bucket->data = preg_replace(Directive::getRequestRateRegex(), '', $bucket->data, -1, $skippedRequestRateValues);

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

$bucket->data = preg_replace(Directive::getCrawlDelayRegex(), '', $bucket->data, -1, $skippedCrawlDelayValues);

Define a constant instead of duplicating this literal "logger" 5 times.
Open

if (isset($this->params['logger']) && $this->params['logger'] instanceof LoggerInterface) {

Remove this commented out code.
Open

// $bucket->data = preg_replace(Directive::getAllowDisallowRegex(), '', $bucket->data, -1, $skippedAllowanceValues);

Avoid unused parameters such as '$closing'.
Open

public function filter($in, $out, &$consumed, $closing) {

Avoid excessively long variable names like $skippedRequestRateValues. Keep variable name length under 20.
Open

$skippedRequestRateValues = 0;

Avoid excessively long variable names like $skippedCrawlDelayValues. Keep variable name length under 20.
Open

$skippedCrawlDelayValues = 0;

Avoid excessively long variable names like $skippedAllowanceValues. Keep variable name length under 20.
Open

$skippedAllowanceValues = 0;

Avoid variables with short names like $in. Configured minimum length is 3.
Open

public function filter($in, $out, &$consumed, $closing) {

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

class SkipDirectivesWithInvalidValuesFilter extends \php_user_filter implements CustomFilterInterface {

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

}

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

$skippedCrawlDelayValues = 0;

Line exceeds 120 characters; contains 130 characters
Open

$this->params['logger']->debug($skippedAllowanceValues . ' char(s) dropped as invalid allow/disallow value.');

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

if ($skippedCrawlDelayValues > 0) {

Line exceeds 120 characters; contains 128 characters
Open

$this->params['logger']->debug($skippedCrawlDelayValues . ' char(s) dropped as invalid Crawl-delay value.');

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

if ($skippedAllowanceValues > 0) {

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

$this->params['logger']->debug($skippedRequestRateValues . ' char(s) dropped as invalid Request-rate value.');

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

$bucket->data = preg_replace(Directive::getCrawlDelayRegex(), '', $bucket->data, -1, $skippedCrawlDelayValues);

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

}

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

public const NAME = 'RTP_skip_directives_invalid_value';

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

while ($bucket = stream_bucket_make_writeable($in)) {

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

$consumed += $bucket->datalen;

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

public function filter($in, $out, &$consumed, $closing) {

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

$this->params['logger']->debug($skippedAllowanceValues . ' char(s) dropped as invalid allow/disallow value.');

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

}

Line exceeds 120 characters; contains 125 characters
Open

$bucket->data = preg_replace(Directive::getRequestRateRegex(), '', $bucket->data, -1, $skippedRequestRateValues);

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

}

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

$skippedAllowanceValues = 0;

Line exceeds 120 characters; contains 125 characters
Open

// $bucket->data = preg_replace(Directive::getAllowDisallowRegex(), '', $bucket->data, -1, $skippedAllowanceValues);

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

stream_bucket_append($out, $bucket);

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

if (isset($this->params['logger']) && $this->params['logger'] instanceof LoggerInterface) {

Line exceeds 120 characters; contains 130 characters
Open

$this->params['logger']->debug($skippedRequestRateValues . ' char(s) dropped as invalid Request-rate value.');

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

$this->params['logger']->debug($skippedCrawlDelayValues . ' char(s) dropped as invalid Crawl-delay value.');

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

public $filtername = self::NAME;

Line exceeds 120 characters; contains 123 characters
Open

$bucket->data = preg_replace(Directive::getCrawlDelayRegex(), '', $bucket->data, -1, $skippedCrawlDelayValues);

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

return PSFS_PASS_ON;

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

}

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

$skippedRequestRateValues = 0;

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

}

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

$bucket->data = preg_replace(Directive::getRequestRateRegex(), '', $bucket->data, -1, $skippedRequestRateValues);

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

if ($skippedRequestRateValues > 0) {

Opening brace should be on a new line
Open

public function filter($in, $out, &$consumed, $closing) {
Category
Status