Skip to content

Commit

Permalink
Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Mar 23, 2024
1 parent 49a40ea commit 3a76c9b
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 177 deletions.
160 changes: 0 additions & 160 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -610,41 +610,11 @@ parameters:
count: 1
path: program/lib/Roundcube/cache/db.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 3
path: program/lib/Roundcube/cache/memcache.php

-
message: "#^Offset non\\-falsy\\-string does not exist on array\\{\\}\\.$#"
count: 1
path: program/lib/Roundcube/cache/memcache.php

-
message: "#^Static property rcube_cache_memcache\\:\\:\\$memcache \\(Memcache\\) does not accept false\\.$#"
count: 2
path: program/lib/Roundcube/cache/memcache.php

-
message: "#^Method rcube_cache_memcached\\:\\:engine\\(\\) should return Memcache but returns Memcached\\.$#"
count: 1
path: program/lib/Roundcube/cache/memcached.php

-
message: "#^Method rcube_cache_memcached\\:\\:engine\\(\\) should return Memcache but returns Memcached\\|false\\.$#"
count: 1
path: program/lib/Roundcube/cache/memcached.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 3
path: program/lib/Roundcube/cache/memcached.php

-
message: "#^Static property rcube_cache_memcached\\:\\:\\$memcache \\(Memcached\\) does not accept false\\.$#"
count: 2
path: program/lib/Roundcube/cache/memcached.php

-
message: "#^Call to function method_exists\\(\\) with Redis and 'del' will always evaluate to true\\.$#"
count: 1
Expand Down Expand Up @@ -760,11 +730,6 @@ parameters:
count: 1
path: program/lib/Roundcube/rcube.php

-
message: "#^Property rcube\\:\\:\\$memcached \\(Memcached\\|null\\) does not accept Memcache\\.$#"
count: 1
path: program/lib/Roundcube/rcube.php

-
message: "#^Property rcube\\:\\:\\$plugins \\(rcube_plugin_api\\) does not accept rcube_dummy_plugin_api\\.$#"
count: 1
Expand Down Expand Up @@ -1630,131 +1595,6 @@ parameters:
count: 1
path: program/lib/Roundcube/rcube_washtml.php

-
message: "#^Parameter \\#1 \\$key \\(string\\) of method rcube_session_db\\:\\:save\\(\\) should be contravariant with parameter \\$key \\(mixed\\) of method rcube_session\\:\\:save\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/db.php

-
message: "#^Parameter \\#1 \\$key \\(string\\) of method rcube_session_db\\:\\:update\\(\\) should be contravariant with parameter \\$key \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/db.php

-
message: "#^Parameter \\#2 \\$newvars \\(string\\) of method rcube_session_db\\:\\:update\\(\\) should be contravariant with parameter \\$newvars \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/db.php

-
message: "#^Parameter \\#2 \\$vars \\(string\\) of method rcube_session_db\\:\\:save\\(\\) should be contravariant with parameter \\$vars \\(mixed\\) of method rcube_session\\:\\:save\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/db.php

-
message: "#^Parameter \\#3 \\$oldvars \\(string\\) of method rcube_session_db\\:\\:update\\(\\) should be contravariant with parameter \\$oldvars \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/db.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: program/lib/Roundcube/session/memcache.php

-
message: "#^Parameter \\#1 \\$key \\(string\\) of method rcube_session_memcache\\:\\:save\\(\\) should be contravariant with parameter \\$key \\(mixed\\) of method rcube_session\\:\\:save\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/memcache.php

-
message: "#^Parameter \\#1 \\$key \\(string\\) of method rcube_session_memcache\\:\\:update\\(\\) should be contravariant with parameter \\$key \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/memcache.php

-
message: "#^Parameter \\#2 \\$newvars \\(string\\) of method rcube_session_memcache\\:\\:update\\(\\) should be contravariant with parameter \\$newvars \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/memcache.php

-
message: "#^Parameter \\#2 \\$vars \\(string\\) of method rcube_session_memcache\\:\\:save\\(\\) should be contravariant with parameter \\$vars \\(mixed\\) of method rcube_session\\:\\:save\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/memcache.php

