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

Bump psalm/phar from 4.30.0 to 5.1.0 #7725

Merged
merged 10 commits into from
Dec 13, 2022
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install dependencies
run: composer i
- name: Install OCP package
run: composer require --dev christophwurst/nextcloud:${{ matrix.ocp-version }} --ignore-platform-reqs
run: composer require --dev nextcloud/ocp:${{ matrix.ocp-version }} --ignore-platform-reqs
- name: Run coding standards check
run: composer run psalm

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"youthweb/urllinker": "^1.3"
},
"require-dev": {
"christophwurst/nextcloud": "^21.0.0",
"psalm/phar": "^4.6",
"nextcloud/ocp": "dev-stable25",
"psalm/phar": "^5.1",
"roave/security-advisories": "dev-master"
},
"autoload": {
Expand Down
138 changes: 122 additions & 16 deletions composer.lock

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

2 changes: 1 addition & 1 deletion lib/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function getImapConnection() {
} catch (Horde_Imap_Client_Exception $e) {
throw new ServiceException(
"Could not connect to IMAP host $host:$port: " . $e->getMessage(),
(int) $e->getCode(),
$e->getCode(),
$e
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function save(): void {
foreach (array_keys(array_flip($val['slice'])) as $slice) {
$data = [];
foreach (array_keys($s['s'], $slice) as $uid) {
/** @var int $uid */
$data[$uid] = is_array($d[$uid])
? serialize($d[$uid])
: $d[$uid];
Expand Down Expand Up @@ -387,7 +388,7 @@ protected function _loadUids($mailbox, $uids, $uidvalid = null): void {
* @return void
*/
protected function _loadSlice($mailbox, $slice) {
$cache_id = $this->_getCid($mailbox, $slice);
$cache_id = $this->_getCid($mailbox, (string)$slice);

if (!empty($this->_loaded[$cache_id])) {
return;
Expand Down
6 changes: 3 additions & 3 deletions lib/Db/MailboxMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @template-extends QBMapper<Mailbox>
*/
namespace OCA\Mail\Db;

use OCA\Mail\Account;
Expand All @@ -41,6 +38,9 @@
use OCP\IDBConnection;
use function array_map;

/**
* @template-extends QBMapper<Mailbox>
*/
class MailboxMapper extends QBMapper {
/** @var ITimeFactory */
private $timeFactory;
Expand Down
3 changes: 3 additions & 0 deletions lib/Db/TrustedSenderMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection;

/**
* @template-extends QBMapper<TrustedSender>
*/
class TrustedSenderMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'mail_trusted_senders');
Expand Down
13 changes: 13 additions & 0 deletions lib/Exception/ClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,21 @@

use Exception;
use OCP\AppFramework\Http;
use Throwable;

class ClientException extends Exception {
/**
* @param string $message [optional] The Exception message to throw.
* @param mixed $code [optional] The Exception code.
* @param null|Throwable $previous [optional] The previous throwable used for the exception chaining.
*/
public function __construct($message = "", $code = 0, Throwable $previous = null) {
if (!is_int($code)) {
$code = (int)$code;
}
parent::__construct($message, $code, $previous);
}

public function getHttpCode(): int {
return Http::STATUS_BAD_REQUEST;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Exception/CouldNotConnectException.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CouldNotConnectException extends ServiceException {
public function __construct(Throwable $previous, string $service, string $host, int $port) {
parent::__construct(
"Connection to {$service} at {$host}:{$port} failed. {$previous->getMessage()}",
(int)$previous->getCode(),
$previous->getCode(),
$previous
);
$this->service = $service;
Expand Down
12 changes: 12 additions & 0 deletions lib/Exception/ServiceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
namespace OCA\Mail\Exception;

use Exception;
use Throwable;

class ServiceException extends Exception {
/**
* @param string $message [optional] The Exception message to throw.
* @param mixed $code [optional] The Exception code.
* @param null|Throwable $previous [optional] The previous throwable used for the exception chaining.
*/
public function __construct($message = "", $code = 0, Throwable $previous = null) {
if (!is_int($code)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@ChristophWurst I'm unsure about the constructor. Psalm mentioned the redundant int casts. ServiceException is often used as wrapper for Horde exceptions. I can't say for sure that every Horde exception is already using a numeric error code.

Copy link
Member

Choose a reason for hiding this comment

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

I remember a time where it was not guaranteed that the code would be an int. This might have been fixed in PHP or the stubs. If psalm no longer complains without the cast then remove it.

$code = (int)$code;
}
parent::__construct($message, $code, $previous);
}
}
4 changes: 2 additions & 2 deletions lib/IMAP/MailboxSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function sync(Account $account,
} catch (Horde_Imap_Client_Exception $e) {
throw new ServiceException(
sprintf("IMAP error synchronizing account %d: %s", $account->getId(), $e->getMessage()),
(int)$e->getCode(),
$e->getCode(),
$e
);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public function syncStats(Account $account, Mailbox $mailbox): void {
$id = $mailbox->getId();
throw new ServiceException(
"Could not fetch stats of mailbox $id. IMAP error: " . $e->getMessage(),
(int)$e->getCode(),
$e->getCode(),
$e
);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion lib/IMAP/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function getFullText(Horde_Imap_Client_Socket $client,
} catch (Horde_Imap_Client_Exception $e) {
throw new ServiceException(
"Could not fetch message source: " . $e->getMessage(),
(int) $e->getCode(),
$e->getCode(),
$e
);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Listener/AccountSynchronizedThreadUpdaterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
use function array_chunk;
use function iterator_to_array;

/**
* @template-implements IEventListener<Event|SynchronizationEvent>
*/
class AccountSynchronizedThreadUpdaterListener implements IEventListener {
private const WRITE_IDS_CHUNK_SIZE = 500;

Expand Down
3 changes: 3 additions & 0 deletions lib/Listener/AddressCollectionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
use Psr\Log\LoggerInterface;
use Throwable;

/**
* @template-implements IEventListener<Event|MessageSentEvent>
*/
class AddressCollectionListener implements IEventListener {
/** @var IUserPreferences */
private $preferences;
Expand Down
3 changes: 3 additions & 0 deletions lib/Listener/AntiAbuseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

/**
* @template-implements IEventListener<Event|BeforeMessageSentEvent>
*/
class AntiAbuseListener implements IEventListener {
/** @var IUserManager */
private $userManager;
Expand Down
3 changes: 3 additions & 0 deletions lib/Listener/DashboardPanelListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

/**
* @template-implements IEventListener<Event|RegisterWidgetEvent>
*/
class DashboardPanelListener implements IEventListener {
/**
* @inheritDoc
Expand Down
3 changes: 3 additions & 0 deletions lib/Listener/DeleteDraftListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
use OCP\EventDispatcher\IEventListener;
use Psr\Log\LoggerInterface;

/**
* @template-implements IEventListener<Event|DraftSavedEvent|OutboxMessageCreatedEvent|DraftMessageCreatedEvent>
*/
class DeleteDraftListener implements IEventListener {
/** @var IMAPClientFactory */
private $imapClientFactory;
Expand Down
Loading