Skip to content

Commit 249bded

Browse files
fix: enforce non-null file status contract
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent f82f641 commit 249bded

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

lib/Db/File.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class File extends Entity {
5353
protected string $uuid = '';
5454
protected ?\DateTime $createdAt = null;
5555
protected string $name = '';
56-
protected ?int $status = null;
56+
protected ?int $status = FileStatus::DRAFT->value;
5757
protected ?string $userId = null;
5858
protected ?int $signedNodeId = null;
5959
protected ?string $signedHash = null;
@@ -100,7 +100,20 @@ public function getUserId(): string {
100100
}
101101

102102
public function getStatusEnum(): FileStatus {
103-
return FileStatus::from($this->status ?? FileStatus::DRAFT->value);
103+
return FileStatus::from($this->getStatus());
104+
}
105+
106+
public function getStatus(): int {
107+
return $this->status ?? FileStatus::DRAFT->value;
108+
}
109+
110+
public function setStatus(int $status): void {
111+
if (FileStatus::tryFrom($status) === null) {
112+
throw new \InvalidArgumentException(sprintf('Invalid file status code: %d', $status));
113+
}
114+
115+
$this->status = $status;
116+
$this->markFieldUpdated('status');
104117
}
105118

106119
public function setStatusEnum(FileStatus $status): void {

0 commit comments

Comments
 (0)