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

nepada / file-upload-control / 9327437708

pending completion
9327437708

Pull #156

github

web-flow
Merge 92839108e into 46a12c798
Pull Request #156: Update mockery/mockery requirement from 1.6.11 to 1.6.12

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

90.91
/src/FileUploadControl/Storage/Metadata/FileUploadMetadata.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\FileUploadControl\Storage\Metadata;
5

6
use Nepada\FileUploadControl\Storage\FileUploadChunk;
7
use Nepada\FileUploadControl\Storage\FileUploadId;
8
use Nette;
9
use Nette\Utils\Json;
10

11
final class FileUploadMetadata
12
{
13

14
    use Nette\SmartObject;
15

16
    public readonly string $name;
17

18
    public readonly int $size;
19

20
    private function __construct(string $name, int $size)
1✔
21
    {
22
        if ($size < 0) {
1✔
23
            throw new \InvalidArgumentException('File upload size cannot be negative.');
1✔
24
        }
25
        $this->name = $name;
1✔
26
        $this->size = $size;
1✔
27
    }
1✔
28

29
    public static function fromFileUploadChunk(FileUploadChunk $fileUploadChunk): self
1✔
30
    {
31
        return new self($fileUploadChunk->fileUpload->getUntrustedName(), $fileUploadChunk->contentRange->getSize());
1✔
32
    }
33

34
    /**
35
     * @param mixed[] $data
36
     * @return FileUploadMetadata
37
     */
38
    public static function fromArray(array $data): self
1✔
39
    {
40
        return new self($data['name'], $data['size']);
1✔
41
    }
42

43
    /**
44
     * @return mixed[]
45
     */
46
    public function toArray(): array
47
    {
48
        return [
49
            'name' => $this->name,
1✔
50
            'size' => $this->size,
1✔
51
        ];
52
    }
53

54
    /**
55
     * @deprecated read the property directly instead
56
     */
57
    public function getName(): string
58
    {
59
        return $this->name;
×
60
    }
61

62
    /**
63
     * @deprecated read the property directly instead
64
     */
65
    public function getSize(): int
66
    {
67
        return $this->size;
×
68
    }
69

70
    public function equals(self $other): bool
1✔
71
    {
72
        return $this->name === $other->name && $this->size === $other->size;
1✔
73
    }
74

75
    public function createFileUploadId(): FileUploadId
76
    {
77
        $data = $this->toArray();
1✔
78
        ksort($data);
1✔
79
        $serialized = Json::encode($data);
1✔
80
        $hash = sha1($serialized, true);
1✔
81
        $id = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($hash));
1✔
82
        return FileUploadId::fromString($id);
1✔
83
    }
84

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