Fix ArrayAccess and JsonSerializable return types

First round of modifications for PHP 8.1

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/29432/head
Côme Chilliet 2021-10-19 17:11:53 +07:00
parent 129de6079e
commit 113756db30
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
34 changed files with 79 additions and 74 deletions

@ -90,10 +90,8 @@ class AuthMechanism implements \JsonSerializable {
/** /**
* Serialize into JSON for client-side JS * Serialize into JSON for client-side JS
*
* @return array
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
$data = $this->jsonSerializeDefinition(); $data = $this->jsonSerializeDefinition();
$data += $this->jsonSerializeIdentifier(); $data += $this->jsonSerializeIdentifier();

@ -137,10 +137,8 @@ class Backend implements \JsonSerializable {
/** /**
* Serialize into JSON for client-side JS * Serialize into JSON for client-side JS
*
* @return array
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
$data = $this->jsonSerializeDefinition(); $data = $this->jsonSerializeDefinition();
$data += $this->jsonSerializeIdentifier(); $data += $this->jsonSerializeIdentifier();

@ -167,10 +167,8 @@ class DefinitionParameter implements \JsonSerializable {
/** /**
* Serialize into JSON for client-side JS * Serialize into JSON for client-side JS
*
* @return string
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'value' => $this->getText(), 'value' => $this->getText(),
'flags' => $this->getFlags(), 'flags' => $this->getFlags(),

@ -396,10 +396,8 @@ class StorageConfig implements \JsonSerializable {
/** /**
* Serialize config to JSON * Serialize config to JSON
*
* @return array
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
$result = []; $result = [];
if (!is_null($this->id)) { if (!is_null($this->id)) {
$result['id'] = $this->id; $result['id'] = $this->id;

@ -50,7 +50,7 @@ class JSDataService implements \JsonSerializable {
$this->appConfig = $appConfig; $this->appConfig = $appConfig;
} }
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'name' => $this->themingDefaults->getName(), 'name' => $this->themingDefaults->getName(),
'url' => $this->themingDefaults->getBaseUrl(), 'url' => $this->themingDefaults->getBaseUrl(),

@ -49,7 +49,7 @@ class JSDataService implements \JsonSerializable {
$this->statusService = $statusService; $this->statusService = $statusService;
} }
public function jsonSerialize() { public function jsonSerialize(): array {
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
if ($user === null) { if ($user === null) {

@ -87,7 +87,7 @@ class Test extends Command {
]; ];
} }
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'description' => 'this is a test event', 'description' => 'this is a test event',
]; ];

@ -104,7 +104,8 @@ class Account implements IAccount {
return $result; return $result;
} }
public function jsonSerialize() { /** @return IAccountPropertyCollection[]|IAccountProperty[] */
public function jsonSerialize(): array {
return $this->properties; return $this->properties;
} }

@ -54,7 +54,7 @@ class AccountProperty implements IAccountProperty {
$this->verificationData = $verificationData; $this->verificationData = $verificationData;
} }
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'name' => $this->getName(), 'name' => $this->getName(),
'value' => $this->getValue(), 'value' => $this->getValue(),

@ -102,7 +102,7 @@ class AccountPropertyCollection implements IAccountPropertyCollection {
return $this; return $this;
} }
public function jsonSerialize() { public function jsonSerialize(): array {
return [$this->collectionName => $this->properties]; return [$this->collectionName => $this->properties];
} }

