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

Refactor files trashbin app #39883

Closed

Conversation

danialRahimy
Copy link
Contributor

@danialRahimy danialRahimy commented Aug 15, 2023

Summary

I did these items in a single file apps/files_trashbin/lib/Trashbin.php for two reasons:

  1. Pull request hasn't been a lot of changes.
  2. I was not sure about some changes.
  • Return early
  • Change the const name for more readability
  • Add functions' return type
  • Update doc types

Checklist

@danialRahimy danialRahimy force-pushed the app_files_trashbin_refactor branch 2 times, most recently from 9d23571 to 24de858 Compare August 15, 2023 12:35
apps/files_trashbin/lib/Trashbin.php Fixed Show fixed Hide fixed
apps/files_trashbin/lib/Trashbin.php Fixed Show fixed Hide fixed
if ($owner !== $user) {
self::copy_recursive($owner . '/files_versions/' . $ownerPath, $owner . '/files_trashbin/versions/' . static::getTrashFilename(basename($ownerPath), $timestamp), $rootView);
}
self::move($rootView, $owner . '/files_versions/' . $ownerPath, $user . '/files_trashbin/versions/' . static::getTrashFilename($filename, $timestamp));

Check notice

Code scanning / Psalm

PossiblyFalseOperand Note

Cannot concatenate with a possibly false false|string
}
self::move($rootView, $owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $user . '/files_trashbin/versions/' . static::getTrashFilename($filename . '.v' . $v['version'], $timestamp));

Check notice

Code scanning / Psalm

PossiblyFalseOperand Note

Cannot concatenate with a possibly false false|string
}

if ($view->is_dir('/files_trashbin/versions/' . $file)) {
$rootView->rename(Filesystem::normalizePath($user . '/files_trashbin/versions/' . $file), Filesystem::normalizePath($owner . '/files_versions/' . $ownerPath));

Check notice

Code scanning / Psalm

PossiblyFalseOperand Note

Cannot concatenate with a possibly false false|string

if ($view->is_dir('/files_trashbin/versions/' . $file)) {
$rootView->rename(Filesystem::normalizePath($user . '/files_trashbin/versions/' . $file), Filesystem::normalizePath($owner . '/files_versions/' . $ownerPath));
} elseif ($versions = self::getVersionsFromTrash($versionedFile, $timestamp, $user)) {

Check notice

Code scanning / Psalm

PossiblyFalseArgument Note

Argument 3 of OCA\Files_Trashbin\Trashbin::getVersionsFromTrash cannot be false, possibly string value expected
} elseif ($versions = self::getVersionsFromTrash($versionedFile, $timestamp, $user)) {
foreach ($versions as $v) {
if ($timestamp) {
$rootView->rename($user . '/files_trashbin/versions/' . static::getTrashFilename($versionedFile . '.v' . $v, $timestamp), $owner . '/files_versions/' . $ownerPath . '.v' . $v);

Check notice

Code scanning / Psalm

PossiblyFalseOperand Note

Cannot concatenate with a possibly false false|string
if ($timestamp) {
$rootView->rename($user . '/files_trashbin/versions/' . static::getTrashFilename($versionedFile . '.v' . $v, $timestamp), $owner . '/files_versions/' . $ownerPath . '.v' . $v);
} else {
$rootView->rename($user . '/files_trashbin/versions/' . $versionedFile . '.v' . $v, $owner . '/files_versions/' . $ownerPath . '.v' . $v);

Check notice

Code scanning / Psalm

PossiblyFalseOperand Note

Cannot concatenate with a possibly false false|string
if ($view->is_dir('files_trashbin/versions/' . $file)) {
$size += self::calculateSize(new View('/' . $user . '/files_trashbin/versions/' . $file));
$view->unlink('files_trashbin/versions/' . $file);
} elseif ($versions = self::getVersionsFromTrash($filename, $timestamp, $user)) {

Check notice

Code scanning / Psalm

PossiblyNullArgument Note

Argument 2 of OCA\Files_Trashbin\Trashbin::getVersionsFromTrash cannot be null, possibly null value provided
apps/files_trashbin/lib/Trashbin.php Fixed Show fixed Hide fixed
@szaimen szaimen added 3. to review Waiting for reviews technical debt labels Aug 15, 2023
@szaimen szaimen added this to the Nextcloud 28 milestone Aug 15, 2023
@szaimen szaimen requested review from a team, icewind1991, blizzz and Fenn-CS and removed request for a team August 15, 2023 12:40
Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com>
Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com>
Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com>
Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com>
Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com>
Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com>
Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com>
…e psalm analysis

Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com>
…ption on doctype

Signed-off-by: Danial Rahimi <48244647+danialRahimy@users.noreply.github.com>
*/
public static function getLocation($user, $filename, $timestamp) {
public static function getLocation($user, $filename, $timestamp): bool|string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public static function getLocation($user, $filename, $timestamp): bool|string {
public static function getLocation(string $user, string $filename, string $timestamp): bool|string {

Copy link
Contributor

@Fenn-CS Fenn-CS left a comment

Choose a reason for hiding this comment

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

Since this is just a refactor and no main functional change you can just use build in type hinting for PHP... I left a few examples but not all, most of the functions can use built in type hinting and that would allow you to delete the comment annotations at the top (leaving behind just the exceptions)

Co-authored-by: F. E Noel Nfebe <fenn25.fn@gmail.com>
Signed-off-by: danial rahimy <48244647+danialRahimy@users.noreply.github.com>
danialRahimy and others added 4 commits August 20, 2023 14:17
Co-authored-by: F. E Noel Nfebe <fenn25.fn@gmail.com>
Signed-off-by: danial rahimy <48244647+danialRahimy@users.noreply.github.com>
Co-authored-by: F. E Noel Nfebe <fenn25.fn@gmail.com>
Signed-off-by: danial rahimy <48244647+danialRahimy@users.noreply.github.com>
Co-authored-by: F. E Noel Nfebe <fenn25.fn@gmail.com>
Signed-off-by: danial rahimy <48244647+danialRahimy@users.noreply.github.com>
Co-authored-by: F. E Noel Nfebe <fenn25.fn@gmail.com>
Signed-off-by: danial rahimy <48244647+danialRahimy@users.noreply.github.com>
@skjnldsv skjnldsv mentioned this pull request Nov 1, 2023
This was referenced Nov 6, 2023
This was referenced Nov 14, 2023
@blizzz blizzz modified the milestones: Nextcloud 28, Nextcloud 29 Nov 23, 2023
This was referenced Mar 12, 2024
This was referenced Mar 20, 2024
@skjnldsv skjnldsv mentioned this pull request Mar 28, 2024
81 tasks
@skjnldsv skjnldsv modified the milestones: Nextcloud 29, Nextcloud 30 Mar 28, 2024
@skjnldsv skjnldsv added 2. developing Work in progress stale Ticket or PR with no recent activity and removed 3. to review Waiting for reviews labels Jul 27, 2024
This was referenced Jul 30, 2024
@skjnldsv skjnldsv closed this Aug 3, 2024
@skjnldsv skjnldsv removed this from the Nextcloud 30 milestone Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress stale Ticket or PR with no recent activity technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants