diff --git a/src/Symfony/Bridge/Twig/AppVariable.php b/src/Symfony/Bridge/Twig/AppVariable.php index eb9cec6dd9..4a22265908 100644 --- a/src/Symfony/Bridge/Twig/AppVariable.php +++ b/src/Symfony/Bridge/Twig/AppVariable.php @@ -111,8 +111,9 @@ class AppVariable if (null === $this->requestStack) { throw new \RuntimeException('The "app.session" variable is not available.'); } + $request = $this->getRequest(); - return ($request = $this->getRequest()) ? $request->getSession() : null; + return $request && $request->hasSession() ? $request->getSession() : null; } /** @@ -154,8 +155,7 @@ class AppVariable public function getFlashes($types = null) { try { - $session = $this->getSession(); - if (null === $session) { + if (null === $session = $this->getSession()) { return []; } } catch (\RuntimeException $e) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/GlobalVariables.php b/src/Symfony/Bundle/FrameworkBundle/Templating/GlobalVariables.php index c3e0cbca4f..22b2551ac6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/GlobalVariables.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/GlobalVariables.php @@ -70,7 +70,9 @@ class GlobalVariables */ public function getSession() { - return ($request = $this->getRequest()) ? $request->getSession() : null; + $request = $this->getRequest(); + + return $request && $request->hasSession() ? $request->getSession() : null; } /** diff --git a/src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php b/src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php index 0a25338818..44fe477945 100644 --- a/src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php +++ b/src/Symfony/Component/HttpKernel/ControllerMetadata/ArgumentMetadataFactory.php @@ -42,10 +42,8 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface /** * Returns an associated type to the given parameter if available. - * - * @return string|null */ - private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function) + private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function): ?string { if (!$type = $parameter->getType()) { return null; diff --git a/src/Symfony/Component/HttpKernel/Profiler/Profiler.php b/src/Symfony/Component/HttpKernel/Profiler/Profiler.php index 39c181677e..f9d94b6f32 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/Profiler.php +++ b/src/Symfony/Component/HttpKernel/Profiler/Profiler.php @@ -242,12 +242,9 @@ class Profiler implements ResetInterface return $this->collectors[$name]; } - /** - * @return int|null - */ - private function getTimestamp($value) + private function getTimestamp(?string $value): ?int { - if (null === $value || '' == $value) { + if (null === $value || '' === $value) { return null; }