Commit 21d2543a authored by catch's avatar catch
Browse files

Issue #3238485 by daffie: [Symfony 6] Add return type hints to the class...

Issue #3238485 by daffie: [Symfony 6] Add return type hints to the class methods of Drupal\Component\DependencyInjection\Container
parent 205729d9
Loading
Loading
Loading
Loading
+7 −7
Changes for core/lib/Drupal/Component/DependencyInjection/Container.php: 7 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -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];
    }
+2 −1
Changes for core/tests/Drupal/FunctionalTests/Bootstrap/ErrorContainer.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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) {
+2 −1
Changes for core/tests/Drupal/FunctionalTests/Bootstrap/ExceptionContainer.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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');
    }