• 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/MutableSetType.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\MutableSetInterface<T>>
21
 *
22
 * @internal
23
 */
24
final readonly class MutableSetType 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
    ) {}
59✔
34

35
    /**
36
     * @throws CoercionException
37
     *
38
     * @return Collection\MutableSetInterface<T>
39
     */
40
    #[\Override]
41
    public function coerce(mixed $value): Collection\MutableSetInterface
42
    {
43
        if (is_iterable($value)) {
22✔
44
            /** @var Type\Type<T> $type */
45
            $type = $this->type;
15✔
46
            /** @var array<T, T> $set */
47
            $set = [];
15✔
48
            $k = null;
15✔
49
            $v = null;
15✔
50
            /** @var bool $iterating */
51
            $iterating = true;
15✔
52
            try {
53
                /**
54
                 * @var array-key $k
55
                 * @var T $v
56
                 */
57
                foreach ($value as $k => $v) {
15✔
58
                    $iterating = false;
14✔
59
                    $v = $type->coerce($v);
14✔
60
                    $set[$v] = $v;
10✔
61
                    $iterating = true;
10✔
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\MutableSet($set);
8✔
72
        }
73

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

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

111
                throw AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e);
2✔
112
            }
113

114
            return new Collection\MutableSet($set);
16✔
115
        }
116

117
        throw AssertException::withValue($value, $this->toString());
28✔
118
    }
119

120
    #[\Override]
121
    public function toString(): string
122
    {
123
        return Str\format('%s<%s>', Collection\MutableSetInterface::class, $this->type->toString());
46✔
124
    }
125
}
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