Skip to content

Commit

Permalink
Fix phpstan errors regarding rcube_uploads trait methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Jan 27, 2024
1 parent 34500a4 commit 1f6a9b8
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 60 deletions.
50 changes: 0 additions & 50 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,6 @@ parameters:
count: 1
path: plugins/filesystem_attachments/filesystem_attachments.php

-
message: "#^Call to an undefined method rcube\\:\\:get_uploaded_file\\(\\)\\.$#"
count: 1
path: plugins/filesystem_attachments/filesystem_attachments.php

-
message: "#^Call to an undefined method rcube\\:\\:list_uploaded_files\\(\\)\\.$#"
count: 1
path: plugins/filesystem_attachments/filesystem_attachments.php

-
message: "#^Call to method getMessage\\(\\) on an unknown class PEAR_Error\\.$#"
count: 1
Expand Down Expand Up @@ -445,11 +435,6 @@ parameters:
count: 1
path: program/include/rcmail_action.php

-
message: "#^Call to an undefined method rcube\\:\\:get_uploaded_file\\(\\)\\.$#"
count: 1
path: program/include/rcmail_attachment_handler.php

-
message: "#^Binary operation \"\\*\" between string and 100 results in an error\\.$#"
count: 1
Expand Down Expand Up @@ -834,38 +819,3 @@ parameters:
message: "#^Variable \\$e might not be defined\\.$#"
count: 1
path: program/lib/Roundcube/spellchecker/googie.php

-
message: "#^Call to an undefined method rcube\\:\\:get_uploaded_file\\(\\)\\.$#"
count: 1
path: tests/ActionTestCase.php

-
message: "#^Call to an undefined method rcube\\:\\:get_uploaded_file\\(\\)\\.$#"
count: 1
path: tests/Actions/Contacts/UploadPhoto.php

-
message: "#^Call to an undefined method rcube\\:\\:get_uploaded_file\\(\\)\\.$#"
count: 1
path: tests/Actions/Mail/AttachmentDelete.php

-
message: "#^Call to an undefined method rcube\\:\\:list_uploaded_files\\(\\)\\.$#"
count: 1
path: tests/Actions/Mail/AttachmentDelete.php

-
message: "#^Call to an undefined method rcube\\:\\:get_uploaded_file\\(\\)\\.$#"
count: 1
path: tests/Actions/Mail/AttachmentRename.php

-
message: "#^Call to an undefined method rcube\\:\\:get_uploaded_file\\(\\)\\.$#"
count: 1
path: tests/Actions/Mail/AttachmentUpload.php

-
message: "#^Call to an undefined method rcube\\:\\:get_uploaded_file\\(\\)\\.$#"
count: 1
path: tests/Actions/Settings/Upload.php
2 changes: 2 additions & 0 deletions plugins/filesystem_attachments/filesystem_attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public function cleanup($args)
$rcube = rcube::get_instance();
$group = $args['group'] ?? null;

