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

ICanBoogie / HTTP / 11879808822

17 Nov 2024 02:50PM UTC coverage: 91.111% (-0.7%) from 91.784%
11879808822

push

github

olvlvl
Use PHPStan 2.0

34 of 38 new or added lines in 4 files covered. (89.47%)

5 existing lines in 1 file now uncovered.

861 of 945 relevant lines covered (91.11%)

20.85 hits per line

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

73.68
/lib/FileList.php
1
<?php
2

3
namespace ICanBoogie\HTTP;
4

5
use ArrayAccess;
6
use ArrayIterator;
7
use Countable;
8
use IteratorAggregate;
9

10
use function count;
11

12
/**
13
 * Represents a list of request files.
14
 *
15
 * @implements ArrayAccess<string, File>
16
 * @implements IteratorAggregate<string, File>
17
 */
18
class FileList implements ArrayAccess, IteratorAggregate, Countable
19
{
20
    /**
21
     * Creates a {@see FileList} instance.
22
     *
23
     * @param array|FileList|null $files
24
     *
25
     * @return FileList
26
     */
27
    public static function from(array|FileList|null $files): self
28
    {
29
        if ($files instanceof self) {
1✔
30
            return clone $files;
1✔
31
        }
32

UNCOV
33
        if (!$files) {
×
UNCOV
34
            return new self([]);
×
35
        }
36

UNCOV
37
        foreach ($files as &$file) {
×
UNCOV
38
            $file = File::from($file);
×
39
        }
40

UNCOV
41
        return new self($files);
×
42
    }
43

44
    /**
45
     * @var File[]
46
     */
47
    private array $list = [];
48

49
    /**
50
     * @param array $files
51
     */
52
    public function __construct(array $files = [])
53
    {
54
        foreach ($files as $id => $file) {
109✔
55
            $this[$id] = $file;
2✔
56
        }
57
    }
58

59
    /**
60
     * Checks if a file exists.
61
     *
62
     * @param mixed $offset File identifier.
63
     */
64
    public function offsetExists(mixed $offset): bool
65
    {
66
        return isset($this->list[$offset]);
4✔
67
    }
68

69
    /**
70
     * Returns a file.
71
     *
72
     * @param mixed $offset File identifier.
73
     *
74
     * @return File|null A {@see File} instance, or `null` if it does not exist.
75
     */
76
    public function offsetGet(mixed $offset): ?File
77
    {
78
        if (!$this->offsetExists($offset)) {
4✔
79
            return null;
2✔
80
        }
81

82
        return $this->list[$offset];
3✔
83
    }
84

85
    /**
86
     * Adds a file.
87
     *
88
     * @param mixed $offset File identifier.
89
     * @param mixed|array|File|FileList $value File.
90
     */
91
    public function offsetSet(mixed $offset, mixed $value): void
92
    {
93
        if (!($value instanceof File || $value instanceof FileList)) {
4✔
94
            $value = File::from($value);
4✔
95
        }
96

97
        $this->list[$offset] = $value;
4✔
98
    }
99

100
    /**
101
     * Removes a file.
102
     *
103
     * @param mixed $offset File identifier.
104
     */
105
    public function offsetUnset(mixed $offset): void
106
    {
107
        unset($this->list[$offset]);
1✔
108
    }
109

110
    /**
111
     * @inheritdoc
112
     *
113
     * @return ArrayIterator<string, File>
114
     */
115
    public function getIterator(): ArrayIterator
116
    {
117
        return new ArrayIterator($this->list);
1✔
118
    }
119

120
    /**
121
     * Returns the number of files in the collection.
122
     *
123
     * @inheritdoc
124
     */
125
    public function count(): int
126
    {
127
        return count($this->list);
1✔
128
    }
129
}
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