Passed
Push — main ( 7300c8...1902e7 )
by Will
13:33
created

other   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 21
c 1
b 0
f 0
dl 0
loc 36
ccs 22
cts 22
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B get() 0 29 6
1
<?php
2
declare(strict_types = 1);
3
namespace hexydec\agentzero;
4
5
/**
6
 * @phpstan-import-type MatchConfig from config
7
 */
8
class other {
9
10
	/**
11
	 * Generates a configuration array for matching other
12
	 * 
13
	 * @return MatchConfig An array with keys representing the string to match, and a value of an array containing parsing and output settings
0 ignored issues
show
Bug introduced by
The type hexydec\agentzero\MatchConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
	 */
15 2
	public static function get() : array {
16 1
		return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('{' => arra...on(...) { /* ... */ })) returns the type array<string,array<string,callable|string>> which is incompatible with the documented return type hexydec\agentzero\MatchConfig.
Loading history...
17 1
			'{' => [
18 1
				'match' => 'any',
19 1
				'categories' => function (string $value) : ?array {
20 2
					if (($start = \mb_strpos($value, '{')) === false) {
21
22 2
					} elseif (($end = \mb_strpos($value, '}', $start)) !== false) {
23 1
						$json = \mb_substr($value, $start, $end - $start + 1);
24
25
						// decode JSON
26 1
						if (($data = \json_decode($json, true)) !== null) {
27 1
							$data = \array_change_key_case((array) $data);
28 1
							$mappings = [
29 1
								'os' => 'platform',
30 1
								'osversion' => 'platformversion',
31 1
								'isdarktheme' => 'darkmode'
32 1
							];
33 1
							$fields = ['os', 'osversion', 'platform', 'platformversion', 'app', 'appversion', 'darkmode'];
34 1
							$cat = [];
35 1
							foreach ($fields AS $item) {
36 1
								if (isset($data[$item])) {
37 1
									$cat[$mappings[$item] ?? $item] = $data[$item];
38
								}
39
							}
40 1
							return $cat;
41
						}
42
					}
43 1
					return null;
44 1
				}
45 1
			]
46 1
		];
47
	}
48
}