From ea9cc7538b80c29f56324a4a115d263d1a635816 Mon Sep 17 00:00:00 2001 From: Dave Long <dave@longwaveconsulting.com> Date: Mon, 4 Mar 2024 16:56:35 +0000 Subject: [PATCH] Issue #3425337 by mondrake: Fix root namespace classes DebugClassLoader forward compatibility warnings --- .../Operations/ScaffoldFileCollection.php | 3 +- core/.deprecation-ignore.txt | 4 - .../Doctrine/StaticReflectionClass.php | 138 ++++++------------ .../FileSystem/RegexDirectoryIterator.php | 3 +- .../Component/Plugin/LazyPluginCollection.php | 6 +- .../Component/Render/HtmlEscapedText.php | 6 +- .../Core/Config/Schema/ArrayElement.php | 3 +- .../Drupal/Core/Database/Query/Condition.php | 3 +- .../Core/Database/Query/InsertTrait.php | 3 +- .../Drupal/Core/Entity/ContentEntityBase.php | 3 +- .../Plugin/DataType/ConfigEntityAdapter.php | 3 +- .../Entity/Plugin/DataType/EntityAdapter.php | 3 +- core/lib/Drupal/Core/GeneratedLink.php | 6 +- .../Core/Session/WriteSafeSessionHandler.php | 18 +-- core/lib/Drupal/Core/Template/Attribute.php | 19 +-- .../Drupal/Core/Template/AttributeArray.php | 15 +- .../Core/TypedData/ComputedItemListTrait.php | 9 +- .../Drupal/Core/TypedData/DataDefinition.php | 12 +- .../TypedData/Plugin/DataType/ItemList.php | 18 +-- .../Core/TypedData/Plugin/DataType/Map.php | 3 +- .../comment/src/CommentFieldItemList.php | 3 +- .../SectionStorage/SectionStorageBase.php | 3 +- .../layout_builder/src/SectionListTrait.php | 3 +- .../migrate/src/Plugin/migrate/id_map/Sql.php | 15 +- .../migrate/source/SourcePluginBase.php | 15 +- .../tests/src/Unit/MigrateExecutableTest.php | 3 +- core/tests/Drupal/Tests/StreamCapturer.php | 3 +- 27 files changed, 107 insertions(+), 216 deletions(-) diff --git a/composer/Plugin/Scaffold/Operations/ScaffoldFileCollection.php b/composer/Plugin/Scaffold/Operations/ScaffoldFileCollection.php index a1bacf597d77..c6e89ef4c791 100644 --- a/composer/Plugin/Scaffold/Operations/ScaffoldFileCollection.php +++ b/composer/Plugin/Scaffold/Operations/ScaffoldFileCollection.php @@ -115,8 +115,7 @@ protected function checkListHasItemWithContent(array $scaffold_files) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->scaffoldFilesByProject); } diff --git a/core/.deprecation-ignore.txt b/core/.deprecation-ignore.txt index 6198b95d4e57..1650f6f8a8b6 100644 --- a/core/.deprecation-ignore.txt +++ b/core/.deprecation-ignore.txt @@ -19,10 +19,6 @@ %Method "Twig\\TokenParser\\TokenParserInterface::[^"]+" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message% %Method "WebDriver\\Service\\CurlServiceInterface::[^"]+" might add "[^"]+" as a native return type declaration in the future. Do the same in implementation "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message% -# Skip root namespace native DebugClassLoader forward compatibility warnings. -# These mostly refer to PHP native classes, could be fixed for PHP 8.1. -%Method "[^\\]+::\w+\(\)" might add "[^"]+" as a native return type declaration in the future. Do the same in (child class|implementation) "[^"]+" now to avoid errors or add an explicit @return annotation to suppress this message% - # The following deprecation is listed for Twig 2 compatibility when unit # testing using \Symfony\Component\ErrorHandler\DebugClassLoader. %The "Twig\\Environment::getTemplateClass\(\)" method is considered internal\. It may change without further notice\. You should not extend it from "Drupal\\Core\\Template\\TwigEnvironment"\.% diff --git a/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php b/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php index b0e60706962a..87acb3dd4002 100644 --- a/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php +++ b/core/lib/Drupal/Component/Annotation/Doctrine/StaticReflectionClass.php @@ -47,8 +47,7 @@ public function __construct(StaticReflectionParser $staticReflectionParser) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getName() + public function getName(): string { return $this->staticReflectionParser->getClassName(); } @@ -56,8 +55,7 @@ public function getName() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getDocComment() + public function getDocComment(): string|FALSE { return $this->staticReflectionParser->getDocComment(); } @@ -65,8 +63,7 @@ public function getDocComment() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getNamespaceName() + public function getNamespaceName(): string { return $this->staticReflectionParser->getNamespaceName(); } @@ -94,8 +91,7 @@ public function hasClassAttribute(string $attribute) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getMethod($name) + public function getMethod($name): \ReflectionMethod { throw new ReflectionException('Method not implemented'); } @@ -103,8 +99,7 @@ public function getMethod($name) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getProperty($name) + public function getProperty($name): \ReflectionProperty { throw new ReflectionException('Method not implemented'); } @@ -120,8 +115,7 @@ public static function export($argument, $return = false) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getConstant($name) + public function getConstant($name): mixed { throw new ReflectionException('Method not implemented'); } @@ -129,8 +123,7 @@ public function getConstant($name) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getConstructor() + public function getConstructor(): ?\ReflectionMethod { throw new ReflectionException('Method not implemented'); } @@ -138,8 +131,7 @@ public function getConstructor() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getDefaultProperties() + public function getDefaultProperties(): array { throw new ReflectionException('Method not implemented'); } @@ -147,8 +139,7 @@ public function getDefaultProperties() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getEndLine() + public function getEndLine(): int|FALSE { throw new ReflectionException('Method not implemented'); } @@ -156,8 +147,7 @@ public function getEndLine() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getExtension() + public function getExtension(): ?\ReflectionExtension { throw new ReflectionException('Method not implemented'); } @@ -165,8 +155,7 @@ public function getExtension() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getExtensionName() + public function getExtensionName(): string|FALSE { throw new ReflectionException('Method not implemented'); } @@ -174,8 +163,7 @@ public function getExtensionName() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getFileName() + public function getFileName(): string|FALSE { throw new ReflectionException('Method not implemented'); } @@ -183,8 +171,7 @@ public function getFileName() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getInterfaceNames() + public function getInterfaceNames(): array { throw new ReflectionException('Method not implemented'); } @@ -192,8 +179,7 @@ public function getInterfaceNames() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getInterfaces() + public function getInterfaces(): array { throw new ReflectionException('Method not implemented'); } @@ -201,8 +187,7 @@ public function getInterfaces() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getMethods($filter = null) + public function getMethods($filter = null): array { throw new ReflectionException('Method not implemented'); } @@ -210,8 +195,7 @@ public function getMethods($filter = null) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getModifiers() + public function getModifiers(): int { throw new ReflectionException('Method not implemented'); } @@ -219,8 +203,7 @@ public function getModifiers() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getParentClass() + public function getParentClass(): \ReflectionClass|FALSE { throw new ReflectionException('Method not implemented'); } @@ -228,8 +211,7 @@ public function getParentClass() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getProperties($filter = null) + public function getProperties($filter = null): array { throw new ReflectionException('Method not implemented'); } @@ -237,8 +219,7 @@ public function getProperties($filter = null) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getShortName() + public function getShortName(): string { throw new ReflectionException('Method not implemented'); } @@ -246,8 +227,7 @@ public function getShortName() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getStartLine() + public function getStartLine(): int|FALSE { throw new ReflectionException('Method not implemented'); } @@ -255,8 +235,7 @@ public function getStartLine() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getStaticProperties() + public function getStaticProperties(): ?array { throw new ReflectionException('Method not implemented'); } @@ -264,8 +243,7 @@ public function getStaticProperties() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getStaticPropertyValue($name, $default = '') + public function getStaticPropertyValue($name, $default = ''): mixed { throw new ReflectionException('Method not implemented'); } @@ -273,8 +251,7 @@ public function getStaticPropertyValue($name, $default = '') /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getTraitAliases() + public function getTraitAliases(): array { throw new ReflectionException('Method not implemented'); } @@ -282,8 +259,7 @@ public function getTraitAliases() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getTraitNames() + public function getTraitNames(): array { throw new ReflectionException('Method not implemented'); } @@ -291,8 +267,7 @@ public function getTraitNames() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getTraits() + public function getTraits(): array { throw new ReflectionException('Method not implemented'); } @@ -300,8 +275,7 @@ public function getTraits() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function hasConstant($name) + public function hasConstant($name): bool { throw new ReflectionException('Method not implemented'); } @@ -309,8 +283,7 @@ public function hasConstant($name) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function hasMethod($name) + public function hasMethod($name): bool { throw new ReflectionException('Method not implemented'); } @@ -318,8 +291,7 @@ public function hasMethod($name) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function hasProperty($name) + public function hasProperty($name): bool { throw new ReflectionException('Method not implemented'); } @@ -327,8 +299,7 @@ public function hasProperty($name) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function implementsInterface($interface) + public function implementsInterface($interface): bool { throw new ReflectionException('Method not implemented'); } @@ -336,8 +307,7 @@ public function implementsInterface($interface) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function inNamespace() + public function inNamespace(): bool { throw new ReflectionException('Method not implemented'); } @@ -345,8 +315,7 @@ public function inNamespace() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function isAbstract() + public function isAbstract(): bool { throw new ReflectionException('Method not implemented'); } @@ -354,8 +323,7 @@ public function isAbstract() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function isCloneable() + public function isCloneable(): bool { throw new ReflectionException('Method not implemented'); } @@ -363,8 +331,7 @@ public function isCloneable() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function isFinal() + public function isFinal(): bool { throw new ReflectionException('Method not implemented'); } @@ -372,8 +339,7 @@ public function isFinal() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function isInstance($object) + public function isInstance($object): bool { throw new ReflectionException('Method not implemented'); } @@ -381,8 +347,7 @@ public function isInstance($object) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function isInstantiable() + public function isInstantiable(): bool { throw new ReflectionException('Method not implemented'); } @@ -390,8 +355,7 @@ public function isInstantiable() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function isInterface() + public function isInterface(): bool { throw new ReflectionException('Method not implemented'); } @@ -399,8 +363,7 @@ public function isInterface() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function isInternal() + public function isInternal(): bool { throw new ReflectionException('Method not implemented'); } @@ -408,8 +371,7 @@ public function isInternal() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function isIterateable() + public function isIterateable(): bool { throw new ReflectionException('Method not implemented'); } @@ -417,8 +379,7 @@ public function isIterateable() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function isSubclassOf($class) + public function isSubclassOf($class): bool { throw new ReflectionException('Method not implemented'); } @@ -426,8 +387,7 @@ public function isSubclassOf($class) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function isTrait() + public function isTrait(): bool { throw new ReflectionException('Method not implemented'); } @@ -435,8 +395,7 @@ public function isTrait() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function isUserDefined() + public function isUserDefined(): bool { throw new ReflectionException('Method not implemented'); } @@ -444,8 +403,7 @@ public function isUserDefined() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function newInstanceArgs(array $args = []) + public function newInstanceArgs(array $args = []): ?object { throw new ReflectionException('Method not implemented'); } @@ -453,8 +411,7 @@ public function newInstanceArgs(array $args = []) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function newInstanceWithoutConstructor() + public function newInstanceWithoutConstructor(): object { throw new ReflectionException('Method not implemented'); } @@ -462,8 +419,7 @@ public function newInstanceWithoutConstructor() /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function setStaticPropertyValue($name, $value) + public function setStaticPropertyValue($name, $value): void { throw new ReflectionException('Method not implemented'); } @@ -471,8 +427,7 @@ public function setStaticPropertyValue($name, $value) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function getConstants(?int $filter = null) + public function getConstants(?int $filter = null): array { throw new ReflectionException('Method not implemented'); } @@ -480,8 +435,7 @@ public function getConstants(?int $filter = null) /** * {@inheritDoc} */ - #[\ReturnTypeWillChange] - public function newInstance(mixed ...$args) + public function newInstance(mixed ...$args): object { throw new ReflectionException('Method not implemented'); } diff --git a/core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php b/core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php index cfa616ae1bf5..cc17aa643c5e 100644 --- a/core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php +++ b/core/lib/Drupal/Component/FileSystem/RegexDirectoryIterator.php @@ -23,8 +23,7 @@ public function __construct($path, $regex) { /** * Implements \RegexIterator::accept(). */ - #[\ReturnTypeWillChange] - public function accept() { + public function accept(): bool { /** @var \SplFileInfo $file_info */ $file_info = $this->getInnerIterator()->current(); return $file_info->isFile() && preg_match($this->getRegex(), $file_info->getFilename()); diff --git a/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php b/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php index 6574c5b3daec..db5b8755051c 100644 --- a/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php +++ b/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php @@ -142,8 +142,7 @@ public function removeInstanceId($instance_id) { $this->remove($instance_id); } - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \ArrayIterator { $instances = []; foreach ($this->getInstanceIds() as $instance_id) { $instances[$instance_id] = $this->get($instance_id); @@ -154,8 +153,7 @@ public function getIterator() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function count() { + public function count(): int { return count($this->instanceIds); } diff --git a/core/lib/Drupal/Component/Render/HtmlEscapedText.php b/core/lib/Drupal/Component/Render/HtmlEscapedText.php index d5121bfb9f28..6ca9538089e6 100644 --- a/core/lib/Drupal/Component/Render/HtmlEscapedText.php +++ b/core/lib/Drupal/Component/Render/HtmlEscapedText.php @@ -41,16 +41,14 @@ public function __toString() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function count() { + public function count(): int { return mb_strlen($this->string); } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function jsonSerialize() { + public function jsonSerialize(): string { return $this->__toString(); } diff --git a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php index e9e4998010bd..11fc9aca2414 100644 --- a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php +++ b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php @@ -114,8 +114,7 @@ public function onChange($name) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->getElements()); } diff --git a/core/lib/Drupal/Core/Database/Query/Condition.php b/core/lib/Drupal/Core/Database/Query/Condition.php index fcd0b5dfba30..377d45cb59d5 100644 --- a/core/lib/Drupal/Core/Database/Query/Condition.php +++ b/core/lib/Drupal/Core/Database/Query/Condition.php @@ -90,8 +90,7 @@ public function __construct($conjunction) { * size of its conditional array minus one, because one element is the * conjunction. */ - #[\ReturnTypeWillChange] - public function count() { + public function count(): int { return count($this->conditions) - 1; } diff --git a/core/lib/Drupal/Core/Database/Query/InsertTrait.php b/core/lib/Drupal/Core/Database/Query/InsertTrait.php index a429c88eead6..808c9f53a117 100644 --- a/core/lib/Drupal/Core/Database/Query/InsertTrait.php +++ b/core/lib/Drupal/Core/Database/Query/InsertTrait.php @@ -179,8 +179,7 @@ protected function getInsertPlaceholderFragment(array $nested_insert_values, arr /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function count() { + public function count(): int { return count($this->insertValues); } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 52b967425676..5371bdfd1655 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -687,8 +687,7 @@ public function getTranslatableFields($include_computed = TRUE) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->getFields()); } diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php index a30106029fcb..46c15afc72a8 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php @@ -69,8 +69,7 @@ public function onChange($property_name) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \ArrayIterator { if (isset($this->entity)) { return $this->getConfigTypedData()->getIterator(); } diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php index 602278487e40..154c1c4e083b 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php @@ -162,8 +162,7 @@ public function applyDefaultValue($notify = TRUE) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \ArrayIterator { return $this->entity instanceof \IteratorAggregate ? $this->entity->getIterator() : new \ArrayIterator([]); } diff --git a/core/lib/Drupal/Core/GeneratedLink.php b/core/lib/Drupal/Core/GeneratedLink.php index 0c484836f11f..7bebcbaf31d8 100644 --- a/core/lib/Drupal/Core/GeneratedLink.php +++ b/core/lib/Drupal/Core/GeneratedLink.php @@ -58,16 +58,14 @@ public function __toString() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function jsonSerialize() { + public function jsonSerialize(): string { return $this->__toString(); } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function count() { + public function count(): int { return mb_strlen($this->__toString()); } diff --git a/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php b/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php index d18340d754b7..3c1f61ece10a 100644 --- a/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php +++ b/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php @@ -43,40 +43,35 @@ public function __construct(\SessionHandlerInterface $wrapped_session_handler, $ /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function close() { + public function close(): bool { return $this->wrappedSessionHandler->close(); } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function destroy($session_id) { + public function destroy($session_id): bool { return $this->wrappedSessionHandler->destroy($session_id); } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function gc($max_lifetime) { + public function gc($max_lifetime): int|FALSE { return $this->wrappedSessionHandler->gc($max_lifetime); } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function open($save_path, $session_id) { + public function open($save_path, $session_id): bool { return $this->wrappedSessionHandler->open($save_path, $session_id); } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function read($session_id) { + public function read($session_id): string|FALSE { $value = $this->wrappedSessionHandler->read($session_id); $this->readSessions[$session_id] = $value; return $value; @@ -85,8 +80,7 @@ public function read($session_id) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function write($session_id, $session_data) { + public function write($session_id, $session_data): bool { // Only write the session when it has been modified. if (isset($this->readSessions[$session_id]) && $this->readSessions[$session_id] === $session_data) { return TRUE; diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index 6a6759d1dbad..a08fdafd17c2 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -90,18 +90,17 @@ public function __construct($attributes = []) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetGet($name) { + public function offsetGet($name): mixed { if (isset($this->storage[$name])) { return $this->storage[$name]; } + return NULL; } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetSet($name, $value) { + public function offsetSet($name, $value): void { $this->storage[$name] = $this->createAttributeValue($name, $value); } @@ -154,16 +153,14 @@ protected function createAttributeValue($name, $value) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetUnset($name) { + public function offsetUnset($name): void { unset($this->storage[$name]); } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetExists($name) { + public function offsetExists($name): bool { return isset($this->storage[$name]); } @@ -358,8 +355,7 @@ public function __clone() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->storage); } @@ -376,8 +372,7 @@ public function storage() { * @return string * The safe string content. */ - #[\ReturnTypeWillChange] - public function jsonSerialize() { + public function jsonSerialize(): string { return (string) $this; } diff --git a/core/lib/Drupal/Core/Template/AttributeArray.php b/core/lib/Drupal/Core/Template/AttributeArray.php index 71127f00471d..2f003f2de6e4 100644 --- a/core/lib/Drupal/Core/Template/AttributeArray.php +++ b/core/lib/Drupal/Core/Template/AttributeArray.php @@ -35,16 +35,14 @@ class AttributeArray extends AttributeValueBase implements \ArrayAccess, \Iterat /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetGet($offset) { + public function offsetGet($offset): mixed { return $this->value[$offset]; } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { if (isset($offset)) { $this->value[$offset] = $value; } @@ -56,16 +54,14 @@ public function offsetSet($offset, $value) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetUnset($offset) { + public function offsetUnset($offset): void { unset($this->value[$offset]); } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetExists($offset) { + public function offsetExists($offset): bool { return isset($this->value[$offset]); } @@ -81,8 +77,7 @@ public function __toString() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->value); } diff --git a/core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php b/core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php index f1d4d4236b2e..8e31e3d1c629 100644 --- a/core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php +++ b/core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php @@ -118,8 +118,7 @@ public function isEmpty() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetExists($offset) { + public function offsetExists($offset): bool { $this->ensureComputedValue(); return parent::offsetExists($offset); } @@ -127,8 +126,7 @@ public function offsetExists($offset) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \ArrayIterator { $this->ensureComputedValue(); return parent::getIterator(); } @@ -136,8 +134,7 @@ public function getIterator() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function count() { + public function count(): int { $this->ensureComputedValue(); return parent::count(); } diff --git a/core/lib/Drupal/Core/TypedData/DataDefinition.php b/core/lib/Drupal/Core/TypedData/DataDefinition.php index a82f819b4cde..a00adefe1c48 100644 --- a/core/lib/Drupal/Core/TypedData/DataDefinition.php +++ b/core/lib/Drupal/Core/TypedData/DataDefinition.php @@ -314,8 +314,7 @@ public function addConstraint($constraint_name, $options = NULL) { * This is for BC support only. * @todo: Remove in https://www.drupal.org/node/1928868. */ - #[\ReturnTypeWillChange] - public function offsetExists($offset) { + public function offsetExists($offset): bool { // PHP's array access does not work correctly with isset(), so we have to // bake isset() in here. See https://bugs.php.net/bug.php?id=41727. return array_key_exists($offset, $this->definition) && isset($this->definition[$offset]); @@ -327,8 +326,7 @@ public function offsetExists($offset) { * This is for BC support only. * @todo: Remove in https://www.drupal.org/node/1928868. */ - #[\ReturnTypeWillChange] - public function &offsetGet($offset) { + public function &offsetGet($offset): mixed { if (!isset($this->definition[$offset])) { $this->definition[$offset] = NULL; } @@ -341,8 +339,7 @@ public function &offsetGet($offset) { * This is for BC support only. * @todo: Remove in https://www.drupal.org/node/1928868. */ - #[\ReturnTypeWillChange] - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { $this->definition[$offset] = $value; } @@ -352,8 +349,7 @@ public function offsetSet($offset, $value) { * This is for BC support only. * @todo: Remove in https://www.drupal.org/node/1928868. */ - #[\ReturnTypeWillChange] - public function offsetUnset($offset) { + public function offsetUnset($offset): void { unset($this->definition[$offset]); } diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php index 0e6a377bc678..ee648a50f86f 100644 --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php @@ -170,8 +170,7 @@ public function first() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetExists($offset) { + public function offsetExists($offset): bool { // We do not want to throw exceptions here, so we do not use get(). return isset($this->list[$offset]); } @@ -179,24 +178,21 @@ public function offsetExists($offset) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetUnset($offset) { + public function offsetUnset($offset): void { $this->removeItem($offset); } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetGet($offset) { + public function offsetGet($offset): mixed { return $this->get($offset); } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetSet($offset, $value) { + public function offsetSet($offset, $value): void { if (!isset($offset)) { // The [] operator has been used. $this->appendItem($value); @@ -235,16 +231,14 @@ public function getItemDefinition() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->list); } /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function count() { + public function count(): int { return count($this->list); } diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php index e216ceb77571..e08e9312e0c7 100644 --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php @@ -183,8 +183,7 @@ public function toArray() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->getProperties()); } diff --git a/core/modules/comment/src/CommentFieldItemList.php b/core/modules/comment/src/CommentFieldItemList.php index 985f8652250d..53420df3e78b 100644 --- a/core/modules/comment/src/CommentFieldItemList.php +++ b/core/modules/comment/src/CommentFieldItemList.php @@ -30,8 +30,7 @@ public function get($index) { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function offsetExists($offset) { + public function offsetExists($offset): bool { // For consistency with what happens in get(), we force offsetExists() to // be TRUE for delta 0. if ($offset === 0) { diff --git a/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php b/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php index 93f8637a564a..3f9d07c860d5 100644 --- a/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php +++ b/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php @@ -38,8 +38,7 @@ public function getStorageType() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function count() { + public function count(): int { return $this->getSectionList()->count(); } diff --git a/core/modules/layout_builder/src/SectionListTrait.php b/core/modules/layout_builder/src/SectionListTrait.php index 3a2947b99e18..7a049dec6c40 100644 --- a/core/modules/layout_builder/src/SectionListTrait.php +++ b/core/modules/layout_builder/src/SectionListTrait.php @@ -25,8 +25,7 @@ abstract protected function setSections(array $sections); /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function count() { + public function count(): int { if ($this->hasBlankSection()) { return 0; } diff --git a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php index 54d55cfb0332..b9261d098943 100644 --- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php @@ -913,8 +913,7 @@ public function destroy() { * * This is called before beginning a foreach loop. */ - #[\ReturnTypeWillChange] - public function rewind() { + public function rewind(): void { $this->currentRow = NULL; $fields = []; foreach ($this->sourceIdFields() as $field) { @@ -935,8 +934,7 @@ public function rewind() { * * This is called when entering a loop iteration, returning the current row. */ - #[\ReturnTypeWillChange] - public function current() { + public function current(): mixed { return $this->currentRow; } @@ -947,8 +945,7 @@ public function current() { * current row. It must be a scalar - we will serialize to fulfill the * requirement, but using getCurrentKey() is preferable. */ - #[\ReturnTypeWillChange] - public function key() { + public function key(): mixed { return serialize($this->currentKey); } @@ -992,8 +989,7 @@ public function currentSource() { * This is called at the bottom of the loop implicitly, as well as explicitly * from rewind(). */ - #[\ReturnTypeWillChange] - public function next() { + public function next(): void { $this->currentRow = $this->result->fetchAssoc(); $this->currentKey = []; if ($this->currentRow) { @@ -1011,8 +1007,7 @@ public function next() { * This is called at the top of the loop, returning TRUE to process the loop * and FALSE to terminate it. */ - #[\ReturnTypeWillChange] - public function valid() { + public function valid(): bool { return $this->currentRow !== FALSE; } diff --git a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php index 3191c7256d4a..90a66e45ed8a 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +++ b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php @@ -343,8 +343,7 @@ protected function getIterator() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function current() { + public function current(): mixed { return $this->currentRow; } @@ -356,8 +355,7 @@ public function current() { * serialize to fulfill the requirement, but using getCurrentIds() is * preferable. */ - #[\ReturnTypeWillChange] - public function key() { + public function key(): mixed { return serialize($this->currentSourceIds); } @@ -367,8 +365,7 @@ public function key() { * Implementation of \Iterator::valid() - called at the top of the loop, * returning TRUE to process the loop and FALSE to terminate it. */ - #[\ReturnTypeWillChange] - public function valid() { + public function valid(): bool { return isset($this->currentRow); } @@ -379,8 +376,7 @@ public function valid() { * should implement initializeIterator() to do any class-specific setup for * iterating source records. */ - #[\ReturnTypeWillChange] - public function rewind() { + public function rewind(): void { $this->getIterator()->rewind(); $this->next(); } @@ -388,8 +384,7 @@ public function rewind() { /** * {@inheritdoc} */ - #[\ReturnTypeWillChange] - public function next() { + public function next(): void { $this->currentSourceIds = NULL; $this->currentRow = NULL; diff --git a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php index 773919205fa1..f6ce4a00b113 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php @@ -448,8 +448,7 @@ protected function getMockSource() { ->onlyMethods(get_class_methods($class)) ->getMockForAbstractClass(); $source->expects($this->once()) - ->method('rewind') - ->willReturn(TRUE); + ->method('rewind'); $source->expects($this->any()) ->method('initializeIterator') ->willReturn([]); diff --git a/core/tests/Drupal/Tests/StreamCapturer.php b/core/tests/Drupal/Tests/StreamCapturer.php index eb7d54aa9b76..2be2ef60f4f0 100644 --- a/core/tests/Drupal/Tests/StreamCapturer.php +++ b/core/tests/Drupal/Tests/StreamCapturer.php @@ -11,8 +11,7 @@ class StreamCapturer extends \php_user_filter { public static $cache = ''; - #[\ReturnTypeWillChange] - public function filter($in, $out, &$consumed, $closing) { + public function filter($in, $out, &$consumed, $closing): int { while ($bucket = stream_bucket_make_writeable($in)) { self::$cache .= $bucket->data; // cSpell:disable-next-line -- GitLab