Issue #3262190 by daffie, longwave: Add miscellaneous return type hints for Symfony 6

merge-requests/1789/head
catch 2022-02-03 17:41:13 +00:00
parent 2ae5a549b6
commit 27158f7c9d
20 changed files with 42 additions and 42 deletions

View File

@ -79,7 +79,7 @@ namespace Drupal\Core\ProxyClass\Routing {
* {@inheritdoc}
*/
public function dump(array $options = array (
))
)): string
{
return $this->lazyLoadItself()->dump($options);
}
@ -87,7 +87,7 @@ namespace Drupal\Core\ProxyClass\Routing {
/**
* {@inheritdoc}
*/
public function getRoutes()
public function getRoutes(): \Symfony\Component\Routing\RouteCollection
{
return $this->lazyLoadItself()->getRoutes();
}

View File

@ -51,7 +51,7 @@ class HtmlResponse extends Response implements CacheableResponseInterface, Attac
*
* @return $this
*/
public function setContent($content) {
public function setContent($content): static {
// A render array can automatically be converted to a string and set the
// necessary metadata.
if (is_array($content) && (isset($content['#markup']))) {

View File

@ -3,6 +3,7 @@
namespace Drupal\Core\Routing;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class LazyRouteCollection extends RouteCollection {
@ -33,8 +34,7 @@ class LazyRouteCollection extends RouteCollection {
* @return int
* The number of routes
*/
#[\ReturnTypeWillChange]
public function count() {
public function count(): int {
return count($this->all());
}
@ -44,7 +44,7 @@ class LazyRouteCollection extends RouteCollection {
* @return \Symfony\Component\Routing\Route[]
* An array of routes
*/
public function all() {
public function all(): array {
return $this->provider->getRoutesByNames(NULL);
}
@ -57,12 +57,12 @@ class LazyRouteCollection extends RouteCollection {
* @return \Symfony\Component\Routing\Route|null
* A Route instance or null when not found
*/
public function get($name) {
public function get($name): ?Route {
try {
return $this->provider->getRouteByName($name);
}
catch (RouteNotFoundException $e) {
return;
return NULL;
}
}

View File

@ -88,7 +88,7 @@ class MatcherDumper implements MatcherDumperInterface {
* Thrown if the table could not be created or the database connection
* failed.
*/
public function dump(array $options = []) {
public function dump(array $options = []): string {
// Convert all of the routes into database records.
// Accumulate the menu masks on top of any we found before.
$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->routes = NULL;
return '';
}
/**
@ -168,7 +170,7 @@ class MatcherDumper implements MatcherDumperInterface {
* A RouteCollection instance representing all routes currently in the
* dumper.
*/
public function getRoutes() {
public function getRoutes(): RouteCollection {
return $this->routes;
}

View File

@ -39,9 +39,10 @@ class NullMatcherDumper implements MatcherDumperInterface {
* @param array $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.
$this->routes = NULL;
return '';
}
/**
@ -51,7 +52,7 @@ class NullMatcherDumper implements MatcherDumperInterface {
* A RouteCollection instance representing all routes currently in the
* dumper.
*/
public function getRoutes() {
public function getRoutes(): RouteCollection {
return $this->routes;
}

View File

@ -25,7 +25,7 @@ class RouteCompiler extends SymfonyRouteCompiler implements RouteCompilerInterfa
* @return \Drupal\Core\Routing\CompiledRoute
* 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
// set and Drupal does not support non UTF-8 routes.
$route->setOption('utf8', TRUE);

View File

@ -94,7 +94,7 @@ class SessionManager extends NativeSessionStorage implements SessionManagerInter
/**
* {@inheritdoc}
*/
public function start() {
public function start(): bool {
if (($this->started || $this->startedLazy) && !$this->closed) {
return $this->started;
}
@ -129,7 +129,7 @@ class SessionManager extends NativeSessionStorage implements SessionManagerInter
/**
* {@inheritdoc}
*/
public function getId() {
public function getId(): string {
$id = parent::getId();
if (empty($id)) {
@ -202,10 +202,10 @@ class SessionManager extends NativeSessionStorage implements SessionManagerInter
/**
* {@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.
if ($this->isCli()) {
return;
return FALSE;
}
// Drupal will always destroy the existing session when regenerating a

View File

@ -28,6 +28,6 @@ interface ContextualValidatorInterface extends ContextualValidatorInterfaceBase
*
* @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;
}

View File

@ -83,7 +83,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface {
/**
* {@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)) {
throw new \LogicException('Passing custom groups is not supported.');
}

View File

@ -23,9 +23,12 @@ class ManyPlaceholderTest extends UnitTestCase {
* @covers \Drupal\big_pipe\Render\BigPipe::sendNoJsPlaceholders
*/
public function testManyNoJsPlaceHolders() {
$session = $this->prophesize(SessionInterface::class);
$session->start()->willReturn(TRUE);
$session->save()->shouldBeCalled();
$bigpipe = new BigPipe(
$this->prophesize(RendererInterface::class)->reveal(),
$this->prophesize(SessionInterface::class)->reveal(),
$session->reveal(),
$this->prophesize(RequestStack::class)->reveal(),
$this->prophesize(HttpKernelInterface::class)->reveal(),
$this->prophesize(EventDispatcherInterface::class)->reveal(),

View File

@ -27,7 +27,7 @@ class SupernovaGenerator implements UrlGeneratorInterface {
/**
* {@inheritdoc}
*/
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH) {
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH): string {
throw new \Exception();
}

View File

@ -104,7 +104,7 @@ final class Serializer extends SymfonySerializer {
/**
* {@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);
}

View File

@ -65,7 +65,7 @@ class SerializerTest extends UnitTestCase {
$mock_serializer->serialize([], 'json', Argument::that(function ($argument) {
return isset($argument['views_style_plugin']) && $argument['views_style_plugin'] instanceof Serializer;
}))
->willReturn()
->willReturn('')
->shouldBeCalled();
$view_serializer_style = new Serializer([], 'dummy_serializer', [], $mock_serializer->reveal(), ['json', 'xml'], ['json' => 'serialization', 'xml' => 'serialization']);

View File

@ -16,7 +16,7 @@ class SerializationTestEncoder implements EncoderInterface {
/**
* {@inheritdoc}
*/
public function encode($data, $format, array $context = []) {
public function encode($data, $format, array $context = []): string {
// @see \Drupal\serialization_test\SerializationTestNormalizer::normalize().
return 'Normalized by ' . $data['normalized_by'] . ', Encoded by SerializationTestEncoder';
}
@ -24,7 +24,7 @@ class SerializationTestEncoder implements EncoderInterface {
/**
* {@inheritdoc}
*/
public function supportsEncoding($format) {
public function supportsEncoding($format): bool {
return static::$format === $format;
}

View File

@ -65,7 +65,7 @@ class TestSessionBag implements SessionBagInterface {
/**
* {@inheritdoc}
*/
public function getName() {
public function getName(): string {
return self::BAG_NAME;
}
@ -79,14 +79,14 @@ class TestSessionBag implements SessionBagInterface {
/**
* {@inheritdoc}
*/
public function getStorageKey() {
public function getStorageKey(): string {
return $this->storageKey;
}
/**
* {@inheritdoc}
*/
public function clear() {
public function clear(): mixed {
$return = $this->attributes;
$this->attributes = [];

View File

@ -28,7 +28,7 @@ class MockMatcher implements RequestMatcherInterface {
/**
* {@inheritdoc}
*/
public function matchRequest(Request $request) {
public function matchRequest(Request $request): array {
$matcher = $this->matcher;
return $matcher($request);
}

View File

@ -70,7 +70,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
$this->containerBuilder = $this->prophesize('\Symfony\Component\DependencyInjection\ContainerBuilder');
$this->containerBuilder->getAliases()->willReturn([]);
$this->containerBuilder->getParameterBag()->willReturn(new ParameterBag());
$this->containerBuilder->getDefinitions()->willReturn(NULL);
$this->containerBuilder->getDefinitions()->willReturn([]);
$this->containerBuilder->isCompiled()->willReturn(TRUE);
$definition = [];

View File

@ -444,14 +444,8 @@ class DrupalTest extends UnitTestCase {
protected function setMockContainerService($service_name, $return = NULL) {
$expects = $this->container->expects($this->once())
->method('get')
->with($service_name);
if (isset($return)) {
$expects->will($this->returnValue($return));
}
else {
$expects->will($this->returnValue(TRUE));
}
->with($service_name)
->willReturn($return ?? new \stdClass());
\Drupal::setContainer($this->container);
}

View File

@ -44,13 +44,13 @@ class FakeAbstractProxy extends AbstractProxy {
*
* @var string
*/
protected $id;
protected $id = '';
public function setId($id) {
$this->id = $id;
}
public function getId() {
public function getId(): string {
return $this->id;
}

View File

@ -103,7 +103,7 @@ class NegotiationMiddlewareTest extends UnitTestCase {
// Some getContentType calls we don't really care about but have to mock.
$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->query = new ParameterBag([]);
$request_mock->request = $request_data->reveal();
@ -143,7 +143,7 @@ class NegotiationMiddlewareTest extends UnitTestCase {
// Some calls we don't care about.
$request->setRequestFormat()->shouldNotBeCalled();
$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->query = new ParameterBag([]);
$request_mock->request = $request_data->reveal();