Skip to content

Commit

Permalink
Merge pull request #3225 from nextcloud/fix/psalm/missing-stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin authored Sep 16, 2024
2 parents 009c3b1 + 70099f4 commit 3abb9d3
Show file tree
Hide file tree
Showing 101 changed files with 15,692 additions and 2,380 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
->getFinder()
->ignoreVCSIgnored(true)
->notPath('build')
->notPath('tests/stubs')
->notPath('l10n')
->notPath('src')
->notPath('vendor')
Expand Down
235 changes: 235 additions & 0 deletions LICENSES/AGPL-3.0-only.txt

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,27 @@ path = ["img/app-dark.svg", "img/app.svg", "img/deny.svg", "img/folder-group.svg
precedence = "aggregate"
SPDX-FileCopyrightText = "2018-2024 Google LLC"
SPDX-License-Identifier = "Apache-2.0"

[[annotations]]
path = ["tests/stubs/doctrine_dbal_**"]
precedence = "aggregate"
SPDX-FileCopyrightText = "none"
SPDX-License-Identifier = "MIT"

[[annotations]]
path = ["tests/stubs/symfony_component_**"]
precedence = "aggregate"
SPDX-FileCopyrightText = "none"
SPDX-License-Identifier = "MIT"

[[annotations]]
path = ["tests/stubs/stecman_component_**"]
precedence = "aggregate"
SPDX-FileCopyrightText = "none"
SPDX-License-Identifier = "MIT"

[[annotations]]
path = ["tests/stubs/icewind_streams_**"]
precedence = "aggregate"
SPDX-FileCopyrightText = "none"
SPDX-License-Identifier = "MIT"
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"nextcloud/ocp": "dev-master"
},
"scripts": {
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './tests/stubs/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm.phar --threads=$(nproc) --no-cache",
Expand Down
6 changes: 3 additions & 3 deletions lib/ACL/ACLCacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ public function getFolderContentsById($fileId) {
public function search($pattern) {
$results = $this->getCache()->search($pattern);
$this->preloadEntries($results);
return array_map([$this, 'formatCacheEntry'], $results);
return array_filter(array_map([$this, 'formatCacheEntry'], $results));
}

public function searchByMime($mimetype) {
$results = $this->getCache()->searchByMime($mimetype);
$this->preloadEntries($results);
return array_map([$this, 'formatCacheEntry'], $results);
return array_filter(array_map([$this, 'formatCacheEntry'], $results));
}

public function searchQuery(ISearchQuery $query) {
$results = $this->getCache()->searchQuery($query);
$this->preloadEntries($results);
return array_map([$this, 'formatCacheEntry'], $results);
return array_filter(array_map([$this, 'formatCacheEntry'], $results));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace OCA\GroupFolders\AppInfo;

use OC\Files\Node\LazyFolder;
use OC\Group;
use OCA\Circles\Events\CircleDestroyedEvent;
use OCA\DAV\Connector\Sabre\Principal;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
Expand Down Expand Up @@ -228,7 +229,7 @@ public function register(IRegistrationContext $context): void {
}

public function boot(IBootContext $context): void {
$context->injectFn(function (IMountProviderCollection $mountProviderCollection, CacheListener $cacheListener, IGroupManager $groupManager): void {
$context->injectFn(function (IMountProviderCollection $mountProviderCollection, CacheListener $cacheListener, Group\Manager $groupManager): void {
$mountProviderCollection->registerProvider($this->getMountProvider());

$groupManager->listen('\OC\Group', 'postDelete', function (IGroup $group) {
Expand Down
1 change: 0 additions & 1 deletion lib/Command/Scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ protected function configure() {
parent::configure();
}

/** @psalm-suppress UndefinedInterfaceMethod setUseTransactions is defined in private class */
protected function execute(InputInterface $input, OutputInterface $output) {
$folderId = $input->getArgument('folder_id');
$all = $input->getOption('all');
Expand Down
2 changes: 1 addition & 1 deletion lib/DAV/GroupFoldersHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function getFolder(string $name): ?array {
private function getDirectoryForFolder(array $folder): GroupFolderNode {
$userHome = '/' . $this->user->getUID() . '/files';
$node = $this->rootFolder->get($userHome . '/' . $folder['mount_point']);
return new GroupFolderNode(Filesystem::getView($userHome), $node, $folder['folder_id']);
return new GroupFolderNode(Filesystem::getView(), $node, $folder['folder_id']);
}

public function getChild($name) {
Expand Down
10 changes: 5 additions & 5 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace OCA\GroupFolders\Folder;

use OC\Files\Cache\Cache;
use OC\Files\Cache\CacheEntry;
use OC\Files\Node\Node;
use OCA\Circles\CirclesManager;
use OCA\Circles\CirclesQueryHelper;
Expand All @@ -18,7 +19,6 @@
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\IConfig;
Expand Down Expand Up @@ -482,7 +482,7 @@ public function searchUsers(int $id, string $search = '', int $limit = 10, int $
/**
* @param string $groupId
* @param int $rootStorageId
* @return list<array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry}>
* @return list<array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?CacheEntry}>
* @throws Exception
*/
public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): array {
Expand Down Expand Up @@ -534,7 +534,7 @@ public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): arr
/**
* @param string[] $groupIds
* @param int $rootStorageId
* @return array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry}[]
* @return array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?CacheEntry}[]
* @throws Exception
*/
public function getFoldersForGroups(array $groupIds, int $rootStorageId = 0): array {
Expand Down Expand Up @@ -592,7 +592,7 @@ public function getFoldersForGroups(array $groupIds, int $rootStorageId = 0): ar
/**
* @param string[] $groupIds
* @param int $rootStorageId
* @return array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry}[]
* @return array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?CacheEntry}[]
* @throws Exception
*/
public function getFoldersFromCircleMemberships(IUser $user, int $rootStorageId = 0): array {
Expand Down Expand Up @@ -877,7 +877,7 @@ public function setFolderACL(int $folderId, bool $acl): void {
/**
* @param IUser $user
* @param int $rootStorageId
* @return list<array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry}>
* @return list<array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?CacheEntry}>
* @throws Exception
*/
public function getFoldersForUser(IUser $user, int $rootStorageId = 0): array {
Expand Down
5 changes: 5 additions & 0 deletions lib/Mount/GroupFolderNoEncryptionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@

use OCP\Files\Storage\IDisableEncryptionStorage;

/**
* @psalm-suppress UnimplementedInterfaceMethod
* Psalm gets confused about missing methods, but those are implemented in OC\Files\Storage\Wrapper\Wrapper,
* so this suppression is fine and necessary as there is nothing wrong.
*/
class GroupFolderNoEncryptionStorage extends GroupFolderStorage implements IDisableEncryptionStorage {
}
3 changes: 2 additions & 1 deletion lib/Mount/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace OCA\GroupFolders\Mount;

use OC\Files\Cache\CacheEntry;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\PermissionsMask;
use OCA\GroupFolders\ACL\ACLManager;
Expand Down Expand Up @@ -102,7 +103,7 @@ private function getRootStorageId(): int {
}

/**
* @return list<array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry}>
* @return list<array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?CacheEntry}>
*/
public function getFoldersForUser(IUser $user): array {
return $this->folderManager->getFoldersForUser($user, $this->getRootStorageId());
Expand Down
120 changes: 86 additions & 34 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,92 @@
findUnusedCode="false"
>
<stubs>
<file name="tests/stub.phpstub" preloadClasses="true"/>
<file name="tests/stubs/doctrine_dbal_schema_abstractasset.php" />
<file name="tests/stubs/doctrine_dbal_schema_column.php" />
<file name="tests/stubs/doctrine_dbal_schema_schema.php" />
<file name="tests/stubs/doctrine_dbal_schema_table.php" />
<file name="tests/stubs/stecman_component_symfony_console_bashcompletion_completion_completionawareinterface.php" />
<file name="tests/stubs/symfony_component_console_command_command.php" />
<file name="tests/stubs/symfony_component_console_helper_table.php" />
<file name="tests/stubs/symfony_component_console_input_inputargument.php" />
<file name="tests/stubs/symfony_component_console_input_inputinterface.php" />
<file name="tests/stubs/symfony_component_console_input_inputoption.php" />
<file name="tests/stubs/symfony_component_console_output_outputinterface.php" />
<file name="tests/stubs/symfony_component_console_question_confirmationquestion.php" />
<file name="tests/stubs/symfony_component_console_question_confirmationquestion.php" />
<file name="tests/stubs/symfony_component_console_question_question.php" />
<file name="tests/stubs/oca_circles_circlesmanager.php" />
<file name="tests/stubs/oca_circles_circlesqueryhelper.php" />
<file name="tests/stubs/oca_circles_events_circledestroyedevent.php" />
<file name="tests/stubs/oca_circles_events_circleresultgenericevent.php" />
<file name="tests/stubs/oca_circles_exceptions_circlenotfoundexception.php" />
<file name="tests/stubs/oca_circles_exceptions_federateditemexception.php" />
<file name="tests/stubs/oca_circles_exceptions_federateditemnotfoundexception.php" />
<file name="tests/stubs/oca_circles_ientity.php" />
<file name="tests/stubs/oca_circles_ifederateduser.php" />
<file name="tests/stubs/oca_circles_iqueryprobe.php" />
<file name="tests/stubs/oca_circles_model_circle.php" />
<file name="tests/stubs/oca_circles_model_federateduser.php" />
<file name="tests/stubs/oca_circles_model_managedmodel.php" />
<file name="tests/stubs/oca_circles_model_probes_basicprobe.php" />
<file name="tests/stubs/oca_circles_model_probes_circleprobe.php" />
<file name="tests/stubs/oca_circles_model_probes_memberprobe.php" />
<file name="tests/stubs/oca_circles_tools_db_iqueryrow.php" />
<file name="tests/stubs/oca_circles_tools_ideserializable.php" />
<file name="tests/stubs/icewind_streams_iteratordirectory.php" />
<file name="tests/stubs/icewind_streams_wrapperhandler.php" />
<file name="tests/stubs/icewind_streams_directory.php" />
<file name="tests/stubs/oc.php" />
<file name="tests/stubs/oc_appframework_ocs_baseresponse.php" />
<file name="tests/stubs/oc_appframework_ocs_v1response.php" />
<file name="tests/stubs/oc_appframework_utility_simplecontainer.php" />
<file name="tests/stubs/oc_core_command_base.php" />
<file name="tests/stubs/oc_files_cache_cache.php" />
<file name="tests/stubs/oc_files_cache_cacheentry.php" />
<file name="tests/stubs/oc_files_cache_scanner.php" />
<file name="tests/stubs/oc_files_cache_wrapper_cachejail.php" />
<file name="tests/stubs/oc_files_cache_wrapper_cachewrapper.php" />
<file name="tests/stubs/oc_files_filesystem.php" />
<file name="tests/stubs/oc_files_mount_mountpoint.php" />
<file name="tests/stubs/oc_files_node_lazyfolder.php" />
<file name="tests/stubs/oc_files_node_node.php" />
<file name="tests/stubs/oc_files_objectstore_objectstorescanner.php" />
<file name="tests/stubs/oc_files_objectstore_objectstorestorage.php" />
<file name="tests/stubs/oc_files_storage_common.php" />
<file name="tests/stubs/oc_files_storage_storage.php" />
<file name="tests/stubs/oc_files_storage_wrapper_jail.php" />
<file name="tests/stubs/oc_files_storage_wrapper_permissionsmask.php" />
<file name="tests/stubs/oc_files_storage_wrapper_quota.php" />
<file name="tests/stubs/oc_files_storage_wrapper_wrapper.php" />
<file name="tests/stubs/oc_files_view.php" />
<file name="tests/stubs/oc_group_manager.php" />
<file name="tests/stubs/oc_hooks_basicemitter.php" />
<file name="tests/stubs/oc_hooks_emitter.php" />
<file name="tests/stubs/oc_hooks_emittertrait.php" />
<file name="tests/stubs/oc_hooks_publicemitter.php" />
<file name="tests/stubs/oc_server.php" />
<file name="tests/stubs/oc_servercontainer.php" />
<file name="tests/stubs/oc_settings_authorizedgroupmapper.php" />
<file name="tests/stubs/oc_user_user.php" />
<file name="tests/stubs/oca_dav_connector_sabre_directory.php" />
<file name="tests/stubs/oca_dav_connector_sabre_node.php" />
<file name="tests/stubs/oca_dav_connector_sabre_principal.php" />
<file name="tests/stubs/oca_files_event_loadadditionalscriptsevent.php" />
<file name="tests/stubs/oca_files_sharing_event_beforetemplaterenderedevent.php" />
<file name="tests/stubs/oca_files_trashbin_expiration.php" />
<file name="tests/stubs/oca_files_trashbin_trash_itrashbackend.php" />
<file name="tests/stubs/oca_files_trashbin_trash_itrashitem.php" />
<file name="tests/stubs/oca_files_trashbin_trash_trashitem.php" />
<file name="tests/stubs/oca_files_versions_expiration.php" />
<file name="tests/stubs/oca_files_versions_versions_ideletableversionbackend.php" />
<file name="tests/stubs/oca_files_versions_versions_imetadataversion.php" />
<file name="tests/stubs/oca_files_versions_versions_imetadataversionbackend.php" />
<file name="tests/stubs/oca_files_versions_versions_ineedsyncversionbackend.php" />
<file name="tests/stubs/oca_files_versions_versions_iversion.php" />
<file name="tests/stubs/oca_files_versions_versions_iversionbackend.php" />
<file name="tests/stubs/oca_files_versions_versions_iversionsimporterbackend.php" />
<file name="tests/stubs/oca_files_versions_versions_version.php" />
<file name="tests/stubs/oca_settings_service_authorizedgroupservice.php" />
</stubs>
<projectFiles>
<directory name="lib" />
Expand All @@ -30,39 +115,6 @@
</ignoreFiles>
</extraFiles>
<issueHandlers>
<UndefinedMagicMethod>
<errorLevel type="suppress">
<referencedMethod name="/Db\\.*::.*/" />
</errorLevel>
</UndefinedMagicMethod>
<UndefinedInterfaceMethod>
<errorLevel type="suppress">
<!-- FIXME Deprecated event handling -->
<referencedMethod name="OCP\IUserManager::listen" />
<referencedMethod name="OCP\IGroupManager::listen" />
</errorLevel>
</UndefinedInterfaceMethod>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="OC\AppFramework\OCS\V1Response"/>
<referencedClass name="OC\AppFramework\Utility\ControllerMethodReflector"/>
<referencedClass name="OC\Security\CSP\ContentSecurityPolicyNonceManager" />
<referencedClass name="OC\Settings\AuthorizedGroupMapper"/>
<referencedClass name="OCA\Files\Event\LoadAdditionalScriptsEvent"/>
<referencedClass name="OCA\Settings\Service\AuthorizedGroupService"/>
</errorLevel>
</UndefinedClass>
<UndefinedDocblockClass>
<errorLevel type="suppress">
<referencedClass name="Doctrine\DBAL\Driver\Statement" />
<referencedClass name="Doctrine\DBAL\Schema\Schema" />
<referencedClass name="Doctrine\DBAL\Schema\SchemaException" />
<referencedClass name="Doctrine\DBAL\Schema\Table" />
<referencedClass name="OC\AppFramework\OCS\BaseResponse"/>
<referencedClass name="OC\Security\CSP\ContentSecurityPolicyNonceManager" />
<referencedClass name="OCA\Settings\Service\AuthorizedGroupService"/>
</errorLevel>
</UndefinedDocblockClass>
<LessSpecificReturnStatement errorLevel="error"/>
<LessSpecificReturnType errorLevel="error"/>
<LessSpecificImplementedReturnType errorLevel="error"/>
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</coverage>
<testsuite name="Nextcloud - Group folders App Tests">
<directory suffix=".php">.</directory>
<exclude>./stubs/</exclude>
</testsuite>
<logging/>
</phpunit>
8 changes: 1 addition & 7 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="lib/ACL/ACLStorageWrapper.php">
<UndefinedClass>
<code><![CDATA[IteratorDirectory]]></code>
</UndefinedClass>
</file>
</files>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0"/>
Loading

0 comments on commit 3abb9d3

Please sign in to comment.