Issue #3238485 by daffie: [Symfony 6] Add return type hints to the class methods of Drupal\Component\DependencyInjection\Container

merge-requests/1294/merge
catch 2021-12-14 09:58:45 +00:00
parent 205729d912
commit 21d2543a2f
3 changed files with 11 additions and 9 deletions

View File

@ -127,7 +127,7 @@ class Container implements ContainerInterface, ResetInterface {
/**
* {@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 @@ class Container implements ContainerInterface, ResetInterface {
// 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 @@ class Container implements ContainerInterface, ResetInterface {
unset($this->services[$id]);
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalid_behavior) {
return;
return NULL;
}
throw $e;
@ -315,14 +315,14 @@ class Container implements ContainerInterface, ResetInterface {
/**
* {@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 @@ class Container implements ContainerInterface, ResetInterface {
/**
* {@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 @@ class Container implements ContainerInterface, ResetInterface {
/**
* {@inheritdoc}
*/
public function initialized($id) {
public function initialized($id): bool {
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}

View File

@ -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) {

View File

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