diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2021-10-19 18:11:53 +0300 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2021-11-23 11:28:56 +0300 |
commit | 113756db30fcbffe9e90b54c29e78dee0676109f (patch) | |
tree | 8eeaad5ea33957cd2c9ef37dbb05c5e779c48216 | |
parent | 129de6079e53e0ac9dbf9d7c25ec1670ae0ff572 (diff) |
Fix ArrayAccess and JsonSerializable return types
First round of modifications for PHP 8.1
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
34 files changed, 79 insertions, 74 deletions
diff --git a/apps/files_external/lib/Lib/Auth/AuthMechanism.php b/apps/files_external/lib/Lib/Auth/AuthMechanism.php index f676957794d..210dd705723 100644 --- a/apps/files_external/lib/Lib/Auth/AuthMechanism.php +++ b/apps/files_external/lib/Lib/Auth/AuthMechanism.php @@ -90,10 +90,8 @@ class AuthMechanism implements \JsonSerializable { /** * Serialize into JSON for client-side JS - * - * @return array */ - public function jsonSerialize() { + public function jsonSerialize(): array { $data = $this->jsonSerializeDefinition(); $data += $this->jsonSerializeIdentifier(); diff --git a/apps/files_external/lib/Lib/Backend/Backend.php b/apps/files_external/lib/Lib/Backend/Backend.php index a6e63eb30d1..021d208aed3 100644 --- a/apps/files_external/lib/Lib/Backend/Backend.php +++ b/apps/files_external/lib/Lib/Backend/Backend.php @@ -137,10 +137,8 @@ class Backend implements \JsonSerializable { /** * Serialize into JSON for client-side JS - * - * @return array */ - public function jsonSerialize() { + public function jsonSerialize(): array { $data = $this->jsonSerializeDefinition(); $data += $this->jsonSerializeIdentifier(); diff --git a/apps/files_external/lib/Lib/DefinitionParameter.php b/apps/files_external/lib/Lib/DefinitionParameter.php index fbfbbfd4686..6b081d5a089 100644 --- a/apps/files_external/lib/Lib/DefinitionParameter.php +++ b/apps/files_external/lib/Lib/DefinitionParameter.php @@ -167,10 +167,8 @@ class DefinitionParameter implements \JsonSerializable { /** * Serialize into JSON for client-side JS - * - * @return string */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'value' => $this->getText(), 'flags' => $this->getFlags(), diff --git a/apps/files_external/lib/Lib/StorageConfig.php b/apps/files_external/lib/Lib/StorageConfig.php index 97b72005018..26ba483b00e 100644 --- a/apps/files_external/lib/Lib/StorageConfig.php +++ b/apps/files_external/lib/Lib/StorageConfig.php @@ -396,10 +396,8 @@ class StorageConfig implements \JsonSerializable { /** * Serialize config to JSON - * - * @return array */ - public function jsonSerialize() { + public function jsonSerialize(): array { $result = []; if (!is_null($this->id)) { $result['id'] = $this->id; diff --git a/apps/theming/lib/Service/JSDataService.php b/apps/theming/lib/Service/JSDataService.php index a6e5d6f8e36..1c4d138a764 100644 --- a/apps/theming/lib/Service/JSDataService.php +++ b/apps/theming/lib/Service/JSDataService.php @@ -50,7 +50,7 @@ class JSDataService implements \JsonSerializable { $this->appConfig = $appConfig; } - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'name' => $this->themingDefaults->getName(), 'url' => $this->themingDefaults->getBaseUrl(), diff --git a/apps/user_status/lib/Service/JSDataService.php b/apps/user_status/lib/Service/JSDataService.php index 6d83591ab2f..c08643ec64f 100644 --- a/apps/user_status/lib/Service/JSDataService.php +++ b/apps/user_status/lib/Service/JSDataService.php @@ -49,7 +49,7 @@ class JSDataService implements \JsonSerializable { $this->statusService = $statusService; } - public function jsonSerialize() { + public function jsonSerialize(): array { $user = $this->userSession->getUser(); if ($user === null) { diff --git a/core/Command/Broadcast/Test.php b/core/Command/Broadcast/Test.php index 91050725e17..86cd30e4b4c 100644 --- a/core/Command/Broadcast/Test.php +++ b/core/Command/Broadcast/Test.php @@ -87,7 +87,7 @@ class Test extends Command { ]; } - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'description' => 'this is a test event', ]; diff --git a/lib/private/Accounts/Account.php b/lib/private/Accounts/Account.php index 1e4189f2b35..540d15cd4b9 100644 --- a/lib/private/Accounts/Account.php +++ b/lib/private/Accounts/Account.php @@ -104,7 +104,8 @@ class Account implements IAccount { return $result; } - public function jsonSerialize() { + /** @return IAccountPropertyCollection[]|IAccountProperty[] */ + public function jsonSerialize(): array { return $this->properties; } diff --git a/lib/private/Accounts/AccountProperty.php b/lib/private/Accounts/AccountProperty.php index 0e6356e9e92..4b7f2b0c04c 100644 --- a/lib/private/Accounts/AccountProperty.php +++ b/lib/private/Accounts/AccountProperty.php @@ -54,7 +54,7 @@ class AccountProperty implements IAccountProperty { $this->verificationData = $verificationData; } - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'name' => $this->getName(), 'value' => $this->getValue(), diff --git a/lib/private/Accounts/AccountPropertyCollection.php b/lib/private/Accounts/AccountPropertyCollection.php index 3aed76d8746..091c5734218 100644 --- a/lib/private/Accounts/AccountPropertyCollection.php +++ b/lib/private/Accounts/AccountPropertyCollection.php @@ -102,7 +102,7 @@ class AccountPropertyCollection implements IAccountPropertyCollection { return $this; } - public function jsonSerialize() { + public function jsonSerialize(): array { return [$this->collectionName => $this->properties]; } diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php index a95fd208155..c67500bcaa4 100644 --- a/lib/private/AppFramework/Http/Request.php +++ b/lib/private/AppFramework/Http/Request.php @@ -199,6 +199,7 @@ class Request implements \ArrayAccess, \Countable, IRequest { * @param string $offset * @return mixed */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return isset($this->items['parameters'][$offset]) ? $this->items['parameters'][$offset] @@ -210,7 +211,7 @@ class Request implements \ArrayAccess, \Countable, IRequest { * @param string $offset * @param mixed $value */ - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { throw new \RuntimeException('You cannot change the contents of the request object'); } @@ -218,7 +219,7 @@ class Request implements \ArrayAccess, \Countable, IRequest { * @see offsetExists * @param string $offset */ - public function offsetUnset($offset) { + public function offsetUnset($offset): void { throw new \RuntimeException('You cannot change the contents of the request object'); } diff --git a/lib/private/AppFramework/Utility/SimpleContainer.php b/lib/private/AppFramework/Utility/SimpleContainer.php index c38dbadf0a9..598c66b6aba 100644 --- a/lib/private/AppFramework/Utility/SimpleContainer.php +++ b/lib/private/AppFramework/Utility/SimpleContainer.php @@ -197,13 +197,15 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { /** * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::has */ - public function offsetExists($id) { + public function offsetExists($id): bool { return $this->container->offsetExists($id); } /** * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get + * @return mixed */ + #[\ReturnTypeWillChange] public function offsetGet($id) { return $this->container->offsetGet($id); } @@ -211,14 +213,14 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { /** * @deprecated 20.0.0 use \OCP\IContainer::registerService */ - public function offsetSet($id, $service) { + public function offsetSet($id, $service): void { $this->container->offsetSet($id, $service); } /** * @deprecated 20.0.0 */ - public function offsetUnset($offset) { + public function offsetUnset($offset): void { $this->container->offsetUnset($offset); } } diff --git a/lib/private/Authentication/Token/DefaultToken.php b/lib/private/Authentication/Token/DefaultToken.php index 5a008586a90..b649fdbb6af 100644 --- a/lib/private/Authentication/Token/DefaultToken.php +++ b/lib/private/Authentication/Token/DefaultToken.php @@ -121,7 +121,7 @@ class DefaultToken extends Entity implements INamedToken { return parent::getPassword(); } - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'id' => $this->id, 'name' => $this->name, diff --git a/lib/private/Authentication/Token/PublicKeyToken.php b/lib/private/Authentication/Token/PublicKeyToken.php index 3351c767ce3..d060fe14103 100644 --- a/lib/private/Authentication/Token/PublicKeyToken.php +++ b/lib/private/Authentication/Token/PublicKeyToken.php @@ -138,7 +138,7 @@ class PublicKeyToken extends Entity implements INamedToken, IWipeableToken { return parent::getPassword(); } - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'id' => $this->id, 'name' => $this->name, diff --git a/lib/private/Cache/CappedMemoryCache.php b/lib/private/Cache/CappedMemoryCache.php index 408c3935ffb..584a53f0ff2 100644 --- a/lib/private/Cache/CappedMemoryCache.php +++ b/lib/private/Cache/CappedMemoryCache.php @@ -63,19 +63,23 @@ class CappedMemoryCache implements ICache, \ArrayAccess { return true; } - public function offsetExists($offset) { + public function offsetExists($offset): bool { return $this->hasKey($offset); } + /** + * @return mixed + */ + #[\ReturnTypeWillChange] public function &offsetGet($offset) { return $this->cache[$offset]; } - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { $this->set($offset, $value); } - public function offsetUnset($offset) { + public function offsetUnset($offset): void { $this->remove($offset); } diff --git a/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php index 5acafed2fda..3f917854aac 100644 --- a/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php +++ b/lib/private/Contacts/ContactsMenu/Actions/LinkAction.php @@ -106,10 +106,7 @@ class LinkAction implements ILinkAction { return $this->appId; } - /** - * @return array - */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'title' => $this->name, 'icon' => $this->icon, diff --git a/lib/private/EventDispatcher/GenericEventWrapper.php b/lib/private/EventDispatcher/GenericEventWrapper.php index 55e23d2ff7f..3574bc8bb83 100644 --- a/lib/private/EventDispatcher/GenericEventWrapper.php +++ b/lib/private/EventDispatcher/GenericEventWrapper.php @@ -100,19 +100,23 @@ class GenericEventWrapper extends GenericEvent { return $this->event->hasArgument($key); } + /** + * @return mixed + */ + #[\ReturnTypeWillChange] public function offsetGet($key) { return $this->event->offsetGet($key); } - public function offsetSet($key, $value) { - return $this->event->offsetSet($key, $value); + public function offsetSet($key, $value): void { + $this->event->offsetSet($key, $value); } - public function offsetUnset($key) { - return $this->event->offsetUnset($key); + public function offsetUnset($key): void { + $this->event->offsetUnset($key); } - public function offsetExists($key) { + public function offsetExists($key): bool { return $this->event->offsetExists($key); } diff --git a/lib/private/Files/Cache/CacheEntry.php b/lib/private/Files/Cache/CacheEntry.php index 156f075c2d0..12f0273fb6e 100644 --- a/lib/private/Files/Cache/CacheEntry.php +++ b/lib/private/Files/Cache/CacheEntry.php @@ -37,18 +37,22 @@ class CacheEntry implements ICacheEntry { $this->data = $data; } - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { $this->data[$offset] = $value; } - public function offsetExists($offset) { + public function offsetExists($offset): bool { return isset($this->data[$offset]); } - public function offsetUnset($offset) { + public function offsetUnset($offset): void { unset($this->data[$offset]); } + /** + * @return mixed + */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { if (isset($this->data[$offset])) { return $this->data[$offset]; diff --git a/lib/private/Files/FileInfo.php b/lib/private/Files/FileInfo.php index 8a8de6e4c19..2f361fc051d 100644 --- a/lib/private/Files/FileInfo.php +++ b/lib/private/Files/FileInfo.php @@ -104,18 +104,22 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { $this->rawSize = $this->data['size'] ?? 0; } - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { $this->data[$offset] = $value; } - public function offsetExists($offset) { + public function offsetExists($offset): bool { return isset($this->data[$offset]); } - public function offsetUnset($offset) { + public function offsetUnset($offset): void { unset($this->data[$offset]); } + /** + * @return mixed + */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { if ($offset === 'type') { return $this->getType(); diff --git a/lib/private/FullTextSearch/Model/IndexDocument.php b/lib/private/FullTextSearch/Model/IndexDocument.php index a1648ab6e2a..3078f12c465 100644 --- a/lib/private/FullTextSearch/Model/IndexDocument.php +++ b/lib/private/FullTextSearch/Model/IndexDocument.php @@ -963,10 +963,8 @@ class IndexDocument implements IIndexDocument, JsonSerializable { /** * @since 15.0.0 - * - * @return array */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'id' => $this->getId(), 'providerId' => $this->getProviderId(), diff --git a/lib/private/FullTextSearch/Model/SearchRequestSimpleQuery.php b/lib/private/FullTextSearch/Model/SearchRequestSimpleQuery.php index 9c9ac71efa9..d6bfe6d9102 100644 --- a/lib/private/FullTextSearch/Model/SearchRequestSimpleQuery.php +++ b/lib/private/FullTextSearch/Model/SearchRequestSimpleQuery.php @@ -168,10 +168,9 @@ final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonS /** - * @return array|mixed * @since 17.0.0 */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'type' => $this->getType(), 'field' => $this->getField(), diff --git a/lib/private/L10N/L10NString.php b/lib/private/L10N/L10NString.php index 33ccc4b1409..de4bc38d744 100644 --- a/lib/private/L10N/L10NString.php +++ b/lib/private/L10N/L10NString.php @@ -82,11 +82,7 @@ class L10NString implements \JsonSerializable { return vsprintf($text, $this->parameters); } - - /** - * @return string - */ - public function jsonSerialize() { + public function jsonSerialize(): string { return $this->__toString(); } } diff --git a/lib/private/Memcache/Cache.php b/lib/private/Memcache/Cache.php index 95213c16849..1d54a705098 100644 --- a/lib/private/Memcache/Cache.php +++ b/lib/private/Memcache/Cache.php @@ -78,19 +78,23 @@ abstract class Cache implements \ArrayAccess, \OCP\ICache { //implement the ArrayAccess interface - public function offsetExists($offset) { + public function offsetExists($offset): bool { return $this->hasKey($offset); } - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { $this->set($offset, $value); } + /** + * @return mixed + */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->get($offset); } - public function offsetUnset($offset) { + public function offsetUnset($offset): void { $this->remove($offset); } } diff --git a/lib/private/Session/CryptoSessionData.php b/lib/private/Session/CryptoSessionData.php index 94ad8f90dcf..2e3bd46da5b 100644 --- a/lib/private/Session/CryptoSessionData.php +++ b/lib/private/Session/CryptoSessionData.php @@ -195,6 +195,7 @@ class CryptoSessionData implements \ArrayAccess, ISession { * @param mixed $offset * @return mixed */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->get($offset); } @@ -203,14 +204,14 @@ class CryptoSessionData implements \ArrayAccess, ISession { * @param mixed $offset * @param mixed $value */ - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { $this->set($offset, $value); } /** * @param mixed $offset */ - public function offsetUnset($offset) { + public function offsetUnset($offset): void { $this->remove($offset); } } diff --git a/lib/private/Session/Session.php b/lib/private/Session/Session.php index b9497983fbb..affba322bec 100644 --- a/lib/private/Session/Session.php +++ b/lib/private/Session/Session.php @@ -55,6 +55,7 @@ abstract class Session implements \ArrayAccess, ISession { * @param mixed $offset * @return mixed */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->get($offset); } @@ -63,14 +64,14 @@ abstract class Session implements \ArrayAccess, ISession { * @param mixed $offset * @param mixed $value */ - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { $this->set($offset, $value); } /** * @param mixed $offset */ - public function offsetUnset($offset) { + public function offsetUnset($offset): void { $this->remove($offset); } diff --git a/lib/public/AppFramework/Services/InitialStateProvider.php b/lib/public/AppFramework/Services/InitialStateProvider.php index c317fad3f5d..dbc48653792 100644 --- a/lib/public/AppFramework/Services/InitialStateProvider.php +++ b/lib/public/AppFramework/Services/InitialStateProvider.php @@ -42,7 +42,9 @@ abstract class InitialStateProvider implements \JsonSerializable { /** * @since 21.0.0 + * @return mixed */ + #[\ReturnTypeWillChange] final public function jsonSerialize() { return $this->getData(); } diff --git a/lib/public/Dashboard/Model/WidgetSetting.php b/lib/public/Dashboard/Model/WidgetSetting.php index c456c63f4f5..fce59a4350b 100644 --- a/lib/public/Dashboard/Model/WidgetSetting.php +++ b/lib/public/Dashboard/Model/WidgetSetting.php @@ -230,10 +230,8 @@ final class WidgetSetting implements JsonSerializable { /** * @since 15.0.0 * @deprecated 20.0.0 - * - * @return array */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'name' => $this->getName(), 'title' => $this->getTitle(), diff --git a/lib/public/Dashboard/Model/WidgetSetup.php b/lib/public/Dashboard/Model/WidgetSetup.php index 1cc8d9ff561..f3e09dcc71b 100644 --- a/lib/public/Dashboard/Model/WidgetSetup.php +++ b/lib/public/Dashboard/Model/WidgetSetup.php @@ -261,10 +261,8 @@ final class WidgetSetup implements JsonSerializable { /** * @since 15.0.0 * @deprecated 20.0.0 - * - * @return array */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'size' => $this->getSizes(), 'menu' => $this->getMenuEntries(), diff --git a/lib/public/Dashboard/Model/WidgetTemplate.php b/lib/public/Dashboard/Model/WidgetTemplate.php index e6f9742fed7..3521960c303 100644 --- a/lib/public/Dashboard/Model/WidgetTemplate.php +++ b/lib/public/Dashboard/Model/WidgetTemplate.php @@ -312,10 +312,8 @@ final class WidgetTemplate implements JsonSerializable { /** * @since 15.0.0 * @deprecated 20.0.0 - * - * @return array */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'icon' => $this->getIcon(), 'css' => $this->getCss(), diff --git a/lib/public/DirectEditing/ATemplate.php b/lib/public/DirectEditing/ATemplate.php index c38fc898dab..53aff0d40ff 100644 --- a/lib/public/DirectEditing/ATemplate.php +++ b/lib/public/DirectEditing/ATemplate.php @@ -57,9 +57,8 @@ abstract class ATemplate implements JsonSerializable { /** * @since 18.0.0 - * @return array|mixed */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'id' => $this->getId(), 'title' => $this->getTitle(), diff --git a/lib/public/EventDispatcher/GenericEvent.php b/lib/public/EventDispatcher/GenericEvent.php index e78ae1827a1..1ba1cc6da14 100644 --- a/lib/public/EventDispatcher/GenericEvent.php +++ b/lib/public/EventDispatcher/GenericEvent.php @@ -156,7 +156,9 @@ class GenericEvent extends Event implements ArrayAccess, IteratorAggregate { * @link https://php.net/manual/en/arrayaccess.offsetget.php * @since 18.0.0 * @deprecated 22.0.0 + * @return mixed */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->arguments[$offset]; } diff --git a/lib/public/Files/Template/Template.php b/lib/public/Files/Template/Template.php index 50d8b406be9..d71ef3b3655 100644 --- a/lib/public/Files/Template/Template.php +++ b/lib/public/Files/Template/Template.php @@ -69,7 +69,7 @@ final class Template implements \JsonSerializable { /** * @since 21.0.0 */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'templateType' => $this->templateType, 'templateId' => $this->templateId, diff --git a/lib/public/Files/Template/TemplateFileCreator.php b/lib/public/Files/Template/TemplateFileCreator.php index 7be45e68ef9..26edf585869 100644 --- a/lib/public/Files/Template/TemplateFileCreator.php +++ b/lib/public/Files/Template/TemplateFileCreator.php @@ -106,7 +106,7 @@ final class TemplateFileCreator implements \JsonSerializable { /** * @since 21.0.0 */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'app' => $this->appId, 'label' => $this->actionName, diff --git a/tests/lib/InitialStateServiceTest.php b/tests/lib/InitialStateServiceTest.php index 2a23774baf1..db4c98b20cf 100644 --- a/tests/lib/InitialStateServiceTest.php +++ b/tests/lib/InitialStateServiceTest.php @@ -54,7 +54,7 @@ class InitialStateServiceTest extends TestCase { [23], [2.3], [new class implements JsonSerializable { - public function jsonSerialize() { + public function jsonSerialize(): int { return 3; } }], |