Skip to content

Commit ea0608f

Browse files
committed
refactor: add PHP 8.3 types to BC-safe class constants
PHP 8.3 allows class constants to declare a type. Adopt it where doing so cannot break third-party apps. Typing an inheritable constant is a hard BC break: a subclass that redeclares it untyped fails to load with "Type of C::FOO must be compatible with P::FOO of type string". Changes are therefore limited to constants that cannot be redeclared by a subclass: - private const (not inherited) - final public/protected const - constants declared in a final class or an enum Interface constants, trait constants, and public/protected constants in non-final (including abstract) classes are left untyped, as is all of lib/public (OCP) and lib/unstable (NCU). One review-requested exception: the public OBJECT_PREFIX/OBJECT_SUFFIX constants of the app-internal CalDAV import helpers (TextImporter, XmlImporter) are typed as well; these classes are not public API and have no subclasses. Only string, int and array are used. float is avoided because it would silently coerce an int literal and change === comparisons. No constant name or value is modified: every changed line adds only the type token, so runtime behaviour is unchanged. Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
1 parent 1e92a39 commit ea0608f

130 files changed

Lines changed: 249 additions & 249 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/contactsinteraction/lib/Migration/FixVcardCategory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class FixVcardCategory implements IRepairStep {
2222

23-
private const CARDS_PER_BATCH = 5000;
23+
private const int CARDS_PER_BATCH = 5000;
2424

2525
public function __construct(
2626
private readonly IDBConnection $connection,

apps/dav/lib/BackgroundJob/CleanupOrphanedChildrenJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CleanupOrphanedChildrenJob extends QueuedJob {
2323
public const ARGUMENT_PARENT_ID = 'parentId';
2424
public const ARGUMENT_LOG_MESSAGE = 'logMessage';
2525

26-
private const BATCH_SIZE = 1000;
26+
private const int BATCH_SIZE = 1000;
2727

2828
public function __construct(
2929
ITimeFactory $time,

apps/dav/lib/BackgroundJob/FederatedCalendarPeriodicSyncJob.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Psr\Log\LoggerInterface;
1919

2020
class FederatedCalendarPeriodicSyncJob extends TimedJob {
21-
private const DOWNLOAD_LIMIT = 500;
21+
private const int DOWNLOAD_LIMIT = 500;
2222

2323
public function __construct(
2424
ITimeFactory $time,

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
177177
*
178178
* @see \OCP\Calendar\ICalendarQuery
179179
*/
180-
private const INDEXED_PROPERTIES = [
180+
private const array INDEXED_PROPERTIES = [
181181
'CATEGORIES',
182182
'COMMENT',
183183
'DESCRIPTION',
@@ -191,7 +191,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
191191
];
192192

193193
/** @var array parameters to index */
194-
private const INDEXED_PARAMETERS = [
194+
private const array INDEXED_PARAMETERS = [
195195
'ATTENDEE' => ['CN'],
196196
'ORGANIZER' => ['CN'],
197197
];

apps/dav/lib/CalDAV/CalendarImpl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function __construct(
4141
) {
4242
}
4343

44-
private const DAV_PROPERTY_USER_ADDRESS = '{http://sabredav.org/ns}email-address';
45-
private const DAV_PROPERTY_USER_ADDRESSES = '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set';
44+
private const string DAV_PROPERTY_USER_ADDRESS = '{http://sabredav.org/ns}email-address';
45+
private const string DAV_PROPERTY_USER_ADDRESSES = '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set';
4646

4747
/**
4848
* @return string defining the technical unique key

apps/dav/lib/CalDAV/EventComparisonService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class EventComparisonService {
1717

1818
/** @var string[] */
19-
private const EVENT_DIFF = [
19+
private const array EVENT_DIFF = [
2020
'RECURRENCE-ID',
2121
'RRULE',
2222
'SEQUENCE',

apps/dav/lib/CalDAV/Federation/FederatedCalendar.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
class FederatedCalendar implements ICalendar, IProperties, IMultiGet {
2525

26-
private const CALENDAR_TYPE = CalDavBackend::CALENDAR_TYPE_FEDERATED;
27-
private const DAV_PROPERTY_CALENDAR_LABEL = '{DAV:}displayname';
28-
private const DAV_PROPERTY_CALENDAR_COLOR = '{http://apple.com/ns/ical/}calendar-color';
26+
private const int CALENDAR_TYPE = CalDavBackend::CALENDAR_TYPE_FEDERATED;
27+
private const string DAV_PROPERTY_CALENDAR_LABEL = '{DAV:}displayname';
28+
private const string DAV_PROPERTY_CALENDAR_COLOR = '{http://apple.com/ns/ical/}calendar-color';
2929

3030
private string $principalUri;
3131
private string $calendarUri;

apps/dav/lib/CalDAV/Federation/FederatedCalendarSyncService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class FederatedCalendarSyncService extends ASyncService {
2424
use TTransactional;
2525

26-
private const SYNC_TOKEN_PREFIX = 'http://sabre.io/ns/sync/';
26+
private const string SYNC_TOKEN_PREFIX = 'http://sabre.io/ns/sync/';
2727

2828
public function __construct(
2929
IClientService $clientService,

apps/dav/lib/CalDAV/ICSExportPlugin/ICSExportPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class ICSExportPlugin extends \Sabre\CalDAV\ICSExportPlugin {
2323
/** @var string */
24-
private const DEFAULT_REFRESH_INTERVAL = 'PT4H';
24+
private const string DEFAULT_REFRESH_INTERVAL = 'PT4H';
2525

2626
/**
2727
* ICSExportPlugin constructor.

apps/dav/lib/CalDAV/Import/TextImporter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
class TextImporter {
1414

15-
public const OBJECT_PREFIX = 'BEGIN:VCALENDAR' . PHP_EOL;
16-
public const OBJECT_SUFFIX = PHP_EOL . 'END:VCALENDAR';
17-
private const COMPONENT_TYPES = ['VEVENT', 'VTODO', 'VJOURNAL', 'VTIMEZONE'];
15+
public const string OBJECT_PREFIX = 'BEGIN:VCALENDAR' . PHP_EOL;
16+
public const string OBJECT_SUFFIX = PHP_EOL . 'END:VCALENDAR';
17+
private const array COMPONENT_TYPES = ['VEVENT', 'VTODO', 'VJOURNAL', 'VTIMEZONE'];
1818

1919
private bool $analyzed = false;
2020
private array $structure = ['VCALENDAR' => [], 'VEVENT' => [], 'VTODO' => [], 'VJOURNAL' => [], 'VTIMEZONE' => []];

0 commit comments

Comments
 (0)