diff --git a/RoboFile.php b/RoboFile.php index 22f4497f3c..785e38e919 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -129,7 +129,7 @@ class RoboFile extends \Robo\Tasks { ->run(); } - public function testUnit(array $opts=['file' => null, 'xml' => false, 'multisite' => false, 'debug' => false]) { + public function testUnit(array $opts = ['file' => null, 'xml' => false, 'multisite' => false, 'debug' => false]) { $command = 'vendor/bin/codecept run unit'; if ($opts['file']) { @@ -147,7 +147,7 @@ class RoboFile extends \Robo\Tasks { return $this->_exec($command); } - public function testIntegration(array $opts=['file' => null, 'xml' => false, 'multisite' => false, 'debug' => false]) { + public function testIntegration(array $opts = ['file' => null, 'xml' => false, 'multisite' => false, 'debug' => false]) { if (getenv('MAILPOET_DEV_SITE')) { $run = $this->confirm("You are about to run tests on the development site. Your DB data will be erased. \nDo you want to proceed?", false); if (!$run) { @@ -175,11 +175,11 @@ class RoboFile extends \Robo\Tasks { return $this->_exec($command); } - public function testMultisiteIntegration($opts=['file' => null, 'xml' => false, 'multisite' => true]) { + public function testMultisiteIntegration($opts = ['file' => null, 'xml' => false, 'multisite' => true]) { return $this->testIntegration($opts); } - public function testCoverage($opts=['file' => null, 'xml' => false]) { + public function testCoverage($opts = ['file' => null, 'xml' => false]) { $command = join(' ', [ 'vendor/bin/codecept run -s acceptance', (($opts['file']) ? $opts['file'] : ''), @@ -230,15 +230,15 @@ class RoboFile extends \Robo\Tasks { return $this->_exec($command); } - public function testDebugUnit($opts=['file' => null, 'xml' => false, 'debug' => true]) { + public function testDebugUnit($opts = ['file' => null, 'xml' => false, 'debug' => true]) { return $this->testUnit($opts); } - public function testDebugIntegration($opts=['file' => null, 'xml' => false, 'debug' => true]) { + public function testDebugIntegration($opts = ['file' => null, 'xml' => false, 'debug' => true]) { return $this->testIntegration($opts); } - public function testAcceptance($opts=['file' => null, 'skip-deps' => false, 'timeout' => null]) { + public function testAcceptance($opts = ['file' => null, 'skip-deps' => false, 'timeout' => null]) { return $this->taskExec( 'COMPOSE_HTTP_TIMEOUT=200 docker-compose run ' . ($opts['skip-deps'] ? '-e SKIP_DEPS=1 ' : '') . @@ -248,7 +248,7 @@ class RoboFile extends \Robo\Tasks { )->dir(__DIR__ . '/tests/docker')->run(); } - public function testAcceptanceMultisite($opts=['file' => null, 'skip-deps' => false, 'timeout' => null]) { + public function testAcceptanceMultisite($opts = ['file' => null, 'skip-deps' => false, 'timeout' => null]) { return $this->taskExec( 'COMPOSE_HTTP_TIMEOUT=200 docker-compose run ' . ($opts['skip-deps'] ? '-e SKIP_DEPS=1 ' : '') . @@ -463,7 +463,7 @@ class RoboFile extends \Robo\Tasks { } } - public function qaPhpstan(array $opts=['php-version' => null]) { + public function qaPhpstan(array $opts = ['php-version' => null]) { $dir = __DIR__; $task = implode(' ', [ 'php -d memory_limit=-1', diff --git a/lib/API/JSON/API.php b/lib/API/JSON/API.php index 6d7d056a2c..fb615fd8f5 100644 --- a/lib/API/JSON/API.php +++ b/lib/API/JSON/API.php @@ -175,7 +175,8 @@ class API { public function processRoute() { try { - if (empty($this->requestEndpointClass) || + if ( + empty($this->requestEndpointClass) || !$this->container->has($this->requestEndpointClass) ) { throw new \Exception(__('Invalid API endpoint.', 'mailpoet')); diff --git a/lib/API/JSON/v1/Services.php b/lib/API/JSON/v1/Services.php index d3900ddd32..939783470d 100644 --- a/lib/API/JSON/v1/Services.php +++ b/lib/API/JSON/v1/Services.php @@ -130,7 +130,7 @@ class Services extends APIEndpoint { $code = !empty($result['code']) ? $result['code'] : Bridge::CHECK_ERROR_UNKNOWN; $errorMessage = $this->wp->__('Error validating MailPoet Sending Service key, please try again later (%s).', 'mailpoet'); // If site runs on localhost - if ( 1 === preg_match("/^(http|https)\:\/\/(localhost|127\.0\.0\.1)/", $this->wp->siteUrl()) ) { + if (1 === preg_match("/^(http|https)\:\/\/(localhost|127\.0\.0\.1)/", $this->wp->siteUrl())) { $errorMessage .= ' ' . $this->wp->__("Note that it doesn't work on localhost.", 'mailpoet'); } $error = sprintf( diff --git a/lib/API/JSON/v1/Settings.php b/lib/API/JSON/v1/Settings.php index 489406304d..b851d91375 100644 --- a/lib/API/JSON/v1/Settings.php +++ b/lib/API/JSON/v1/Settings.php @@ -139,7 +139,7 @@ class Settings extends APIEndpoint { // Tracking and re-engagement Emails $meta['showNotice'] = false; - if ($oldSettings['tracking'] !== $this->settings->get('tracking') ) { + if ($oldSettings['tracking'] !== $this->settings->get('tracking')) { try { $meta = $this->updateReEngagementEmailStatus($this->settings->get('tracking')); } catch (\Exception $e) { diff --git a/lib/Analytics/Reporter.php b/lib/Analytics/Reporter.php index cb8da3425e..47cd0e94ab 100644 --- a/lib/Analytics/Reporter.php +++ b/lib/Analytics/Reporter.php @@ -80,7 +80,7 @@ class Reporter { } public function getData() { - global $wpdb, $wp_version, $woocommerce; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + global $wpdb, $wp_version, $woocommerce; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps $mta = $this->settings->get('mta', []); $newsletters = $this->newslettersRepository->getAnalytics(); $isCronTriggerMethodWP = $this->settings->get('cron_trigger.method') === CronTrigger::METHOD_WORDPRESS; diff --git a/lib/AutomaticEmails/AutomaticEmails.php b/lib/AutomaticEmails/AutomaticEmails.php index 344947fb30..d60ce22fc3 100644 --- a/lib/AutomaticEmails/AutomaticEmails.php +++ b/lib/AutomaticEmails/AutomaticEmails.php @@ -45,7 +45,8 @@ class AutomaticEmails { foreach ($registeredGroups as $group) { $automaticEmail = $this->wp->applyFilters($group, []); - if (!$this->validateAutomaticEmailDataFields($automaticEmail) || + if ( + !$this->validateAutomaticEmailDataFields($automaticEmail) || !$this->validateAutomaticEmailEventsDataFields($automaticEmail['events']) ) { continue; diff --git a/lib/Config/Installer.php b/lib/Config/Installer.php index e5983f9c49..a36c70d194 100644 --- a/lib/Config/Installer.php +++ b/lib/Config/Installer.php @@ -28,7 +28,8 @@ class Installer { } public function getPluginInformation($data, $action = '', $args = null) { - if ($action === 'plugin_information' + if ( + $action === 'plugin_information' && isset($args->slug) && $args->slug === $this->slug ) { diff --git a/lib/Config/Menu.php b/lib/Config/Menu.php index 69a240f3a7..c738df9064 100644 --- a/lib/Config/Menu.php +++ b/lib/Config/Menu.php @@ -499,7 +499,8 @@ class Menu { return false; } // Check if page already exists - if (get_plugin_page_hook($_REQUEST['page'], '') + if ( + get_plugin_page_hook($_REQUEST['page'], '') || WPFunctions::get()->getPluginPageHook($_REQUEST['page'], self::MAIN_PAGE_SLUG) ) { return false; diff --git a/lib/Config/Populator.php b/lib/Config/Populator.php index 3af2aa334b..ec655d2d11 100644 --- a/lib/Config/Populator.php +++ b/lib/Config/Populator.php @@ -304,7 +304,7 @@ class Populator { 'enabled' => empty($settingsDbVersion), // enable on new installs only 'message' => $currentLabelText, ]); - } elseif (isset($woocommerceOptinOnCheckout['message']) && $woocommerceOptinOnCheckout['message'] === $legacyLabelText ) { + } elseif (isset($woocommerceOptinOnCheckout['message']) && $woocommerceOptinOnCheckout['message'] === $legacyLabelText) { $this->settings->set('woocommerce.optin_on_checkout.message', $currentLabelText); } // reset mailer log diff --git a/lib/Config/ServicesChecker.php b/lib/Config/ServicesChecker.php index c1262d985b..4bfad3de2a 100644 --- a/lib/Config/ServicesChecker.php +++ b/lib/Config/ServicesChecker.php @@ -33,7 +33,8 @@ class ServicesChecker { $mssKeySpecified = Bridge::isMSSKeySpecified(); $mssKey = $this->settings->get(Bridge::API_KEY_STATE_SETTING_NAME); - if (!$mssKeySpecified + if ( + !$mssKeySpecified || empty($mssKey['state']) || $mssKey['state'] == Bridge::KEY_INVALID ) { @@ -49,7 +50,8 @@ class ServicesChecker { WPNotice::displayError($error, '', '', false, false); } return false; - } elseif ($mssKey['state'] == Bridge::KEY_EXPIRING + } elseif ( + $mssKey['state'] == Bridge::KEY_EXPIRING && !empty($mssKey['data']['expire_at']) ) { if ($displayErrorNotice) { @@ -80,7 +82,8 @@ class ServicesChecker { $displayErrorNotice = false; } - if (!$premiumKeySpecified + if ( + !$premiumKeySpecified || empty($premiumKey['state']) || $premiumKey['state'] === Bridge::KEY_INVALID || $premiumKey['state'] === Bridge::KEY_ALREADY_USED @@ -102,7 +105,8 @@ class ServicesChecker { WPNotice::displayWarning($error); } return false; - } elseif ($premiumKey['state'] === Bridge::KEY_EXPIRING + } elseif ( + $premiumKey['state'] === Bridge::KEY_EXPIRING && !empty($premiumKey['data']['expire_at']) ) { if ($displayErrorNotice) { diff --git a/lib/Cron/DaemonHttpRunner.php b/lib/Cron/DaemonHttpRunner.php index 971eb34b09..9564c1ff5f 100644 --- a/lib/Cron/DaemonHttpRunner.php +++ b/lib/Cron/DaemonHttpRunner.php @@ -64,7 +64,8 @@ class DaemonHttpRunner { if (!$this->settingsDaemonData) { $error = WPFunctions::get()->__('Daemon does not exist.', 'mailpoet'); } else { - if (!isset($requestData['token']) || + if ( + !isset($requestData['token']) || $requestData['token'] !== $this->settingsDaemonData['token'] ) { $error = 'Invalid or missing token.'; @@ -81,7 +82,8 @@ class DaemonHttpRunner { $this->daemon->run($this->settingsDaemonData); // If we're using the WordPress trigger, check the conditions to stop cron if necessary $enableCronSelfDeactivation = WPFunctions::get()->applyFilters('mailpoet_cron_enable_self_deactivation', false); - if ($enableCronSelfDeactivation + if ( + $enableCronSelfDeactivation && $this->isCronTriggerMethodWordPress() && !$this->checkWPTriggerExecutionRequirements() ) { diff --git a/lib/Cron/Triggers/WordPress.php b/lib/Cron/Triggers/WordPress.php index d5c772d2bf..a2333aa7b4 100644 --- a/lib/Cron/Triggers/WordPress.php +++ b/lib/Cron/Triggers/WordPress.php @@ -338,7 +338,7 @@ class WordPress { $type = $options['type']; foreach ($options['scheduled_in'] as $scheduledIn) { foreach ($options['status'] as $status) { - if (! empty($this->tasksCounts[$type][$scheduledIn][$status])) { + if (!empty($this->tasksCounts[$type][$scheduledIn][$status])) { $count += $this->tasksCounts[$type][$scheduledIn][$status]; } } diff --git a/lib/Cron/Workers/Scheduler.php b/lib/Cron/Workers/Scheduler.php index 2a3f52b8b3..6d2203205b 100644 --- a/lib/Cron/Workers/Scheduler.php +++ b/lib/Cron/Workers/Scheduler.php @@ -221,7 +221,8 @@ class Scheduler { $queue->delete(); return false; } - if ($newsletter->role !== WelcomeScheduler::WORDPRESS_ALL_ROLES + if ( + $newsletter->role !== WelcomeScheduler::WORDPRESS_ALL_ROLES && !in_array($newsletter->role, ((array)$wpUser)['roles']) ) { $queue->delete(); diff --git a/lib/Cron/Workers/SendingQueue/Migration.php b/lib/Cron/Workers/SendingQueue/Migration.php index d9a72e3cb7..40bd9dfa77 100644 --- a/lib/Cron/Workers/SendingQueue/Migration.php +++ b/lib/Cron/Workers/SendingQueue/Migration.php @@ -30,7 +30,8 @@ class Migration extends SimpleWorker { $unmigratedQueueSubscribers = $this->getTaskIdsForUnmigratedSubscribers(); } - if (!$unmigratedColumns || + if ( + !$unmigratedColumns || ($unmigratedQueuesCount == 0 && count($unmigratedQueueSubscribers) == 0) ) { diff --git a/lib/Cron/Workers/SendingQueue/Tasks/Newsletter.php b/lib/Cron/Workers/SendingQueue/Tasks/Newsletter.php index 051679be93..2dff0c2532 100644 --- a/lib/Cron/Workers/SendingQueue/Tasks/Newsletter.php +++ b/lib/Cron/Workers/SendingQueue/Tasks/Newsletter.php @@ -147,7 +147,8 @@ class Newsletter { $renderedNewsletter = $this->gaTracking->applyGATracking($renderedNewsletter, $newsletter); } // check if this is a post notification and if it contains at least 1 ALC post - if ($newsletter->type === NewsletterModel::TYPE_NOTIFICATION_HISTORY && + if ( + $newsletter->type === NewsletterModel::TYPE_NOTIFICATION_HISTORY && $this->postsTask->getAlcPostsCount($renderedNewsletter, $newsletter) === 0 ) { // delete notification history record since it will never be sent @@ -232,7 +233,8 @@ class Newsletter { public function markNewsletterAsSent($newsletter, $queue) { // if it's a standard or notification history newsletter, update its status - if ($newsletter->type === NewsletterModel::TYPE_STANDARD || + if ( + $newsletter->type === NewsletterModel::TYPE_STANDARD || $newsletter->type === NewsletterModel::TYPE_NOTIFICATION_HISTORY ) { $newsletter->status = NewsletterModel::STATUS_SENT; diff --git a/lib/Entities/SubscriberEntity.php b/lib/Entities/SubscriberEntity.php index 9e0307ec74..c518bf99ac 100644 --- a/lib/Entities/SubscriberEntity.php +++ b/lib/Entities/SubscriberEntity.php @@ -257,13 +257,15 @@ class SubscriberEntity { * @param string $status */ public function setStatus($status) { - if (!in_array($status, [ - self::STATUS_BOUNCED, - self::STATUS_INACTIVE, - self::STATUS_SUBSCRIBED, - self::STATUS_UNCONFIRMED, - self::STATUS_UNSUBSCRIBED, - ])) { + if ( + !in_array($status, [ + self::STATUS_BOUNCED, + self::STATUS_INACTIVE, + self::STATUS_SUBSCRIBED, + self::STATUS_UNCONFIRMED, + self::STATUS_UNSUBSCRIBED, + ]) + ) { throw new \InvalidArgumentException("Invalid status '{$status}' given to subscriber!"); } $this->status = $status; @@ -350,16 +352,18 @@ class SubscriberEntity { * @param string $source */ public function setSource($source) { - if (!in_array($source, [ - 'api', - 'form', - 'unknown', - 'imported', - 'administrator', - 'wordpress_user', - 'woocommerce_user', - 'woocommerce_checkout', - ])) { + if ( + !in_array($source, [ + 'api', + 'form', + 'unknown', + 'imported', + 'administrator', + 'wordpress_user', + 'woocommerce_user', + 'woocommerce_checkout', + ]) + ) { throw new \InvalidArgumentException("Invalid source '{$source}' given to subscriber!"); } $this->source = $source; diff --git a/lib/Form/Block/BlockRendererHelper.php b/lib/Form/Block/BlockRendererHelper.php index 623076b95f..2aaa103be1 100644 --- a/lib/Form/Block/BlockRendererHelper.php +++ b/lib/Form/Block/BlockRendererHelper.php @@ -119,8 +119,10 @@ class BlockRendererHelper { if (in_array($block['id'], ['email', 'last_name', 'first_name'], true)) { $automationId = 'data-automation-id="form_' . $block['id'] . '_label" '; } - if (isset($block['params']['label']) - && strlen(trim($block['params']['label'])) > 0) { + if ( + isset($block['params']['label']) + && strlen(trim($block['params']['label'])) > 0 + ) { $html .= '
@@ -201,7 +201,8 @@ class Widget extends \WP_Widget { if ($form->getStatus() !== FormEntity::STATUS_ENABLED) return ''; $formType = 'widget'; - if (isset($instance['form_type']) && in_array( + if ( + isset($instance['form_type']) && in_array( $instance['form_type'], [ 'html', @@ -209,7 +210,8 @@ class Widget extends \WP_Widget { 'iframe', 'shortcode', ] - )) { + ) + ) { $formType = $instance['form_type']; } diff --git a/lib/Mailer/MetaInfo.php b/lib/Mailer/MetaInfo.php index 73f21db0a7..26546aa01b 100644 --- a/lib/Mailer/MetaInfo.php +++ b/lib/Mailer/MetaInfo.php @@ -57,7 +57,7 @@ class MetaInfo { return $this->makeMetaInfo($type, $subscriber->status, $subscriber->source); } - private function makeMetaInfo($emailType, $subscriberStatus, $subscriberSource) { + private function makeMetaInfo($emailType, $subscriberStatus, $subscriberSource) { return [ 'email_type' => $emailType, 'subscriber_status' => $subscriberStatus, diff --git a/lib/Mailer/Methods/MailPoet.php b/lib/Mailer/Methods/MailPoet.php index 6419d42f21..604b88a9fc 100644 --- a/lib/Mailer/Methods/MailPoet.php +++ b/lib/Mailer/Methods/MailPoet.php @@ -74,7 +74,8 @@ class MailPoet { public function processSendError($result, $subscriber, $newsletter) { if (!empty($result['code']) && $result['code'] === API::RESPONSE_CODE_KEY_INVALID) { Bridge::invalidateKey(); - } elseif (!empty($result['code']) + } elseif ( + !empty($result['code']) && $result['code'] === API::RESPONSE_CODE_CAN_NOT_SEND && $result['message'] === MailerError::MESSAGE_EMAIL_NOT_AUTHORIZED ) { diff --git a/lib/Models/Newsletter.php b/lib/Models/Newsletter.php index 39e69318e1..83165aa479 100644 --- a/lib/Models/Newsletter.php +++ b/lib/Models/Newsletter.php @@ -163,13 +163,15 @@ class Newsletter extends Model { return $this; } } - if (in_array($status, [ - self::STATUS_DRAFT, - self::STATUS_SCHEDULED, - self::STATUS_SENDING, - self::STATUS_SENT, - self::STATUS_ACTIVE, - ])) { + if ( + in_array($status, [ + self::STATUS_DRAFT, + self::STATUS_SCHEDULED, + self::STATUS_SENDING, + self::STATUS_SENT, + self::STATUS_ACTIVE, + ]) + ) { $this->set('status', $status); $this->save(); } @@ -404,26 +406,30 @@ class Newsletter extends Model { } public static function filterStatus($orm, $status = false) { - if (in_array($status, [ + if ( + in_array($status, [ self::STATUS_DRAFT, self::STATUS_SCHEDULED, self::STATUS_SENDING, self::STATUS_SENT, self::STATUS_ACTIVE, - ])) { + ]) + ) { $orm->where('status', $status); } return $orm; } public static function filterType($orm, $type = false, $group = false) { - if (in_array($type, [ + if ( + in_array($type, [ self::TYPE_STANDARD, self::TYPE_WELCOME, self::TYPE_AUTOMATIC, self::TYPE_NOTIFICATION, self::TYPE_NOTIFICATION_HISTORY, - ])) { + ]) + ) { if ($type === self::TYPE_AUTOMATIC && $group) { $orm = $orm->join( NewsletterOptionField::$_table, diff --git a/lib/Models/StatisticsNewsletters.php b/lib/Models/StatisticsNewsletters.php index ff23dbb0b2..ef71251194 100644 --- a/lib/Models/StatisticsNewsletters.php +++ b/lib/Models/StatisticsNewsletters.php @@ -11,9 +11,10 @@ class StatisticsNewsletters extends Model { public static function createMultiple(array $data) { $values = []; foreach ($data as $value) { - if (!empty($value['newsletter_id']) && - !empty($value['subscriber_id']) && - !empty($value['queue_id']) + if ( + !empty($value['newsletter_id']) && + !empty($value['subscriber_id']) && + !empty($value['queue_id']) ) { $values[] = $value['newsletter_id']; $values[] = $value['subscriber_id']; diff --git a/lib/Newsletter/Links/Links.php b/lib/Newsletter/Links/Links.php index 0928ef891f..ad736f7723 100644 --- a/lib/Newsletter/Links/Links.php +++ b/lib/Newsletter/Links/Links.php @@ -184,9 +184,10 @@ class Links { } public function ensureInstantUnsubscribeLink(array $processedLinks) { - if (in_array( - NewsletterLinkEntity::INSTANT_UNSUBSCRIBE_LINK_SHORT_CODE, - array_column($processedLinks, 'link')) + if ( + in_array( + NewsletterLinkEntity::INSTANT_UNSUBSCRIBE_LINK_SHORT_CODE, + array_column($processedLinks, 'link')) ) { return $processedLinks; } @@ -211,7 +212,8 @@ class Links { // convert either only link shortcodes or all hashes links if "convert all" // option is specified - if (($newsletterLink instanceof NewsletterLinkEntity) && + if ( + ($newsletterLink instanceof NewsletterLinkEntity) && (preg_match('/\[link:/', $newsletterLink->getUrl()) || $convertAll) ) { $content = str_replace($link, $newsletterLink->getUrl(), $content); diff --git a/lib/Newsletter/Renderer/Blocks/AbandonedCartContent.php b/lib/Newsletter/Renderer/Blocks/AbandonedCartContent.php index bb8333544d..1573aca410 100644 --- a/lib/Newsletter/Renderer/Blocks/AbandonedCartContent.php +++ b/lib/Newsletter/Renderer/Blocks/AbandonedCartContent.php @@ -36,7 +36,8 @@ class AbandonedCartContent { $optionField = $newsletterOption->getOptionField(); return $optionField && $optionField->getName() === 'event'; })->first(); - if (($groupOption instanceof NewsletterOptionEntity && $groupOption->getValue() !== WooCommerceEmail::SLUG) + if ( + ($groupOption instanceof NewsletterOptionEntity && $groupOption->getValue() !== WooCommerceEmail::SLUG) || ($eventOption instanceof NewsletterOptionEntity && $eventOption->getValue() !== AbandonedCart::SLUG) ) { // Do not display the block if not an AbandonedCart email diff --git a/lib/Newsletter/Renderer/Blocks/Image.php b/lib/Newsletter/Renderer/Blocks/Image.php index 785e046914..3bbb71bd8c 100644 --- a/lib/Newsletter/Renderer/Blocks/Image.php +++ b/lib/Newsletter/Renderer/Blocks/Image.php @@ -60,7 +60,8 @@ class Image { $element['height'] = (int)ceil($element['height'] / $ratio); } // resize image if the image is padded and wider than padded column width - if ($element['fullWidth'] === false && + if ( + $element['fullWidth'] === false && $element['width'] > ($columnBaseWidth - $paddedWidth) ) { $ratio = $element['width'] / ($columnBaseWidth - $paddedWidth); diff --git a/lib/Newsletter/Renderer/Blocks/Text.php b/lib/Newsletter/Renderer/Blocks/Text.php index ae349c6b35..a197cb40f4 100644 --- a/lib/Newsletter/Renderer/Blocks/Text.php +++ b/lib/Newsletter/Renderer/Blocks/Text.php @@ -91,9 +91,10 @@ class Text { false; // if previous or next paragraphs are empty OR previous paragraph // is a heading, insert a break line - if (!$nextElement || - !$previousElement || - (preg_match('/h\d+/', $previousElementTag)) + if ( + !$nextElement || + !$previousElement || + (preg_match('/h\d+/', $previousElementTag)) ) { $paragraph = $this->insertLineBreak($paragraph); } diff --git a/lib/Newsletter/Renderer/Columns/Renderer.php b/lib/Newsletter/Renderer/Columns/Renderer.php index af4a2dae25..27b8c3d5de 100644 --- a/lib/Newsletter/Renderer/Columns/Renderer.php +++ b/lib/Newsletter/Renderer/Columns/Renderer.php @@ -129,7 +129,8 @@ class Renderer { } private function getBgColorAttribute($styles, $image) { - if (($image === null || $image['src'] === null) + if ( + ($image === null || $image['src'] === null) && isset($styles['backgroundColor']) && $styles['backgroundColor'] !== 'transparent' ) { diff --git a/lib/Newsletter/Scheduler/WelcomeScheduler.php b/lib/Newsletter/Scheduler/WelcomeScheduler.php index 07830c85a5..b2480b4496 100644 --- a/lib/Newsletter/Scheduler/WelcomeScheduler.php +++ b/lib/Newsletter/Scheduler/WelcomeScheduler.php @@ -52,7 +52,8 @@ class WelcomeScheduler { if (empty($newsletters)) return false; $result = []; foreach ($newsletters as $newsletter) { - if ($newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_EVENT) === 'segment' && + if ( + $newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_EVENT) === 'segment' && in_array($newsletter->getOptionValue(NewsletterOptionFieldEntity::NAME_SEGMENT), $segments) ) { $sendingTask = $this->createWelcomeNotificationSendingTask($newsletter, $subscriberId); @@ -80,13 +81,15 @@ class WelcomeScheduler { // do not schedule welcome newsletter if roles have not changed $oldRole = $oldUserData['roles']; $newRole = $wpUser['roles']; - if ($newsletterRole === self::WORDPRESS_ALL_ROLES || + if ( + $newsletterRole === self::WORDPRESS_ALL_ROLES || !array_diff($oldRole, $newRole) ) { continue; } } - if ($newsletterRole === self::WORDPRESS_ALL_ROLES || + if ( + $newsletterRole === self::WORDPRESS_ALL_ROLES || in_array($newsletterRole, $wpUser['roles']) ) { $this->createWelcomeNotificationSendingTask($newsletter, $subscriberId); diff --git a/lib/Newsletter/Shortcodes/Categories/Subscriber.php b/lib/Newsletter/Shortcodes/Categories/Subscriber.php index 6cd64b204f..9af203c0ae 100644 --- a/lib/Newsletter/Shortcodes/Categories/Subscriber.php +++ b/lib/Newsletter/Shortcodes/Categories/Subscriber.php @@ -56,7 +56,8 @@ class Subscriber implements CategoryInterface { case 'count': return (string)$this->subscribersRepository->getTotalSubscribers(); default: - if (preg_match('/cf_(\d+)/', $shortcodeDetails['action'], $customField) && + if ( + preg_match('/cf_(\d+)/', $shortcodeDetails['action'], $customField) && !empty($subscriber->getId()) ) { $customField = $this->subscriberCustomFieldRepository->findOneBy([ diff --git a/lib/Router/Endpoints/Track.php b/lib/Router/Endpoints/Track.php index 201d7aced4..faf0aa4ea2 100644 --- a/lib/Router/Endpoints/Track.php +++ b/lib/Router/Endpoints/Track.php @@ -80,7 +80,8 @@ class Track { public function _processTrackData($data) { $data = (object)$this->links->transformUrlDataObject($data); - if (empty($data->queue_id) || // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + if ( + empty($data->queue_id) || // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps empty($data->subscriber_id) || // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps empty($data->subscriber_token) // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps ) { diff --git a/lib/Segments/DynamicSegments/FilterDataMapper.php b/lib/Segments/DynamicSegments/FilterDataMapper.php index 1a9f824861..8a6ba74df8 100644 --- a/lib/Segments/DynamicSegments/FilterDataMapper.php +++ b/lib/Segments/DynamicSegments/FilterDataMapper.php @@ -213,7 +213,8 @@ class FilterDataMapper { $filterData['country_code'] = $data['country_code']; $filterData['operator'] = $data['operator'] ?? DynamicSegmentFilterData::OPERATOR_ANY; } elseif ($data['action'] === WooCommerceNumberOfOrders::ACTION_NUMBER_OF_ORDERS) { - if (!isset($data['number_of_orders_type']) + if ( + !isset($data['number_of_orders_type']) || !isset($data['number_of_orders_count']) || $data['number_of_orders_count'] < 0 || !isset($data['number_of_orders_days']) || $data['number_of_orders_days'] < 1 ) { @@ -223,7 +224,8 @@ class FilterDataMapper { $filterData['number_of_orders_count'] = $data['number_of_orders_count']; $filterData['number_of_orders_days'] = $data['number_of_orders_days']; } elseif ($data['action'] === WooCommerceTotalSpent::ACTION_TOTAL_SPENT) { - if (!isset($data['total_spent_type']) + if ( + !isset($data['total_spent_type']) || !isset($data['total_spent_amount']) || $data['total_spent_amount'] < 0 || !isset($data['total_spent_days']) || $data['total_spent_days'] < 1 ) { diff --git a/lib/Segments/WP.php b/lib/Segments/WP.php index 7c43edc181..4b68cd6867 100644 --- a/lib/Segments/WP.php +++ b/lib/Segments/WP.php @@ -92,7 +92,8 @@ class WP { } // we want to mark a new subscriber as unsubscribed when the checkbox on Woo checkout is unchecked - if (isset($_POST[WooCommerceSubscription::CHECKOUT_OPTIN_PRESENCE_CHECK_INPUT_NAME]) + if ( + isset($_POST[WooCommerceSubscription::CHECKOUT_OPTIN_PRESENCE_CHECK_INPUT_NAME]) && !isset($_POST[WooCommerceSubscription::CHECKOUT_OPTIN_INPUT_NAME]) ) { $status = SubscriberEntity::STATUS_UNSUBSCRIBED; diff --git a/lib/Services/Bridge.php b/lib/Services/Bridge.php index 9120ab9e9b..778dd0e7bd 100644 --- a/lib/Services/Bridge.php +++ b/lib/Services/Bridge.php @@ -132,7 +132,8 @@ class Bridge { } public function storeMSSKeyAndState($key, $state) { - if (empty($state['state']) + if ( + empty($state['state']) || $state['state'] === self::KEY_CHECK_ERROR ) { return false; @@ -167,7 +168,8 @@ class Bridge { ]; if (!empty($result['code']) && isset($stateMap[$result['code']])) { - if ($stateMap[$result['code']] == self::KEY_VALID + if ( + $stateMap[$result['code']] == self::KEY_VALID && !empty($result['data']['expire_at']) ) { $keyState = self::KEY_EXPIRING; @@ -185,7 +187,8 @@ class Bridge { } public function storePremiumKeyAndState($key, $state) { - if (empty($state['state']) + if ( + empty($state['state']) || $state['state'] === self::KEY_CHECK_ERROR ) { return false; diff --git a/lib/Statistics/Track/Clicks.php b/lib/Statistics/Track/Clicks.php index 4ebe0dfa46..831b0bb479 100644 --- a/lib/Statistics/Track/Clicks.php +++ b/lib/Statistics/Track/Clicks.php @@ -98,9 +98,10 @@ class Clicks { $queue, $userAgent ); - if ($userAgent instanceof UserAgentEntity && - ($userAgent->getUserAgentType() === UserAgentEntity::USER_AGENT_TYPE_HUMAN - || $statisticsClicks->getUserAgentType() === UserAgentEntity::USER_AGENT_TYPE_MACHINE) + if ( + $userAgent instanceof UserAgentEntity && + ($userAgent->getUserAgentType() === UserAgentEntity::USER_AGENT_TYPE_HUMAN + || $statisticsClicks->getUserAgentType() === UserAgentEntity::USER_AGENT_TYPE_MACHINE) ) { $statisticsClicks->setUserAgent($userAgent); $statisticsClicks->setUserAgentType($userAgent->getUserAgentType()); diff --git a/lib/Statistics/Track/Opens.php b/lib/Statistics/Track/Opens.php index 74b3c8dda2..614d28d3aa 100644 --- a/lib/Statistics/Track/Opens.php +++ b/lib/Statistics/Track/Opens.php @@ -54,7 +54,8 @@ class Opens { if ($oldStatistics) { if (!empty($data->userAgent)) { $userAgent = $this->userAgentsRepository->findOrCreate($data->userAgent); - if ($userAgent->getUserAgentType() === UserAgentEntity::USER_AGENT_TYPE_HUMAN + if ( + $userAgent->getUserAgentType() === UserAgentEntity::USER_AGENT_TYPE_HUMAN || $oldStatistics->getUserAgentType() === UserAgentEntity::USER_AGENT_TYPE_MACHINE ) { $oldStatistics->setUserAgent($userAgent); diff --git a/lib/Subscribers/ImportExport/Export/Export.php b/lib/Subscribers/ImportExport/Export/Export.php index 9991655d39..e53a6d2fb9 100644 --- a/lib/Subscribers/ImportExport/Export/Export.php +++ b/lib/Subscribers/ImportExport/Export/Export.php @@ -160,7 +160,8 @@ class Export { // sorted by segment name (due to slow queries when using ORDER BY and LIMIT), // we need to keep track of processed segments so that we do not create header // multiple times when switching from one segment to another and back. - if ((!count($processedSegments) || $lastSegment !== $currentSegment) && + if ( + (!count($processedSegments) || $lastSegment !== $currentSegment) && (!in_array($lastSegment, $processedSegments) || !in_array($currentSegment, $processedSegments)) ) { $this->writeXLSX( @@ -173,7 +174,8 @@ class Export { $lastSegment = ucwords($subscriber['segment_name']); // detect RTL language and set Excel to properly display the sheet $rTLRegex = '/\p{Arabic}|\p{Hebrew}/u'; - if (!$xLSXWriter->rtl && ( + if ( + !$xLSXWriter->rtl && ( preg_grep($rTLRegex, $subscriber) || preg_grep($rTLRegex, $this->formattedSubscriberFieldsWithList)) ) { diff --git a/lib/Subscribers/ImportExport/Import/Import.php b/lib/Subscribers/ImportExport/Import/Import.php index 0492a89aec..6e58fe1427 100644 --- a/lib/Subscribers/ImportExport/Import/Import.php +++ b/lib/Subscribers/ImportExport/Import/Import.php @@ -104,8 +104,9 @@ class Import { ]; // 1. data should contain all required fields // 2. column names should only contain alphanumeric & underscore characters - if (count(array_intersect_key(array_flip($requiredDataFields), $data)) !== count($requiredDataFields) || - preg_grep('/[^a-zA-Z0-9_]/', array_keys($data['columns'])) + if ( + count(array_intersect_key(array_flip($requiredDataFields), $data)) !== count($requiredDataFields) || + preg_grep('/[^a-zA-Z0-9_]/', array_keys($data['columns'])) ) { throw new \Exception(__('Missing or invalid import data.', 'mailpoet')); } @@ -268,7 +269,7 @@ class Import { // We attempt converting with both date formats foreach ($data as $index => $date) { - if (empty($date) ) { + if (empty($date)) { $dateTimeDates[$index] = $date; $customFormatDates[$index] = $date; continue; diff --git a/lib/Subscription/Captcha.php b/lib/Subscription/Captcha.php index 889991b3c4..2f4b65caf7 100644 --- a/lib/Subscription/Captcha.php +++ b/lib/Subscription/Captcha.php @@ -55,7 +55,8 @@ class Captcha { // Check limits per recipient if enabled if ($subscriberEmail) { $subscriber = Subscriber::where('email', $subscriberEmail)->findOne(); - if ($subscriber instanceof Subscriber + if ( + $subscriber instanceof Subscriber && $subscriber->countConfirmations >= $subscriptionCaptchaRecipientLimit ) { return true; diff --git a/lib/Subscription/Pages.php b/lib/Subscription/Pages.php index a8ecf0d410..57fe5365d1 100644 --- a/lib/Subscription/Pages.php +++ b/lib/Subscription/Pages.php @@ -205,7 +205,8 @@ class Pages { } public function unsubscribe() { - if (!$this->isPreview() + if ( + !$this->isPreview() && ($this->subscriber !== null) && ($this->subscriber->status !== Subscriber::STATUS_UNSUBSCRIBED) ) { diff --git a/lib/WP/DateTime.php b/lib/WP/DateTime.php index b8921f0e41..2d49a9b3e6 100644 --- a/lib/WP/DateTime.php +++ b/lib/WP/DateTime.php @@ -34,23 +34,23 @@ class DateTime { return $dateFormat; } - public function getCurrentTime($format=false) { + public function getCurrentTime($format = false) { if (empty($format)) $format = $this->getTimeFormat(); return $this->wp->currentTime($format); } - public function getCurrentDate($format=false) { + public function getCurrentDate($format = false) { if (empty($format)) $format = $this->getDateFormat(); return $this->getCurrentTime($format); } - public function formatTime($timestamp, $format=false) { + public function formatTime($timestamp, $format = false) { if (empty($format)) $format = $this->getTimeFormat(); return date($format, $timestamp); } - public function formatDate($timestamp, $format=false) { + public function formatDate($timestamp, $format = false) { if (empty($format)) $format = $this->getDateFormat(); return date($format, $timestamp); @@ -61,9 +61,9 @@ class DateTime { * formatted and mapped from DEFAULT_TIME_FORMAT to WordPress time strings. */ public function getTimeInterval( - $startTime='00:00:00', - $timeStep='+1 hour', - $totalSteps=24 + $startTime = '00:00:00', + $timeStep = '+1 hour', + $totalSteps = 24 ) { $steps = []; diff --git a/lib/WP/Functions.php b/lib/WP/Functions.php index 0f9b5aa2ff..4d3b24269a 100644 --- a/lib/WP/Functions.php +++ b/lib/WP/Functions.php @@ -559,7 +559,7 @@ class Functions { return wp_parse_url($url, $component); } - public function wpSpecialcharsDecode($string, $quoteStyle = ENT_NOQUOTES ) { + public function wpSpecialcharsDecode($string, $quoteStyle = ENT_NOQUOTES) { return wp_specialchars_decode($string, $quoteStyle); } diff --git a/mailpoet_initializer.php b/mailpoet_initializer.php index 057c73697f..7a4844cb0c 100644 --- a/mailpoet_initializer.php +++ b/mailpoet_initializer.php @@ -65,7 +65,8 @@ Env::init( $requirements = new RequirementsChecker(); $requirementsCheckResults = $requirements->checkAllRequirements(); -if (!$requirementsCheckResults[RequirementsChecker::TEST_PDO_EXTENSION] || +if ( + !$requirementsCheckResults[RequirementsChecker::TEST_PDO_EXTENSION] || !$requirementsCheckResults[RequirementsChecker::TEST_VENDOR_SOURCE] ) { return; diff --git a/tasks/code_sniffer/MailPoet/Sniffs/ControlStructures/FunctionDeclarationSniff.php b/tasks/code_sniffer/MailPoet/Sniffs/ControlStructures/FunctionDeclarationSniff.php index a648e72649..7a528da7fe 100644 --- a/tasks/code_sniffer/MailPoet/Sniffs/ControlStructures/FunctionDeclarationSniff.php +++ b/tasks/code_sniffer/MailPoet/Sniffs/ControlStructures/FunctionDeclarationSniff.php @@ -54,7 +54,8 @@ class FunctionDeclarationSniff implements Sniff { public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - if (isset($tokens[$stackPtr]['parenthesis_opener']) === false + if ( + isset($tokens[$stackPtr]['parenthesis_opener']) === false || isset($tokens[$stackPtr]['parenthesis_closer']) === false || $tokens[$stackPtr]['parenthesis_opener'] === null || $tokens[$stackPtr]['parenthesis_closer'] === null @@ -156,7 +157,8 @@ class FunctionDeclarationSniff implements Sniff { $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($opener - 1), $closeBracket, true); $next = $phpcsFile->findNext(T_WHITESPACE, ($opener + 1), null, true); - if ($tokens[$prev]['line'] < $tokens[$opener]['line'] + if ( + $tokens[$prev]['line'] < $tokens[$opener]['line'] && $tokens[$next]['line'] > $tokens[$opener]['line'] ) { // Clear the whole line. @@ -242,7 +244,8 @@ class FunctionDeclarationSniff implements Sniff { true ); - if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line'] + if ( + $tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line'] && $tokens[$prev]['line'] === $tokens[$closeBracket]['line'] ) { $error = 'The closing parenthesis of a multi-line ' . $type . ' declaration must be on a new line'; @@ -268,7 +271,8 @@ class FunctionDeclarationSniff implements Sniff { true ); - if ($tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line'] + if ( + $tokens[$closeBracket]['line'] !== $tokens[$tokens[$closeBracket]['parenthesis_opener']]['line'] && $tokens[$prev]['line'] === $tokens[$closeBracket]['line'] ) { $error = 'The closing parenthesis of a multi-line use declaration must be on a new line'; @@ -285,7 +289,8 @@ class FunctionDeclarationSniff implements Sniff { $lastLine = $tokens[$openBracket]['line']; for ($i = ($openBracket + 1); $i < $closeBracket; $i++) { if ($tokens[$i]['line'] !== $lastLine) { - if ($i === $tokens[$stackPtr]['parenthesis_closer'] + if ( + $i === $tokens[$stackPtr]['parenthesis_closer'] || ($tokens[$i]['code'] === T_WHITESPACE && (($i + 1) === $closeBracket || ($i + 1) === $tokens[$stackPtr]['parenthesis_closer'])) diff --git a/tasks/form-export/form-export.php b/tasks/form-export/form-export.php index 48200a4fa0..177bd0f351 100644 --- a/tasks/form-export/form-export.php +++ b/tasks/form-export/form-export.php @@ -177,7 +177,7 @@ function mailpoetReplaceAssetUrl(string $url): array { /** * @see https://stackoverflow.com/questions/24316347/how-to-format-var-export-to-php5-4-array-syntax */ -function mailpoetVarExport($var, $indent=" "): string { +function mailpoetVarExport($var, $indent = " "): string { switch (gettype($var)) { case 'string': return '\'' . addcslashes($var, "\\\$'\r\n\t\v\f") . '\''; diff --git a/tests/_support/DefaultsExtension.php b/tests/_support/DefaultsExtension.php index fbde0b75cd..16fec52a09 100644 --- a/tests/_support/DefaultsExtension.php +++ b/tests/_support/DefaultsExtension.php @@ -94,7 +94,7 @@ class DefaultsExtension extends Extension { delete_transient('_wc_activation_redirect'); // mark all WC cron actions complete - $tableName = ! empty($wpdb->actionscheduler_actions) ? $wpdb->actionscheduler_actions : $wpdb->prefix . 'actionscheduler_actions';// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + $tableName = !empty($wpdb->actionscheduler_actions) ? $wpdb->actionscheduler_actions : $wpdb->prefix . 'actionscheduler_actions';// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps $sql = "UPDATE {$tableName} SET status = 'complete'"; $wpdb->query($sql); } diff --git a/tests/acceptance/Newsletters/EditorProductsCest.php b/tests/acceptance/Newsletters/EditorProductsCest.php index c314a03224..e9d87b1e04 100644 --- a/tests/acceptance/Newsletters/EditorProductsCest.php +++ b/tests/acceptance/Newsletters/EditorProductsCest.php @@ -68,7 +68,7 @@ class EditorProductsCest { } // Add product image - $image = $i->cliToArray(['media', 'import', dirname(__DIR__) . '/../_data/600x400.jpg', '--title="A product picture"', '--porcelain']); + $image = $i->cliToArray(['media', 'import', dirname(__DIR__) . '/../_data/600x400.jpg', '--title="A product picture"', '--porcelain']); $imageUrlData = $i->cliToArray(['post', 'get', $image[0], '--field=guid']); $imageUrl = $imageUrlData[0]; diff --git a/tests/integration/API/JSON/v1/SegmentsTest.php b/tests/integration/API/JSON/v1/SegmentsTest.php index b26abea5e0..62bae20a77 100644 --- a/tests/integration/API/JSON/v1/SegmentsTest.php +++ b/tests/integration/API/JSON/v1/SegmentsTest.php @@ -250,7 +250,7 @@ class SegmentsTest extends \MailPoetTest { expect($subsribers)->count(0); } - private function createForm(string $formName, array $settings ) { + private function createForm(string $formName, array $settings) { $form = new FormEntity($formName); $form->setSettings($settings); $this->entityManager->persist($form); diff --git a/tests/integration/Cron/Workers/WooCommerceOrdersTest.php b/tests/integration/Cron/Workers/WooCommerceOrdersTest.php index 7dc349317b..2997a27335 100644 --- a/tests/integration/Cron/Workers/WooCommerceOrdersTest.php +++ b/tests/integration/Cron/Workers/WooCommerceOrdersTest.php @@ -123,7 +123,7 @@ class WooCommerceOrdersTest extends \MailPoetTest { $this->entityManager->clear(); $tasks = $this->scheduledTaskRepository->findBy(['type' => WooCommercePastOrders::TASK_TYPE]); expect($tasks)->count(1); - expect($tasks[0]->getStatus())->equals(null); // null means 'running' + expect($tasks[0]->getStatus())->equals(null); // null means 'running' } public function testItContinuesFromLastId() { diff --git a/tests/integration/Newsletter/RendererTest.php b/tests/integration/Newsletter/RendererTest.php index 35bfd0e31c..1d61e9d66a 100644 --- a/tests/integration/Newsletter/RendererTest.php +++ b/tests/integration/Newsletter/RendererTest.php @@ -663,7 +663,7 @@ class RendererTest extends \MailPoetTest { } public function makeAttachment($upload, $parentPostId = 0) { - if ( ! function_exists( 'wp_crop_image' ) ) { + if (!function_exists( 'wp_crop_image' )) { include( ABSPATH . 'wp-admin/includes/image.php' ); } diff --git a/tests/integration/Newsletter/Scheduler/PostNotificationTest.php b/tests/integration/Newsletter/Scheduler/PostNotificationTest.php index 35cbc20dfe..0ac4b73908 100644 --- a/tests/integration/Newsletter/Scheduler/PostNotificationTest.php +++ b/tests/integration/Newsletter/Scheduler/PostNotificationTest.php @@ -339,7 +339,7 @@ class PostNotificationTest extends \MailPoetTest { } private function createNewsletterOptions(NewsletterEntity $newsletter, array $options) { - foreach ($options as $name => $value) { + foreach ($options as $name => $value) { $newsletterOptionField = $this->newsletterOptionFieldsRepository->findOneBy([ 'name' => $name, ]); diff --git a/tests/integration/Subscribers/ImportExport/Import/ImportTest.php b/tests/integration/Subscribers/ImportExport/Import/ImportTest.php index 13f3a6de37..2ee5b70fca 100644 --- a/tests/integration/Subscribers/ImportExport/Import/ImportTest.php +++ b/tests/integration/Subscribers/ImportExport/Import/ImportTest.php @@ -309,7 +309,7 @@ class ImportTest extends \MailPoetTest { 'subscribed_ip' => '127.0.0.1', 'confirmed_at' => '2020-12-31 16:32:48', 'confirmed_ip' => '127.1.1.1', - ], [ + ], [ 'first_name' => 'Steve', 'last_name' => 'Sorrow', 'email' => 'sTeve.sorrow@exaMple.com',