Skip to content

Commit

Permalink
fix(dav): Remove usage of indirect thecodingmachine/safe dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Oct 24, 2023
1 parent c5d8240 commit 17445f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
16 changes: 8 additions & 8 deletions apps/dav/lib/UserMigration/CalendarMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace OCA\DAV\UserMigration;

use function Safe\substr;
use function substr;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin;
Expand All @@ -50,7 +50,6 @@
use Sabre\VObject\Property\ICalendar\DateTime;
use Sabre\VObject\Reader as VObjectReader;
use Sabre\VObject\UUIDUtil;
use Safe\Exceptions\StringsException;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
Expand Down Expand Up @@ -185,12 +184,13 @@ function (ICalendar $calendar) use ($user, $output) {

private function getUniqueCalendarUri(IUser $user, string $initialCalendarUri): string {
$principalUri = $this->getPrincipalUri($user);
try {
$initialCalendarUri = substr($initialCalendarUri, 0, strlen(CalendarMigrator::MIGRATED_URI_PREFIX)) === CalendarMigrator::MIGRATED_URI_PREFIX
? $initialCalendarUri
: CalendarMigrator::MIGRATED_URI_PREFIX . $initialCalendarUri;
} catch (StringsException $e) {
throw new CalendarMigratorException('Failed to get unique calendar URI', 0, $e);

$initialCalendarUri = substr($initialCalendarUri, 0, strlen(CalendarMigrator::MIGRATED_URI_PREFIX)) === CalendarMigrator::MIGRATED_URI_PREFIX
? $initialCalendarUri
: CalendarMigrator::MIGRATED_URI_PREFIX . $initialCalendarUri;

if ($initialCalendarUri === false) {

Check failure on line 192 in apps/dav/lib/UserMigration/CalendarMigrator.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TypeDoesNotContainType

apps/dav/lib/UserMigration/CalendarMigrator.php:192:7: TypeDoesNotContainType: string does not contain false (see https://psalm.dev/056)

Check failure

Code scanning / Psalm

TypeDoesNotContainType Error

string does not contain false
throw new CalendarMigratorException('Failed to get unique calendar URI');
}

$existingCalendarUris = array_map(
Expand Down
27 changes: 12 additions & 15 deletions apps/dav/lib/UserMigration/ContactsMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

namespace OCA\DAV\UserMigration;

use function Safe\sort;
use function Safe\substr;
use function sort;
use function substr;
use OCA\DAV\AppInfo\Application;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\Plugin as CardDAVPlugin;
Expand All @@ -46,8 +46,6 @@
use Sabre\VObject\Reader as VObjectReader;
use Sabre\VObject\Splitter\VCard as VCardSplitter;
use Sabre\VObject\UUIDUtil;
use Safe\Exceptions\ArrayException;
use Safe\Exceptions\StringsException;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
Expand Down Expand Up @@ -165,12 +163,12 @@ function (array $addressBookInfo) use ($user, $output) {
private function getUniqueAddressBookUri(IUser $user, string $initialAddressBookUri): string {
$principalUri = $this->getPrincipalUri($user);

try {
$initialAddressBookUri = substr($initialAddressBookUri, 0, strlen(ContactsMigrator::MIGRATED_URI_PREFIX)) === ContactsMigrator::MIGRATED_URI_PREFIX
? $initialAddressBookUri
: ContactsMigrator::MIGRATED_URI_PREFIX . $initialAddressBookUri;
} catch (StringsException $e) {
throw new ContactsMigratorException('Failed to get unique address book URI', 0, $e);
$initialAddressBookUri = substr($initialAddressBookUri, 0, strlen(ContactsMigrator::MIGRATED_URI_PREFIX)) === ContactsMigrator::MIGRATED_URI_PREFIX
? $initialAddressBookUri
: ContactsMigrator::MIGRATED_URI_PREFIX . $initialAddressBookUri;

if ($initialAddressBookUri === false) {

Check failure on line 170 in apps/dav/lib/UserMigration/ContactsMigrator.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TypeDoesNotContainType

apps/dav/lib/UserMigration/ContactsMigrator.php:170:7: TypeDoesNotContainType: string does not contain false (see https://psalm.dev/056)

Check failure

Code scanning / Psalm

TypeDoesNotContainType Error

string does not contain false
throw new ContactsMigratorException('Failed to get unique address book URI');
}

$existingAddressBookUris = array_map(
Expand Down Expand Up @@ -303,11 +301,10 @@ private function getAddressBookImports(array $importFiles): array {
fn (string $filename) => pathinfo($filename, PATHINFO_EXTENSION) === ContactsMigrator::METADATA_EXT,
);

try {
sort($addressBookImports);
sort($metadataImports);
} catch (ArrayException $e) {
throw new ContactsMigratorException('Failed to sort address book files in ' . ContactsMigrator::PATH_ROOT, 0, $e);
$addressBookSort = sort($addressBookImports);
$metadataSort = sort($metadataImports);
if ($addressBookSort === false || $metadataSort === false) {
throw new ContactsMigratorException('Failed to sort address book files in ' . ContactsMigrator::PATH_ROOT);
}

if (count($addressBookImports) !== count($metadataImports)) {
Expand Down

0 comments on commit 17445f4

Please sign in to comment.