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

Update Psalm to 5.9 to sync with server #2646

Merged
merged 4 commits into from
Dec 4, 2023
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sabre/dav": "^4.1",
"sabre/xml": "^2.2",
"symfony/event-dispatcher": "^5.3.11",
"psalm/phar": "^4.10",
"psalm/phar": "^5.9",
"nextcloud/coding-standard": "^1.0",
"nextcloud/ocp": "dev-master"
},
Expand Down
47 changes: 26 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Symfony\Component\Console\Output\OutputInterface;

class ListCommand extends Base {
/** @var array<int,string> */
public const PERMISSION_NAMES = [
Constants::PERMISSION_READ => 'read',
Constants::PERMISSION_UPDATE => 'write',
Expand Down Expand Up @@ -132,7 +133,7 @@ private function permissionsToString(int $permissions): string {
if ($permissions === 0) {
return 'none';
}
return implode(', ', array_filter(self::PERMISSION_NAMES, function ($possiblePermission) use ($permissions) {
return implode(', ', array_filter(self::PERMISSION_NAMES, function (int $possiblePermission) use ($permissions) {
return $possiblePermission & $permissions;
}, ARRAY_FILTER_USE_KEY));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ private function filterNonAdminFolder(array $folder): ?array {
}

/**
* @param array{id: mixed, mount_point: mixed, groups: array<string, array{displayName: string, type: string, permissions: integer}>, quota: int, size: int, acl: bool} $folder
* @return array{id: mixed, mount_point: mixed, groups:array<string, integer>, group_details: array<empty, empty>|mixed, quota: int, size: int, acl: bool}
* @param array{acl: bool, groups: array<string, array{displayName: string, type: string, permissions: int}>, id: int, manage: array<array-key, array{displayname?: string, id?: string, type?: "group"|"user"|"circle"}>, mount_point: mixed, quota: int, size: int} $folder
* @return array{acl: bool, group_details: array<string, array{displayName: string, type: string, permissions: int}>, groups: array<string, int>, id: int, manage: array<array-key, array{displayname?: string, id?: string, type?: "group"|"user"|"circle"}>, mount_point: mixed, quota: int, size: int}
*/
private function formatFolder(array $folder): array {
// keep compatibility with the old 'groups' field
Expand Down
2 changes: 1 addition & 1 deletion lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private function getAllApplicable(): array {
* @param CirclesQueryHelper|null $queryHelper
* @param string|null $entityId the type of the entity
*
* @return array{displayname?: string, id?: string, type?: "group"|"user"|"circle"}
* @return array{displayName: string, permissions: int, type: 'circle'|'group'}
*/
private function generateApplicableMapEntry(
array $row,
Expand Down
3 changes: 3 additions & 0 deletions lib/Listeners/CircleDestroyedEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* @template-implements IEventListener<CircleDestroyedEvent>
*/
class CircleDestroyedEventListener implements IEventListener {
public function __construct(
private FolderManager $folderManager,
Expand Down
5 changes: 5 additions & 0 deletions lib/Listeners/LoadAdditionalScriptsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@

namespace OCA\GroupFolders\Listeners;

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* @template-implements IEventListener<LoadAdditionalScriptsEvent|BeforeTemplateRenderedEvent>
Copy link
Contributor

Choose a reason for hiding this comment

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

It never works when I use | is that situation. Any trick or it simply worked for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, it first failed because I had forgotten to use the classes, but then it worked. Also I think this kind of things were improved in last psalm versions.

*/
class LoadAdditionalScriptsListener implements IEventListener {
public function handle(Event $event): void {
\OCP\Util::addScript('groupfolders', 'groupfolders-files');
Expand Down
5 changes: 4 additions & 1 deletion lib/Mount/GroupFolderStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public function getFolderId(): int {
return $this->folderId;
}

/**
* @psalm-suppress FalsableReturnStatement Return type of getOwner is not clear even in server
*/
public function getOwner($path) {
$user = $this->userSession->getUser();
if ($user !== null) {
Expand All @@ -70,7 +73,7 @@ public function getCache($path = '', $storage = null) {
}

public function getScanner($path = '', $storage = null) {
/** @var \OC\Files\Storage\Storage $storage */
/** @var \OC\Files\Storage\Wrapper\Wrapper $storage */
if (!$storage) {
$storage = $this;
}
Expand Down
1 change: 1 addition & 0 deletions lib/Versions/ExpireManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected function getAutoExpireList(int $time, array $versions): array {
$newInterval = false; // version checked so we can move to the next one
} else { // time to move on to the next interval
$interval++;
/** @psalm-suppress InvalidArrayOffset We know that $interval is <= 6 thanks to the -1 intervalEndsAfter in the last step */
$step = self::MAX_VERSIONS_PER_INTERVAL[$interval]['step'];
$nextVersion = $prevTimestamp - $step;
if (self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] === -1) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Versions/GroupVersionsExpireManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function expireAll(): void {
}

/**
* @param array{id: int, mount_point: string, groups: array<empty, empty>|array<array-key, int>, quota: int, size: int, acl: bool} $folder
* @param array{acl: bool, groups: array<array-key, array<array-key, int|string>>, id: int, mount_point: mixed, quota: int, size: 0} $folder
*/
public function expireFolder(array $folder): void {
$view = new View('/__groupfolders/versions/' . $folder['id']);
Expand Down
28 changes: 14 additions & 14 deletions lib/Versions/VersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ public function useBackendForStorage(IStorage $storage): bool {
return true;
}

public function getVersionsForFile(IUser $user, FileInfo $fileInfo): array {
$mount = $fileInfo->getMountPoint();
public function getVersionsForFile(IUser $user, FileInfo $file): array {
$mount = $file->getMountPoint();
if (!($mount instanceof GroupMountPoint)) {
return [];
}

try {
$folderId = $mount->getFolderId();
/** @var Folder $versionsFolder */
$versionsFolder = $this->getVersionsFolder($mount->getFolderId())->get((string)$fileInfo->getId());
$versionsFolder = $this->getVersionsFolder($mount->getFolderId())->get((string)$file->getId());

$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$nodes = $userFolder->getById($fileInfo->getId());
$file = array_pop($nodes);
$nodes = $userFolder->getById($file->getId());
$node = array_pop($nodes);

$versions = $this->getVersionsForFileFromDB($fileInfo, $user, $folderId);
$versions = $this->getVersionsForFileFromDB($file, $user, $folderId);

// Early exit if we find any version in the database.
// Else we continue to populate the DB from what's on disk.
Expand All @@ -84,10 +84,10 @@ public function getVersionsForFile(IUser $user, FileInfo $fileInfo): array {

// Insert the entry in the DB for the current version.
$versionEntity = new GroupVersionEntity();
$versionEntity->setFileId($file->getId());
$versionEntity->setTimestamp($file->getMTime());
$versionEntity->setSize($file->getSize());
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
$versionEntity->setFileId($node->getId());
$versionEntity->setTimestamp($node->getMTime());
$versionEntity->setSize($node->getSize());
$versionEntity->setMimetype($this->mimeTypeLoader->getId($node->getMimetype()));
$versionEntity->setDecodedMetadata([]);
$this->groupVersionsMapper->insert($versionEntity);

Expand All @@ -99,25 +99,25 @@ public function getVersionsForFile(IUser $user, FileInfo $fileInfo): array {
}

$versionEntity = new GroupVersionEntity();
$versionEntity->setFileId($file->getId());
$versionEntity->setFileId($node->getId());
// HACK: before this commit, versions were created with the current timestamp instead of the version's mtime.
// This means that the name of some versions is the exact mtime of the next version. This behavior is now fixed.
// To prevent occasional conflicts between the last version and the current one, we decrement the last version mtime.
$mtime = (int)$version->getName();
if ($mtime === $file->getMTime()) {
if ($mtime === $node->getMTime()) {
$versionEntity->setTimestamp($mtime - 1);
$version->move($version->getParent()->getPath() . '/' . ($mtime - 1));
} else {
$versionEntity->setTimestamp($mtime);
}
$versionEntity->setSize($version->getSize());
// Use the main file mimetype for this initialization as the original mimetype is unknown.
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
$versionEntity->setMimetype($this->mimeTypeLoader->getId($node->getMimetype()));
$versionEntity->setDecodedMetadata([]);
$this->groupVersionsMapper->insert($versionEntity);
}

return $this->getVersionsForFileFromDB($file, $user, $folderId);
return $this->getVersionsForFileFromDB($node, $user, $folderId);
} catch (NotFoundException $e) {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="tests/psalm-baseline.xml"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<stubs>
<file name="tests/stub.phpstub" preloadClasses="true"/>
Expand Down
46 changes: 6 additions & 40 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,52 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.x-dev@">
<files psalm-version="5.16.0@2897ba636551a8cb61601cc26f6ccfbba6c36591">
<file src="lib/ACL/ACLStorageWrapper.php">
<InvalidNullableReturnType occurrences="2">
<InvalidNullableReturnType>
<code>filemtime</code>
<code>hash</code>
</InvalidNullableReturnType>
<UndefinedClass occurrences="1">
<UndefinedClass>
<code>IteratorDirectory</code>
</UndefinedClass>
<UndefinedInterfaceMethod occurrences="1">
<code>getDirectoryContent</code>
</UndefinedInterfaceMethod>
<UndefinedMethod occurrences="2">
<code>parent::getMetaData($path)</code>
<code>parent::writeStream($path, $stream, $size)</code>
</UndefinedMethod>
</file>
<file src="lib/AppInfo/Application.php">
<UndefinedClass occurrences="2">
<code>BeforeTemplateRenderedEvent</code>
<code>CircleDestroyedEvent</code>
</UndefinedClass>
</file>
<file src="lib/Folder/FolderManager.php">
<MismatchingDocblockReturnType occurrences="1">
<code>array{id: mixed, mount_point: mixed, groups: array&lt;empty, empty&gt;|mixed, quota: int, size: int|mixed, acl: bool}|false</code>
</MismatchingDocblockReturnType>
</file>
<file src="lib/Helper/LazyFolder.php">
<InvalidReturnStatement occurrences="2">
<code>$this-&gt;__call(__FUNCTION__, func_get_args())</code>
<code>$this-&gt;__call(__FUNCTION__, func_get_args())</code>
</InvalidReturnStatement>
</file>
<file src="lib/Mount/RootPermissionsMask.php">
<UndefinedMethod occurrences="1">
<code>parent::getMetaData($path)</code>
</UndefinedMethod>
</file>
<file src="lib/Trash/GroupTrashItem.php">
<UndefinedMethod occurrences="1">
<code>parent::__construct($backend, $originalLocation, $deletedTime, $trashPath, $fileInfo, $user)</code>
</UndefinedMethod>
</file>
<file src="lib/Versions/ExpireManager.php">
<TypeDoesNotContainType occurrences="2">
<code>self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] === -1</code>
<code>self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] === -1</code>
<TypeDoesNotContainType>
<code><![CDATA[self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] === -1]]></code>
<code><![CDATA[self::MAX_VERSIONS_PER_INTERVAL[$interval]['intervalEndsAfter'] === -1]]></code>
</TypeDoesNotContainType>
</file>
</files>
Loading
Loading