Remove phpstan errors from the rest of the code

[MAILPOET-3235]
This commit is contained in:
Jan Lysý
2021-01-12 12:15:35 +01:00
committed by Veljko V
parent 479f2cf198
commit 4390a1932d
9 changed files with 27 additions and 9 deletions

View File

@ -12,7 +12,7 @@ class DaemonHttpRunner {
public $timer;
public $token;
/** @var Daemon */
/** @var Daemon|null */
private $daemon;
/** @var CronHelper */
@ -69,6 +69,9 @@ class DaemonHttpRunner {
if (!empty($error)) {
return $this->abortWithError($error);
}
if ($this->daemon === null) {
return $this->abortWithError(WPFunctions::get()->__('Daemon does not set correctly.', 'mailpoet'));
}
$this->settingsDaemonData['token'] = $this->token;
$this->daemon->run($this->settingsDaemonData);
// If we're using the WordPress trigger, check the conditions to stop cron if necessary

View File

@ -8,6 +8,7 @@ use MailPoet\Cron\Workers\SendingQueue\Tasks\Links;
use MailPoet\Cron\Workers\SendingQueue\Tasks\Mailer as MailerTask;
use MailPoet\Cron\Workers\SendingQueue\Tasks\Newsletter as NewsletterTask;
use MailPoet\Cron\Workers\StatsNotifications\Scheduler as StatsNotificationsScheduler;
use MailPoet\Entities\NewsletterEntity;
use MailPoet\Logging\LoggerFactory;
use MailPoet\Mailer\MailerError;
use MailPoet\Mailer\MailerLog;
@ -167,7 +168,9 @@ class SendingQueue {
['newsletter_id' => $newsletter->id, 'task_id' => $queue->taskId]
);
$this->newsletterTask->markNewsletterAsSent($newsletter, $queue);
$this->statsNotificationsScheduler->schedule($this->newslettersRepository->findOneById($newsletter->id));
$newsletter = $this->newslettersRepository->findOneById($newsletter->id);
assert($newsletter instanceof NewsletterEntity);
$this->statsNotificationsScheduler->schedule($newsletter);
}
$this->enforceSendingAndExecutionLimits($timer);
}

View File

@ -7,6 +7,7 @@ use MailPoet\Cron\CronHelper;
use MailPoet\Entities\NewsletterEntity;
use MailPoet\Entities\NewsletterLinkEntity;
use MailPoet\Entities\ScheduledTaskEntity;
use MailPoet\Entities\SendingQueueEntity;
use MailPoet\Entities\StatsNotificationEntity;
use MailPoet\Mailer\Mailer;
use MailPoet\Mailer\MetaInfo;
@ -117,8 +118,12 @@ class Worker {
throw new \RuntimeException('Missing newsletter entity for statistic notification.');
}
$link = $this->newsletterLinkRepository->findTopLinkForNewsletter((int)$newsletter->getId());
$context = $this->prepareContext($newsletter, $link);
$subject = $newsletter->getLatestQueue()->getNewsletterRenderedSubject();
$sendingQueue = $newsletter->getLatestQueue();
if (!$sendingQueue instanceof SendingQueueEntity) {
throw new \RuntimeException('Missing sending queue entity for statistic notification.');
}
$context = $this->prepareContext($newsletter, $sendingQueue, $link);
$subject = $sendingQueue->getNewsletterRenderedSubject();
return [
'subject' => sprintf(_x('Stats for email %s', 'title of an automatic email containing statistics (newsletter open rate, click rate, etc)', 'mailpoet'), $subject),
'body' => [
@ -128,12 +133,12 @@ class Worker {
];
}
private function prepareContext(NewsletterEntity $newsletter, NewsletterLinkEntity $link = null) {
private function prepareContext(NewsletterEntity $newsletter, SendingQueueEntity $sendingQueue, NewsletterLinkEntity $link = null) {
$statistics = $this->newsletterStatisticsRepository->getStatistics($newsletter);
$clicked = ($statistics->getClickCount() * 100) / $statistics->getTotalSentCount();
$opened = ($statistics->getOpenCount() * 100) / $statistics->getTotalSentCount();
$unsubscribed = ($statistics->getUnsubscribeCount() * 100) / $statistics->getTotalSentCount();
$subject = $newsletter->getLatestQueue()->getNewsletterRenderedSubject();
$subject = $sendingQueue->getNewsletterRenderedSubject();
$subscribersCount = $this->subscribersRepository->getTotalSubscribers();
$hasValidApiKey = $this->subscribersFeature->hasValidApiKey();
$context = [