Skip to content

Commit

Permalink
[!!!][TASK] Resolve most #[ReturnTypeWillChange] attributes
Browse files Browse the repository at this point in the history
Sets return types for most classes that implement
PHP SPL classes. Only "mixed" return types are not
set: That would be hard breaking for extensions
that support both core v11 and v12, since it is not
PHP 7.4 compatible. Those places are marked with
an @todo to switch to mixed in v13.

Resolves: #98035
Releases: main
Change-Id: Icd62a69270a6718c8356108e55a0729779609c53
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75310
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
Crell authored and sbuerk committed Sep 26, 2022
1 parent c1df89b commit 847a963
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 242 deletions.
5 changes: 0 additions & 5 deletions Build/phpstan/phpstan-baseline.neon
Expand Up @@ -135,11 +135,6 @@ parameters:
count: 1
path: ../../typo3/sysext/backend/Classes/Tree/Renderer/UnorderedListTreeRenderer.php

-
message: "#^Method TYPO3\\\\CMS\\\\Backend\\\\Tree\\\\TreeNodeCollection\\:\\:asort\\(\\) should return bool but return statement is missing\\.$#"
count: 1
path: ../../typo3/sysext/backend/Classes/Tree/TreeNodeCollection.php

-
message: "#^Variable \\$columnsConfiguration in empty\\(\\) always exists and is not falsy\\.$#"
count: 1
Expand Down
Expand Up @@ -29,11 +29,8 @@ public function addModuleData(DataProviderInterface $module, ModuleData $moduleD

/**
* @param object $object
* @return string
* @todo Set return type to string as breaking patch in v12.
*/
#[\ReturnTypeWillChange]
public function getHash($object)
public function getHash($object): string
{
if ($object instanceof ModuleInterface) {
return $object->getIdentifier();
Expand Down
14 changes: 8 additions & 6 deletions typo3/sysext/backend/Classes/Controller/MfaAjaxController.php
Expand Up @@ -157,14 +157,16 @@ protected function initializeUser(int $userId, string $tableName): AbstractUserA
*/
protected function getResponseData(bool $success, string $message, ?AbstractUserAuthentication $user = null): array
{
$flashMessageQueue = new FlashMessageQueue('backend');
$flashMessageQueue->enqueue(
new FlashMessage(
$message,
$this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_mfa.xlf:ajax.' . ($success ? 'success' : 'error'))
)
);
$payload = [
'success' => $success,
'status' => (new FlashMessageQueue('backend'))->enqueue(
new FlashMessage(
$message,
$this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_mfa.xlf:ajax.' . ($success ? 'success' : 'error'))
)
),
'status' => $flashMessageQueue,
];

if ($user !== null) {
Expand Down
12 changes: 5 additions & 7 deletions typo3/sysext/backend/Classes/Tree/SortedTreeNodeCollection.php
Expand Up @@ -26,7 +26,7 @@ class SortedTreeNodeCollection extends TreeNodeCollection
/**
* Checks if a specific node is inside the collection
*
* @param \TYPO3\CMS\Backend\Tree\TreeNode $node
* @param TreeNode $node
* @return bool
*/
public function contains(TreeNode $node)
Expand All @@ -37,7 +37,7 @@ public function contains(TreeNode $node)
/**
* Returns the offset key of given node
*
* @param \TYPO3\CMS\Backend\Tree\TreeNode $node
* @param TreeNode $node
* @return int
*/
protected function offsetOf(TreeNode $node)
Expand All @@ -48,7 +48,7 @@ protected function offsetOf(TreeNode $node)
/**
* Binary search that returns the offset of a given node
*
* @param \TYPO3\CMS\Backend\Tree\TreeNode $node
* @param TreeNode $node
* @param int $start
* @param int $end
* @return int
Expand Down Expand Up @@ -89,11 +89,9 @@ protected function normalize()
/**
* Adds a node to the internal list in a sorted approach
*
* @param \TYPO3\CMS\Backend\Tree\TreeNode $node
* @todo: Set return type to void in v12 as breaking patch and drop #[\ReturnTypeWillChange]
* @param TreeNode $node
*/
#[\ReturnTypeWillChange]
public function append($node)
public function append($node): void
{
parent::append($node);
$this->asort();
Expand Down
14 changes: 4 additions & 10 deletions typo3/sysext/backend/Classes/Tree/TreeNodeCollection.php
Expand Up @@ -43,12 +43,11 @@ public function __construct(array $data = [])
* Sorts the internal nodes array
*
* @param int $flags Optional parameter, ignored. Added to be compatible with asort method signature in PHP 8.
* @todo: Set return type to void in v12 as breaking patch and drop #[\ReturnTypeWillChange]
*/
#[\ReturnTypeWillChange]
public function asort($flags = SORT_REGULAR)
public function asort($flags = SORT_REGULAR): bool
{
$this->uasort([$this, 'nodeCompare']);
return true;
}

/**
Expand All @@ -67,11 +66,8 @@ public function nodeCompare(TreeNode $node, TreeNode $otherNode)

/**
* Returns class state to be serialized.
*
* @todo: Change signature to __serialize(): array in v12
*/
#[\ReturnTypeWillChange]
public function __serialize()
public function __serialize(): array
{
return $this->toArray();
}
Expand All @@ -80,10 +76,8 @@ public function __serialize()
* Fills the current node with the given serialized information
*
* @throws Exception if the deserialized object type is not identical to the current one
* @todo: Change signature to __unserialize(array $arrayRepresentation): void in v12
*/
#[\ReturnTypeWillChange]
public function __unserialize($arrayRepresentation)
public function __unserialize($arrayRepresentation): void
{
if ($arrayRepresentation['serializeClassName'] !== static::class) {
throw new Exception('Deserialized object type is not identical!', 1294586647);
Expand Down
34 changes: 7 additions & 27 deletions typo3/sysext/core/Classes/Collection/AbstractRecordCollection.php
Expand Up @@ -95,12 +95,10 @@ public function __construct()
}

/**
* (PHP 5 >= 5.1.0)
* Return the current element
*
* @link https://php.net/manual/en/iterator.current.php
* @return mixed Can return any type.
* @todo: Set return type to mixed when PHP >= 8.0 is required and drop #[\ReturnTypeWillChange]
* @todo: Set return type to mixed in v13
*/
#[\ReturnTypeWillChange]
public function current()
Expand All @@ -109,25 +107,18 @@ public function current()
}

/**
* (PHP 5 >= 5.1.0)
* Move forward to next element
*
* @link https://php.net/manual/en/iterator.next.php
* @todo: Set return type to void in v12 as breaking patch and drop #[\ReturnTypeWillChange]
*/
#[\ReturnTypeWillChange]
public function next()
public function next(): void
{
$this->storage->next();
}

/**
* (PHP 5 >= 5.1.0)
* Return the key of the current element
*
* @link https://php.net/manual/en/iterator.key.php
* @return int|string 0 on failure.
* @todo: Set return type to mixed when PHP >= 8.0 is required and drop #[\ReturnTypeWillChange]
* @todo: Set return type to mixed in v13
*/
#[\ReturnTypeWillChange]
public function key()
Expand All @@ -137,28 +128,21 @@ public function key()
}

/**
* (PHP 5 >= 5.1.0)
* Checks if current position is valid
*
* @link https://php.net/manual/en/iterator.valid.php
* @return bool The return value will be casted to boolean and then evaluated.
* @todo: Set return type to bool in v12 as breaking patch and drop #[\ReturnTypeWillChange]
* @return bool The return value will be cast to boolean and then evaluated.
*/
#[\ReturnTypeWillChange]
public function valid()
public function valid(): bool
{
return $this->storage->valid();
}

/**
* (PHP 5 >= 5.1.0)
* Rewind the Iterator to the first element
*
* @link https://php.net/manual/en/iterator.rewind.php
* @todo: Set return type to void in v12 as breaking patch and drop #[\ReturnTypeWillChange]
*/
#[\ReturnTypeWillChange]
public function rewind()
public function rewind(): void
{
$this->storage->rewind();
}
Expand All @@ -182,15 +166,11 @@ public function __unserialize(array $arrayRepresentation): void
}

/**
* (PHP 5 >= 5.1.0)
* Count elements of an object
*
* @link https://php.net/manual/en/countable.count.php
* @return int The custom count as an integer.
* @todo: Set return type to in in v12 as breaking patch and drop #[\ReturnTypeWillChange]
*/
#[\ReturnTypeWillChange]
public function count()
public function count(): int
{
return $this->storage->count();
}
Expand Down
13 changes: 6 additions & 7 deletions typo3/sysext/core/Classes/Log/LogRecord.php
Expand Up @@ -17,6 +17,8 @@

/**
* Log record
*
* @todo: Consider declaring this DTO final
*/
class LogRecord implements \ArrayAccess
{
Expand Down Expand Up @@ -290,10 +292,8 @@ public function toArray()
* Checks whether an offset exists, required by ArrayAccess interface
*
* @param mixed $offset
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
public function offsetExists($offset): bool
{
$offsetExists = false;
if (in_array($offset, $this->gettableProperties, true) && isset($this->{$offset})) {
Expand All @@ -307,6 +307,7 @@ public function offsetExists($offset)
*
* @param mixed $offset
* @return mixed
* @todo: Set return type to mixed in v13
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
Expand All @@ -323,8 +324,7 @@ public function offsetGet($offset)
* @param mixed $offset
* @param mixed $value
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
if (in_array($offset, $this->settableProperties, true)) {
$this->{$offset} = $offset;
Expand All @@ -336,8 +336,7 @@ public function offsetSet($offset, $value)
*
* @param mixed $offset
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
if (in_array($offset, $this->settableProperties, true)) {
unset($this->{$offset});
Expand Down
8 changes: 2 additions & 6 deletions typo3/sysext/core/Classes/Messaging/FlashMessageQueue.php
Expand Up @@ -60,11 +60,8 @@ public function getIdentifier()
*
* @param FlashMessage $message Instance of \TYPO3\CMS\Core\Messaging\FlashMessage, representing a message
* @throws \TYPO3\CMS\Core\Exception
* @return FlashMessageQueue Self to allow chaining
* @todo: Set return type to void in v12 as breaking patch and drop #[\ReturnTypeWillChange]
*/
#[\ReturnTypeWillChange]
public function enqueue($message): FlashMessageQueue
public function enqueue($message): void
{
if (!($message instanceof FlashMessage)) {
throw new Exception(
Expand All @@ -77,7 +74,6 @@ public function enqueue($message): FlashMessageQueue
} else {
parent::enqueue($message);
}
return $this;
}

/**
Expand All @@ -91,7 +87,7 @@ public function addMessage(FlashMessage $message)
/**
* This method is empty, as it will not move any flash message (e.g. from the session)
*
* @todo: Set return type to mixed when PHP >= 8.0 is required and drop #[\ReturnTypeWillChange]
* @todo: Set return type to mixed in v13
*/
#[\ReturnTypeWillChange]
public function dequeue()
Expand Down
Expand Up @@ -78,6 +78,7 @@ public function setDescription($description)
* Return the key of the current element
*
* @return string
* @todo: Set return type to mixed in v13
*/
#[\ReturnTypeWillChange]
public function key()
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/core/Classes/Resource/MetaDataAspect.php
Expand Up @@ -98,7 +98,7 @@ public function offsetExists($offset): bool
/**
* @param mixed $offset
* @return mixed
* @todo Set return type to mixed as breaking change in v12 and remove #[\ReturnTypeWillChange].
* @todo: Set return type to mixed in v13
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
Expand Down Expand Up @@ -144,7 +144,7 @@ public function rewind(): void
* Gets the current value of iteration
*
* @return mixed
* @todo Set return type to mixed as breaking change in v12 and remove #[\ReturnTypeWillChange].
* @todo: Set return type to mixed in v13
*/
#[\ReturnTypeWillChange]
public function current()
Expand Down
Expand Up @@ -22,18 +22,13 @@
*/
class EmptyFileSearchResult implements FileSearchResultInterface
{
/**
* @return int
* @see Countable::count()
*/
public function count(): int
{
return 0;
}

/**
* @see Iterator::current()
* @todo change return type to mixed in TYPO3 v12 (breaking).
* @todo: Set return type to mixed in v13
*/
#[\ReturnTypeWillChange]
public function current(): void
Expand All @@ -42,35 +37,24 @@ public function current(): void
}

/**
* @see Iterator::key()
* @todo change return type to mixed in TYPO3 v12 (breaking).
* @todo: Set return type to mixed in v13
*/
#[\ReturnTypeWillChange]
public function key(): void
{
// Noop
}

/**
* @see Iterator::next()
*/
public function next(): void
{
// Noop
}

/**
* @see Iterator::rewind()
*/
public function rewind(): void
{
// Noop
}

/**
* @return bool
* @see Iterator::valid()
*/
public function valid(): bool
{
return false;
Expand Down

0 comments on commit 847a963

Please sign in to comment.