Skip to content

Commit

Permalink
Fix various phpstan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Jan 28, 2024
1 parent c47accb commit 845db4c
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 212 deletions.
180 changes: 0 additions & 180 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,145 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Access to an undefined property rcube\\:\\:\\$task\\.$#"
count: 1
path: plugins/emoticons/emoticons.php

-
message: "#^Access to an undefined property rcube\\:\\:\\$action\\.$#"
count: 6
path: plugins/enigma/enigma.php

-
message: "#^Access to an undefined property rcube\\:\\:\\$task\\.$#"
count: 3
path: plugins/enigma/enigma.php

-
message: "#^Cannot call method getExpirationDateTime\\(\\) on class\\-string\\|object\\.$#"
count: 1
path: plugins/enigma/lib/enigma_driver_gnupg.php

-
message: "#^Cannot access property \\$mime_id on string\\.$#"
count: 2
path: plugins/enigma/lib/enigma_driver_phpssl.php

-
message: "#^Cannot access property \\$uid on string\\.$#"
count: 1
path: plugins/enigma/lib/enigma_driver_phpssl.php

-
message: "#^Cannot call method get_part_body\\(\\) on string\\.$#"
count: 1
path: plugins/enigma/lib/enigma_driver_phpssl.php

-
message: "#^Access to an undefined property object\\:\\:\\$body\\.$#"
count: 1
path: plugins/enigma/lib/enigma_engine.php

-
message: "#^Access to an undefined property object\\:\\:\\$body_modified\\.$#"
count: 1
path: plugins/enigma/lib/enigma_engine.php

-
message: "#^Access to an undefined property object\\:\\:\\$mime_id\\.$#"
count: 1
path: plugins/enigma/lib/enigma_engine.php

-
message: "#^Access to an undefined property object\\:\\:\\$size\\.$#"
count: 1
path: plugins/enigma/lib/enigma_engine.php

-
message: "#^Cannot access property \\$mime_id on array\\.$#"
count: 1
path: plugins/enigma/lib/enigma_engine.php

-
message: "#^Cannot access property \\$mimetype on array\\.$#"
count: 1
path: plugins/enigma/lib/enigma_engine.php

-
message: "#^Cannot access property \\$parts on array\\.$#"
count: 1
path: plugins/enigma/lib/enigma_engine.php

-
message: "#^Variable \\$key in empty\\(\\) always exists and is not falsy\\.$#"
count: 2
path: plugins/enigma/lib/enigma_engine.php

-
message: "#^Variable \\$sign_key in empty\\(\\) always exists and is not falsy\\.$#"
count: 1
path: plugins/enigma/lib/enigma_engine.php

-
message: "#^Variable \\$headers might not be defined\\.$#"
count: 1
path: plugins/enigma/lib/enigma_mime_message.php

-
message: "#^Variable \\$message might not be defined\\.$#"
count: 2
path: plugins/enigma/lib/enigma_mime_message.php

-
message: "#^Variable \\$keyid might not be defined\\.$#"
count: 2
path: plugins/enigma/lib/enigma_ui.php

-
message: "#^Default value of the parameter \\#3 \\$strict \\(false\\) of method example_addressbook_backend\\:\\:search\\(\\) is incompatible with type int\\.$#"
count: 1
path: plugins/example_addressbook/example_addressbook_backend.php

-
message: "#^Binary operation \"\\+\" between string and 1 results in an error\\.$#"
count: 1
path: plugins/filesystem_attachments/filesystem_attachments.php

-
message: "#^Call to method getMessage\\(\\) on an unknown class PEAR_Error\\.$#"
count: 1
path: plugins/managesieve/lib/Roundcube/rcube_sieve.php

-
message: "#^Default value of the parameter \\#4 \\$port \\(int\\) of method rcube_sieve\\:\\:__construct\\(\\) is incompatible with type string\\.$#"
count: 1
path: plugins/managesieve/lib/Roundcube/rcube_sieve.php

-
message: "#^Undefined variable\\: \\$list$#"
count: 1
path: plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php

-
message: "#^Undefined variable\\: \\$msg$#"
count: 1
path: plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php

-
message: "#^Variable \\$list in empty\\(\\) is never defined\\.$#"
count: 1
path: plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php

-
message: "#^Variable \\$msg in empty\\(\\) is never defined\\.$#"
count: 1
path: plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php

