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

valkyrjaio / valkyrja / 15919194437

27 Jun 2025 05:50AM UTC coverage: 44.051%. Remained the same
15919194437

push

github

MelechMizrachi
Type: Fix Collection unit test failure.

4965 of 11271 relevant lines covered (44.05%)

20.08 hits per line

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

0.0
/src/Valkyrja/Type/Collection/TypeCollection.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <melechmizrachi@gmail.com>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Valkyrja\Type\Collection;
15

16
use Valkyrja\Type\BuiltIn\Support\Arr;
17
use Valkyrja\Type\Collection\Contract\Collection as Contract;
18
use Valkyrja\Type\Type;
19

20
use function array_keys;
21
use function count;
22
use function in_array;
23

24
/**
25
 * Class TypeCollection.
26
 *
27
 * @author   Melech Mizrachi
28
 *
29
 * @template K of array-key
30
 * @template T of string|int|float|bool|array|object|null
31
 *
32
 * @implements Contract<K, T>
33
 */
34
class TypeCollection implements Contract
35
{
36
    /**
37
     * The collection of items.
38
     *
39
     * @var array<K, T>
40
     */
41
    protected array $collection = [];
42

43
    /**
44
     * Collection constructor.
45
     *
46
     * @param class-string<Type> $type
47
     * @param array<K, T>        $collection
48
     */
49
    public function __construct(protected string $type, array $collection)
50
    {
51
        $this->setAll($collection);
×
52
    }
53

54
    /**
55
     * @inheritDoc
56
     */
57
    public function setAll(array $collection): static
58
    {
59
        $this->collection = $collection;
×
60

61
        return $this;
×
62
    }
63

64
    /**
65
     * @inheritDoc
66
     */
67
    public function exists($value): bool
68
    {
69
        return in_array($value, $this->collection, true);
×
70
    }
71

72
    /**
73
     * @inheritDoc
74
     */
75
    public function all(): array
76
    {
77
        return $this->collection;
×
78
    }
79

80
    /**
81
     * @inheritDoc
82
     */
83
    public function keys(): array
84
    {
85
        return array_keys($this->collection);
×
86
    }
87

88
    /**
89
     * @inheritDoc
90
     */
91
    public function count(): int
92
    {
93
        return count($this->collection);
×
94
    }
95

96
    /**
97
     * @inheritDoc
98
     */
99
    public function isEmpty(): bool
100
    {
101
        return empty($this->collection);
×
102
    }
103

104
    /**
105
     * @inheritDoc
106
     */
107
    public function __get(string|int $key): string|int|float|bool|array|object|null
108
    {
109
        return $this->get($key);
×
110
    }
111

112
    /**
113
     * @inheritDoc
114
     */
115
    public function __set(string|int $key, $value): void
116
    {
117
        $this->set($key, $value);
×
118
    }
119

120
    /**
121
     * @inheritDoc
122
     */
123
    public function get(string|int $key, string|int|float|bool|array|object|null $default = null): string|int|float|bool|array|object|null
124
    {
125
        return $this->has($key) ? $this->collection[$key] : $default;
×
126
    }
127

128
    /**
129
     * @inheritDoc
130
     */
131
    public function has(string|int $key): bool
132
    {
133
        return isset($this->collection[$key]);
×
134
    }
135

136
    /**
137
     * @inheritDoc
138
     */
139
    public function set(string|int $key, string|int|float|bool|array|object|null $value): static
140
    {
141
        $this->collection[$key] = $value;
×
142

143
        return $this;
×
144
    }
145

146
    /**
147
     * @inheritDoc
148
     */
149
    public function __isset(string|int $key): bool
150
    {
151
        return $this->has($key);
×
152
    }
153

154
    /**
155
     * @inheritDoc
156
     */
157
    public function __unset(string|int $key): void
158
    {
159
        $this->remove($key);
×
160
    }
161

162
    /**
163
     * @inheritDoc
164
     */
165
    public function remove(string|int $key): static
166
    {
167
        if (! $this->has($key)) {
×
168
            return $this;
×
169
        }
170

171
        unset($this->collection[$key]);
×
172

173
        return $this;
×
174
    }
175

176
    /**
177
     * @inheritDoc
178
     */
179
    public function __toString(): string
180
    {
181
        return Arr::toString($this->collection);
×
182
    }
183
}
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