@ -199,6 +199,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
* @param string $offset * @param string $offset
* @return mixed * @return mixed
*/ */
#[\ReturnTypeWillChange]
public function offsetGet($offset) { public function offsetGet($offset) {
return isset($this->items['parameters'][$offset]) return isset($this->items['parameters'][$offset])
? $this->items['parameters'][$offset] ? $this->items['parameters'][$offset]
@ -210,7 +211,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
* @param string $offset * @param string $offset
* @param mixed $value * @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'); throw new \RuntimeException('You cannot change the contents of the request object');
} }
@ -218,7 +219,7 @@ class Request implements \ArrayAccess, \Countable, IRequest {
* @see offsetExists * @see offsetExists
* @param string $offset * @param string $offset
*/ */
public function offsetUnset($offset) { public function offsetUnset($offset): void {
throw new \RuntimeException('You cannot change the contents of the request object'); throw new \RuntimeException('You cannot change the contents of the request object');
} }

@ -197,13 +197,15 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer {
/** /**
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::has * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::has
*/ */
public function offsetExists($id) { public function offsetExists($id): bool {
return $this->container->offsetExists($id); return $this->container->offsetExists($id);
} }
/** /**
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
* @return mixed
*/ */
#[\ReturnTypeWillChange]
public function offsetGet($id) { public function offsetGet($id) {
return $this->container->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 * @deprecated 20.0.0 use \OCP\IContainer::registerService
*/ */
public function offsetSet($id, $service) { public function offsetSet($id, $service): void {
$this->container->offsetSet($id, $service); $this->container->offsetSet($id, $service);
} }
/** /**
* @deprecated 20.0.0 * @deprecated 20.0.0
*/ */
public function offsetUnset($offset) { public function offsetUnset($offset): void {
$this->container->offsetUnset($offset); $this->container->offsetUnset($offset);
} }
} }

@ -121,7 +121,7 @@ class DefaultToken extends Entity implements INamedToken {
return parent::getPassword(); return parent::getPassword();
} }
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'id' => $this->id, 'id' => $this->id,
'name' => $this->name, 'name' => $this->name,

@ -138,7 +138,7 @@ class PublicKeyToken extends Entity implements INamedToken, IWipeableToken {
return parent::getPassword(); return parent::getPassword();
} }
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'id' => $this->id, 'id' => $this->id,
'name' => $this->name, 'name' => $this->name,

@ -63,19 +63,23 @@ class CappedMemoryCache implements ICache, \ArrayAccess {
return true; return true;
} }
public function offsetExists($offset) { public function offsetExists($offset): bool {
return $this->hasKey($offset); return $this->hasKey($offset);
} }
/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function &offsetGet($offset) { public function &offsetGet($offset) {
return $this->cache[$offset]; return $this->cache[$offset];
} }
public function offsetSet($offset, $value) { public function offsetSet($offset, $value): void {
$this->set($offset, $value); $this->set($offset, $value);
} }
public function offsetUnset($offset) { public function offsetUnset($offset): void {
$this->remove($offset); $this->remove($offset);
} }

