Issue #3262190 by daffie, longwave: Add miscellaneous return type hints for Symfony 6
parent
2ae5a549b6
commit
27158f7c9d
|
@ -79,7 +79,7 @@ namespace Drupal\Core\ProxyClass\Routing {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function dump(array $options = array (
|
public function dump(array $options = array (
|
||||||
))
|
)): string
|
||||||
{
|
{
|
||||||
return $this->lazyLoadItself()->dump($options);
|
return $this->lazyLoadItself()->dump($options);
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ namespace Drupal\Core\ProxyClass\Routing {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getRoutes()
|
public function getRoutes(): \Symfony\Component\Routing\RouteCollection
|
||||||
{
|
{
|
||||||
return $this->lazyLoadItself()->getRoutes();
|
return $this->lazyLoadItself()->getRoutes();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ class HtmlResponse extends Response implements CacheableResponseInterface, Attac
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setContent($content) {
|
public function setContent($content): static {
|
||||||
// A render array can automatically be converted to a string and set the
|
// A render array can automatically be converted to a string and set the
|
||||||
// necessary metadata.
|
// necessary metadata.
|
||||||
if (is_array($content) && (isset($content['#markup']))) {
|
if (is_array($content) && (isset($content['#markup']))) {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Drupal\Core\Routing;
|
namespace Drupal\Core\Routing;
|
||||||
|
|
||||||
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||||
|
use Symfony\Component\Routing\Route;
|
||||||
use Symfony\Component\Routing\RouteCollection;
|
use Symfony\Component\Routing\RouteCollection;
|
||||||
|
|
||||||
class LazyRouteCollection extends RouteCollection {
|
class LazyRouteCollection extends RouteCollection {
|
||||||
|
@ -33,8 +34,7 @@ class LazyRouteCollection extends RouteCollection {
|
||||||
* @return int
|
* @return int
|
||||||
* The number of routes
|
* The number of routes
|
||||||
*/
|
*/
|
||||||
#[\ReturnTypeWillChange]
|
public function count(): int {
|
||||||
public function count() {
|
|
||||||
return count($this->all());
|
return count($this->all());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class LazyRouteCollection extends RouteCollection {
|
||||||
* @return \Symfony\Component\Routing\Route[]
|
* @return \Symfony\Component\Routing\Route[]
|
||||||
* An array of routes
|
* An array of routes
|
||||||
*/
|
*/
|
||||||
public function all() {
|
public function all(): array {
|
||||||
return $this->provider->getRoutesByNames(NULL);
|
return $this->provider->getRoutesByNames(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,12 +57,12 @@ class LazyRouteCollection extends RouteCollection {
|
||||||
* @return \Symfony\Component\Routing\Route|null
|
* @return \Symfony\Component\Routing\Route|null
|
||||||
* A Route instance or null when not found
|
* A Route instance or null when not found
|
||||||
*/
|
*/
|
||||||
public function get($name) {
|
public function get($name): ?Route {
|
||||||
try {
|
try {
|
||||||
return $this->provider->getRouteByName($name);
|
return $this->provider->getRouteByName($name);
|
||||||
}
|
}
|
||||||
catch (RouteNotFoundException $e) {
|
catch (RouteNotFoundException $e) {
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ class MatcherDumper implements MatcherDumperInterface {
|
||||||
* Thrown if the table could not be created or the database connection
|
* Thrown if the table could not be created or the database connection
|
||||||
* failed.
|
* failed.
|
||||||
*/
|
*/
|
||||||
public function dump(array $options = []) {
|
public function dump(array $options = []): string {
|
||||||
// Convert all of the routes into database records.
|
// Convert all of the routes into database records.
|
||||||
// Accumulate the menu masks on top of any we found before.
|
// Accumulate the menu masks on top of any we found before.
|
||||||
$masks = array_flip($this->state->get('routing.menu_masks.' . $this->tableName, []));
|
$masks = array_flip($this->state->get('routing.menu_masks.' . $this->tableName, []));
|
||||||
|
@ -159,6 +159,8 @@ class MatcherDumper implements MatcherDumperInterface {
|
||||||
$this->state->set('routing.menu_masks.' . $this->tableName, $masks);
|
$this->state->set('routing.menu_masks.' . $this->tableName, $masks);
|
||||||
|
|
||||||
$this->routes = NULL;
|
$this->routes = NULL;
|
||||||
|
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,7 +170,7 @@ class MatcherDumper implements MatcherDumperInterface {
|
||||||
* A RouteCollection instance representing all routes currently in the
|
* A RouteCollection instance representing all routes currently in the
|
||||||
* dumper.
|
* dumper.
|
||||||
*/
|
*/
|
||||||
public function getRoutes() {
|
public function getRoutes(): RouteCollection {
|
||||||
return $this->routes;
|
return $this->routes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,10 @@ class NullMatcherDumper implements MatcherDumperInterface {
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* An array of options.
|
* An array of options.
|
||||||
*/
|
*/
|
||||||
public function dump(array $options = []) {
|
public function dump(array $options = []): string {
|
||||||
// The dumper is reused for multiple providers, so reset the queued routes.
|
// The dumper is reused for multiple providers, so reset the queued routes.
|
||||||
$this->routes = NULL;
|
$this->routes = NULL;
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +52,7 @@ class NullMatcherDumper implements MatcherDumperInterface {
|
||||||
* A RouteCollection instance representing all routes currently in the
|
* A RouteCollection instance representing all routes currently in the
|
||||||
* dumper.
|
* dumper.
|
||||||
*/
|
*/
|
||||||
public function getRoutes() {
|
public function getRoutes(): RouteCollection {
|
||||||
return $this->routes;
|
return $this->routes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class RouteCompiler extends SymfonyRouteCompiler implements RouteCompilerInterfa
|
||||||
* @return \Drupal\Core\Routing\CompiledRoute
|
* @return \Drupal\Core\Routing\CompiledRoute
|
||||||
* A CompiledRoute instance.
|
* A CompiledRoute instance.
|
||||||
*/
|
*/
|
||||||
public static function compile(Route $route) {
|
public static function compile(Route $route): CompiledRoute {
|
||||||
// Symfony 4 requires that all UTF-8 route patterns have the "utf8" option
|
// Symfony 4 requires that all UTF-8 route patterns have the "utf8" option
|
||||||
// set and Drupal does not support non UTF-8 routes.
|
// set and Drupal does not support non UTF-8 routes.
|
||||||
$route->setOption('utf8', TRUE);
|
$route->setOption('utf8', TRUE);
|
||||||
|
|
|
@ -94,7 +94,7 @@ class SessionManager extends NativeSessionStorage implements SessionManagerInter
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function start() {
|
public function start(): bool {
|
||||||
if (($this->started || $this->startedLazy) && !$this->closed) {
|
if (($this->started || $this->startedLazy) && !$this->closed) {
|
||||||
return $this->started;
|
return $this->started;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ class SessionManager extends NativeSessionStorage implements SessionManagerInter
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getId() {
|
public function getId(): string {
|
||||||
$id = parent::getId();
|
$id = parent::getId();
|
||||||
|
|
||||||
if (empty($id)) {
|
if (empty($id)) {
|
||||||
|
@ -202,10 +202,10 @@ class SessionManager extends NativeSessionStorage implements SessionManagerInter
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function regenerate($destroy = FALSE, $lifetime = NULL) {
|
public function regenerate($destroy = FALSE, $lifetime = NULL): bool {
|
||||||
// Nothing to do if we are not allowed to change the session.
|
// Nothing to do if we are not allowed to change the session.
|
||||||
if ($this->isCli()) {
|
if ($this->isCli()) {
|
||||||
return;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drupal will always destroy the existing session when regenerating a
|
// Drupal will always destroy the existing session when regenerating a
|
||||||
|
|
|
@ -28,6 +28,6 @@ interface ContextualValidatorInterface extends ContextualValidatorInterfaceBase
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function validate($value, $constraints = NULL, $groups = NULL, $is_root_call = TRUE);
|
public function validate($value, $constraints = NULL, $groups = NULL, $is_root_call = TRUE): static;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function validate($data, $constraints = NULL, $groups = NULL, $is_root_call = TRUE) {
|
public function validate($data, $constraints = NULL, $groups = NULL, $is_root_call = TRUE): static {
|
||||||
if (isset($groups)) {
|
if (isset($groups)) {
|
||||||
throw new \LogicException('Passing custom groups is not supported.');
|
throw new \LogicException('Passing custom groups is not supported.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,12 @@ class ManyPlaceholderTest extends UnitTestCase {
|
||||||
* @covers \Drupal\big_pipe\Render\BigPipe::sendNoJsPlaceholders
|
* @covers \Drupal\big_pipe\Render\BigPipe::sendNoJsPlaceholders
|
||||||
*/
|
*/
|
||||||
public function testManyNoJsPlaceHolders() {
|
public function testManyNoJsPlaceHolders() {
|
||||||
|
$session = $this->prophesize(SessionInterface::class);
|
||||||
|
$session->start()->willReturn(TRUE);
|
||||||
|
$session->save()->shouldBeCalled();
|
||||||
$bigpipe = new BigPipe(
|
$bigpipe = new BigPipe(
|
||||||
$this->prophesize(RendererInterface::class)->reveal(),
|
$this->prophesize(RendererInterface::class)->reveal(),
|
||||||
$this->prophesize(SessionInterface::class)->reveal(),
|
$session->reveal(),
|
||||||
$this->prophesize(RequestStack::class)->reveal(),
|
$this->prophesize(RequestStack::class)->reveal(),
|
||||||
$this->prophesize(HttpKernelInterface::class)->reveal(),
|
$this->prophesize(HttpKernelInterface::class)->reveal(),
|
||||||
$this->prophesize(EventDispatcherInterface::class)->reveal(),
|
$this->prophesize(EventDispatcherInterface::class)->reveal(),
|
||||||
|
|
|
@ -27,7 +27,7 @@ class SupernovaGenerator implements UrlGeneratorInterface {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH) {
|
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH): string {
|
||||||
throw new \Exception();
|
throw new \Exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ final class Serializer extends SymfonySerializer {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsDenormalization($data, $type, $format = NULL, array $context = []) {
|
public function supportsDenormalization($data, $type, $format = NULL, array $context = []): bool {
|
||||||
return $this->selfSupportsDenormalization($data, $type, $format, $context) || $this->fallbackNormalizer->supportsDenormalization($data, $type, $format, $context);
|
return $this->selfSupportsDenormalization($data, $type, $format, $context) || $this->fallbackNormalizer->supportsDenormalization($data, $type, $format, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class SerializerTest extends UnitTestCase {
|
||||||
$mock_serializer->serialize([], 'json', Argument::that(function ($argument) {
|
$mock_serializer->serialize([], 'json', Argument::that(function ($argument) {
|
||||||
return isset($argument['views_style_plugin']) && $argument['views_style_plugin'] instanceof Serializer;
|
return isset($argument['views_style_plugin']) && $argument['views_style_plugin'] instanceof Serializer;
|
||||||
}))
|
}))
|
||||||
->willReturn()
|
->willReturn('')
|
||||||
->shouldBeCalled();
|
->shouldBeCalled();
|
||||||
|
|
||||||
$view_serializer_style = new Serializer([], 'dummy_serializer', [], $mock_serializer->reveal(), ['json', 'xml'], ['json' => 'serialization', 'xml' => 'serialization']);
|
$view_serializer_style = new Serializer([], 'dummy_serializer', [], $mock_serializer->reveal(), ['json', 'xml'], ['json' => 'serialization', 'xml' => 'serialization']);
|
||||||
|
|
|
@ -16,7 +16,7 @@ class SerializationTestEncoder implements EncoderInterface {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function encode($data, $format, array $context = []) {
|
public function encode($data, $format, array $context = []): string {
|
||||||
// @see \Drupal\serialization_test\SerializationTestNormalizer::normalize().
|
// @see \Drupal\serialization_test\SerializationTestNormalizer::normalize().
|
||||||
return 'Normalized by ' . $data['normalized_by'] . ', Encoded by SerializationTestEncoder';
|
return 'Normalized by ' . $data['normalized_by'] . ', Encoded by SerializationTestEncoder';
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class SerializationTestEncoder implements EncoderInterface {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function supportsEncoding($format) {
|
public function supportsEncoding($format): bool {
|
||||||
return static::$format === $format;
|
return static::$format === $format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class TestSessionBag implements SessionBagInterface {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getName() {
|
public function getName(): string {
|
||||||
return self::BAG_NAME;
|
return self::BAG_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,14 +79,14 @@ class TestSessionBag implements SessionBagInterface {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getStorageKey() {
|
public function getStorageKey(): string {
|
||||||
return $this->storageKey;
|
return $this->storageKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function clear() {
|
public function clear(): mixed {
|
||||||
$return = $this->attributes;
|
$return = $this->attributes;
|
||||||
$this->attributes = [];
|
$this->attributes = [];
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ class MockMatcher implements RequestMatcherInterface {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function matchRequest(Request $request) {
|
public function matchRequest(Request $request): array {
|
||||||
$matcher = $this->matcher;
|
$matcher = $this->matcher;
|
||||||
return $matcher($request);
|
return $matcher($request);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
||||||
$this->containerBuilder = $this->prophesize('\Symfony\Component\DependencyInjection\ContainerBuilder');
|
$this->containerBuilder = $this->prophesize('\Symfony\Component\DependencyInjection\ContainerBuilder');
|
||||||
$this->containerBuilder->getAliases()->willReturn([]);
|
$this->containerBuilder->getAliases()->willReturn([]);
|
||||||
$this->containerBuilder->getParameterBag()->willReturn(new ParameterBag());
|
$this->containerBuilder->getParameterBag()->willReturn(new ParameterBag());
|
||||||
$this->containerBuilder->getDefinitions()->willReturn(NULL);
|
$this->containerBuilder->getDefinitions()->willReturn([]);
|
||||||
$this->containerBuilder->isCompiled()->willReturn(TRUE);
|
$this->containerBuilder->isCompiled()->willReturn(TRUE);
|
||||||
|
|
||||||
$definition = [];
|
$definition = [];
|
||||||
|
|
|
@ -444,14 +444,8 @@ class DrupalTest extends UnitTestCase {
|
||||||
protected function setMockContainerService($service_name, $return = NULL) {
|
protected function setMockContainerService($service_name, $return = NULL) {
|
||||||
$expects = $this->container->expects($this->once())
|
$expects = $this->container->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($service_name);
|
->with($service_name)
|
||||||
|
->willReturn($return ?? new \stdClass());
|
||||||
if (isset($return)) {
|
|
||||||
$expects->will($this->returnValue($return));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$expects->will($this->returnValue(TRUE));
|
|
||||||
}
|
|
||||||
|
|
||||||
\Drupal::setContainer($this->container);
|
\Drupal::setContainer($this->container);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,13 +44,13 @@ class FakeAbstractProxy extends AbstractProxy {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $id;
|
protected $id = '';
|
||||||
|
|
||||||
public function setId($id) {
|
public function setId($id) {
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId() {
|
public function getId(): string {
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ class NegotiationMiddlewareTest extends UnitTestCase {
|
||||||
|
|
||||||
// Some getContentType calls we don't really care about but have to mock.
|
// Some getContentType calls we don't really care about but have to mock.
|
||||||
$request_data = $this->prophesize(ParameterBag::class);
|
$request_data = $this->prophesize(ParameterBag::class);
|
||||||
$request_data->get('ajax_iframe_upload', FALSE)->shouldBeCalled();
|
$request_data->get('ajax_iframe_upload', FALSE)->willReturn(FALSE)->shouldBeCalled();
|
||||||
$request_mock = $request->reveal();
|
$request_mock = $request->reveal();
|
||||||
$request_mock->query = new ParameterBag([]);
|
$request_mock->query = new ParameterBag([]);
|
||||||
$request_mock->request = $request_data->reveal();
|
$request_mock->request = $request_data->reveal();
|
||||||
|
@ -143,7 +143,7 @@ class NegotiationMiddlewareTest extends UnitTestCase {
|
||||||
// Some calls we don't care about.
|
// Some calls we don't care about.
|
||||||
$request->setRequestFormat()->shouldNotBeCalled();
|
$request->setRequestFormat()->shouldNotBeCalled();
|
||||||
$request_data = $this->prophesize(ParameterBag::class);
|
$request_data = $this->prophesize(ParameterBag::class);
|
||||||
$request_data->get('ajax_iframe_upload', FALSE)->shouldBeCalled();
|
$request_data->get('ajax_iframe_upload', FALSE)->willReturn(FALSE)->shouldBeCalled();
|
||||||
$request_mock = $request->reveal();
|
$request_mock = $request->reveal();
|
||||||
$request_mock->query = new ParameterBag([]);
|
$request_mock->query = new ParameterBag([]);
|
||||||
$request_mock->request = $request_data->reveal();
|
$request_mock->request = $request_data->reveal();
|
||||||
|
|
Loading…
Reference in New Issue