GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — develop ( 3d4c79...7ab88f )
by Baptiste
05:30
created

first()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 22
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 2
nop 1
dl 0
loc 22
ccs 8
cts 8
cp 1
crap 3
rs 9.9666
c 0
b 0
f 0
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>
0 ignored issues
show
Bug introduced by
The type Innmind\Immutable\list 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
function unwrap($structure): array
16
{
17
    /** @psalm-suppress DocblockTypeContradiction */
18 125
    if (!$structure instanceof Set && !$structure instanceof Sequence) {
0 ignored issues
show
introduced by
$structure is always a sub-type of Innmind\Immutable\Set.
Loading history...
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(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $structure->reduc...ion(...) { /* ... */ }) returns the type Innmind\Immutable\R which is incompatible with the type-hinted return array.
Loading history...
30 124
        [],
0 ignored issues
show
Bug introduced by
array() of type array is incompatible with the type Innmind\Immutable\R expected by parameter $carry of Innmind\Immutable\Set::reduce(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        /** @scrutinizer ignore-type */ [],
Loading history...
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) {
0 ignored issues
show
introduced by
$structure is always a sub-type of Innmind\Immutable\Set.
Loading history...
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) {
0 ignored issues
show
introduced by
$structure is always a sub-type of Innmind\Immutable\Set.
Loading history...
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