1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Pheature\Model\Toggle; |
6
|
|
|
|
7
|
|
|
use Pheature\Core\Toggle\Read\Segment; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @psalm-import-type SegmentPayload from Segment |
11
|
|
|
*/ |
12
|
|
|
class InCollectionMatchingSegment implements Segment |
13
|
|
|
{ |
14
|
|
|
public const NAME = 'in_collection_matching_segment'; |
15
|
|
|
private string $id; |
16
|
|
|
/** @var SegmentPayload */ |
|
|
|
|
17
|
|
|
private array $criteria; |
18
|
|
|
|
19
|
|
|
/** @param SegmentPayload $criteria */ |
20
|
9 |
|
public function __construct(string $id, array $criteria) |
21
|
|
|
{ |
22
|
9 |
|
$this->id = $id; |
23
|
9 |
|
$this->criteria = $criteria; |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
8 |
|
public function id(): string |
27
|
|
|
{ |
28
|
8 |
|
return $this->id; |
29
|
|
|
} |
30
|
|
|
|
31
|
8 |
|
public function type(): string |
32
|
|
|
{ |
33
|
8 |
|
return self::NAME; |
34
|
|
|
} |
35
|
|
|
|
36
|
8 |
|
public function criteria(): array |
37
|
|
|
{ |
38
|
8 |
|
return $this->criteria; |
39
|
|
|
} |
40
|
|
|
|
41
|
8 |
|
public function match(array $payload): bool |
42
|
|
|
{ |
43
|
8 |
|
if (empty($this->criteria)) { |
44
|
1 |
|
return false; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** @var mixed $criterionValue */ |
48
|
7 |
|
foreach ($this->criteria as $field => $criterionValue) { |
49
|
7 |
|
if (!array_key_exists($field, $payload)) { |
50
|
1 |
|
return false; |
51
|
|
|
} |
52
|
|
|
|
53
|
7 |
|
if (!$this->isAMatch($payload[$field], $criterionValue)) { |
54
|
3 |
|
return false; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
3 |
|
return true; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param mixed $payloadValue |
63
|
|
|
* @param mixed $criterionValue |
64
|
|
|
*/ |
65
|
7 |
|
private function isAMatch($payloadValue, $criterionValue): bool |
66
|
|
|
{ |
67
|
7 |
|
if (is_array($criterionValue)) { |
68
|
5 |
|
return in_array($payloadValue, $criterionValue, true); |
69
|
|
|
} |
70
|
|
|
|
71
|
4 |
|
return $payloadValue === $criterionValue; |
72
|
|
|
} |
73
|
|
|
|
74
|
8 |
|
public function toArray(): array |
75
|
|
|
{ |
76
|
|
|
return [ |
77
|
8 |
|
'id' => $this->id, |
78
|
|
|
'type' => self::NAME, |
79
|
8 |
|
'criteria' => $this->criteria, |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
8 |
|
public function jsonSerialize(): array |
84
|
|
|
{ |
85
|
8 |
|
return $this->toArray(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
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