Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix ArrayAccess and JsonSerializable return types
First round of modifications for PHP 8.1

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Nov 23, 2021
1 parent 129de60 commit 113756d
Show file tree
Hide file tree
Showing 34 changed files with 79 additions and 74 deletions.
4 changes: 1 addition & 3 deletions apps/files_external/lib/Lib/Auth/AuthMechanism.php
Expand Up @@ -90,10 +90,8 @@ public function setScheme($scheme) {

/**
* Serialize into JSON for client-side JS
*
* @return array
*/
public function jsonSerialize() {
public function jsonSerialize(): array {
$data = $this->jsonSerializeDefinition();
$data += $this->jsonSerializeIdentifier();

Expand Down
4 changes: 1 addition & 3 deletions apps/files_external/lib/Lib/Backend/Backend.php
Expand Up @@ -137,10 +137,8 @@ public function setLegacyAuthMechanismCallback(callable $callback) {

/**
* Serialize into JSON for client-side JS
*
* @return array
*/
public function jsonSerialize() {
public function jsonSerialize(): array {
$data = $this->jsonSerializeDefinition();
$data += $this->jsonSerializeIdentifier();

Expand Down
4 changes: 1 addition & 3 deletions apps/files_external/lib/Lib/DefinitionParameter.php
Expand Up @@ -167,10 +167,8 @@ public function setTooltip(string $tooltip) {

/**
* Serialize into JSON for client-side JS
*
* @return string
*/
public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'value' => $this->getText(),
'flags' => $this->getFlags(),
Expand Down
4 changes: 1 addition & 3 deletions apps/files_external/lib/Lib/StorageConfig.php
Expand Up @@ -396,10 +396,8 @@ public function setType($type) {

/**
* Serialize config to JSON
*
* @return array
*/
public function jsonSerialize() {
public function jsonSerialize(): array {
$result = [];
if (!is_null($this->id)) {
$result['id'] = $this->id;
Expand Down
2 changes: 1 addition & 1 deletion apps/theming/lib/Service/JSDataService.php
Expand Up @@ -50,7 +50,7 @@ public function __construct(
$this->appConfig = $appConfig;
}

public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'name' => $this->themingDefaults->getName(),
'url' => $this->themingDefaults->getBaseUrl(),
Expand Down
2 changes: 1 addition & 1 deletion apps/user_status/lib/Service/JSDataService.php
Expand Up @@ -49,7 +49,7 @@ public function __construct(IUserSession $userSession,
$this->statusService = $statusService;
}

public function jsonSerialize() {
public function jsonSerialize(): array {
$user = $this->userSession->getUser();

if ($user === null) {
Expand Down
2 changes: 1 addition & 1 deletion core/Command/Broadcast/Test.php
Expand Up @@ -87,7 +87,7 @@ public function getUids(): array {
];
}

public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'description' => 'this is a test event',
];
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Accounts/Account.php
Expand Up @@ -104,7 +104,8 @@ public function getFilteredProperties(string $scope = null, string $verified = n
return $result;
}

public function jsonSerialize() {
/** @return IAccountPropertyCollection[]|IAccountProperty[] */
public function jsonSerialize(): array {
return $this->properties;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Accounts/AccountProperty.php
Expand Up @@ -54,7 +54,7 @@ public function __construct(string $name, string $value, string $scope, string $
$this->verificationData = $verificationData;
}

public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'name' => $this->getName(),
'value' => $this->getValue(),
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Accounts/AccountPropertyCollection.php
Expand Up @@ -102,7 +102,7 @@ public function removePropertyByValue(string $value): IAccountPropertyCollection
return $this;
}

public function jsonSerialize() {
public function jsonSerialize(): array {
return [$this->collectionName => $this->properties];
}

Expand Down
5 changes: 3 additions & 2 deletions lib/private/AppFramework/Http/Request.php
Expand Up @@ -199,6 +199,7 @@ public function offsetExists($offset): bool {
* @param string $offset
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset) {
return isset($this->items['parameters'][$offset])
? $this->items['parameters'][$offset]
Expand All @@ -210,15 +211,15 @@ public function offsetGet($offset) {
* @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');
}

/**
* @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');
}

Expand Down
8 changes: 5 additions & 3 deletions lib/private/AppFramework/Utility/SimpleContainer.php
Expand Up @@ -197,28 +197,30 @@ protected function sanitizeName($name) {
/**
* @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);
}

/**
* @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);
}
}
2 changes: 1 addition & 1 deletion lib/private/Authentication/Token/DefaultToken.php
Expand Up @@ -121,7 +121,7 @@ public function getPassword() {
return parent::getPassword();
}

public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'id' => $this->id,
'name' => $this->name,
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Authentication/Token/PublicKeyToken.php
Expand Up @@ -138,7 +138,7 @@ public function getPassword() {
return parent::getPassword();
}

public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'id' => $this->id,
'name' => $this->name,
Expand Down
10 changes: 7 additions & 3 deletions lib/private/Cache/CappedMemoryCache.php
Expand Up @@ -63,19 +63,23 @@ public function clear($prefix = '') {
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);
}

Expand Down
5 changes: 1 addition & 4 deletions lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
Expand Up @@ -106,10 +106,7 @@ public function getAppId(): string {
return $this->appId;
}

/**
* @return array
*/
public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'title' => $this->name,
'icon' => $this->icon,
Expand Down
14 changes: 9 additions & 5 deletions lib/private/EventDispatcher/GenericEventWrapper.php
Expand Up @@ -100,19 +100,23 @@ public function hasArgument($key) {
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);
}

Expand Down
10 changes: 7 additions & 3 deletions lib/private/Files/Cache/CacheEntry.php
Expand Up @@ -37,18 +37,22 @@ public function __construct(array $data) {
$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];
Expand Down
10 changes: 7 additions & 3 deletions lib/private/Files/FileInfo.php
Expand Up @@ -104,18 +104,22 @@ public function __construct($path, $storage, $internalPath, $data, $mount, $owne
$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();
Expand Down
4 changes: 1 addition & 3 deletions lib/private/FullTextSearch/Model/IndexDocument.php
Expand Up @@ -963,10 +963,8 @@ public function __destruct() {

/**
* @since 15.0.0
*
* @return array
*/
public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'id' => $this->getId(),
'providerId' => $this->getProviderId(),
Expand Down
Expand Up @@ -168,10 +168,9 @@ public function addValueBool(bool $value): ISearchRequestSimpleQuery {


/**
* @return array|mixed
* @since 17.0.0
*/
public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'type' => $this->getType(),
'field' => $this->getField(),
Expand Down
6 changes: 1 addition & 5 deletions lib/private/L10N/L10NString.php
Expand Up @@ -82,11 +82,7 @@ public function __toString(): string {
return vsprintf($text, $this->parameters);
}


/**
* @return string
*/
public function jsonSerialize() {
public function jsonSerialize(): string {
return $this->__toString();
}
}
10 changes: 7 additions & 3 deletions lib/private/Memcache/Cache.php
Expand Up @@ -78,19 +78,23 @@ abstract public function clear($prefix = '');

//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);
}
}
5 changes: 3 additions & 2 deletions lib/private/Session/CryptoSessionData.php
Expand Up @@ -195,6 +195,7 @@ public function offsetExists($offset): bool {
* @param mixed $offset
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset) {
return $this->get($offset);
}
Expand All @@ -203,14 +204,14 @@ public function offsetGet($offset) {
* @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);
}
}

0 comments on commit 113756d

Please sign in to comment.