Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve container return type annotations #33388

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@
</RedundantCondition>
<TypeDoesNotContainType occurrences="2">
<code>get_class($res) === 'OpenSSLAsymmetricKey'</code>
<code>is_object($res)</code>
</TypeDoesNotContainType>
</file>
<file src="apps/encryption/lib/Crypto/EncryptAll.php">
Expand Down Expand Up @@ -3159,7 +3160,6 @@
<code>bool</code>
<code>int</code>
<code>string</code>
<code>string</code>
</InvalidReturnType>
<InvalidScalarArgument occurrences="5">
<code>$lastChunkPos</code>
Expand Down Expand Up @@ -3619,6 +3619,9 @@
<code>\OCP\Calendar\Room\IManager</code>
<code>\OCP\Files\Folder|null</code>
</ImplementedReturnTypeMismatch>
<InvalidArgument occurrences="1">
<code>new GenericEvent($user)</code>
</InvalidArgument>
<InvalidCatch occurrences="1"/>
<UndefinedDocblockClass occurrences="1">
<code>\OC\OCSClient</code>
Expand Down
9 changes: 9 additions & 0 deletions lib/private/AppFramework/Utility/SimpleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public function __construct() {
$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) {
return $this->query($id);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
use OC\User\DisplayNameCache;
use OC\User\Listeners\BeforeUserDeletedListener;
use OC\User\Listeners\UserChangedListener;
use OC\User\Session;
use OCA\Theming\ImageManager;
use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util;
Expand Down Expand Up @@ -1672,15 +1673,15 @@ public function getUserSession() {
* @deprecated 20.0.0
*/
public function getSession() {
return $this->get(IUserSession::class)->getSession();
return $this->get(Session::class)->getSession();
}

/**
* @param \OCP\ISession $session
*/
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);
}

Expand Down
7 changes: 7 additions & 0 deletions lib/private/ServerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ public function has($id, bool $noRecursion = false): bool {
}

/**
* @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
*/
public function query(string $name, bool $autoload = true) {
Expand Down
8 changes: 5 additions & 3 deletions lib/public/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
final class Server {
/**
* @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 NotFoundExceptionInterface
* @since 25.0.0
Expand Down