Passed
Push — main ( e55150...6ce6d7 )
by Will
02:49
created

urls   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 19
c 2
b 0
f 0
dl 0
loc 30
ccs 20
cts 20
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 23 6
1
<?php
2
declare(strict_types = 1);
3
namespace hexydec\agentzero;
4
5
/**
6
 * @phpstan-import-type props from config
7
 */
8
class urls {
9
10
	/**
11
	 * Generates a configuration array for matching URL's
12
	 * 
13
	 * @return props An array with keys representing the string to match, and a value of an array containing parsing and output settings
14
	 */
15 8
	public static function get() : array {
16 1
		$fn = function (string $value, int $i, array $tokens) : ?array {
17 8
			if (($start = \stripos($value, 'http://')) === false) {
18 6
				if (($start = \stripos($value, 'https://')) === false) {
19 3
					$start = \stripos($value, 'www.');
20
				}
21
			}
22 8
			if ($start !== false) {
23 8
				$url = \rtrim(\substr($value, $start, \strcspn($value, '), ', $start)), '?+');
24 8
				$data = $i > 0 ? crawlers::getApp($tokens[--$i]) : [];
25 8
				return \array_merge([
26 8
					'type' => 'robot',
27 8
					'url' => $url,
28 8
					'category' => empty($data['app']) ? 'scraper' : 'crawler'
29 8
				], $data);
30
			}
31 3
			return null;
32 1
		};
33 1
		return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('http://' =...zero\props('any', $fn)) returns the type array<string,hexydec\agentzero\props> which is incompatible with the documented return type hexydec\agentzero\props.
Loading history...
34 1
			'http://' => new props('any', $fn),
35 1
			'https://' => new props('any', $fn),
36 1
			'www.' => new props('start', $fn),
37 1
			'.com' => new props('any', $fn),
38 1
		];
39
	}
40
}