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

Add psalm template annotation to container get method #30498

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 2 additions & 15 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1301,11 +1301,6 @@
<code>$i</code>
</UndefinedInterfaceMethod>
</file>
<file src="apps/files/lib/Listener/LegacyLoadAdditionalScriptsAdapter.php">
<InvalidArgument occurrences="1">
<code>$legacyEvent</code>
</InvalidArgument>
</file>
<file src="apps/files/lib/Service/DirectEditingService.php">
<UndefinedInterfaceMethod occurrences="1">
<code>getEditors</code>
Expand Down Expand Up @@ -1639,8 +1634,7 @@
<InvalidArgument occurrences="1">
<code>$files_list</code>
</InvalidArgument>
<InvalidScalarArgument occurrences="3">
<code>$freeSpace</code>
<InvalidScalarArgument occurrences="1">
<code>$maxUploadFilesize</code>
<code>$maxUploadFilesize</code>
</InvalidScalarArgument>
Expand Down Expand Up @@ -1681,11 +1675,6 @@
<code>isSharable</code>
</InvalidReturnType>
</file>
<file src="apps/files_sharing/lib/Listener/LegacyBeforeTemplateRenderedListener.php">
<InvalidArgument occurrences="1">
<code>$legacyEvent</code>
</InvalidArgument>
</file>
<file src="apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php">
<InvalidArgument occurrences="1">
<code>$exception-&gt;getMessage()</code>
Expand Down Expand Up @@ -1967,10 +1956,8 @@
</InvalidScalarArgument>
</file>
<file src="apps/sharebymail/lib/ShareByMailProvider.php">
<InvalidScalarArgument occurrences="4">
<InvalidScalarArgument occurrences="2">
<code>$share-&gt;getId()</code>
<code>$shareId</code>
<code>$shareId</code>
<code>(int)$data['id']</code>
</InvalidScalarArgument>
</file>
Expand Down
6 changes: 6 additions & 0 deletions lib/private/AppFramework/Utility/SimpleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public function __construct() {
$this->container = new Container();
}

/**
* @psalm-suppress MoreSpecificImplementedParamType
* @psalm-template T
* @psalm-param class-string<T> $id
* @psalm-return T
*/
public function get(string $id) {
return $this->query($id);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/EventDispatcher/SymfonyAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ private static function detectEventAndName($a, $b) {
* @param string $eventName The name of the event to dispatch. The name of
* the event is the name of the method that is
* invoked on listeners.
* @param Event|null $event The event to pass to the event handlers/listeners
* If not supplied, an empty Event instance is created
* @param Event|GenericEvent|null $event The event to pass to the event handlers/listeners
* If not supplied, an empty Event instance is created
*
* @return object the emitted event
* @deprecated 20.0.0
Expand Down
40 changes: 26 additions & 14 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,10 @@ public function __construct($webRoot, \OC\Config $config) {
$this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class);
/** @deprecated 19.0.0 */
$this->registerDeprecatedAlias('Throttler', Throttler::class);
$this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) {

/** @deprecated 24.0.0 */
$this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class);
$this->registerService(Checker::class, function (ContainerInterface $c) {
// IConfig and IAppManager requires a working database. This code
// might however be called when ownCloud is not yet setup.
if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
Expand Down Expand Up @@ -1156,8 +1159,10 @@ public function __construct($webRoot, \OC\Config $config) {
/** @deprecated 19.0.0 */
$this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);

$this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
$this->registerService('ThemingDefaults', function (Server $c) {
$this->registerAlias(\OC_Defaults::class, ThemingDefaults::class);
/** @deprecated 24.0.0 */
$this->registerDeprecatedAlias('ThemingDefaults', ThemingDefaults::class);
CarlSchwan marked this conversation as resolved.
Show resolved Hide resolved
$this->registerService(ThemingDefaults::class, function (Server $c) {
/*
* Dark magic for autoloader.
* If we do a class_exists it will try to load the class which will
Expand Down Expand Up @@ -1206,7 +1211,9 @@ public function __construct($webRoot, \OC\Config $config) {
$this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);

$this->registerService('CryptoWrapper', function (ContainerInterface $c) {
/** @deprecated 24.0.0 */
$this->registerDeprecatedAlias('CryptoWrapper', CryptoWrapper::class);
$this->registerService(CryptoWrapper::class, function (ContainerInterface $c) {
// FIXME: Instantiiated here due to cyclic dependency
$request = new Request(
[
Expand Down Expand Up @@ -1261,7 +1268,7 @@ public function __construct($webRoot, \OC\Config $config) {
$c->get(SymfonyAdapter::class),
$c->get(IMailer::class),
$c->get(IURLGenerator::class),
$c->get('ThemingDefaults'),
$c->get(ThemingDefaults::class),
$c->get(IEventDispatcher::class),
$c->get(IUserSession::class),
$c->get(KnownUserService::class)
Expand Down Expand Up @@ -1302,7 +1309,9 @@ public function __construct($webRoot, \OC\Config $config) {
);
});

$this->registerService('LockdownManager', function (ContainerInterface $c) {
/** @deprecated 24.0.0 */
$this->registerDeprecatedAlias('LockdownManager', LockdownManager::class);
$this->registerService(LockdownManager::class, function (ContainerInterface $c): LockdownManager {
return new LockdownManager(function () use ($c) {
return $c->get(ISession::class);
});
Expand Down Expand Up @@ -1645,6 +1654,7 @@ public function getUserSession() {
* @deprecated 20.0.0
*/
public function getSession() {
/** @psalm-suppress UndefinedInterfaceMethod */
return $this->get(IUserSession::class)->getSession();
}

Expand All @@ -1653,6 +1663,7 @@ public function getSession() {
*/
public function setSession(\OCP\ISession $session) {
$this->get(SessionStorage::class)->setSession($session);
/** @psalm-suppress UndefinedInterfaceMethod */
$this->get(IUserSession::class)->setSession($session);
$this->get(Store::class)->setSession($session);
}
Expand Down Expand Up @@ -1763,7 +1774,7 @@ public function getMemCacheFactory() {
* @deprecated 20.0.0
*/
public function getGetRedisFactory() {
return $this->get('RedisFactory');
return $this->get(RedisFactory::class);
}


Expand Down Expand Up @@ -1974,6 +1985,7 @@ public function getWebRoot() {
* @deprecated 20.0.0
*/
public function getOcsClient() {
/** @psalm-suppress UndefinedClass */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw this code looks broken since I couldn't find where the class or alias OcsClient is defined. This, fortunately, doesn't seems to be called anywhere: http://carlschwan.eu:6070/search?q=OcsClient

return $this->get('OcsClient');
}

Expand Down Expand Up @@ -2117,27 +2129,27 @@ public function getCommentsManager() {
}

/**
* @return \OCA\Theming\ThemingDefaults
* @return ThemingDefaults
* @deprecated 20.0.0
*/
public function getThemingDefaults() {
return $this->get('ThemingDefaults');
return $this->get(ThemingDefaults::class);
}

/**
* @return \OC\IntegrityCheck\Checker
* @deprecated 20.0.0
*/
public function getIntegrityCodeChecker() {
return $this->get('IntegrityCodeChecker');
return $this->get(Checker::class);
}

/**
* @return \OC\Session\CryptoWrapper
* @return CryptoWrapper
* @deprecated 20.0.0
*/
public function getSessionCryptoWrapper() {
return $this->get('CryptoWrapper');
return $this->get(CryptoWrapper::class);
}

/**
Expand Down Expand Up @@ -2243,7 +2255,7 @@ public function getAutoCompleteManager() {
* @deprecated 20.0.0
*/
public function getLDAPProvider() {
return $this->get('LDAPProvider');
return $this->get(ILDAPProvider::class);
}

/**
Expand All @@ -2269,7 +2281,7 @@ public function getAppDataDir($app) {
* @deprecated 20.0.0
*/
public function getLockdownManager() {
return $this->get('LockdownManager');
return $this->get(LockdownManager::class);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions lib/private/Template/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
namespace OC\Template;

use OCP\Defaults;
use Throwable;

class Base {
private $template; // The template
Expand Down Expand Up @@ -92,7 +91,7 @@ protected function getCoreTemplateDirs($theme, $serverRoot) {
/**
* Assign variables
* @param string $key key
* @param array|bool|integer|string|Throwable $value value
* @param mixed $value value
* @return bool
*
* This function assigns a variable. It can be accessed via $_[$key] in
Expand Down