From 21d2543a2f6bf5569a9b7b50a6a9df5a902bc15a Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Tue, 14 Dec 2021 09:58:45 +0000
Subject: [PATCH] Issue #3238485 by daffie: [Symfony 6] Add return type hints
 to the class methods of Drupal\Component\DependencyInjection\Container

---
 .../Component/DependencyInjection/Container.php    | 14 +++++++-------
 .../FunctionalTests/Bootstrap/ErrorContainer.php   |  3 ++-
 .../Bootstrap/ExceptionContainer.php               |  3 ++-
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/core/lib/Drupal/Component/DependencyInjection/Container.php b/core/lib/Drupal/Component/DependencyInjection/Container.php
index 127656539ad5..235cceab412c 100644
--- a/core/lib/Drupal/Component/DependencyInjection/Container.php
+++ b/core/lib/Drupal/Component/DependencyInjection/Container.php
@@ -127,7 +127,7 @@ public function __construct(array $container_definition = []) {
   /**
    * {@inheritdoc}
    */
-  public function get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
+  public function get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE): ?object {
     if ($this->hasParameter('_deprecated_service_list')) {
       if ($deprecation = $this->getParameter('_deprecated_service_list')[$id] ?? '') {
         @trigger_error($deprecation, E_USER_DEPRECATED);
@@ -160,7 +160,7 @@ public function get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_IN
     // is used, the actual wanted behavior is to re-try getting the service at a
     // later point.
     if (!$definition) {
-      return;
+      return NULL;
     }
 
     // Definition is a keyed array, so [0] is only defined when it is a
@@ -180,7 +180,7 @@ public function get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_IN
       unset($this->services[$id]);
 
       if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalid_behavior) {
-        return;
+        return NULL;
       }
 
       throw $e;
@@ -315,14 +315,14 @@ public function set($id, $service) {
   /**
    * {@inheritdoc}
    */
-  public function has($id) {
+  public function has($id): bool {
     return isset($this->aliases[$id]) || isset($this->services[$id]) || isset($this->serviceDefinitions[$id]);
   }
 
   /**
    * {@inheritdoc}
    */
-  public function getParameter($name) {
+  public function getParameter($name): array|bool|string|int|float|NULL {
     if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) {
       if (!$name) {
         throw new ParameterNotFoundException('');
@@ -337,7 +337,7 @@ public function getParameter($name) {
   /**
    * {@inheritdoc}
    */
-  public function hasParameter($name) {
+  public function hasParameter($name): bool {
     return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters);
   }
 
@@ -355,7 +355,7 @@ public function setParameter($name, $value) {
   /**
    * {@inheritdoc}
    */
-  public function initialized($id) {
+  public function initialized($id): bool {
     if (isset($this->aliases[$id])) {
       $id = $this->aliases[$id];
     }
diff --git a/core/tests/Drupal/FunctionalTests/Bootstrap/ErrorContainer.php b/core/tests/Drupal/FunctionalTests/Bootstrap/ErrorContainer.php
index e88cc88c9050..3cb81e0b29b2 100644
--- a/core/tests/Drupal/FunctionalTests/Bootstrap/ErrorContainer.php
+++ b/core/tests/Drupal/FunctionalTests/Bootstrap/ErrorContainer.php
@@ -3,6 +3,7 @@
 namespace Drupal\FunctionalTests\Bootstrap;
 
 use Drupal\Core\DependencyInjection\Container;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Container base class which triggers an error.
@@ -12,7 +13,7 @@ class ErrorContainer extends Container {
   /**
    * {@inheritdoc}
    */
-  public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) {
+  public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE): ?object {
     if ($id === 'http_kernel') {
       // Enforce a recoverable error.
       $callable = function (ErrorContainer $container) {
diff --git a/core/tests/Drupal/FunctionalTests/Bootstrap/ExceptionContainer.php b/core/tests/Drupal/FunctionalTests/Bootstrap/ExceptionContainer.php
index b33d263495aa..de1fc0c17112 100644
--- a/core/tests/Drupal/FunctionalTests/Bootstrap/ExceptionContainer.php
+++ b/core/tests/Drupal/FunctionalTests/Bootstrap/ExceptionContainer.php
@@ -3,6 +3,7 @@
 namespace Drupal\FunctionalTests\Bootstrap;
 
 use Drupal\Core\DependencyInjection\Container;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Base container which throws an exception.
@@ -12,7 +13,7 @@ class ExceptionContainer extends Container {
   /**
    * {@inheritdoc}
    */
-  public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) {
+  public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE): ?object {
     if ($id === 'http_kernel') {
       throw new \Exception('Thrown exception during Container::get');
     }
-- 
GitLab