-
message: "#^Parameter \\#3 \\$oldvars \\(string\\) of method rcube_session_memcache\\:\\:update\\(\\) should be contravariant with parameter \\$oldvars \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/memcache.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: program/lib/Roundcube/session/memcached.php

-
message: "#^Parameter \\#1 \\$key \\(string\\) of method rcube_session_memcached\\:\\:save\\(\\) should be contravariant with parameter \\$key \\(mixed\\) of method rcube_session\\:\\:save\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/memcached.php

-
message: "#^Parameter \\#1 \\$key \\(string\\) of method rcube_session_memcached\\:\\:update\\(\\) should be contravariant with parameter \\$key \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/memcached.php

-
message: "#^Parameter \\#2 \\$newvars \\(string\\) of method rcube_session_memcached\\:\\:update\\(\\) should be contravariant with parameter \\$newvars \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/memcached.php

-
message: "#^Parameter \\#2 \\$vars \\(string\\) of method rcube_session_memcached\\:\\:save\\(\\) should be contravariant with parameter \\$vars \\(mixed\\) of method rcube_session\\:\\:save\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/memcached.php

-
message: "#^Parameter \\#3 \\$oldvars \\(string\\) of method rcube_session_memcached\\:\\:update\\(\\) should be contravariant with parameter \\$oldvars \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/memcached.php

-
message: "#^Call to function method_exists\\(\\) with Redis and 'del' will always evaluate to true\\.$#"
count: 1
path: program/lib/Roundcube/session/redis.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: program/lib/Roundcube/session/redis.php

-
message: "#^Parameter \\#1 \\$key \\(string\\) of method rcube_session_redis\\:\\:save\\(\\) should be contravariant with parameter \\$key \\(mixed\\) of method rcube_session\\:\\:save\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/redis.php

-
message: "#^Parameter \\#1 \\$key \\(string\\) of method rcube_session_redis\\:\\:update\\(\\) should be contravariant with parameter \\$key \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/redis.php

-
message: "#^Parameter \\#2 \\$newvars \\(string\\) of method rcube_session_redis\\:\\:update\\(\\) should be contravariant with parameter \\$newvars \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/redis.php

-
message: "#^Parameter \\#2 \\$vars \\(array\\) of method rcube_session_redis\\:\\:save\\(\\) should be contravariant with parameter \\$vars \\(mixed\\) of method rcube_session\\:\\:save\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/redis.php

-
message: "#^Parameter \\#3 \\$oldvars \\(string\\) of method rcube_session_redis\\:\\:update\\(\\) should be contravariant with parameter \\$oldvars \\(mixed\\) of method rcube_session\\:\\:update\\(\\)$#"
count: 1
path: program/lib/Roundcube/session/redis.php

-
message: "#^Property rcube\\:\\:\\$storage \\(rcube_storage\\|null\\) does not accept StorageMock\\.$#"
count: 1
path: tests/ActionTestCase.php

-
message: "#^Parameter \\#1 \\$browser \\(Tests\\\\Browser\\\\Browser\\) of method Tests\\\\Browser\\\\Components\\\\App\\:\\:assert\\(\\) should be contravariant with parameter \\$browser \\(Laravel\\\\Dusk\\\\Browser\\) of method Laravel\\\\Dusk\\\\Component\\:\\:assert\\(\\)$#"
count: 1
Expand Down
4 changes: 2 additions & 2 deletions program/lib/Roundcube/cache/memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class rcube_cache_memcache extends rcube_cache
/**
* Instance of memcache handler
*
* @var Memcache
* @var Memcache|false|null
*/
protected static $memcache;

