Passed
Push — main ( 03a93c...274053 )
by Will
13:21
created

other::get()   B

Complexity

Conditions 7
Paths 1

Size

Total Lines 45
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 7.0368

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 45
ccs 30
cts 33
cp 0.9091
rs 8.5066
cc 7
nc 1
nop 0
crap 7.0368
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
							$cat = [];
28 1
							$data = \array_change_key_case((array) $data);
29
30
							// special case for chrome - browser
31 1
							if ($data['app'] === 'com.google.chrome.ios') {
32
								$cat['browser'] = 'Chrome';
33
								$cat['browserversion'] = $data['appversion'] ?? null;
34
								unset($data['app'], $data['appversion']);
35
							}
36
37
							// map values
38 1
							$map = [
39 1
								'os' => 'platform',
40 1
								'osversion' => 'platformversion',
41 1
								'isdarktheme' => 'darkmode'
42 1
							];
43 1
							$fields = ['os', 'osversion', 'platform', 'platformversion', 'app', 'appversion', 'isdarktheme'];
44 1
							$values = [
45 1
								'com.google.GoogleMobile' => 'Google',
46 1
								'com.google.android.gms' => 'Google',
47 1
								'com.google.Gmail' => 'Gmail',
48 1
								'com.google.photos' => 'Google Photos',
49 1
								'com.google.ios.youtube' => 'YouTube'
50 1
							];
51 1
							foreach ($fields AS $item) {
52 1
								if (isset($data[$item])) {
53 1
									$cat[$map[$item] ?? $item] = $values[$data[$item]] ?? $data[$item];
54
								}
55
							}
56 1
							return $cat;
57
						}
58
					}
59 1
					return null;
60 1
				}
61 1
			]
62 1
		];
63
	}
64
}