Skip to content

Commit 90a58f7

Browse files
committed
fix(api): Offload integer validation to the server dispatcher
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 6b479e1 commit 90a58f7

1 file changed

Lines changed: 3 additions & 13 deletions

File tree

lib/Controller/APIController.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public function getRetentions(): DataResponse {
8686
* Create a retention rule
8787
*
8888
* @param int $tagid Tag the retention is based on
89-
* @param 0|1|2|3 $timeunit Time unit of the retention (days, weeks, months, years)
89+
* @param int<0, 3> $timeunit Time unit of the retention (days, weeks, months, years)
9090
* @psalm-param Constants::UNIT_* $timeunit
9191
* @param positive-int $timeamount Amount of time units that have to be passed
92-
* @param 0|1 $timeafter Whether retention time is based creation time (0) or modification time (1)
92+
* @param int<0, 1> $timeafter Whether retention time is based creation time (0) or modification time (1)
9393
* @psalm-param Constants::MODE_* $timeafter
9494
* @return DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'tagid'|'timeunit'|'timeamount'|'timeafter'}, array{}>|DataResponse<Http::STATUS_CREATED, Files_RetentionRule, array{}>
9595
*
@@ -103,16 +103,6 @@ public function addRetention(int $tagid, int $timeunit, int $timeamount, int $ti
103103
return new DataResponse(['error' => 'tagid'], Http::STATUS_BAD_REQUEST);
104104
}
105105

106-
if ($timeunit < 0 || $timeunit > 3) {
107-
return new DataResponse(['error' => 'timeunit'], Http::STATUS_BAD_REQUEST);
108-
}
109-
if ($timeamount < 1) {
110-
return new DataResponse(['error' => 'timeamount'], Http::STATUS_BAD_REQUEST);
111-
}
112-
if ($timeafter < 0 || $timeafter > 1) {
113-
return new DataResponse(['error' => 'timeafter'], Http::STATUS_BAD_REQUEST);
114-
}
115-
116106
$qb = $this->db->getQueryBuilder();
117107
$qb->insert('retention')
118108
->setValue('tag_id', $qb->createNamedParameter($tagid))
@@ -140,7 +130,7 @@ public function addRetention(int $tagid, int $timeunit, int $timeamount, int $ti
140130
* Delete a retention rule
141131
*
142132
* @param int $id Retention rule to delete
143-
* @return DataResponse<Http::STATUS_NO_CONTENT|Http::STATUS_NOT_FOUND, list<empty>, array{}>
133+
* @return DataResponse<Http::STATUS_NO_CONTENT|Http::STATUS_NOT_FOUND, array{}, array{}>
144134
*
145135
* 204: Retention rule deleted
146136
* 404: Retention rule not found

0 commit comments

Comments
 (0)