|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\Immutable; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\Immutable\Exception\EmptySet; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @template T |
|
10
|
|
|
* |
|
11
|
|
|
* @param Set<T>|Sequence<T> $structure |
|
12
|
|
|
* |
|
13
|
|
|
* @return list<T> |
|
|
|
|
|
|
14
|
|
|
*/ |
|
15
|
|
|
function unwrap($structure): array |
|
16
|
|
|
{ |
|
17
|
|
|
/** @psalm-suppress DocblockTypeContradiction */ |
|
18
|
125 |
|
if (!$structure instanceof Set && !$structure instanceof Sequence) { |
|
|
|
|
|
|
19
|
1 |
|
$given = Type::determine($structure); |
|
20
|
|
|
|
|
21
|
1 |
|
throw new \TypeError("Argument 1 must be of type Set|Sequence, $given given"); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @psalm-suppress MixedAssignment |
|
26
|
|
|
* |
|
27
|
|
|
* @var list<T> |
|
28
|
|
|
*/ |
|
29
|
124 |
|
return $structure->reduce( |
|
|
|
|
|
|
30
|
124 |
|
[], |
|
|
|
|
|
|
31
|
|
|
static function(array $carry, $t): array { |
|
32
|
122 |
|
$carry[] = $t; |
|
33
|
|
|
|
|
34
|
122 |
|
return $carry; |
|
35
|
124 |
|
}, |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Concatenate all elements with the given separator |
|
41
|
|
|
* |
|
42
|
|
|
* @param Set<string>|Sequence<string> $structure |
|
43
|
|
|
*/ |
|
44
|
|
|
function join(string $separator, $structure): Str |
|
45
|
|
|
{ |
|
46
|
|
|
/** @psalm-suppress DocblockTypeContradiction */ |
|
47
|
10 |
|
if (!$structure instanceof Set && !$structure instanceof Sequence) { |
|
|
|
|
|
|
48
|
1 |
|
$given = Type::determine($structure); |
|
49
|
|
|
|
|
50
|
1 |
|
throw new \TypeError("Argument 2 must be of type Set|Sequence, $given given"); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
9 |
|
if ($structure instanceof Set) { |
|
|
|
|
|
|
54
|
2 |
|
assertSet('string', $structure, 2); |
|
55
|
|
|
} else { |
|
56
|
7 |
|
assertSequence('string', $structure, 2); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
7 |
|
return Str::of(\implode($separator, unwrap($structure))); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @template T |
|
64
|
|
|
* |
|
65
|
|
|
* @throws EmptySet |
|
66
|
|
|
* |
|
67
|
|
|
* @param Set<T> $set |
|
68
|
|
|
* |
|
69
|
|
|
* @return T |
|
70
|
|
|
*/ |
|
71
|
|
|
function first(Set $set) |
|
72
|
|
|
{ |
|
73
|
2 |
|
if ($set->empty()) { |
|
74
|
1 |
|
throw new EmptySet; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
1 |
|
$seed = new \stdClass; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @psalm-suppress MissingClosureParamType |
|
81
|
|
|
* @var T |
|
82
|
|
|
*/ |
|
83
|
1 |
|
return $set->reduce( |
|
84
|
1 |
|
$seed, |
|
85
|
|
|
static function($first, $value) use ($seed) { |
|
86
|
1 |
|
if ($first === $seed) { |
|
87
|
|
|
/** @var T */ |
|
88
|
1 |
|
return $value; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** @var T */ |
|
92
|
1 |
|
return $first; |
|
93
|
1 |
|
}, |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @throws \TypeError |
|
99
|
|
|
*/ |
|
100
|
|
|
function assertSet(string $type, Set $set, int $position): void |
|
101
|
|
|
{ |
|
102
|
18 |
|
if (!$set->isOfType($type)) { |
|
103
|
6 |
|
throw new \TypeError("Argument $position must be of type Set<$type>, Set<{$set->type()}> given"); |
|
104
|
|
|
} |
|
105
|
13 |
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @throws \TypeError |
|
109
|
|
|
*/ |
|
110
|
|
|
function assertMap(string $key, string $value, Map $map, int $position): void |
|
111
|
|
|
{ |
|
112
|
9 |
|
if (!$map->isOfType($key, $value)) { |
|
113
|
3 |
|
throw new \TypeError("Argument $position must be of type Map<$key, $value>, Map<{$map->keyType()}, {$map->valueType()}> given"); |
|
114
|
|
|
} |
|
115
|
7 |
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @throws \TypeError |
|
119
|
|
|
*/ |
|
120
|
|
|
function assertSequence(string $type, Sequence $sequence, int $position): void |
|
121
|
|
|
{ |
|
122
|
38 |
|
if (!$sequence->isOfType($type)) { |
|
123
|
5 |
|
throw new \TypeError("Argument $position must be of type Sequence<$type>, Sequence<{$sequence->type()}> given"); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
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