PHPStan level 3 #1603

Merged
nupplaPhil merged 15 commits from Art4/friendica-addons:phpstan-level-3 into develop 2025-04-27 02:17:42 +02:00
Showing only changes of commit 06b4f164f5 - Show all commits

cast db stmt object to array

Art4 2025-03-14 08:21:08 +00:00

View file

@ -50,14 +50,14 @@ function notifyall_post()
$recipients = DBA::p("SELECT DISTINCT `email` FROM `user`" . DBA::buildCondition($condition), $condition);
if (! $recipients || !is_iterable($recipients)) {
if (! $recipients) {
Art4 marked this conversation as resolved Outdated

Instead of checking for this, $recipients should be assigned the result of DBA::toArray(DBA:p(...)) in order for the later foreach() to be valid. Normally, the DBA::p output requires the use of DBA::fetch() in a loop.

Sure, the PDOStatement is iterable, but the mysqli-produced result resource probably isn't.

Instead of checking for this, `$recipients` should be assigned the result of `DBA::toArray(DBA:p(...))` in order for the later `foreach()` to be valid. Normally, the `DBA::p` output requires the use of `DBA::fetch()` in a loop. Sure, the `PDOStatement` is iterable, but the `mysqli`-produced result resource probably isn't.

Done, thank you.

Done, thank you.
DI::sysmsg()->addNotice(DI::l10n()->t('No recipients found.'));
return;
}
$notifyEmail = new NotifyAllEmail(DI::l10n(), DI::config(), DI::baseUrl(), $text);
foreach ($recipients as $recipient) {
foreach (DBA::toArray($recipients) as $recipient) {
DI::emailer()->send($notifyEmail->withRecipient($recipient['email']));
}