Browse Source

Improve container return type annotations

Signed-off-by: Julius Härtl <jus@bitgrid.net>
pull/33388/head
Julius Härtl 3 years ago
parent
commit
cea2f79bbd
No known key found for this signature in database GPG Key ID: 4C614C6ED2CDE6DF
  1. 5
      build/psalm-baseline.xml
  2. 9
      lib/private/AppFramework/Utility/SimpleContainer.php
  3. 5
      lib/private/Server.php
  4. 7
      lib/private/ServerContainer.php
  5. 8
      lib/public/Server.php

5
build/psalm-baseline.xml

@ -840,6 +840,7 @@
</RedundantCondition> </RedundantCondition>
<TypeDoesNotContainType occurrences="2"> <TypeDoesNotContainType occurrences="2">
<code>get_class($res) === 'OpenSSLAsymmetricKey'</code> <code>get_class($res) === 'OpenSSLAsymmetricKey'</code>
<code>is_object($res)</code>
</TypeDoesNotContainType> </TypeDoesNotContainType>
</file> </file>
<file src="apps/encryption/lib/Crypto/EncryptAll.php"> <file src="apps/encryption/lib/Crypto/EncryptAll.php">
@ -3159,7 +3160,6 @@
<code>bool</code> <code>bool</code>
<code>int</code> <code>int</code>
<code>string</code> <code>string</code>
<code>string</code>
</InvalidReturnType> </InvalidReturnType>
<InvalidScalarArgument occurrences="5"> <InvalidScalarArgument occurrences="5">
<code>$lastChunkPos</code> <code>$lastChunkPos</code>
@ -3619,6 +3619,9 @@
<code>\OCP\Calendar\Room\IManager</code> <code>\OCP\Calendar\Room\IManager</code>
<code>\OCP\Files\Folder|null</code> <code>\OCP\Files\Folder|null</code>
</ImplementedReturnTypeMismatch> </ImplementedReturnTypeMismatch>
<InvalidArgument occurrences="1">
<code>new GenericEvent($user)</code>
</InvalidArgument>
<InvalidCatch occurrences="1"/> <InvalidCatch occurrences="1"/>
<UndefinedDocblockClass occurrences="1"> <UndefinedDocblockClass occurrences="1">
<code>\OC\OCSClient</code> <code>\OC\OCSClient</code>

9
lib/private/AppFramework/Utility/SimpleContainer.php

@ -53,6 +53,15 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer {
$this->container = new Container(); $this->container = new Container();
} }
/**
* @template T
* @param class-string<T>|string $id
* @return T|mixed
* @psalm-template S as class-string<T>|string
* @psalm-param S $id
* @psalm-return (S is class-string<T> ? T : mixed)
* @throws QueryException
*/
public function get(string $id) { public function get(string $id) {
return $this->query($id); return $this->query($id);
} }

5
lib/private/Server.php

@ -155,6 +155,7 @@ use OC\Template\JSCombiner;
use OC\User\DisplayNameCache; use OC\User\DisplayNameCache;
use OC\User\Listeners\BeforeUserDeletedListener; use OC\User\Listeners\BeforeUserDeletedListener;
use OC\User\Listeners\UserChangedListener; use OC\User\Listeners\UserChangedListener;
use OC\User\Session;
use OCA\Theming\ImageManager; use OCA\Theming\ImageManager;
use OCA\Theming\ThemingDefaults; use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util; use OCA\Theming\Util;
@ -1672,7 +1673,7 @@ class Server extends ServerContainer implements IServerContainer {
* @deprecated 20.0.0 * @deprecated 20.0.0
*/ */
public function getSession() { public function getSession() {
return $this->get(IUserSession::class)->getSession();
return $this->get(Session::class)->getSession();
} }
/** /**
@ -1680,7 +1681,7 @@ class Server extends ServerContainer implements IServerContainer {
*/ */
public function setSession(\OCP\ISession $session) { public function setSession(\OCP\ISession $session) {
$this->get(SessionStorage::class)->setSession($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); $this->get(Store::class)->setSession($session);
} }

7
lib/private/ServerContainer.php

@ -127,6 +127,13 @@ class ServerContainer extends SimpleContainer {
} }
/** /**
* @template T
* @param class-string<T>|string $name
* @return T|mixed
* @psalm-template S as class-string<T>|string
* @psalm-param S $name
* @psalm-return (S is class-string<T> ? T : mixed)
* @throws QueryException
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
*/ */
public function query(string $name, bool $autoload = true) { public function query(string $name, bool $autoload = true) {

8
lib/public/Server.php

@ -41,9 +41,11 @@ use Psr\Container\NotFoundExceptionInterface;
final class Server { final class Server {
/** /**
* @template T * @template T
* @template S as class-string<T>|string
* @param S $serviceName
* @return (S is class-string<T> ? T : mixed)
* @param class-string<T>|string $serviceName
* @return T|mixed
* @psalm-template S as class-string<T>|string
* @psalm-param S $serviceName
* @psalm-return (S is class-string<T> ? T : mixed)
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @since 25.0.0 * @since 25.0.0

Loading…
Cancel
Save