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

nepada / file-upload-control / 4581408359

pending completion
4581408359

Pull #103

github

GitHub
Merge ed661242b into c8546f895
Pull Request #103: Update nepada/coding-standard requirement from 7.6.0 to 7.7.0

641 of 710 relevant lines covered (90.28%)

0.9 hits per line

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

95.83
/src/FileUploadControl/Storage/ContentRange.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\FileUploadControl\Storage;
5

6
use Nette;
7
use Nette\Utils\Strings;
8

9
final class ContentRange
10
{
11

12
    use Nette\SmartObject;
13

14
    private int $start;
15

16
    private int $end;
17

18
    private int $size;
19

20
    private function __construct(int $start, int $end, int $size)
1✔
21
    {
22
        if ($start < 0) {
1✔
23
            throw new \InvalidArgumentException("Start ($start) cannot be negative.");
×
24
        }
25
        if ($end < $start) {
1✔
26
            throw new \InvalidArgumentException("Start ($start) cannot be larger than end ($end).");
1✔
27
        }
28
        if ($size <= $end) {
1✔
29
            throw new \InvalidArgumentException("End ($end) cannot be larger or equal to size ($size).");
1✔
30
        }
31
        $this->start = $start;
1✔
32
        $this->end = $end;
1✔
33
        $this->size = $size;
1✔
34
    }
1✔
35

36
    public static function ofSize(int $size): ContentRange
1✔
37
    {
38
        return new self(0, $size - 1, $size);
1✔
39
    }
40

41
    public static function fromHttpHeaderValue(string $header): ContentRange
1✔
42
    {
43
        $match = Strings::match($header, '~^\s*bytes\s+(\d+)-(\d+)/(\d+)\s*$~i');
1✔
44
        if ($match === null) {
1✔
45
            throw new \InvalidArgumentException("Malformed content-range header '$header'.");
1✔
46
        }
47
        return new self((int) $match[1], (int) $match[2], (int) $match[3]);
1✔
48
    }
49

50
    public function getStart(): int
51
    {
52
        return $this->start;
1✔
53
    }
54

55
    public function getEnd(): int
56
    {
57
        return $this->end;
1✔
58
    }
59

60
    public function getRangeSize(): int
61
    {
62
        return $this->end - $this->start + 1;
1✔
63
    }
64

65
    public function getSize(): int
66
    {
67
        return $this->size;
1✔
68
    }
69

70
    public function containsFirstByte(): bool
71
    {
72
        return $this->start === 0;
1✔
73
    }
74

75
    public function containsLastByte(): bool
76
    {
77
        return $this->end === ($this->size - 1);
1✔
78
    }
79

80
}
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