Skip to content

Commit

Permalink
prefer union types over ? for nullable parameter type declarations
Browse files Browse the repository at this point in the history
Signed-off-by: dartcafe <[email protected]>
  • Loading branch information
dartcafe committed Sep 20, 2024
1 parent 819bd86 commit f7ab8c0
Show file tree
Hide file tree
Showing 30 changed files with 51 additions and 51 deletions.
4 changes: 2 additions & 2 deletions lib/Controller/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ public function getSession(): JSONResponse {

/**
* Watch poll for updates
* @param ?int $offset only watch changes after this timestamp
* @param int|null $offset only watch changes after this timestamp
*/
#[PublicPage]
#[ShareTokenRequired]
public function watchPoll(?int $offset): JSONResponse {
public function watchPoll(int|null $offset): JSONResponse {
return $this->responseLong(fn () => [
'updates' => $this->watchService->watchUpdates($this->userSession->getShare()->getPollId(), $offset)
]);
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/WatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function __construct(
/**
* Watch poll for updates
* @param int $pollId poll id of poll to wqatch
* @param ?int $offset only watch changes after this timestamp
* @param int|null $offset only watch changes after this timestamp
*/
#[NoAdminRequired]
#[NoCSRFRequired]
public function watchPoll(int $pollId, ?int $offset): JSONResponse {
public function watchPoll(int $pollId, int|null $offset): JSONResponse {
return $this->responseLong(fn () => ['updates' => $this->watchService->watchUpdates($pollId, $offset)]);
}
}
2 changes: 1 addition & 1 deletion lib/Dashboard/PollWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getIconClass(): string {
return 'icon-polls-dark';
}

public function getUrl(): ?string {
public function getUrl(): string|null {
return $this->urlGenerator->linkToRouteAbsolute(AppConstants::APP_ID . '.page.index');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Comment extends EntityWithUser implements JsonSerializable {
public $id = null;
protected int $pollId = 0;
protected string $userId = '';
protected ?string $comment = null;
protected string|null $comment = null;
protected int $timestamp = 0;
protected int $deleted = 0;

Expand Down
6 changes: 3 additions & 3 deletions lib/Db/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class Log extends Entity implements JsonSerializable {
// schema columns
public $id = null;
protected int $pollId = 0;
protected ?string $userId = '';
protected ?string $displayName = '';
protected ?string $messageId = '';
protected string|null $userId = '';
protected string|null $displayName = '';
protected string|null $messageId = '';
protected int $created = 0;
protected int $processed = 0;

Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Option extends EntityWithUser implements JsonSerializable {
protected int $deleted = 0;

// joined columns
protected ?string $userVoteAnswer = '';
protected string|null $userVoteAnswer = '';
protected int $optionLimit = 0;
protected int $voteLimit = 0;
protected int $userCountYesVotes = 0;
Expand Down
10 changes: 5 additions & 5 deletions lib/Db/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class Poll extends EntityWithUser implements JsonSerializable {
public $id = null;
protected string $type = '';
protected string $title = '';
protected ?string $description = '';
protected ?string $owner = '';
protected string|null $description = '';
protected string|null $owner = '';
protected int $created = 0;
protected int $expire = 0;
protected int $deleted = 0;
Expand All @@ -146,15 +146,15 @@ class Poll extends EntityWithUser implements JsonSerializable {
protected int $hideBookedUp = 0;
protected int $useNo = 0;
protected int $lastInteraction = 0;
protected ?string $miscSettings = '';
protected string|null $miscSettings = '';

// joined columns
protected ?int $isCurrentUserLocked = 0;
protected int|null $isCurrentUserLocked = 0;
protected int $maxDate = 0;
protected int $minDate = 0;
protected string $userRole = self::ROLE_NONE;
protected string $shareToken = '';
protected ?string $groupShares = '';
protected string|null $groupShares = '';
protected int $countOptions = 0;

// subqueried columns
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/PollMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ protected function joinOptionsForMaxDate(IQueryBuilder &$qb, string $fromAlias):
/**
* Subquery for votes count
*/
protected function subQueryVotesCount(string $fromAlias, IParameter $currentUserId, ?IParameter $answerFilter = null): IQueryBuilder {
protected function subQueryVotesCount(string $fromAlias, IParameter $currentUserId, IParameter|null $answerFilter = null): IQueryBuilder {
$subAlias = 'user_vote_sub';

$subQuery = $this->db->getQueryBuilder();
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Preferences extends Entity implements JsonSerializable {
public $id = 0;
protected string $userId = '';
protected int $timestamp = 0;
protected ?string $preferences = '';
protected string|null $preferences = '';

public function __construct() {
$this->addType('timestamp', 'int');
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/PreferencesMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(IDBConnection $db) {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Preferences
*/
public function find(?string $userId): Preferences {
public function find(string|null $userId): Preferences {
$qb = $this->db->getQueryBuilder();

$qb->select('*')
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/QBMapperWithUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class QBMapperWithUser extends QBMapper {
public function __construct(
IDBConnection $db,
string $tableName,
?string $entityClass = null
string|null $entityClass = null
) {
parent::__construct($db, $tableName, $entityClass);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Db/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ class Share extends EntityWithUser implements JsonSerializable {
protected string $type = '';
protected string $label = '';
protected string $userId = '';
protected ?string $displayName = null;
protected ?string $emailAddress = null;
protected string|null $displayName = null;
protected string|null $emailAddress = null;
protected int $invitationSent = 0;
protected int $reminderSent = 0;
protected int $locked = 0;
protected ?string $miscSettings = '';
protected string|null $miscSettings = '';
protected int $deleted = 0;

// joined columns
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/TableManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function removeOrphaned(): void {
*
* @psalm-return list<string>
*/
public function deleteAllDuplicates(?IOutput $output = null): array {
public function deleteAllDuplicates(IOutput|null $output = null): array {
$messages = [];
foreach (TableSchema::UNIQUE_INDICES as $tableName => $index) {
$count = $this->deleteDuplicates($tableName, $index['columns']);
Expand Down Expand Up @@ -346,7 +346,7 @@ public function fixVotes(): void {
}
}

public function resetLastInteraction(?int $timestamp = null): array {
public function resetLastInteraction(int|null $timestamp = null): array {
$messages = [];
$timestamp = $timestamp ?? time();
$query = $this->connection->getQueryBuilder();
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/UserMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getParticipants(int $pollId): array {
return $users;
}

public function getUserFromUserBase(string $userId, ?int $pollId = null): User {
public function getUserFromUserBase(string $userId, int|null $pollId = null): User {
$user = $this->userManager->get($userId);
if ($user instanceof IUser) {
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Vote extends EntityWithUser implements JsonSerializable {
protected int $deleted = 0;

// joined columns
protected ?int $optionId = null;
protected int|null $optionId = null;

public function __construct() {
$this->addType('id', 'int');
Expand Down
8 changes: 4 additions & 4 deletions lib/Event/BaseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use OCP\EventDispatcher\Event;

abstract class BaseEvent extends Event {
protected ?string $activityObjectType = null;
protected ?string $eventId = null;
protected string|null $activityObjectType = null;
protected string|null $eventId = null;
protected array $activitySubjectParams = [];
protected bool $log = true;
protected Poll $poll;
Expand Down Expand Up @@ -73,7 +73,7 @@ public function getNotification(): array {
return [];
}

public function getActivityObjectType(): ?string {
public function getActivityObjectType(): string|null {
return $this->activityObjectType;
}

Expand All @@ -84,7 +84,7 @@ public function getActivityObjectId(): int {
return $this->eventObject->getId();
}

public function getActivityType(): ?string {
public function getActivityType(): string|null {
return $this->eventId;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Exceptions/ShareAlreadyExistsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
class ShareAlreadyExistsException extends Exception {
public function __construct(
string $e = 'Share already exists',
private ?Share $existingShare = null,
private Share|null $existingShare = null,
) {
parent::__construct($e, Http::STATUS_OK);
}
public function getShare(): ?Share {
public function getShare(): Share|null {
return $this->existingShare;
}
}
2 changes: 1 addition & 1 deletion lib/Helper/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function findShare(int $pollId, string $userId): Share {
return Server::get(ShareMapper::class)->findByPollAndUser($pollId, $userId);
}

public static function getL10N(?string $lang = null): IL10N {
public static function getL10N(string|null $lang = null): IL10N {
return Server::get(IFactory::class)->get(AppConstants::APP_ID, $lang);
}
public static function isAppEnabled(string $app): bool {
Expand Down
12 changes: 6 additions & 6 deletions lib/Model/CalendarEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class CalendarEvent implements \JsonSerializable {
protected array $occurrences = [];
protected bool $hasRRule;
protected array $rRule;
protected ?int $matchOccurrence = null;
protected int|null $matchOccurrence = null;
protected array $event;

public function __construct(
protected array $iCal,
protected ICalendar $calendar,
protected ?DateTimeImmutable $filterFrom = null,
protected ?DateTimeImmutable $filterTo = null,
protected ?DateTimeZone $timezone = null
protected DateTimeImmutable|null $filterFrom = null,
protected DateTimeImmutable|null $filterTo = null,
protected DateTimeZone|null $timezone = null
) {
$this->event = $this->iCal['objects'][0];
$this->hasRRule = isset($this->event['RRULE']);
Expand All @@ -42,7 +42,7 @@ public function __construct(
}

// Getters for calendar information
public function getCalendarName(): ?string {
public function getCalendarName(): string|null {
return $this->calendar->getDisplayName();
}

Expand All @@ -64,7 +64,7 @@ public function getCalendarUri(): string {
}
}

public function getDisplayColor(): ?string {
public function getDisplayColor(): string|null {
return $this->calendar->getDisplayColor();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Model/Mail/ReminderMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function addBodyText(): void {
));
}

private function getReminderReason() : ?string {
private function getReminderReason() : string|null {
if ($this->poll->getExpire()) {
return self::REASON_EXPIRATION;
} elseif ($this->poll->getType() === Poll::TYPE_DATE) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Model/Settings/AppSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private function stringToBool(string $value, bool $default): bool {
};
}

private function boolToString(?bool $value): string {
private function boolToString(bool|null $value): string {
if ($value) {
return 'yes';
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Provider/ActivityProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
) {
}

public function parse($language, IEvent $event, ?IEvent $previousEvent = null) {
public function parse($language, IEvent $event, IEvent|null $previousEvent = null) {
if ($event->getApp() !== AppConstants::APP_ID) {
throw new \InvalidArgumentException();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/CalendarService.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function getEvents(int $optionId): array {
return $events;
}

private function getCalendarFromEvent(array $event): ?ICalendar {
private function getCalendarFromEvent(array $event): ICalendar|null {
foreach ($this->calendars as $calendar) {
if ($calendar->getKey() === $event['calendar-key']) {
return $calendar;
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/LogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(
/**
* Log poll activity
*/
public function setLog(int $pollId, string $messageId, ?string $userId = null): void {
public function setLog(int $pollId, string $messageId, string|null $userId = null): void {
$this->log = new Log();
$this->log->setPollId($pollId);
$this->log->setCreated(time());
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function sendNotifications(): void {
}
}

public function sendInvitation(Share $share, ?SentResult &$sentResult = null): SentResult|null {
public function sendInvitation(Share $share, SentResult|null &$sentResult = null): SentResult|null {
foreach ($this->userMapper->getUserFromShare($share)->getMembers() as $recipient) {
$invitation = new InvitationMail($recipient->getId(), $share);

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/PollService.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function listForAdmin(): array {
* Update poll configuration
* @return Poll
*/
public function takeover(int $pollId, ?UserBase $targetUser = null): Poll {
public function takeover(int $pollId, UserBase|null $targetUser = null): Poll {
if (!$targetUser) {
$targetUser = $this->userSession->getUser();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ private function resolveGroup(Share $share): array {
* @param Share $share
* @param SentResult $sentResult to collect results
*/
public function sendInvitation(Share $share, ?SentResult &$sentResult = null): SentResult|null {
public function sendInvitation(Share $share, SentResult|null &$sentResult = null): SentResult|null {
if (in_array($share->getType(), [Share::TYPE_USER, Share::TYPE_ADMIN], true)) {
$this->notificationService->sendInvitation($share->getPollId(), $share->getUserId());
} elseif ($share->getType() === Share::TYPE_GROUP) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/VoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private function checkLimits(Option $option): void {
/**
* Set vote
*/
public function set(int $optionId, string $setTo): ?Vote {
public function set(int $optionId, string $setTo): Vote|null {
$option = $this->optionMapper->find($optionId);
$poll = $this->pollMapper->find($option->getPollId());
$poll->request(Poll::PERMISSION_VOTE_EDIT);
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/WatchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
/**
* Watch poll for updates
*/
public function watchUpdates(int $pollId, ?int $offset = null): array {
public function watchUpdates(int $pollId, int|null $offset = null): array {
$this->pollMapper->find($pollId)->request(Poll::PERMISSION_POLL_VIEW);

$start = time();
Expand Down
4 changes: 2 additions & 2 deletions lib/UserSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class UserSession {
public const CLIENT_TZ = 'ncPollsClientTimeZone';

public const TABLE = Share::TABLE;
protected ?UserBase $currentUser = null;
// protected ?Share $share = null;
protected UserBase|null $currentUser = null;
// protected Share|null $share = null;

/**
* @psalm-suppress PossiblyUnusedMethod
Expand Down

0 comments on commit f7ab8c0

Please sign in to comment.