-
message: "#^Variable \\$parts in empty\\(\\) always exists and is not falsy\\.$#"
count: 1
path: plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php

-
message: "#^Variable \\$forward_tests in empty\\(\\) is never defined\\.$#"
count: 1
Expand Down Expand Up @@ -220,11 +80,6 @@ parameters:
count: 1
path: plugins/password/drivers/plesk.php

-
message: "#^Call to method getMessage\\(\\) on an unknown class PEAR_Error\\.$#"
count: 1
path: plugins/password/drivers/poppassd.php

-
message: "#^Call to method Auth\\(\\) on an unknown class TinyCPConnector\\.$#"
count: 1
Expand Down Expand Up @@ -455,11 +310,6 @@ parameters:
count: 1
path: program/include/rcmail_sendmail.php

-
message: "#^Call to method getMessage\\(\\) on an unknown class PEAR_Error\\.$#"
count: 1
path: program/include/rcmail_sendmail.php

-
message: "#^Variable \\$headers might not be defined\\.$#"
count: 1
Expand Down Expand Up @@ -505,31 +355,11 @@ parameters:
count: 1
path: program/lib/Roundcube/html.php

-
message: "#^Call to method getCode\\(\\) on an unknown class PEAR_Error\\.$#"
count: 1
path: program/lib/Roundcube/rcube.php

-
message: "#^Call to method getMessage\\(\\) on an unknown class PEAR_Error\\.$#"
count: 2
path: program/lib/Roundcube/rcube.php

-
message: "#^Call to method getUserInfo\\(\\) on an unknown class PEAR_Error\\.$#"
count: 1
path: program/lib/Roundcube/rcube.php

-
message: "#^Default value of the parameter \\#3 \\$ttl \\(int\\) of method rcube\\:\\:get_cache\\(\\) is incompatible with type string\\.$#"
count: 1
path: program/lib/Roundcube/rcube.php

-
message: "#^Parameter \\$arg of method rcube\\:\\:raise_error\\(\\) has invalid type PEAR_Error\\.$#"
count: 1
path: program/lib/Roundcube/rcube.php

-
message: "#^Variable \\$labels in empty\\(\\) always exists and is always falsy\\.$#"
count: 1
Expand Down Expand Up @@ -625,11 +455,6 @@ parameters:
count: 1
path: program/lib/Roundcube/rcube_imap.php

-
message: "#^Variable \\$headers in empty\\(\\) always exists and is not falsy\\.$#"
count: 1
path: program/lib/Roundcube/rcube_imap.php

-
message: "#^Default value of the parameter \\#5 \\$ttl \\(int\\) of method rcube_imap_cache\\:\\:__construct\\(\\) is incompatible with type string\\.$#"
count: 1
Expand Down Expand Up @@ -750,11 +575,6 @@ parameters:
count: 1
path: program/lib/Roundcube/rcube_session.php

-
message: "#^Call to method getMessage\\(\\) on an unknown class PEAR_Error\\.$#"
count: 1
path: program/lib/Roundcube/rcube_smtp.php

-
message: "#^Variable \\$host in empty\\(\\) always exists and is not falsy\\.$#"
count: 1
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ parameters:
- .
excludePaths:
- vendor
scanFiles:
- vendor/pear/pear-core-minimal/src/PEAR.php
8 changes: 4 additions & 4 deletions plugins/emoticons/emoticons.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class emoticons extends rcube_plugin
*/
public function init()
{
$rcube = rcube::get_instance();
$rcube = rcmail::get_instance();

$this->add_hook('message_part_after', [$this, 'message_part_after']);
$this->add_hook('html_editor', [$this, 'html_editor']);
Expand All @@ -41,7 +41,7 @@ public function message_part_after($args)
if ($args['type'] == 'plain') {
$this->load_config();

$rcube = rcube::get_instance();
$rcube = rcmail::get_instance();
if (!$rcube->config->get('emoticons_display', false)) {
return $args;
}
Expand All @@ -57,7 +57,7 @@ public function message_part_after($args)
*/
public function html_editor($args)
{
$rcube = rcube::get_instance();
$rcube = rcmail::get_instance();

$this->load_config();

Expand All @@ -74,7 +74,7 @@ public function html_editor($args)
*/
public function preferences_list($args)
{
$rcube = rcube::get_instance();
$rcube = rcmail::get_instance();
$dont_override = $rcube->config->get('dont_override', []);

if ($args['section'] == 'mailview' && !in_array('emoticons_display', $dont_override)) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/enigma/enigma.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class enigma extends rcube_plugin
*/
public function init()
{
$this->rc = rcube::get_instance();
$this->rc = rcmail::get_instance();

if ($this->rc->task == 'mail') {
// message parse/display hooks
Expand Down
1 change: 1 addition & 0 deletions plugins/enigma/lib/enigma_driver_gnupg.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ protected function parse_key($key)
$ekey->reference = $key;

foreach ($key->getSubKeys() as $idx => $subkey) {
/** @var Crypt_GPG_SubKey $subkey */
$skey = new enigma_subkey();
$skey->id = $subkey->getId();
$skey->revoked = $subkey->isRevoked();
Expand Down
2 changes: 2 additions & 0 deletions plugins/enigma/lib/enigma_driver_phpssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function sign($text, $key, $mode = null) {}

public function verify($struct, $message)
{
/*
// use common temp dir
$msg_file = rcube_utils::temp_filename('enigmsg');
$cert_file = rcube_utils::temp_filename('enigcrt');
Expand Down Expand Up @@ -115,6 +116,7 @@ public function verify($struct, $message)
@unlink($cert_file);
return $sig;
*/
}

public function import($content, $isfile = false, $passwords = []) {}
Expand Down
19 changes: 11 additions & 8 deletions plugins/enigma/lib/enigma_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,22 @@ public function part_structure($p, $body = null)
*/
public function part_body($p)
{
/** @var rcube_message_part $part */
$part = $p['part'];

// encrypted attachment, see parse_plain_encrypted()
if (!empty($p['part']->need_decryption) && $p['part']->body === null) {
if (!empty($part->need_decryption) && $part->body === null) {
$this->load_pgp_driver();

$storage = $this->rc->get_storage();
$body = $storage->get_message_part($p['object']->uid, $p['part']->mime_id, $p['part'], null, null, true, 0, false);
$body = $storage->get_message_part($p['object']->uid, $part->mime_id, $part, null, null, true, 0, false);
$result = $this->pgp_decrypt($body);

// @TODO: what to do on error?
if ($result === true) {
$p['part']->body = $body;
$p['part']->size = strlen($body);
$p['part']->body_modified = true;
$part->body = $body;
$part->size = strlen($body);
$part->body_modified = true;
}
}

Expand Down Expand Up @@ -1008,7 +1011,7 @@ public function list_keys($pattern = '')
* @param string $email E-mail address
* @param bool $can_sign Need a key for signing?
*
* @return enigma_key The key
* @return ?enigma_key The key
*/
public function find_key($email, $can_sign = false)
{
Expand All @@ -1021,7 +1024,7 @@ public function find_key($email, $can_sign = false)

if ($result instanceof enigma_error) {
self::raise_error($result, __LINE__);
return;
return null;
}

$mode = $can_sign ? enigma_key::CAN_SIGN : enigma_key::CAN_ENCRYPT;
Expand Down Expand Up @@ -1261,7 +1264,7 @@ private function get_part_body($msg, $part)
*
* @param string &$body Message body
*
* @return array Message structure
* @return rcube_message_part Message structure
*/
private function parse_body(&$body)
{
Expand Down
4 changes: 4 additions & 0 deletions plugins/enigma/lib/enigma_mime_message.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ public function get($params = null, $filename = null, $skip_head = false)
'disposition' => 'inline',
'filename' => 'encrypted.asc',
]);
} else {
throw new Exception('Unexpected message type');
}

// Use saved boundary
Expand Down Expand Up @@ -304,6 +306,8 @@ protected function contentHeaders()
$headers['Content-Type'] = "multipart/encrypted;{$eol}"
. " protocol=\"application/pgp-encrypted\";{$eol}"
. " boundary=\"{$boundary}\"";
} else {
throw new Exception('Unexpected message type');
}

return $headers;
Expand Down
12 changes: 8 additions & 4 deletions plugins/enigma/lib/enigma_ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,14 @@ public function password_prompt($status, $params = [])
}
}

$data = [
'keyid' => $keyid,
'user' => $data[$keyid],
];
if (isset($keyid)) {
$data = [
'keyid' => $keyid,
'user' => $data[$keyid] ?? null,
];
} else {
$data = [];
}

if (!empty($params)) {
$data = array_merge($params, $data);
Expand Down
Loading

0 comments on commit 845db4c

Please sign in to comment.