Skip to content

Commit

Permalink
Fix psalm errors
Browse files Browse the repository at this point in the history
Signed-off-by: jld3103 <[email protected]>
  • Loading branch information
provokateurin committed Mar 30, 2023
1 parent eee0a76 commit c7ec317
Show file tree
Hide file tree
Showing 151 changed files with 351 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
use OCP\EventDispatcher\IEventListener;
use OCP\Log\Audit\CriticalActionPerformedEvent;

/**
* @template-implements IEventListener<CriticalActionPerformedEvent>
*/
class CriticalActionPerformedEventListener extends Action implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof CriticalActionPerformedEvent)) {
Expand Down
3 changes: 3 additions & 0 deletions apps/comments/lib/Listener/CommentsEntityEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* @template-implements IEventListener<CommentsEntityEvent>
*/
class CommentsEntityEventListener implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof CommentsEntityEvent)) {
Expand Down
3 changes: 3 additions & 0 deletions apps/comments/lib/Listener/LoadAdditionalScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

/**
* @template-implements IEventListener<LoadAdditionalScriptsEvent>
*/
class LoadAdditionalScripts implements IEventListener {
public function handle(Event $event): void {
if (!($event instanceof LoadAdditionalScriptsEvent)) {
Expand Down
3 changes: 3 additions & 0 deletions apps/comments/lib/Listener/LoadSidebarScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

/**
* @template-implements IEventListener<LoadSidebar>
*/
class LoadSidebarScripts implements IEventListener {

private ICommentsManager $commentsManager;
Expand Down
2 changes: 1 addition & 1 deletion apps/comments/lib/Search/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct(string $search,
string $authorName,
string $path) {
parent::__construct(
(int) $comment->getId(),
$comment->getId(),
$comment->getMessage()
/* @todo , [link to file] */
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
use Sabre\VObject\UUIDUtil;
use Throwable;

/**
* @template-implements IEventListener<ContactInteractedWithEvent>
*/
class ContactInteractionListener implements IEventListener {
private RecentContactMapper $mapper;
private CardSearchDao $cardSearchDao;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/EventComparisonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private function removeIfUnchanged(VEvent $filterEvent, array &$eventsToFilter):
*
* @param VCalendar $new
* @param VCalendar|null $old
* @return array<string, VEvent[]>
* @return array<string, VEvent[]|null>
*/
public function findModified(VCalendar $new, ?VCalendar $old): array {
$newEventComponents = $new->getComponents();
Expand Down
2 changes: 2 additions & 0 deletions apps/dav/lib/CalDAV/Proxy/ProxyMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
* Class ProxyMapper
*
* @package OCA\DAV\CalDAV\Proxy
*
* @template-extends QBMapper<Proxy>
*/
class ProxyMapper extends QBMapper {
public const PERMISSION_READ = 1;
Expand Down
1 change: 1 addition & 0 deletions apps/dav/lib/CalDAV/Reminder/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private function prepareNotificationSubject(INotification $notification): void {
$now = $this->timeFactory->getDateTime();
$title = $this->getTitleFromParameters($parameters);

/** @var \DateInterval|false $diff */
$diff = $startTime->diff($now);
if ($diff === false) {
return;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function schedule(Message $iTipMessage) {
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
return;
}
$recipientName = $iTipMessage->recipientName ? (string)$iTipMessage->recipientName : null;
$recipientName = $iTipMessage->recipientName;

$newEvents = $iTipMessage->message;
$oldEvents = $this->getVCalendar();
Expand Down
6 changes: 3 additions & 3 deletions apps/dav/lib/CardDAV/AddressBookImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __construct(
* @return string defining the technical unique key
* @since 5.0.0
*/
public function getKey() {
public function getKey(): string {
return $this->addressBookInfo['id'];
}

Expand Down Expand Up @@ -119,7 +119,7 @@ public function getDisplayName() {
* @since 5.0.0
*/
public function search($pattern, $searchProperties, $options) {
$results = $this->backend->search($this->getKey(), $pattern, $searchProperties, $options);
$results = $this->backend->search((int)$this->getKey(), $pattern, $searchProperties, $options);

$withTypes = \array_key_exists('types', $options) && $options['types'] === true;

Expand Down Expand Up @@ -234,7 +234,7 @@ protected function readCard($cardData) {
protected function createUid() {
do {
$uid = $this->getUid();
$contact = $this->backend->getContact($this->getKey(), $uid . '.vcf');
$contact = $this->backend->getContact((int)$this->getKey(), $uid . '.vcf');
} while (!empty($contact));

return $uid;
Expand Down
3 changes: 2 additions & 1 deletion apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -989,11 +989,12 @@ public function updateShares(IShareable $shareable, array $add, array $remove):
* @param string $pattern which should match within the $searchProperties
* @param array $searchProperties defines the properties within the query pattern should match
* @param array $options = array() to define the search behavior
* - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array
* - 'escape_like_param' - If set to false wildcards _ and % are not escaped, otherwise they are
* - 'limit' - Set a numeric limit for the search results
* - 'offset' - Set the offset for the limited search results
* - 'wildcard' - Whether the search should use wildcards
* @psalm-param array{escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options
* @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options
* @return array an array of contacts which are arrays of key-value-pairs
*/
public function search($addressBookId, $pattern, $searchProperties, $options = []): array {
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Comments/EntityTypeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct(
\Closure $childExistsFunction
) {
$name = trim($name);
if (empty($name) || !is_string($name)) {
if (empty($name)) {
throw new \InvalidArgumentException('"name" parameter must be non-empty string');
}
$this->name = $name;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function onReport($reportName, $report, $uri) {
try {
$resultFileIds = $this->processFilterRules($filterRules);
} catch (TagNotFoundException $e) {
throw new PreconditionFailed('Cannot filter by non-existing tag', 0, $e);
throw new PreconditionFailed('Cannot filter by non-existing tag');
}

// find sabre nodes by file id, restricted to the root node path
Expand Down
1 change: 1 addition & 0 deletions apps/dav/lib/Connector/Sabre/Principal.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ protected function searchUserPrincipals(array $searchProperties, $test = 'allof'

case 'allof':
default:
/** @var array<array-key, mixed> $results */
return array_values(array_intersect(...$results));
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/ShareTypeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static function xmlDeserialize(Reader $reader) {
*/
public function xmlSerialize(Writer $writer) {
foreach ($this->shareTypes as $shareType) {
$writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType);
$writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', (string)$shareType);
}
}
}
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/ShareeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function xmlSerialize(Writer $writer) {
$writer->startElement('{' . self::NS_NEXTCLOUD . '}sharee');
$writer->writeElement('{' . self::NS_NEXTCLOUD . '}id', $share->getSharedWith());
$writer->writeElement('{' . self::NS_NEXTCLOUD . '}display-name', $share->getSharedWithDisplayName());
$writer->writeElement('{' . self::NS_NEXTCLOUD . '}type', $share->getShareType());
$writer->writeElement('{' . self::NS_NEXTCLOUD . '}type', (string)$share->getShareType());
$writer->endElement();
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/DAV/CustomPropertiesBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class CustomPropertiesBackend implements BackendInterface {
/**
* Properties set by one user, readable by all others
*
* @var array[]
* @var string[]
*/
private const PUBLISHED_READ_ONLY_PROPERTIES = [
'{urn:ietf:params:xml:ns:caldav}calendar-availability',
Expand Down
6 changes: 3 additions & 3 deletions apps/dav/lib/Events/CalendarShareUpdatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
class CalendarShareUpdatedEvent extends Event {
private int $calendarId;

/** @var array{id: int, uri: string, '{http://calendarserver.org/ns/}getctag': string, '{http://sabredav.org/ns}sync-token': int, '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set': SupportedCalendarComponentSet, '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp': ScheduleCalendarTransp } */
/** @var array{id: int, uri: string, '{http://calendarserver.org/ns/}getctag': string, '{http://sabredav.org/ns}sync-token': int, '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set': SupportedCalendarComponentSet, '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp': ScheduleCalendarTransp, '{urn:ietf:params:xml:ns:caldav}calendar-timezone': ?string } */
private array $calendarData;

/** @var list<array{href: string, commonName: string, status: int, readOnly: bool, '{http://owncloud.org/ns}principal': string, '{http://owncloud.org/ns}group-share': bool}> */
Expand All @@ -54,7 +54,7 @@ class CalendarShareUpdatedEvent extends Event {
* CalendarShareUpdatedEvent constructor.
*
* @param int $calendarId
* @param array{id: int, uri: string, '{http://calendarserver.org/ns/}getctag': string, '{http://sabredav.org/ns}sync-token': int, '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set': SupportedCalendarComponentSet, '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp': ScheduleCalendarTransp } $calendarData
* @param array{id: int, uri: string, '{http://calendarserver.org/ns/}getctag': string, '{http://sabredav.org/ns}sync-token': int, '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set': SupportedCalendarComponentSet, '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp': ScheduleCalendarTransp, '{urn:ietf:params:xml:ns:caldav}calendar-timezone': ?string } $calendarData
* @param list<array{href: string, commonName: string, status: int, readOnly: bool, '{http://owncloud.org/ns}principal': string, '{http://owncloud.org/ns}group-share': bool}> $oldShares
* @param list<array{href: string, commonName: string, readOnly: bool}> $added
* @param list<string> $removed
Expand All @@ -81,7 +81,7 @@ public function getCalendarId(): int {
}

/**
* @return array{id: int, uri: string, '{http://calendarserver.org/ns/}getctag': string, '{http://sabredav.org/ns}sync-token': int, '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set': SupportedCalendarComponentSet, '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp': ScheduleCalendarTransp }
* @return array{id: int, uri: string, '{http://calendarserver.org/ns/}getctag': string, '{http://sabredav.org/ns}sync-token': int, '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set': SupportedCalendarComponentSet, '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp': ScheduleCalendarTransp, '{urn:ietf:params:xml:ns:caldav}calendar-timezone': ?string }
* @since 20.0.0
*/
public function getCalendarData(): array {
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Files/FileSearchBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ private function castValue(SearchPropertyDefinition $property, $value) {
return max(0, 0 + $value);
}
$date = \DateTime::createFromFormat(\DateTimeInterface::ATOM, (string)$value);
return ($date instanceof \DateTime && $date->getTimestamp() !== false) ? $date->getTimestamp() : 0;
return ($date instanceof \DateTime) ? $date->getTimestamp() : 0;
default:
return $value;
}
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/Listener/ActivityUpdaterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
use Throwable;
use function sprintf;

/**
* @template-implements IEventListener<CalendarCreatedEvent|CalendarUpdatedEvent|CalendarMovedToTrashEvent|CalendarRestoredEvent|CalendarDeletedEvent|CalendarObjectCreatedEvent|CalendarObjectUpdatedEvent|CalendarObjectMovedEvent|CalendarObjectMovedToTrashEvent|CalendarObjectRestoredEvent|CalendarObjectDeletedEvent>
*/
class ActivityUpdaterListener implements IEventListener {

/** @var ActivityBackend */
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/Listener/AddressbookListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
use Throwable;
use function sprintf;

/**
* @template-implements IEventListener<AddressBookCreatedEvent|AddressBookUpdatedEvent|AddressBookDeletedEvent|AddressBookShareUpdatedEvent>
*/
class AddressbookListener implements IEventListener {
/** @var ActivityBackend */
private $activityBackend;
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/Listener/BirthdayListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* @template-implements IEventListener<CardCreatedEvent|CardUpdatedEvent|CardDeletedEvent>
*/
class BirthdayListener implements IEventListener {
private BirthdayService $birthdayService;

Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/Listener/CalendarContactInteractionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
use function strpos;
use function substr;

/**
* @template-implements IEventListener<CalendarObjectCreatedEvent|CalendarObjectUpdatedEvent|CalendarShareUpdatedEvent>
*/
class CalendarContactInteractionListener implements IEventListener {
private const URI_USERS = 'principals/users/';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
use function strpos;

/**
* @template-implements IEventListener<\OCA\DAV\Events\CalendarDeletedEvent>
* @template-implements IEventListener<CalendarDeletedEvent>
*/
class CalendarDeletionDefaultUpdaterListener implements IEventListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
use Throwable;
use function sprintf;

/**
* @template-implements IEventListener<CalendarMovedToTrashEvent>
*/
class CalendarObjectReminderUpdaterListener implements IEventListener {

/** @var ReminderBackend */
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/Listener/CalendarPublicationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
use OCP\EventDispatcher\IEventListener;
use Psr\Log\LoggerInterface;

/**
* @template-implements IEventListener<CalendarPublishedEvent>
*/
class CalendarPublicationListener implements IEventListener {
private Backend $activityBackend;
private LoggerInterface $logger;
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/Listener/CalendarShareUpdateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
use OCP\EventDispatcher\IEventListener;
use Psr\Log\LoggerInterface;

/**
* @template-implements IEventListener<CalendarShareUpdatedEvent>
*/
class CalendarShareUpdateListener implements IEventListener {
private Backend $activityBackend;
private LoggerInterface $logger;
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/Listener/CardListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
use Throwable;
use function sprintf;

/**
* @template-implements IEventListener<CardCreatedEvent|CardUpdatedEvent|CardDeletedEvent>
*/
class CardListener implements IEventListener {
/** @var ActivityBackend */
private $activityBackend;
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/Listener/ClearPhotoCacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* @template-implements IEventListener<CardUpdatedEvent|CardDeletedEvent>
*/
class ClearPhotoCacheListener implements IEventListener {
private PhotoCache $photoCache;

Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/Listener/SubscriptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
use OCP\EventDispatcher\IEventListener;
use Psr\Log\LoggerInterface;

/**
* @template-implements IEventListener<SubscriptionCreatedEvent|SubscriptionDeletedEvent>
*/
class SubscriptionListener implements IEventListener {
private IJobList $jobList;
private RefreshWebcalService $refreshWebcalService;
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/Listener/TrustedServerRemovedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
use OCP\EventDispatcher\IEventListener;
use OCP\Federation\Events\TrustedServerRemovedEvent;

/**
* @template-implements IEventListener<TrustedServerRemovedEvent>
*/
class TrustedServerRemovedListener implements IEventListener {
private CardDavBackend $cardDavBackend;

Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/Listener/UserPreferenceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* @template-implements IEventListener<BeforePreferenceSetEvent|BeforePreferenceDeletedEvent>
*/
class UserPreferenceListener implements IEventListener {

protected IJobList $jobList;
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AppleProvisioningPlugin extends ServerPlugin {
protected $userSession;

/**
* @var \OC_Defaults
* @var \OCA\Theming\ThemingDefaults
*/
protected $themingDefaults;

Expand All @@ -77,7 +77,7 @@ class AppleProvisioningPlugin extends ServerPlugin {
public function __construct(
IUserSession $userSession,
IURLGenerator $urlGenerator,
\OC_Defaults $themingDefaults,
\OCA\Theming\ThemingDefaults $themingDefaults,
IRequest $request,
IL10N $l10n,
\Closure $uuidClosure
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Search/ContactsSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
return SearchResult::paginated(
$this->getName(),
$formattedResults,
$query->getCursor() + count($formattedResults)
(int)$query->getCursor() + count($formattedResults)
);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Search/EventsSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function search(IUser $user,
return SearchResult::paginated(
$this->getName(),
$formattedResults,
$query->getCursor() + count($formattedResults)
(int)$query->getCursor() + count($formattedResults)
);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Search/TasksSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function search(IUser $user,
return SearchResult::paginated(
$this->getName(),
$formattedResults,
$query->getCursor() + count($formattedResults)
(int)$query->getCursor() + count($formattedResults)
);
}

Expand Down
Loading

0 comments on commit c7ec317

Please sign in to comment.