• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

azjezz / psl / 22520865518

28 Feb 2026 12:36PM UTC coverage: 97.768% (+0.2%) from 97.532%
22520865518

Pull #586

github

azjezz
more tests

Signed-off-by: azjezz <azjezz@protonmail.com>
Pull Request #586: add more tests

16 of 16 new or added lines in 4 files covered. (100.0%)

20 existing lines in 13 files now uncovered.

7492 of 7663 relevant lines covered (97.77%)

43.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.22
/src/Psl/Type/Internal/SetType.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Type\Internal;
6

7
use Psl\Collection;
8
use Psl\Str;
9
use Psl\Type;
10
use Psl\Type\Exception\AssertException;
11
use Psl\Type\Exception\CoercionException;
12
use Throwable;
13

14
use function is_iterable;
15
use function is_object;
16

17
/**
18
 * @template T of array-key
19
 *
20
 * @extends Type\Type<Collection\SetInterface<T>>
21
 *
22
 * @internal
23
 */
24
final readonly class SetType extends Type\Type
25
{
26
    /**
27
     * @psalm-mutation-free
28
     *
29
     * @param Type\TypeInterface<T> $type
30
     */
31
    public function __construct(
32
        private readonly Type\TypeInterface $type,
33
    ) {}
52✔
34

35
    /**
36
     * @throws CoercionException
37
     *
38
     * @return Collection\SetInterface<T>
39
     */
40
    #[\Override]
41
    public function coerce(mixed $value): Collection\SetInterface
42
    {
43
        if (is_iterable($value)) {
21✔
44
            /** @var Type\Type<T> $type */
45
            $type = $this->type;
14✔
46
            /** @var array<T, T> $set */
47
            $set = [];
14✔
48
            $k = null;
14✔
49
            $v = null;
14✔
50
            /** @var bool $iterating */
51
            $iterating = true;
14✔
52
            try {
53
                /**
54
                 * @var array-key $k
55
                 * @var T $v
56
                 */
57
                foreach ($value as $k => $v) {
14✔
58
                    $iterating = false;
13✔
59
                    $v = $type->coerce($v);
13✔
60
                    $set[$v] = $v;
9✔
61
                    $iterating = true;
9✔
62
                }
63
            } catch (Throwable $e) {
7✔
64
                if ($iterating) {
7✔
65
                    throw CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($k), $e);
3✔
66
                }
67

68
                throw CoercionException::withValue($v, $this->toString(), PathExpression::path($k), $e);
4✔
69
            }
70

71
            return new Collection\Set($set);
7✔
72
        }
73

74
        throw CoercionException::withValue($value, $this->toString());
7✔
75
    }
76

77
    /**
78
     * @throws AssertException
79
     *
80
     * @return Collection\SetInterface<T>
81
     *
82
     * @psalm-assert Collection\SetInterface<T> $value
83
     */
84
    #[\Override]
85
    public function assert(mixed $value): Collection\SetInterface
86
    {
87
        if (is_object($value) && $value instanceof Collection\SetInterface) {
40✔
88
            /** @var Type\Type<T> $type */
89
            $type = $this->type;
16✔
90
            /** @var array<T, T> $set */
91
            $set = [];
16✔
92
            $v = null;
16✔
93
            $k = null;
16✔
94
            /** @var bool $iterating */
95
            $iterating = true;
16✔
96
            try {
97
                foreach ($value as $k => $v) {
16✔
98
                    $iterating = false;
16✔
99
                    $v = $type->assert($v);
16✔
100
                    $set[$v] = $v;
14✔
101
                    $iterating = true;
14✔
102
                }
103
            } catch (Throwable $e) {
2✔
104
                if ($iterating) {
2✔
UNCOV
105
                    throw AssertException::withValue(null, $this->toString(), PathExpression::iteratorError($k), $e);
×
106
                }
107

108
                throw AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e);
2✔
109
            }
110

111
            return new Collection\Set($set);
14✔
112
        }
113

114
        throw AssertException::withValue($value, $this->toString());
24✔
115
    }
116

117
    #[\Override]
118
    public function toString(): string
119
    {
120
        return Str\format('%s<%s>', Collection\SetInterface::class, $this->type->toString());
42✔
121
    }
122
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc