Skip to content

Commit 9979b6d

Browse files
authored
Merge pull request #23377 from nextcloud/enhancement/psalm-annotate-icontainer
Annotate IContainer so Psalm knows what resove and query return
2 parents 2b36842 + f464ef0 commit 9979b6d

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

apps/workflowengine/lib/Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ protected function getBuildInOperators(): array {
695695
}
696696

697697
/**
698-
* @return IEntity[]
698+
* @return ICheck[]
699699
*/
700700
protected function getBuildInChecks(): array {
701701
try {

lib/base.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ private static function registerAccountHooks() {
859859
}
860860

861861
private static function registerAppRestrictionsHooks() {
862+
/** @var \OC\Group\Manager $groupManager */
862863
$groupManager = self::$server->query(\OCP\IGroupManager::class);
863864
$groupManager->listen('\OC\Group', 'postDelete', function (\OCP\IGroup $group) {
864865
$appManager = self::$server->getAppManager();

lib/private/AppFramework/App.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
use OC\AppFramework\DependencyInjection\DIContainer;
3636
use OC\AppFramework\Http\Dispatcher;
37+
use OC\AppFramework\Http\Request;
3738
use OC\HintException;
3839
use OCP\AppFramework\Http;
3940
use OCP\AppFramework\Http\ICallbackResponse;
@@ -114,9 +115,13 @@ public static function getAppIdForClass(string $className, string $topNamespace
114115
*/
115116
public static function main(string $controllerName, string $methodName, DIContainer $container, array $urlParams = null) {
116117
if (!is_null($urlParams)) {
117-
$container->query(IRequest::class)->setUrlParameters($urlParams);
118+
/** @var Request $request */
119+
$request = $container->query(IRequest::class);
120+
$request->setUrlParameters($urlParams);
118121
} elseif (isset($container['urlParams']) && !is_null($container['urlParams'])) {
119-
$container->query(IRequest::class)->setUrlParameters($container['urlParams']);
122+
/** @var Request $request */
123+
$request = $container->query(IRequest::class);
124+
$request->setUrlParameters($container['urlParams']);
120125
}
121126
$appName = $container['AppName'];
122127

lib/private/Collaboration/Collaborators/Search.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ public function search($search, array $shareTypes, $lookup, $limit, $offset) {
6868
foreach ($this->pluginList[$type] as $plugin) {
6969
/** @var ISearchPlugin $searchPlugin */
7070
$searchPlugin = $this->c->resolve($plugin);
71-
$hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult);
71+
$hasMoreResults = $searchPlugin->search($search, $limit, $offset, $searchResult) || $hasMoreResults;
7272
}
7373
}
7474

7575
// Get from lookup server, not a separate share type
7676
if ($lookup) {
7777
$searchPlugin = $this->c->resolve(LookupPlugin::class);
78-
$hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult);
78+
$hasMoreResults = $searchPlugin->search($search, $limit, $offset, $searchResult) || $hasMoreResults;
7979
}
8080

8181
// sanitizing, could go into the plugins as well

lib/public/IContainer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@
5252
interface IContainer extends ContainerInterface {
5353

5454
/**
55+
* @template T
56+
*
5557
* If a parameter is not registered in the container try to instantiate it
5658
* by using reflection to find out how to build the class
5759
* @param string $name the class name to resolve
60+
* @psalm-param string|class-string<T> $name
5861
* @return \stdClass
62+
* @psalm-return ($name is class-string ? T : mixed)
5963
* @since 8.2.0
6064
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
6165
* @throws ContainerExceptionInterface if the class could not be found or instantiated
@@ -66,9 +70,13 @@ public function resolve($name);
6670
/**
6771
* Look up a service for a given name in the container.
6872
*
73+
* @template T
74+
*
6975
* @param string $name
76+
* @psalm-param string|class-string<T> $name
7077
* @param bool $autoload Should we try to autoload the service. If we are trying to resolve built in types this makes no sense for example
7178
* @return mixed
79+
* @psalm-return ($name is class-string ? T : mixed)
7280
* @throws ContainerExceptionInterface if the query could not be resolved
7381
* @throws QueryException if the query could not be resolved
7482
* @since 6.0.0

0 commit comments

Comments
 (0)