Skip to content

Commit

Permalink
Polish s.t. the pre-merge checks pass.
Browse files Browse the repository at this point in the history
Signed-off-by: Claus-Justus Heine <Claus-Justus.Heine@IANS.Uni-Stuttgart.DE>
  • Loading branch information
Claus-Justus Heine authored and tcitworld committed Jan 20, 2023
1 parent 9adf7c8 commit 1ef937c
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 45 deletions.
13 changes: 9 additions & 4 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ public function boot(IBootContext $context): void {
$context->injectFn([$this, 'registerCalendarReminders']);
}

public function registerHooks() {
public function registerHooks(HookManager $hm,
EventDispatcherInterface $dispatcher,
IAppContainer $container,
IServerContainer $serverContainer) {
/** @var HookManager $hm */
$hm = $this->getContainer()->query(HookManager::class);
$hm->setup();
Expand Down Expand Up @@ -306,7 +309,7 @@ private function setupCalendarProvider(ICalendarManager $calendarManager,
}

public function registerCalendarManagerV2(ICalendarManagerV2 $calendarManager,
IAppContainer $container): void {
IAppContainer $container): void {
$calendarManager->register(function () use ($container, $calendarManager) {
$user = \OC::$server->getUserSession()->getUser();
if ($user !== null) {
Expand All @@ -319,9 +322,11 @@ public function registerCalendarManagerV2(ICalendarManagerV2 $calendarManager,
* @param ICalendarManagerV2 $calendarManager
* @param string $userId
*/
public function setupCalendarProviderV2(ICalendarManagerV2 $calendarManager, $userId) {
public function setupCalendarProviderV2(ICalendarManagerV2 $calendarManager,
IAppContainer $container,
$userId) {
/** @var CalendarManager $cm */
$cm = $this->getContainer()->query(CalendarManager::class);
$cm = $container->query(CalendarManager::class);
$cm->setupCalendarProviderV2($calendarManager, $userId);
}

Expand Down
24 changes: 12 additions & 12 deletions apps/dav/lib/CalDAV/CalendarImplV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ public function __construct(Calendar $calendar, array $calendarInfo,

/**
* @return string defining the technical unique key
* @since 19.0.0
* @since 21.0.0
*/
public function getKey(): string {
return (string) $this->calendarInfo['id'];
return $this->calendarInfo['id'];
}

/**
* In comparison to getKey() this function returns a human readable (maybe translated) name
* @return null|string
* @since 19.0.0
* @since 21.0.0
*/
public function getDisplayName(): string {
public function getDisplayName(): ?string {
return $this->calendarInfo['{DAV:}displayname'];
}

/**
* Calendar color
* @return null|string
* @since 19.0.0
* @since 21.0.0
*/
public function getDisplayColor(): string {
public function getDisplayColor(): ?string {
return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color'];
}

Expand All @@ -90,7 +90,7 @@ public function getDisplayColor(): string {
* @param integer|null $limit - limit number of search results
* @param integer|null $offset - offset for paging of search results
* @return array an array of events/journals/todos which are arrays of key-value-pairs
* @since 19.0.0
* @since 21.0.0
*/
public function search($pattern, array $searchProperties=[], array $options=[], int $limit = null, int $offset = null): array {
return $this->backend->search($this->calendarInfo, $pattern,
Expand All @@ -99,7 +99,7 @@ public function search($pattern, array $searchProperties=[], array $options=[],

/**
* @return bool
* @since 19.0.0
* @since 21.0.0
*/
public function isWriteable(): bool {
$permissions = $this->calendar->getACL();
Expand All @@ -125,7 +125,7 @@ public function isWriteable(): bool {
/**
* @param string $uri
* @return ICalendarObjectV2|null
* @since 19.0.0
* @since 21.0.0
*/
public function getByUri(string $uri): ?ICalendarObjectV2 {
if ($calendarObjectData = $this->backend->getCalendarObject($this->getKey(), $uri)) {
Expand All @@ -141,11 +141,11 @@ public function getByUri(string $uri): ?ICalendarObjectV2 {

/**
* @param VCalendar $vObject
* @return ICalendarObjectV2
* @return ICalendarObjectV2|null
* @throws BadRequest
* @since 19.0.0
* @since 21.0.0
*/
public function create(VCalendar $vObject): ICalendarObjectV2 {
public function create(VCalendar $vObject): ?ICalendarObjectV2 {
CalendarObjectImplV2::validateCalendarData($vObject);
$uuid = UUIDUtil::getUUID() . '.ics';
$this->backend->createCalendarObject($this->getKey(), $uuid, $vObject->serialize());
Expand Down
1 change: 0 additions & 1 deletion apps/dav/tests/unit/CalDAV/CalendarImplTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use Sabre\VObject\Component\VEvent;
use Sabre\VObject\ITip\Message;
use Sabre\VObject\Reader;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

/**
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/tests/unit/CalDAV/CalendarManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ public function testSetupCalendarProviderV2() {
$calendarManager = $this->createMock(ManagerV2::class);
$calendarManager->expects($this->at(0))
->method('registerCalendar')
->willReturnCallback(function() {
->willReturnCallback(function () {
$parameter = func_get_arg(0);
$this->assertInstanceOf(CalendarImplV2::class, $parameter);
$this->assertEquals(123, $parameter->getKey());
});

$calendarManager->expects($this->at(1))
->method('registerCalendar')
->willReturnCallback(function() {
->willReturnCallback(function () {
$parameter = func_get_arg(0);
$this->assertInstanceOf(CalendarImplV2::class, $parameter);
$this->assertEquals(456, $parameter->getKey());
Expand Down
10 changes: 6 additions & 4 deletions lib/private/Calendar/ManagerV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OCP\Calendar\ICalendarV2;
use OCP\Calendar\IManagerV2;
use OCP\Calendar\ICalendarObjectV2;

class ManagerV2 implements IManagerV2 {

Expand All @@ -48,15 +49,15 @@ class ManagerV2 implements IManagerV2 {
* ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]]
* @param integer|null $limit - limit number of search results
* @param integer|null $offset - offset for paging of search results
* @return array an array of events/journals/todos which are arrays of arrays of key-value-pairs
* @return ICalendarObjectV2[] an array of events/journals/todos which are arrays of arrays of key-value-pairs
* @since 13.0.0
*/
public function search($pattern, array $searchProperties=[], array $options=[], int $limit = null, int $offset=null): array {
$this->loadCalendars();
$result = [];
foreach($this->calendars as $calendar) {
foreach ($this->calendars as $calendar) {
$r = $calendar->search($pattern, $searchProperties, $options, $limit, $offset);
foreach($r as $o) {
foreach ($r as $o) {
$o['calendar-key'] = $calendar->getKey();
$result[] = $o;
}
Expand Down Expand Up @@ -133,7 +134,7 @@ public function clear(): void {
* loads all calendars
*/
private function loadCalendars() {
foreach($this->calendarLoaders as $callable) {
foreach ($this->calendarLoaders as $callable) {
$callable($this);
}
$this->calendarLoaders = [];
Expand All @@ -144,6 +145,7 @@ private function loadCalendars() {
*
* @param string $key
* @return ICalendarV2|null
* @since 21.0.0
*/
public function getCalendar(string $key): ?ICalendarV2 {
return isset($this->calendars[$key]) ? $this->calendars[$key] : null;
Expand Down
12 changes: 6 additions & 6 deletions lib/public/Calendar/ICalendarObjectV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,39 @@
* Interface ICalendarObjectV2
*
* @package OCP
* @since 20.0.0
* @since 21.0.0
*/
interface ICalendarObjectV2 {

/**
* @return string defining the technical unique key
* @since 20.0.0
* @since 21.0.0
*/
public function getCalendarKey(): string;

/**
* @return string calendar object unique URI
* @since 20.0.0
* @since 21.0.0
*/
public function getUri(): string;

/**
* @return VCalendar the calendar object data
* @since 20.0.0
* @since 21.0.0
*/
public function getVObject(): VCalendar;

/**
* Update calendar object data
*
* @param VCalendar $data
* @since 20.0.0
* @since 21.0.0
*/
public function update(VCalendar $data): void;

/**
* Delete calendar object
* @since 20.0.0
* @since 21.0.0
*/
public function delete(): void;
}
10 changes: 5 additions & 5 deletions lib/public/Calendar/ICalendarV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ public function getByUri(string $uri): ?ICalendarObjectV2;
* ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]]
* @param integer|null $limit - limit number of search results
* @param integer|null $offset - offset for paging of search results
* @return ICalendarObjectV2[]
* @since 20.0.0
* @return array an array of events/journals/todos which are arrays of key-value-pairs
* @since 19.0.0
*/
public function search(string $pattern, array $searchProperties=[], array $options=[], int $limit=null, int $offset=null): ?array;
public function search(string $pattern, array $searchProperties=[], array $options=[], int $limit=null, int $offset=null): array;

/**
* Create a new calendar object into a calendar. Accepts a VCalendar object for calendar data.
*
* @param VCalendar $vObject
* @return ICalendarObjectV2
* @return ICalendarObjectV2|null
* @since 20.0.0
*/
public function create(VCalendar $vObject): ICalendarObjectV2;
public function create(VCalendar $vObject): ?ICalendarObjectV2;
}
20 changes: 10 additions & 10 deletions lib/public/Calendar/IManagerV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@
*
* Events/Journals/Todos are expressed as instances of ICalendarObjectV2
*
* @since 20.0.0
* @since 21.0.0
*/
interface IManagerV2 {

/**
* Check if calendars are available
*
* @return bool true if enabled, false if not
* @since 20.0.0
* @since 21.0.0
*/
public function isEnabled(): bool;

/**
* Get all registered calendars
*
* @return ICalendarV2[]
* @since 20.0.0
* @since 21.0.0
*/
public function getCalendars(): array;

Expand All @@ -56,7 +56,7 @@ public function getCalendars(): array;
*
* @param string $key
* @return ICalendarV2|null
* @since 20.0.0
* @since 21.0.0
*/
public function getCalendar(string $key): ?ICalendarV2;

Expand All @@ -71,16 +71,16 @@ public function getCalendar(string $key): ?ICalendarV2;
* @param integer|null $limit - limit number of search results
* @param integer|null $offset - offset for paging of search results
* @return ICalendarObjectV2[]
* @since 20.0.0
* @since 21.0.0
*/
public function search(string $pattern, array $searchProperties=[], array $options=[], int $limit=null, int $offset=null): ?array;
public function search(string $pattern, array $searchProperties=[], array $options=[], int $limit=null, int $offset=null): array;

/**
* Registers a calendar
*
* @param ICalendarV2 $calendar
* @return void
* @since 20.0.0
* @since 21.0.0
*/
public function registerCalendar(ICalendarV2 $calendar): void;

Expand All @@ -89,7 +89,7 @@ public function registerCalendar(ICalendarV2 $calendar): void;
*
* @param ICalendarV2 $calendar
* @return void
* @since 20.0.0
* @since 21.0.0
*/
public function unregisterCalendar(ICalendarV2 $calendar): void;

Expand All @@ -99,14 +99,14 @@ public function unregisterCalendar(ICalendarV2 $calendar): void;
*
* @param Closure $callable
* @return void
* @since 20.0.0
* @since 21.0.0
*/
public function register(Closure $callable): void;

/**
* removes all registered calendar instances
* @return void
* @since 20.0.0
* @since 21.0.0
*/
public function clear(): void;
}
1 change: 0 additions & 1 deletion tests/lib/Calendar/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use Psr\Log\LoggerInterface;
use Sabre\VObject\Document;
use Sabre\VObject\Reader;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

/*
Expand Down

0 comments on commit 1ef937c

Please sign in to comment.