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

nepada / file-upload-control / 11552994760

28 Oct 2024 11:28AM UTC coverage: 81.674% (+0.04%) from 81.633%
11552994760

push

github

xificurk
Loosen ContentRange validation to support zero-byte uploads (fixes #165)

7 of 7 new or added lines in 1 file covered. (100.0%)

722 of 884 relevant lines covered (81.67%)

0.82 hits per line

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

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

4
namespace Nepada\FileUploadControl\Storage;
5

6
use Nette;
7

8
final class FileUploadChunk
9
{
10

11
    use Nette\SmartObject;
12

13
    public readonly Nette\Http\FileUpload $fileUpload;
14

15
    public readonly ContentRange $contentRange;
16

17
    private function __construct(Nette\Http\FileUpload $fileUpload, ContentRange $contentRange)
1✔
18
    {
19
        if (! $fileUpload->isOk()) {
1✔
20
            throw new \InvalidArgumentException("Expected successful file upload, but upload of '{$fileUpload->getUntrustedName()}' has failed with error {$fileUpload->getError()}.");
1✔
21
        }
22

23
        if ($fileUpload->getSize() !== $contentRange->getRangeSize()) {
1✔
24
            throw new \InvalidArgumentException(sprintf(
1✔
25
                'Content range size of %d does not match file upload size %d.',
1✔
26
                $contentRange->getRangeSize(),
1✔
27
                $fileUpload->getSize(),
1✔
28
            ));
29
        }
30

31
        $this->fileUpload = $fileUpload;
1✔
32
        $this->contentRange = $contentRange;
1✔
33
    }
1✔
34

35
    public static function completeUpload(Nette\Http\FileUpload $fileUpload): self
1✔
36
    {
37
        return new self($fileUpload, ContentRange::ofSize($fileUpload->getSize()));
1✔
38
    }
39

40
    public static function partialUpload(Nette\Http\FileUpload $fileUpload, ContentRange $contentRange): self
1✔
41
    {
42
        return new self($fileUpload, $contentRange);
1✔
43
    }
44

45
    /**
46
     * @deprecated read the property directly instead
47
     */
48
    public function getFileUpload(): Nette\Http\FileUpload
49
    {
50
        return $this->fileUpload;
×
51
    }
52

53
    /**
54
     * @deprecated read the property directly instead
55
     */
56
    public function getContentRange(): ContentRange
57
    {
58
        return $this->contentRange;
×
59
    }
60

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

© 2025 Coveralls, Inc