From 7dcd8cf539c4d7a1403695c438c746c6fa5dcc7b Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 5 May 2022 23:11:22 +0200 Subject: [PATCH] Add return type hints (#6) This adds a few return type hints to address deprecation notices and be forwards-compatible with future Symfony versions. These changes are compatible even with PHP 7.2. --- src/JMS/ObjectRouting/Metadata/ClassMetadata.php | 4 ++-- src/JMS/ObjectRouting/Twig/RoutingExtension.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/JMS/ObjectRouting/Metadata/ClassMetadata.php b/src/JMS/ObjectRouting/Metadata/ClassMetadata.php index 615cc00..dc7856e 100644 --- a/src/JMS/ObjectRouting/Metadata/ClassMetadata.php +++ b/src/JMS/ObjectRouting/Metadata/ClassMetadata.php @@ -39,7 +39,7 @@ public function merge(MergeableInterface $object): void $this->routes = array_merge($this->routes, $object->routes); } - public function serialize() + public function serialize(): string { return serialize( array( @@ -49,7 +49,7 @@ public function serialize() ); } - public function unserialize($str) + public function unserialize($str): void { list( $this->routes, diff --git a/src/JMS/ObjectRouting/Twig/RoutingExtension.php b/src/JMS/ObjectRouting/Twig/RoutingExtension.php index 209bad4..e53e58f 100644 --- a/src/JMS/ObjectRouting/Twig/RoutingExtension.php +++ b/src/JMS/ObjectRouting/Twig/RoutingExtension.php @@ -15,7 +15,7 @@ public function __construct(ObjectRouter $router) $this->router = $router; } - public function getFunctions() + public function getFunctions(): array { return [ new TwigFunction('object_path', [$this, 'path']), @@ -23,12 +23,12 @@ public function getFunctions() ]; } - public function url($type, $object, array $extraParams = []) + public function url($type, $object, array $extraParams = []): string { return $this->router->generate($type, $object, true, $extraParams); } - public function path($type, $object, array $extraParams = []) + public function path($type, $object, array $extraParams = []): string { return $this->router->generate($type, $object, false, $extraParams); }