Expand All @@ -44,7 +44,7 @@ public function __construct($userid, $prefix = '', $ttl = 0, $packed = true, $in
/**
* Get global handle for memcache access
*
* @return Memcache
* @return Memcache|false
*/
public static function engine()
{
Expand Down
4 changes: 2 additions & 2 deletions program/lib/Roundcube/cache/memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class rcube_cache_memcached extends rcube_cache
/**
* Instance of memcached handler
*
* @var Memcached
* @var Memcached|false|null
*/
protected static $memcache;

Expand All @@ -50,7 +50,7 @@ public function __construct($userid, $prefix = '', $ttl = 0, $packed = true, $in
/**
* Get global handle for memcache access
*
* @return Memcache
* @return Memcached|false
*/
public static function engine()
{
Expand Down
2 changes: 1 addition & 1 deletion program/lib/Roundcube/cache/redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct($userid, $prefix = '', $ttl = 0, $packed = true, $in
/**
* Get global handle for redis access
*
* @return Redis
* @return Redis|false
*/
public static function engine()
{
Expand Down
12 changes: 6 additions & 6 deletions program/lib/Roundcube/rcube.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ class rcube
/** @var ?rcube_db Instance of database class */
public $db;

/** @var ?Memcache Instance of Memcache class */
/** @var Memcache|false|null Instance of Memcache class */
public $memcache;

/** @var ?Memcached Instance of Memcached class */
/** @var Memcached|false|null Instance of Memcached class */
public $memcached;

/** @var ?Redis Instance of Redis class */
/** @var Redis|false|null Instance of Redis class */
public $redis;

/** @var ?rcube_session Instance of rcube_session class */
Expand Down Expand Up @@ -166,7 +166,7 @@ public function get_dbh()
/**
* Get global handle for memcache access
*
* @return Memcache The memcache engine
* @return Memcache|false The memcache engine
*/
public function get_memcache()
{
Expand All @@ -180,7 +180,7 @@ public function get_memcache()
/**
* Get global handle for memcached access
*
* @return Memcached The memcached engine
* @return Memcached|false The memcached engine
*/
public function get_memcached()
{
Expand All @@ -194,7 +194,7 @@ public function get_memcached()
/**
* Get global handle for redis access
*
* @return Redis The redis engine
* @return Redis|false The redis engine
*/
public function get_redis()
{
Expand Down
17 changes: 17 additions & 0 deletions program/lib/Roundcube/rcube_session.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,25 @@ abstract public function destroy($key);
#[ReturnTypeWillChange]
abstract public function read($key);

/**
* Write data to the session store
*
* @param string $key Session identifier
* @param string $vars Session data
*
* @return bool True on success, False on failure
*/
abstract protected function save($key, $vars);

/**
* Write data to the session store
*
* @param string $key Session identifier
* @param string $newvars New session data string
* @param string $oldvars Old session data string
*
* @return bool True on success, False on failure
*/
abstract protected function update($key, $newvars, $oldvars);

/**
Expand Down
2 changes: 1 addition & 1 deletion program/lib/Roundcube/session/memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class rcube_session_memcache extends rcube_session
{
/** @var Memcache The memcache driver */
/** @var Memcache|false|null The memcache driver */
private $memcache;

/** @var bool Debug state */
Expand Down
2 changes: 1 addition & 1 deletion program/lib/Roundcube/session/memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class rcube_session_memcached extends rcube_session
{
/** @var Memcached The memcache driver */
/** @var Memcached|false|null The memcache driver */
private $memcache;

/** @var bool Debug state */
Expand Down
10 changes: 8 additions & 2 deletions program/lib/Roundcube/session/php.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ public function read($key)
return '';
}

protected function save($key, $vars) {}
protected function save($key, $vars)
{
return true;
}

protected function update($key, $newvars, $oldvars) {}
protected function update($key, $newvars, $oldvars)
{
return true;
}

/**
* Object constructor
Expand Down
3 changes: 2 additions & 1 deletion program/lib/Roundcube/session/redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function destroy($key)
{
if ($key) {
try {
// @phpstan-ignore-next-line
$result = method_exists($this->redis, 'del')
? $this->redis->del($key)
: $this->redis->delete($key);
Expand Down Expand Up @@ -171,7 +172,7 @@ protected function update($key, $newvars, $oldvars)
* Write data to redis store
*
* @param string $key Session identifier
* @param array $vars Session data
* @param string $vars Session data
*
* @return bool True on success, False on failure
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/ActionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static function initSession()
public static function mockStorage()
{
$rcmail = rcmail::get_instance();
$rcmail->storage = new StorageMock();
$rcmail->storage = new StorageMock(); // @phpstan-ignore-line

return $rcmail->storage;
}
Expand Down

0 comments on commit 3a76c9b

Please sign in to comment.