Skip to content

Commit d72a25d

Browse files
fixup! feat: Calendar Import
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
1 parent 968d789 commit d72a25d

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

apps/dav/lib/Command/ImportCalendar.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9393
$options = new CalendarImportOptions();
9494
$options->setSupersede($supersede);
9595
if ($errors !== null) {
96-
if (!in_array($errors, CalendarImportOptions::ERROR_OPTIONS, true)) {
97-
throw new InvalidArgumentException('Invalid errors option specified');
98-
}
9996
$options->setErrors($errors);
10097
}
10198
if ($validation !== null) {
102-
if (!in_array($validation, CalendarImportOptions::VALIDATE_OPTIONS, true)) {
103-
throw new InvalidArgumentException('Invalid validation option specified');
104-
}
10599
$options->setValidate($validation);
106100
}
107-
// evaluate if provided format is supported
108-
if (!in_array($format, ImportService::FORMATS, true)) {
109-
throw new InvalidArgumentException("Format <$format> is not valid.");
110-
}
111101
$options->setFormat($format);
112102
// evaluate if a valid location was given and is usable otherwise default to stdin
113103
$timeStarted = microtime(true);

lib/public/Calendar/CalendarImportOptions.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88
namespace OCP\Calendar;
99

10+
use InvalidArgumentException;
11+
use OCA\DAV\CalDAV\Import\ImportService;
12+
1013
/**
1114
* Calendar Import Options
1215
*
@@ -49,8 +52,11 @@ public function getFormat(): string {
4952
*
5053
* @param 'ical'|'jcal'|'xcal' $format
5154
*/
52-
public function setFormat(string $format): void {
53-
$this->format = $format;
55+
public function setFormat(string $value): void {
56+
if (!in_array($value, ImportService::FORMATS, true)) {
57+
throw new InvalidArgumentException("Format <$value> is not valid.");
58+
}
59+
$this->format = $value;
5460
}
5561

5662
/**
@@ -79,15 +85,15 @@ public function getErrors(): int {
7985
/**
8086
* Sets how to handle object errors
8187
*
82-
* @param int $errors 0 - continue, 1 - fail
88+
* @param int $value 0 - continue, 1 - fail
8389
*
84-
* @template $errors of self::ERROR_*
90+
* @template $value of self::ERROR_*
8591
*/
86-
public function setErrors(int $errors): void {
87-
if (!in_array($errors, self::ERROR_OPTIONS, true)) {
88-
throw new \InvalidArgumentException("Invalid errors handling type <$errors> specified, only ERROR_CONTINUE or ERROR_FAIL allowed");
92+
public function setErrors(int $value): void {
93+
if (!in_array($value, CalendarImportOptions::ERROR_OPTIONS, true)) {
94+
throw new InvalidArgumentException('Invalid errors option specified');
8995
}
90-
$this->errors = $errors;
96+
$this->errors = $value;
9197
}
9298

9399
/**
@@ -102,15 +108,15 @@ public function getValidate(): int {
102108
/**
103109
* Sets how to handle object validation
104110
*
105-
* @param int $validate 0 - no validation, 1 - validate and skip on issue, 2 - validate and fail on issue
111+
* @param int $value 0 - no validation, 1 - validate and skip on issue, 2 - validate and fail on issue
106112
*
107-
* @template $validate of self::VALIDATE_*
113+
* @template $value of self::VALIDATE_*
108114
*/
109-
public function setValidate(int $validate): void {
110-
if (!in_array($validate, self::VALIDATE_OPTIONS, true)) {
111-
throw new \InvalidArgumentException("Invalid validation handling type <$validate> specified, only VALIDATE_NONE, VALIDATE_SKIP or VALIDATE_FAIL allowed");
115+
public function setValidate(int $value): void {
116+
if (!in_array($value, CalendarImportOptions::VALIDATE_OPTIONS, true)) {
117+
throw new InvalidArgumentException('Invalid validation option specified');
112118
}
113-
$this->validate = $validate;
119+
$this->validate = $value;
114120
}
115121

116122
}

0 commit comments

Comments
 (0)