// @phpstan-ignore-next-line
foreach ($rcube->list_uploaded_files($group) as $file) {
if ($file['path'] && $this->verify_path($file['path']) && file_exists($file['path'])) {
unlink($file['path']);
Expand All @@ -172,6 +173,7 @@ protected static function file_id()
$id = preg_replace('/[^0-9]/', '', $rcube->user->ID . $sec . $usec);

// make sure the ID is really unique (#1489546)
// @phpstan-ignore-next-line
while ($rcube->get_uploaded_file($id)) {
// increment last four characters
$x = substr($id, -4) + 1;
Expand Down
2 changes: 1 addition & 1 deletion program/include/rcmail_attachment_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct()
$file_id = rcube_utils::get_input_string('_file', rcube_utils::INPUT_GET);
$compose_id = rcube_utils::get_input_string('_id', rcube_utils::INPUT_GET);
$uid = rcube_utils::get_input_string('_uid', rcube_utils::INPUT_GET);
$rcube = rcube::get_instance();
$rcube = rcmail::get_instance();

$this->download = !empty($_GET['_download']);

Expand Down
2 changes: 1 addition & 1 deletion tests/ActionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ protected function fileUpload($group)

$rcmail->insert_uploaded_file($file);

$upload = rcube::get_instance()->get_uploaded_file($file['id']);
$upload = rcmail::get_instance()->get_uploaded_file($file['id']);

$this->assertTrue(is_array($upload));

Expand Down
2 changes: 1 addition & 1 deletion tests/Actions/Contacts/UploadPhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function test_run()
$this->assertTrue(strpos($result['exec'], 'this.replace_contact_photo("' . $file['id'] . '");') !== false);
$this->assertTrue(strpos($result['exec'], 'this.photo_upload_end();') !== false);

$upload = rcube::get_instance()->get_uploaded_file($file['id']);
$upload = rcmail::get_instance()->get_uploaded_file($file['id']);
$this->assertSame($file['name'], $upload['name']);
$this->assertSame($file['type'], $upload['mimetype']);
$this->assertSame($file['size'], $upload['size']);
Expand Down
5 changes: 2 additions & 3 deletions tests/Actions/Mail/AttachmentDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Actions_Mail_AttachmentDelete extends ActionTestCase
*/
public function test_run()
{
$rcmail = rcube::get_instance();
$rcmail = rcmail::get_instance();
$action = new rcmail_action_mail_attachment_delete();
$output = $this->initOutput(rcmail_action::MODE_AJAX, 'mail', 'delete-attachment');

Expand Down Expand Up @@ -46,7 +46,6 @@ public function test_run()
$this->assertSame(['Content-Type: application/json; charset=UTF-8'], $output->headers);
$this->assertSame('delete-attachment', $result['action']);
$this->assertSame('this.remove_from_attachment_list("rcmfile' . $file['id'] . '");', trim($result['exec']));

$this->assertNull(rcube::get_instance()->get_uploaded_file($file['id']));
$this->assertNull($rcmail->get_uploaded_file($file['id']));
}
}
4 changes: 2 additions & 2 deletions tests/Actions/Mail/AttachmentRename.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Actions_Mail_AttachmentRename extends ActionTestCase
*/
public function test_run()
{
$rcmail = rcube::get_instance();
$rcmail = rcmail::get_instance();
$action = new rcmail_action_mail_attachment_rename();
$output = $this->initOutput(rcmail_action::MODE_AJAX, 'mail', 'rename-attachment');

Expand All @@ -33,7 +33,7 @@ public function test_run()
$this->assertSame('rename-attachment', $result['action']);
$this->assertSame('this.rename_attachment_handler("rcmfile' . $file['id'] . '","mod.gif");', trim($result['exec']));

$upload = rcube::get_instance()->get_uploaded_file($file['id']);
$upload = $rcmail->get_uploaded_file($file['id']);
$this->assertSame($_POST['_name'], $upload['name']);
$this->assertSame($_POST['_id'], $upload['group']);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Actions/Mail/AttachmentUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function test_run()
$this->assertTrue(strpos($result['exec'], 'this.add2attachment_list("rcmfile' . $file['id'] . '"') !== false);
$this->assertTrue(strpos($result['exec'], 'this.auto_save_start(false);') !== false);

$upload = rcube::get_instance()->get_uploaded_file($file['id']);
$upload = rcmail::get_instance()->get_uploaded_file($file['id']);
$this->assertSame($file['name'], $upload['name']);
$this->assertSame($file['type'], $upload['mimetype']);
$this->assertSame($file['size'], $upload['size']);
Expand Down
2 changes: 1 addition & 1 deletion tests/Actions/Settings/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function test_run()
$this->assertSame('upload', $result['action']);
$this->assertTrue(strpos($result['exec'], 'this.add2attachment_list("rcmfile' . $file['id'] . '"') !== false);

$upload = rcube::get_instance()->get_uploaded_file($file['id']);
$upload = rcmail::get_instance()->get_uploaded_file($file['id']);
$this->assertSame($file['name'], $upload['name']);
$this->assertSame($file['type'], $upload['mimetype']);
$this->assertSame($file['size'], $upload['size']);
Expand Down

0 comments on commit 1f6a9b8

Please sign in to comment.