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

Annotate IContainer so Psalm knows what resove and query return #23377

Merged
merged 2 commits into from
Oct 14, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/workflowengine/lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ protected function getBuildInOperators(): array {
}

/**
* @return IEntity[]
* @return ICheck[]
*/
protected function getBuildInChecks(): array {
try {
Expand Down
1 change: 1 addition & 0 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ private static function registerAccountHooks() {
}

private static function registerAppRestrictionsHooks() {
/** @var \OC\Group\Manager $groupManager */
$groupManager = self::$server->query(\OCP\IGroupManager::class);
$groupManager->listen('\OC\Group', 'postDelete', function (\OCP\IGroup $group) {
$appManager = self::$server->getAppManager();
Expand Down
9 changes: 7 additions & 2 deletions lib/private/AppFramework/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

use OC\AppFramework\DependencyInjection\DIContainer;
use OC\AppFramework\Http\Dispatcher;
use OC\AppFramework\Http\Request;
use OC\HintException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\ICallbackResponse;
Expand Down Expand Up @@ -114,9 +115,13 @@ public static function getAppIdForClass(string $className, string $topNamespace
*/
public static function main(string $controllerName, string $methodName, DIContainer $container, array $urlParams = null) {
if (!is_null($urlParams)) {
$container->query(IRequest::class)->setUrlParameters($urlParams);
/** @var Request $request */
$request = $container->query(IRequest::class);
$request->setUrlParameters($urlParams);
} elseif (isset($container['urlParams']) && !is_null($container['urlParams'])) {
$container->query(IRequest::class)->setUrlParameters($container['urlParams']);
/** @var Request $request */
$request = $container->query(IRequest::class);
$request->setUrlParameters($container['urlParams']);
}
$appName = $container['AppName'];

Expand Down
4 changes: 2 additions & 2 deletions lib/private/Collaboration/Collaborators/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ public function search($search, array $shareTypes, $lookup, $limit, $offset) {
foreach ($this->pluginList[$type] as $plugin) {
/** @var ISearchPlugin $searchPlugin */
$searchPlugin = $this->c->resolve($plugin);
$hasMoreResults |= $searchPlugin->search($search, $limit, $offset, $searchResult);
$hasMoreResults = $searchPlugin->search($search, $limit, $offset, $searchResult) || $hasMoreResults;
Copy link
Member Author

Choose a reason for hiding this comment

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

@blizzz hope the logic is unchanged. The search call should always happen no matter the value of $hasMoreResults, right? Asking because there might be semantics of the short-circuit evaluation of an or.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right ... but yes - the search should happen in every plugin and then it is combined afterwards.

}
}

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

// sanitizing, could go into the plugins as well
Expand Down
8 changes: 8 additions & 0 deletions lib/public/IContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@
interface IContainer extends ContainerInterface {

/**
* @template T
*
* If a parameter is not registered in the container try to instantiate it
* by using reflection to find out how to build the class
* @param string $name the class name to resolve
* @psalm-param string|class-string<T> $name
* @return \stdClass
* @psalm-return ($name is class-string ? T : mixed)
* @since 8.2.0
* @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
* @throws ContainerExceptionInterface if the class could not be found or instantiated
Expand All @@ -66,9 +70,13 @@ public function resolve($name);
/**
* Look up a service for a given name in the container.
*
* @template T
*
* @param string $name
* @psalm-param string|class-string<T> $name
* @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
* @return mixed
* @psalm-return ($name is class-string ? T : mixed)
* @throws ContainerExceptionInterface if the query could not be resolved
* @throws QueryException if the query could not be resolved
* @since 6.0.0
Expand Down