|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
namespace hexydec\agentzero; |
|
4
|
|
|
|
|
5
|
|
|
class props { |
|
6
|
|
|
|
|
7
|
|
|
protected string $type; |
|
8
|
|
|
protected array|\Closure $props; |
|
9
|
|
|
|
|
10
|
1 |
|
public function __construct(string $type, array|\Closure $props) { |
|
11
|
1 |
|
$this->type = $type; |
|
12
|
1 |
|
$this->props = $props; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
87 |
|
public function match(\stdClass $obj, string $search, array $tokens) { |
|
16
|
87 |
|
$type = $this->type; |
|
17
|
87 |
|
$searchlower = \mb_strtolower($search); |
|
18
|
87 |
|
foreach ($tokens AS $i => $token) { |
|
19
|
87 |
|
$tokenlower = \mb_strtolower($token); |
|
20
|
|
|
switch ($type) { |
|
21
|
|
|
|
|
22
|
|
|
// match from start of string |
|
23
|
87 |
|
case 'start': |
|
24
|
87 |
|
if (\str_starts_with($tokenlower, $searchlower)) { |
|
25
|
87 |
|
$this->set($obj, $token, $i, $tokens, $search); |
|
26
|
|
|
} |
|
27
|
87 |
|
break; |
|
28
|
|
|
|
|
29
|
|
|
// match anywhere in the string |
|
30
|
87 |
|
case 'any': |
|
31
|
87 |
|
if (\str_contains($tokenlower, $searchlower)) { |
|
32
|
85 |
|
$this->set($obj, $token, $i, $tokens, $search); |
|
33
|
|
|
} |
|
34
|
87 |
|
break; |
|
35
|
|
|
|
|
36
|
|
|
// match end of token |
|
37
|
87 |
|
case 'end': |
|
38
|
87 |
|
if (\str_ends_with($tokenlower, $searchlower)) { |
|
39
|
11 |
|
$this->set($obj, $token, $i, $tokens, $search); |
|
40
|
|
|
} |
|
41
|
87 |
|
break; |
|
42
|
|
|
|
|
43
|
|
|
// match anywhere in the string |
|
44
|
87 |
|
case 'exact': |
|
45
|
87 |
|
if ($tokenlower === $searchlower) { |
|
46
|
74 |
|
$this->set($obj, $token, $i, $tokens, $search); |
|
47
|
74 |
|
break 2; |
|
48
|
|
|
} else { |
|
49
|
87 |
|
break; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Sets parsed UA properties, and calls callbacks to generate properties and sets them to the output object |
|
57
|
|
|
* |
|
58
|
|
|
* @param \stdClass $browser A stdClass object to which the properties will be set |
|
59
|
|
|
* @param MatchValue|\Closure $props An array of properties or a Closure to generate properties |
|
|
|
|
|
|
60
|
|
|
* @param string $value The current token value |
|
61
|
|
|
* @param int $i The ID of the current token |
|
62
|
|
|
* @param array<string> &$tokens The tokens array |
|
63
|
|
|
* @return void |
|
64
|
|
|
*/ |
|
65
|
87 |
|
public function set(\stdClass $obj, string $value, int $i, array $tokens, string $key) : void { |
|
66
|
87 |
|
$props = $this->props; |
|
67
|
87 |
|
if ($props instanceof \Closure) { |
|
68
|
87 |
|
$props = $props($value, $i, $tokens, $key); |
|
69
|
|
|
} |
|
70
|
87 |
|
if (\is_array($props)) { |
|
71
|
87 |
|
foreach ($props AS $key => $item) { |
|
72
|
87 |
|
if ($item !== null && !isset($obj->{$key})) { |
|
73
|
87 |
|
$obj->{$key} = $item; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths