Skip to content

Commit

Permalink
Merge pull request #2695 from nextcloud/backport/2646/stable28
Browse files Browse the repository at this point in the history
[stable28] Update Psalm to 5.9 to sync with server
  • Loading branch information
come-nc authored Jan 2, 2024
2 parents 3a1d97c + aec14e9 commit 448955f
Show file tree
Hide file tree
Showing 15 changed files with 843 additions and 347 deletions.
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-stable28"
},
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

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

28 changes: 14 additions & 14 deletions lib/ACL/ACLStorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@ public function getPermissions($path) {
return $this->storage->getPermissions($path) & $this->getACLPermissionsForPath($path);
}

public function rename($path1, $path2) {
if (strpos($path1, $path2) === 0) {
$part = substr($path1, strlen($path2));
public function rename($source, $target) {
if (strpos($source, $target) === 0) {
$part = substr($source, strlen($target));
//This is a rename of the transfer file to the original file
if (strpos($part, '.ocTransferId') === 0) {
return $this->checkPermissions($path2, Constants::PERMISSION_CREATE) && parent::rename($path1, $path2);
return $this->checkPermissions($target, Constants::PERMISSION_CREATE) && parent::rename($source, $target);
}
}
$permissions = $this->file_exists($path2) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
$sourceParent = dirname($path1);
$permissions = $this->file_exists($target) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
$sourceParent = dirname($source);
if ($sourceParent === '.') {
$sourceParent = '';
}
return $this->checkPermissions($sourceParent, Constants::PERMISSION_DELETE) &&
$this->checkPermissions($path1, Constants::PERMISSION_UPDATE & Constants::PERMISSION_READ) &&
$this->checkPermissions($path2, $permissions) &&
parent::rename($path1, $path2);
$this->checkPermissions($source, Constants::PERMISSION_UPDATE & Constants::PERMISSION_READ) &&
$this->checkPermissions($target, $permissions) &&
parent::rename($source, $target);
}

public function opendir($path) {
Expand All @@ -118,11 +118,11 @@ public function opendir($path) {
return IteratorDirectory::wrap($items);
}

public function copy($path1, $path2) {
$permissions = $this->file_exists($path2) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
return $this->checkPermissions($path2, $permissions) &&
$this->checkPermissions($path1, Constants::PERMISSION_READ) &&
parent::copy($path1, $path2);
public function copy($source, $target) {
$permissions = $this->file_exists($target) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
return $this->checkPermissions($target, $permissions) &&
$this->checkPermissions($source, Constants::PERMISSION_READ) &&
parent::copy($source, $target);
}

public function touch($path, $mtime = null) {
Expand Down
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>
*/
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
24 changes: 12 additions & 12 deletions lib/Versions/VersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ 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());

$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 @@ -80,10 +80,10 @@ public function getVersionsForFile(IUser $user, FileInfo $fileInfo): array {

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

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

$versionEntity = new GroupVersionEntity();
$versionEntity->setFileId($fileInfo->getId());
$versionEntity->setFileId($file->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 === $fileInfo->getMTime()) {
if ($mtime === $file->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($fileInfo->getMimetype()));
$versionEntity->setMimetype($this->mimeTypeLoader->getId($file->getMimetype()));
$versionEntity->setDecodedMetadata([]);
$this->groupVersionsMapper->insert($versionEntity);
}

return $this->getVersionsForFileFromDB($fileInfo, $user, $folderId);
return $this->getVersionsForFileFromDB($file, $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

0 comments on commit 448955f

Please sign in to comment.