From b169b1e12d33f1b9f9f0ed679395ca763710870d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 28 Jul 2022 07:50:17 +0200 Subject: [PATCH] Improve container return type annotations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/AppFramework/Utility/SimpleContainer.php | 10 ++++++++++ lib/private/Server.php | 5 +++-- lib/private/ServerContainer.php | 8 ++++++++ lib/public/Server.php | 8 +++++--- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/private/AppFramework/Utility/SimpleContainer.php b/lib/private/AppFramework/Utility/SimpleContainer.php index 429382aa223b2..f498e1b387d5f 100644 --- a/lib/private/AppFramework/Utility/SimpleContainer.php +++ b/lib/private/AppFramework/Utility/SimpleContainer.php @@ -34,6 +34,7 @@ use OCP\AppFramework\QueryException; use OCP\IContainer; use Pimple\Container; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use ReflectionClass; use ReflectionException; @@ -53,6 +54,15 @@ public function __construct() { $this->container = new Container(); } + /** + * @template T + * @param class-string|string $id + * @return T|mixed + * @psalm-template S as class-string|string + * @psalm-param S $id + * @psalm-return (S is class-string ? T : mixed) + * @throws QueryException + */ public function get(string $id) { return $this->query($id); } diff --git a/lib/private/Server.php b/lib/private/Server.php index bcbb6ef6b00d3..4a031d2988403 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -153,6 +153,7 @@ use OC\Template\JSCombiner; use OC\User\Listeners\UserChangedListener; use OC\User\Listeners\UserDeletedListener; +use OC\User\Session; use OCA\Theming\ImageManager; use OCA\Theming\ThemingDefaults; use OCA\Theming\Util; @@ -1652,7 +1653,7 @@ public function getUserSession() { * @deprecated 20.0.0 */ public function getSession() { - return $this->get(IUserSession::class)->getSession(); + return $this->get(Session::class)->getSession(); } /** @@ -1660,7 +1661,7 @@ public function getSession() { */ public function setSession(\OCP\ISession $session) { $this->get(SessionStorage::class)->setSession($session); - $this->get(IUserSession::class)->setSession($session); + $this->get(Session::class)->setSession($session); $this->get(Store::class)->setSession($session); } diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php index d6bec7526b731..6bd98715c1290 100644 --- a/lib/private/ServerContainer.php +++ b/lib/private/ServerContainer.php @@ -30,6 +30,7 @@ use OC\AppFramework\DependencyInjection\DIContainer; use OC\AppFramework\Utility\SimpleContainer; use OCP\AppFramework\QueryException; +use Psr\Container\ContainerExceptionInterface; use function explode; use function strtolower; @@ -127,6 +128,13 @@ public function has($id, bool $noRecursion = false): bool { } /** + * @template T + * @param class-string|string $name + * @return T|mixed + * @psalm-template S as class-string|string + * @psalm-param S $name + * @psalm-return (S is class-string ? T : mixed) + * @throws QueryException * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get */ public function query(string $name, bool $autoload = true) { diff --git a/lib/public/Server.php b/lib/public/Server.php index f4522e8ae1080..92560e2b17e4f 100644 --- a/lib/public/Server.php +++ b/lib/public/Server.php @@ -41,9 +41,11 @@ final class Server { /** * @template T - * @template S as class-string|string - * @param S $serviceName - * @return (S is class-string ? T : mixed) + * @param class-string|string $serviceName + * @return T|mixed + * @psalm-template S as class-string|string + * @psalm-param S $serviceName + * @psalm-return (S is class-string ? T : mixed) * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @since 25.0.0