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

@ -91,6 +91,7 @@ class PurchasedProduct {
} }
$woocommerceProducts = array_map(function($product) { $woocommerceProducts = array_map(function($product) {
assert($product instanceof \WP_Post);
return [ return [
'id' => $product->ID, 'id' => $product->ID,
'name' => $product->post_title, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps 'name' => $product->post_title, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps

View File

@ -968,6 +968,7 @@ class MP2Migrator {
$segmentsIds = implode(',', $segments); $segmentsIds = implode(',', $segments);
return '[mailpoet_subscribers_count segments=' . $segmentsIds . ']'; return '[mailpoet_subscribers_count segments=' . $segmentsIds . ']';
} }
return '';
} }
/** /**

View File

@ -12,7 +12,7 @@ class DaemonHttpRunner {
public $timer; public $timer;
public $token; public $token;
/** @var Daemon */ /** @var Daemon|null */
private $daemon; private $daemon;
/** @var CronHelper */ /** @var CronHelper */
@ -69,6 +69,9 @@ class DaemonHttpRunner {
if (!empty($error)) { if (!empty($error)) {
return $this->abortWithError($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->settingsDaemonData['token'] = $this->token;
$this->daemon->run($this->settingsDaemonData); $this->daemon->run($this->settingsDaemonData);
// If we're using the WordPress trigger, check the conditions to stop cron if necessary // 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\Mailer as MailerTask;
use MailPoet\Cron\Workers\SendingQueue\Tasks\Newsletter as NewsletterTask; use MailPoet\Cron\Workers\SendingQueue\Tasks\Newsletter as NewsletterTask;
use MailPoet\Cron\Workers\StatsNotifications\Scheduler as StatsNotificationsScheduler; use MailPoet\Cron\Workers\StatsNotifications\Scheduler as StatsNotificationsScheduler;
use MailPoet\Entities\NewsletterEntity;
use MailPoet\Logging\LoggerFactory; use MailPoet\Logging\LoggerFactory;
use MailPoet\Mailer\MailerError; use MailPoet\Mailer\MailerError;
use MailPoet\Mailer\MailerLog; use MailPoet\Mailer\MailerLog;
@ -167,7 +168,9 @@ class SendingQueue {
['newsletter_id' => $newsletter->id, 'task_id' => $queue->taskId] ['newsletter_id' => $newsletter->id, 'task_id' => $queue->taskId]
); );
$this->newsletterTask->markNewsletterAsSent($newsletter, $queue); $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); $this->enforceSendingAndExecutionLimits($timer);
} }

View File

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

View File

@ -373,6 +373,9 @@ class ContainerConfigurator implements IContainerConfigurator {
} }
public static function getPremiumService($id, ContainerInterface $container = null) { public static function getPremiumService($id, ContainerInterface $container = null) {
if ($container === null) {
return null;
}
if (!$container->has(IContainerConfigurator::PREMIUM_CONTAINER_SERVICE_SLUG)) { if (!$container->has(IContainerConfigurator::PREMIUM_CONTAINER_SERVICE_SLUG)) {
return null; return null;
} }

View File

@ -32,7 +32,7 @@ class TablePrefixMetadataFactory extends ClassMetadataFactory {
// prefix tables only after they are saved to cache so the prefix does not get included in cache // prefix tables only after they are saved to cache so the prefix does not get included in cache
// (getMetadataFor can call itself recursively but it saves to cache only after the recursive calls) // (getMetadataFor can call itself recursively but it saves to cache only after the recursive calls)
$isCached = $this->getCacheDriver()->contains($classMetadata->getName() . $this->cacheSalt); $isCached = ($cache = $this->getCacheDriver()) ? $cache->contains($classMetadata->getName() . $this->cacheSalt) : false;
if ($classMetadata instanceof ClassMetadata && $isCached) { if ($classMetadata instanceof ClassMetadata && $isCached) {
$this->addPrefix($classMetadata); $this->addPrefix($classMetadata);
$this->prefixedMap[$classMetadata->getName()] = true; $this->prefixedMap[$classMetadata->getName()] = true;

View File

@ -73,12 +73,12 @@ class Links {
$linkToReplace = $processedLink['link']; $linkToReplace = $processedLink['link'];
$replacementLink = $processedLink['processed_link']; $replacementLink = $processedLink['processed_link'];
if ($processedLink['type'] == self::LINK_TYPE_SHORTCODE) { if ($processedLink['type'] == self::LINK_TYPE_SHORTCODE) {
$content = str_replace($linkToReplace, $replacementLink, $content); $content = str_replace($linkToReplace, $replacementLink, (string)$content);
} }
$content = preg_replace( $content = preg_replace(
'/\[(.*?)\](\(' . preg_quote($linkToReplace, '/') . '\))/', '/\[(.*?)\](\(' . preg_quote($linkToReplace, '/') . '\))/',
'[$1](' . $replacementLink . ')', '[$1](' . $replacementLink . ')',
$content (string)$content
); );
} }
return [ return [

View File

@ -12,6 +12,7 @@ class DOM {
*/ */
public static function splitOn(DomNode $bound, DomNode $cutElement) { public static function splitOn(DomNode $bound, DomNode $cutElement) {
$ignoreTextAndCommentNodes = false; $ignoreTextAndCommentNodes = false;
$grandparent = $cutElement->parent;
for ($parent = $cutElement->parent; $bound != $parent; $parent = $grandparent) { for ($parent = $cutElement->parent; $bound != $parent; $parent = $grandparent) {
// Clone parent node without children, but with attributes // Clone parent node without children, but with attributes
$parent->after($parent->toString()); $parent->after($parent->toString());
@ -23,6 +24,7 @@ class DOM {
} }
// Reattach cut_element and right siblings to grandparent // Reattach cut_element and right siblings to grandparent
/* @phpstan-ignore-next-line Because there is a wrong annotation in the library tburry/pquery */
$grandparent = $parent->parent; $grandparent = $parent->parent;
$indexAfterParent = $parent->index() + 1; $indexAfterParent = $parent->index() + 1;
$right->move($grandparent, $indexAfterParent); $right->move($grandparent, $indexAfterParent);