@ -106,10 +106,7 @@ class LinkAction implements ILinkAction {
return $this->appId; return $this->appId;
} }
/** public function jsonSerialize(): array {
* @return array
*/
public function jsonSerialize() {
return [ return [
'title' => $this->name, 'title' => $this->name,
'icon' => $this->icon, 'icon' => $this->icon,

@ -100,19 +100,23 @@ class GenericEventWrapper extends GenericEvent {
return $this->event->hasArgument($key); return $this->event->hasArgument($key);
} }
/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($key) { public function offsetGet($key) {
return $this->event->offsetGet($key); return $this->event->offsetGet($key);
} }
public function offsetSet($key, $value) { public function offsetSet($key, $value): void {
return $this->event->offsetSet($key, $value); $this->event->offsetSet($key, $value);
} }
public function offsetUnset($key) { public function offsetUnset($key): void {
return $this->event->offsetUnset($key); $this->event->offsetUnset($key);
} }
public function offsetExists($key) { public function offsetExists($key): bool {
return $this->event->offsetExists($key); return $this->event->offsetExists($key);
} }

@ -37,18 +37,22 @@ class CacheEntry implements ICacheEntry {
$this->data = $data; $this->data = $data;
} }
public function offsetSet($offset, $value) { public function offsetSet($offset, $value): void {
$this->data[$offset] = $value; $this->data[$offset] = $value;
} }
public function offsetExists($offset) { public function offsetExists($offset): bool {
return isset($this->data[$offset]); return isset($this->data[$offset]);
} }
public function offsetUnset($offset) { public function offsetUnset($offset): void {
unset($this->data[$offset]); unset($this->data[$offset]);
} }
/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset) { public function offsetGet($offset) {
if (isset($this->data[$offset])) { if (isset($this->data[$offset])) {
return $this->data[$offset]; return $this->data[$offset];

@ -104,18 +104,22 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
$this->rawSize = $this->data['size'] ?? 0; $this->rawSize = $this->data['size'] ?? 0;
} }
public function offsetSet($offset, $value) { public function offsetSet($offset, $value): void {
$this->data[$offset] = $value; $this->data[$offset] = $value;
} }
public function offsetExists($offset) { public function offsetExists($offset): bool {
return isset($this->data[$offset]); return isset($this->data[$offset]);
} }
public function offsetUnset($offset) { public function offsetUnset($offset): void {
unset($this->data[$offset]); unset($this->data[$offset]);
} }
/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset) { public function offsetGet($offset) {
if ($offset === 'type') { if ($offset === 'type') {
return $this->getType(); return $this->getType();

@ -963,10 +963,8 @@ class IndexDocument implements IIndexDocument, JsonSerializable {
/** /**
* @since 15.0.0 * @since 15.0.0
*
* @return array
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'id' => $this->getId(), 'id' => $this->getId(),
'providerId' => $this->getProviderId(), 'providerId' => $this->getProviderId(),

@ -168,10 +168,9 @@ final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonS
/** /**
* @return array|mixed
* @since 17.0.0 * @since 17.0.0
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'type' => $this->getType(), 'type' => $this->getType(),
'field' => $this->getField(), 'field' => $this->getField(),

@ -82,11 +82,7 @@ class L10NString implements \JsonSerializable {
return vsprintf($text, $this->parameters); return vsprintf($text, $this->parameters);
} }
public function jsonSerialize(): string {
/**
* @return string
*/
public function jsonSerialize() {
return $this->__toString(); return $this->__toString();
} }
} }

@ -78,19 +78,23 @@ abstract class Cache implements \ArrayAccess, \OCP\ICache {
//implement the ArrayAccess interface //implement the ArrayAccess interface
public function offsetExists($offset) { public function offsetExists($offset): bool {
return $this->hasKey($offset); return $this->hasKey($offset);
} }
public function offsetSet($offset, $value) { public function offsetSet($offset, $value): void {
$this->set($offset, $value); $this->set($offset, $value);
} }
/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset) { public function offsetGet($offset) {
return $this->get($offset); return $this->get($offset);
} }
public function offsetUnset($offset) { public function offsetUnset($offset): void {
$this->remove($offset); $this->remove($offset);
} }
} }

@ -195,6 +195,7 @@ class CryptoSessionData implements \ArrayAccess, ISession {
* @param mixed $offset * @param mixed $offset
* @return mixed * @return mixed
*/ */
#[\ReturnTypeWillChange]
public function offsetGet($offset) { public function offsetGet($offset) {
return $this->get($offset); return $this->get($offset);
} }
@ -203,14 +204,14 @@ class CryptoSessionData implements \ArrayAccess, ISession {
* @param mixed $offset * @param mixed $offset
* @param mixed $value * @param mixed $value
*/ */
public function offsetSet($offset, $value) { public function offsetSet($offset, $value): void {
$this->set($offset, $value); $this->set($offset, $value);
} }
/** /**
* @param mixed $offset * @param mixed $offset
*/ */
public function offsetUnset($offset) { public function offsetUnset($offset): void {
$this->remove($offset); $this->remove($offset);
} }
} }

@ -55,6 +55,7 @@ abstract class Session implements \ArrayAccess, ISession {
* @param mixed $offset * @param mixed $offset
* @return mixed * @return mixed
*/ */
#[\ReturnTypeWillChange]
public function offsetGet($offset) { public function offsetGet($offset) {
return $this->get($offset); return $this->get($offset);
} }
@ -63,14 +64,14 @@ abstract class Session implements \ArrayAccess, ISession {
* @param mixed $offset * @param mixed $offset
* @param mixed $value * @param mixed $value
*/ */
public function offsetSet($offset, $value) { public function offsetSet($offset, $value): void {
$this->set($offset, $value); $this->set($offset, $value);
} }
/** /**
* @param mixed $offset * @param mixed $offset
*/ */
public function offsetUnset($offset) { public function offsetUnset($offset): void {
$this->remove($offset); $this->remove($offset);
} }

@ -42,7 +42,9 @@ abstract class InitialStateProvider implements \JsonSerializable {
/** /**
* @since 21.0.0 * @since 21.0.0
* @return mixed
*/ */
#[\ReturnTypeWillChange]
final public function jsonSerialize() { final public function jsonSerialize() {
return $this->getData(); return $this->getData();
} }

@ -230,10 +230,8 @@ final class WidgetSetting implements JsonSerializable {
/** /**
* @since 15.0.0 * @since 15.0.0
* @deprecated 20.0.0 * @deprecated 20.0.0
*
* @return array
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'name' => $this->getName(), 'name' => $this->getName(),
'title' => $this->getTitle(), 'title' => $this->getTitle(),

@ -261,10 +261,8 @@ final class WidgetSetup implements JsonSerializable {
/** /**
* @since 15.0.0 * @since 15.0.0
* @deprecated 20.0.0 * @deprecated 20.0.0
*
* @return array
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'size' => $this->getSizes(), 'size' => $this->getSizes(),
'menu' => $this->getMenuEntries(), 'menu' => $this->getMenuEntries(),

@ -312,10 +312,8 @@ final class WidgetTemplate implements JsonSerializable {
/** /**
* @since 15.0.0 * @since 15.0.0
* @deprecated 20.0.0 * @deprecated 20.0.0
*
* @return array
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'icon' => $this->getIcon(), 'icon' => $this->getIcon(),
'css' => $this->getCss(), 'css' => $this->getCss(),

@ -57,9 +57,8 @@ abstract class ATemplate implements JsonSerializable {
/** /**
* @since 18.0.0 * @since 18.0.0
* @return array|mixed
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'id' => $this->getId(), 'id' => $this->getId(),
'title' => $this->getTitle(), 'title' => $this->getTitle(),

@ -156,7 +156,9 @@ class GenericEvent extends Event implements ArrayAccess, IteratorAggregate {
* @link https://php.net/manual/en/arrayaccess.offsetget.php * @link https://php.net/manual/en/arrayaccess.offsetget.php
* @since 18.0.0 * @since 18.0.0
* @deprecated 22.0.0 * @deprecated 22.0.0
* @return mixed
*/ */
#[\ReturnTypeWillChange]
public function offsetGet($offset) { public function offsetGet($offset) {
return $this->arguments[$offset]; return $this->arguments[$offset];
} }

@ -69,7 +69,7 @@ final class Template implements \JsonSerializable {
/** /**
* @since 21.0.0 * @since 21.0.0
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'templateType' => $this->templateType, 'templateType' => $this->templateType,
'templateId' => $this->templateId, 'templateId' => $this->templateId,

@ -106,7 +106,7 @@ final class TemplateFileCreator implements \JsonSerializable {
/** /**
* @since 21.0.0 * @since 21.0.0
*/ */
public function jsonSerialize() { public function jsonSerialize(): array {
return [ return [
'app' => $this->appId, 'app' => $this->appId,
'label' => $this->actionName, 'label' => $this->actionName,

@ -54,7 +54,7 @@ class InitialStateServiceTest extends TestCase {
[23], [23],
[2.3], [2.3],
[new class implements JsonSerializable { [new class implements JsonSerializable {
public function jsonSerialize() { public function jsonSerialize(): int {
return 3; return 3;
} }
}], }],