t1gor/Robots.txt-Parser-Class

View on GitHub
source/Parser/Url.php

Summary

Maintainability
A
1 hr
Test Coverage

Showing 91 of 91 total issues

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

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 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

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

    protected string $in = '';
    Severity: Minor
    Found in source/Parser/Url.php by phpmd

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

    public function __construct(string $in) {
    Severity: Minor
    Found in source/Parser/Url.php by phpmd

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

    class Url implements LoggerAwareInterface {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    * URL encoder according to RFC 3986
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    ']' => '!%5D!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '$' => '!%24!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    $this->in = $this->encode(trim($in));
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    * @return string string
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    *
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '@' => '!%40!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    */
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '!' => '!%21!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '(' => '!%28!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '/' => '!%2F!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    ];
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    * @link http://publicmind.in/blog/url-encoding/
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '#' => '!%23!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    ')' => '!%29!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '*' => '!%2A!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    protected function encode(string $url): string {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    ':' => '!%3A!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    /**
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    * @param string $url
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '?' => '!%3F!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '[' => '!%5B!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    "'" => '!%27!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '+' => '!%2B!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    return preg_replace(array_values($reserved), array_keys($reserved), rawurlencode($url));
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    * Returns a string containing the encoded URL with disallowed characters converted to their percentage encodings.
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    *
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    ',' => '!%2C!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    protected function parse(string $url) {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    if ($parsed === false) {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    $this->log("URL scheme invalid or missing for {$url}");
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    if (!is_int($parsed['port'])) {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    }
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    */
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    $this->log("Failed to parse URL from {$url}");
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    if ($parsed !== false) {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    return $parsed['custom'];
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '&' => '!%26!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    if (!isset($parsed['scheme']) || !static::isValidScheme($parsed['scheme'])) {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    return false;
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    }
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    protected string $in = '';
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    public function __construct(string $in) {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '=' => '!%3D!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    }
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    $parsed = $this->parse($this->in);
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    }
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    }
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    $this->log("URL port should be a number, {$parsed['port']} found for {$url}");
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    return $parsed;
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    use LogsIfAvailableTrait;
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    *
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    $reserved = [
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    ';' => '!%3B!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    return false;
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    }
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    $parsed['custom'] = ($parsed['path'] ?? '/') . (isset($parsed['query']) ? '?' . $parsed['query'] : '');
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    * @param string $url
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    $parsed = parse_url($url);
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    return false;
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    $parsed['port'] = getservbyname($parsed['scheme'], 'tcp');
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    return in_array($scheme, ['http', 'https', 'ftp', 'sftp']);
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    * Parse URL
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    *
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    public function getPath() {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    /**
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    $this->log("URL host invalid or missing for {$url}");
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    }
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    }
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    '%' => '!%25!ui',
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    * @return array|false
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    if (!isset($parsed['host']) || !HostName::isValid($parsed['host'])) {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    public static function isValidScheme(string $scheme): bool {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    *
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    }
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    if (!isset($parsed['port'])) {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    return false;
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    }
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    }
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

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

    return $this->in;
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

    Opening brace should be on a new line
    Open

    public function __construct(string $in) {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

    Opening brace should be on a new line
    Open

    public static function isValidScheme(string $scheme): bool {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

    Opening brace should be on a new line
    Open

    protected function parse(string $url) {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

    Opening brace should be on a new line
    Open

    protected function encode(string $url): string {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

    Opening brace should be on a new line
    Open

    public function getPath() {
    Severity: Minor
    Found in source/Parser/Url.php by phpcodesniffer

    There are no issues that match your filters.

    Category
    Status