source/Directive.php
Avoid using static access to class 't1gor\RobotsTxtParser\Directive' in method 'getRegex'. Open
Open
return "/^(?!(" . implode('|', Directive::getAll()) . ")\s*:+).+/mui";
- Read upRead up
- Exclude checks
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
Opening brace of a class must be on the line after the definition Open
Open
abstract class Directive {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @link https://yandex.com/support/webmaster/robot-workings/user-agent.html#user-agent
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const CACHE = 'cache';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const DISALLOW = 'disallow';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @link https://yandex.com/support/webmaster/robot-workings/crawl-delay.html#crawl-delay
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @link http://www.conman.org/people/spc/robots2.html
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$rule = trim(str_ireplace($directive . ':', '', $rule));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const USERAGENT = 'user-agent';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const CLEAN_PARAM = 'clean-param';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function getRequestRateRegex(): string {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function getAllowDisallowRegex(): string {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const SITEMAP = 'sitemap';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const REQUEST_RATE = 'request-rate';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
self::DISALLOW,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
self::HOST,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if ($directive !== false) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
self::USERAGENT,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
self::CACHE_DELAY,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @link https://yandex.com/support/webmaster/robot-workings/clean-param.html#clean-param
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function stripInline(string $rule): string {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const ALLOW = 'allow';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const CRAWL_DELAY = 'crawl-delay';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
self::CRAWL_DELAY,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function getCrawlDelayRegex(): string {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @link https://yandex.com/support/webmaster/robot-workings/sitemap.html#sitemap
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function getAll(): array {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
self::REQUEST_RATE,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function getRegex(): string {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @TODO finish me
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function attemptGetInline(string $rule) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const VISIT_TIME = 'visit-time';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
self::ALLOW,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (0 === strpos(mb_strtolower($rule), $directive . ':')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $directive;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @link https://yandex.com/support/webmaster/robot-workings/allow-disallow.html#allow-disallow
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const CACHE_DELAY = 'cache-delay';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
self::SITEMAP,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
self::CLEAN_PARAM,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
self::VISIT_TIME,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
foreach (static::getAll() as $directive) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $rule;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Extended standard directives
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return "/^" . self::REQUEST_RATE . ":+\s*(?![0-9]+\/[0-9]+).*/mui";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return "/^" . self::CRAWL_DELAY . ":+\s*(\D+)$/mui";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return "/^(" . self::ALLOW . "|" . self::DISALLOW . "):+\s*\\{1}.*$/mui";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
const HOST = 'host';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return "/^(?!(" . implode('|', Directive::getAll()) . ")\s*:+).+/mui";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$directive = static::attemptGetInline($rule);
- Exclude checks
Opening brace should be on a new line Open
Open
public static function stripInline(string $rule): string {
- Exclude checks
Opening brace should be on a new line Open
Open
public static function attemptGetInline(string $rule) {
- Exclude checks
Opening brace should be on a new line Open
Open
public static function getAll(): array {
- Exclude checks
Opening brace should be on a new line Open
Open
public static function getRegex(): string {
- Exclude checks
Opening brace should be on a new line Open
Open
public static function getCrawlDelayRegex(): string {
- Exclude checks
Opening brace should be on a new line Open
Open
public static function getRequestRateRegex(): string {
- Exclude checks
Opening brace should be on a new line Open
Open
public static function getAllowDisallowRegex(): string {
- Exclude checks