frameworks   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 34
c 2
b 0
f 0
dl 0
loc 53
ccs 40
cts 40
cp 1
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B get() 0 46 6
1
<?php
2
declare(strict_types = 1);
3
namespace hexydec\agentzero;
4
5
class frameworks {
6
7
	/**
8
	 * Generates a configuration array for matching app frameworks
9
	 * 
10
	 * @return array<string,props> An array with keys representing the string to match, and values a props object defining how to generate the match and which properties to set
11
	 */
12 6
	public static function get() : array {
13 1
		return [
14 1
			'Electron/' => new props('start', fn (string $value) : array => [
15 5
				'framework' => 'Electron',
16 5
				'frameworkversion' => \explode('/', $value, 3)[1]
17 5
			]),
18 1
			'MAUI' => new props('start', [
19 1
				'framework' => 'MAUI'
20 1
			]),
21 1
			'Cordova' => new props('start', fn (string $value) : array => [
22 2
				'framework' => 'Cordova',
23 2
				'frameworkversion' => \explode('/', $value, 3)[1]
24 2
			]),
25 1
			'Alamofire/' => new props('start', fn (string $value) : array => [
26 1
				'framework' => 'Alamofire',
27 1
				'frameworkversion' => \explode('/', $value, 3)[1]
28 1
			]),
29 1
			'.NET CLR ' => new props('start', function (string $value, int $i, array $tokens) : array {
30
31
				// find latest version as often specifdies many versions
32 6
				$levels = [];
33 6
				for ($n = $i; $n < \count($tokens); $n++) { // may happen multiple times if there are multiple captures, but only look forward as only the first will be written
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
34 6
					if (\mb_stripos($tokens[$n], '.NET CLR ') === 0) {
35 6
						$ver = \array_map('\\intval', \explode('.', \mb_substr($tokens[$n], 9)));
36 6
						foreach ($ver AS $key => $item) {
37 6
							if ($item > ($levels[$key] ?? 0)) {
38 6
								$levels = $ver;
39 6
							} elseif ($item < ($levels[$key] ?? 0)) {
40 4
								break;
41
							}
42
						}
43
					}
44
				}
45 6
				return [
46 6
					'framework' => '.NET Common Language Runtime',
47 6
					'frameworkversion' => \implode('.', $levels)
48 6
				];
49 1
			}),
50 1
			'libwww-perl/' => new props('start', fn (string $value) : array => [
51 2
				'type' => 'robot',
52 2
				'category' => 'scraper',
53 2
				'app' => 'LibWWW Perl',
54 2
				'appname' => 'libwww-perl',
55 2
				'appversion' => \explode('/', $value, 3)[1],
56 2
				'framework' => 'LibWWW Perl',
57 2
				'frameworkversion' => \explode('/', $value, 3)[1]
58 2
			])
59 1
		];
60
	}
61
}