Passed
Push — main ( 96c748...5a0913 )
by Will
03:13 queued 13s
created

other::get()   A

Complexity

Conditions 6
Paths 1

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 14.5383

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 28
ccs 8
cts 21
cp 0.381
rs 9.0111
cc 6
nc 1
nop 0
crap 14.5383
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 1
	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 1
					if (($start = \mb_strpos($value, '{')) === false) {
21
22 1
					} elseif (($end = \mb_strpos($value, '}', $start)) !== false) {
23
						$json = \mb_substr($value, $start, $end - $start + 1);
24
25
						// decode JSON
26
						if (($data = \json_decode($json, true)) !== null) {
27
							$data = \array_change_key_case((array) $data);
28
							$mappings = [
29
								'os' => 'platform',
30
								'osversion' => 'platformversion'
31
							];
32
							$fields = ['os', 'osversion', 'platform', 'platformversion', 'app', 'appversion'];
33
							$cat = [];
34
							foreach ($fields AS $item) {
35
								if (isset($data[$item])) {
36
									$cat[$mappings[$item] ?? $item] = $data[$item];
37
								}
38
							}
39
							return $cat;
40
						}
41
					}
42 1
					return null;
43 1
				}
44 1
			]
45 1
		];
46
	}
47
}