source/Parser/Url.php
Showing 91 of 91 total issues
Function parse
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
protected function parse(string $url) { $parsed = parse_url($url); if ($parsed === false) { $this->log("Failed to parse URL from {$url}");
- Read upRead up
Avoid too many return
statements within this method. Open
Open
return $parsed;
Avoid using static access to class 't1gor\RobotsTxtParser\Parser\HostName' in method 'parse'. Open
Open
if (!isset($parsed['host']) || !HostName::isValid($parsed['host'])) {
- Read upRead up
- Exclude checks
Avoid variables with short names like $in. Configured minimum length is 3. Open
Open
protected string $in = '';
- Read upRead up
- Exclude checks
Avoid variables with short names like $in. Configured minimum length is 3. Open
Open
public function __construct(string $in) {
- Read upRead up
- Exclude checks
Opening brace of a class must be on the line after the definition Open
Open
class Url implements LoggerAwareInterface {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* URL encoder according to RFC 3986
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
']' => '!%5D!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'$' => '!%24!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->in = $this->encode(trim($in));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return string 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
'@' => '!%40!ui',
- 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
'!' => '!%21!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'(' => '!%28!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'/' => '!%2F!ui',
- 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 http://publicmind.in/blog/url-encoding/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'#' => '!%23!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
')' => '!%29!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'*' => '!%2A!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
protected function encode(string $url): string {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
':' => '!%3A!ui',
- 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
* @param string $url
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'?' => '!%3F!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'[' => '!%5B!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
"'" => '!%27!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'+' => '!%2B!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return preg_replace(array_values($reserved), array_keys($reserved), rawurlencode($url));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Returns a string containing the encoded URL with disallowed characters converted to their percentage encodings.
- 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
',' => '!%2C!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
protected function parse(string $url) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if ($parsed === false) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->log("URL scheme invalid or missing for {$url}");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (!is_int($parsed['port'])) {
- 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
$this->log("Failed to parse URL from {$url}");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if ($parsed !== false) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $parsed['custom'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'&' => '!%26!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (!isset($parsed['scheme']) || !static::isValidScheme($parsed['scheme'])) {
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
protected string $in = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function __construct(string $in) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
'=' => '!%3D!ui',
- 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
$parsed = $this->parse($this->in);
- 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
$this->log("URL port should be a number, {$parsed['port']} found for {$url}");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $parsed;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
use LogsIfAvailableTrait;
- 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
$reserved = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
';' => '!%3B!ui',
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$parsed['custom'] = ($parsed['path'] ?? '/') . (isset($parsed['query']) ? '?' . $parsed['query'] : '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $url
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$parsed = parse_url($url);
- 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
$parsed['port'] = getservbyname($parsed['scheme'], 'tcp');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return in_array($scheme, ['http', 'https', 'ftp', 'sftp']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Parse URL
- 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 function getPath() {
- 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
$this->log("URL host invalid or missing for {$url}");
- 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
'%' => '!%25!ui',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return array|false
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (!isset($parsed['host']) || !HostName::isValid($parsed['host'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function isValidScheme(string $scheme): bool {
- 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
if (!isset($parsed['port'])) {
- 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
}
- 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 $this->in;
- Exclude checks
Opening brace should be on a new line Open
Open
public function __construct(string $in) {
- Exclude checks
Opening brace should be on a new line Open
Open
public static function isValidScheme(string $scheme): bool {
- Exclude checks
Opening brace should be on a new line Open
Open
protected function parse(string $url) {
- Exclude checks
Opening brace should be on a new line Open
Open
protected function encode(string $url): string {
- Exclude checks
Opening brace should be on a new line Open
Open
public function getPath() {
- Exclude checks