Skip to content

Commit

Permalink
Merge pull request civicrm#44 from totten/master-nfc
Browse files Browse the repository at this point in the history
(NFC) Update to current code standard
  • Loading branch information
totten authored Jul 12, 2019
2 parents 7d65618 + 3630f8d commit 52bd266
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 66 deletions.
5 changes: 3 additions & 2 deletions src/API/MailingPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function preview($apiRequest) {
$flexMailer = new FlexMailer(array(
'is_preview' => TRUE,
'mailing' => $mailing,
'job' => $job, // HMM?
'job' => $job,
'attachments' => \CRM_Core_BAO_File::getEntityFile('civicrm_mailing',
$mailing->id),
));
Expand All @@ -70,7 +70,8 @@ public static function preview($apiRequest) {
'subject' => $task->getMailParam('Subject'),
'body_html' => $task->getMailParam('html'),
'body_text' => $task->getMailParam('text'),
'_rendered_by_' => 'flexmailer', // To support tests
// Flag our role in processing this - to support tests.
'_rendered_by_' => 'flexmailer',
));
}

Expand Down
1 change: 1 addition & 0 deletions src/ClickTracker/ClickTrackerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace Civi\FlexMailer\ClickTracker;

interface ClickTrackerInterface {

/**
* @param string $msg
* @param int $mailing_id
Expand Down
30 changes: 10 additions & 20 deletions src/FlexMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@
+--------------------------------------------------------------------+
*/
namespace Civi\FlexMailer;

use Civi\FlexMailer\Event\ComposeBatchEvent;
use Civi\FlexMailer\Event\RunEvent;
use Civi\FlexMailer\Event\SendBatchEvent;
use Civi\FlexMailer\Event\WalkBatchesEvent;
use Civi\FlexMailer\Listener\DefaultBatcher;
use Civi\FlexMailer\Listener\DefaultComposer;
use Civi\FlexMailer\Listener\DefaultSender;
use Civi\FlexMailer\Listener\HookAdapter;
use Civi\FlexMailer\Listener\OpenTracker;
use \Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Class FlexMailer
Expand Down Expand Up @@ -77,13 +73,6 @@
* to do. If your listener does the work required for the event, then
* you can disable the default listener by calling `$event->stopPropagation()`.
*
* @see CRM_Utils_Hook::container
* @see Civi\Core\Container
* @see DefaultBatcher
* @see DefaultComposer
* @see DefaultSender
* @see HookAdapter
* @see OpenTracker
* @link http://symfony.com/doc/current/components/event_dispatcher.html
*/
class FlexMailer {
Expand Down Expand Up @@ -125,7 +114,7 @@ public static function getEventTypes() {
public $context;

/**
* @var EventDispatcherInterface
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
private $dispatcher;

Expand Down Expand Up @@ -156,7 +145,7 @@ public static function createAndRun($job, $deprecatedMessageMailer, $deprecatedT
* - mailing: \CRM_Mailing_BAO_Mailing
* - job: \CRM_Mailing_BAO_MailingJob
* - attachments: array
* @param EventDispatcherInterface $dispatcher
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
*/
public function __construct($context = array(), EventDispatcherInterface $dispatcher = NULL) {
$this->context = $context;
Expand All @@ -169,7 +158,8 @@ public function __construct($context = array(), EventDispatcherInterface $dispat
* @throws \CRM_Core_Exception
*/
public function run() {
$flexMailer = $this; // PHP 5.3
// PHP 5.3
$flexMailer = $this;

if (count($this->validate()) > 0) {
throw new \CRM_Core_Exception("FlexMailer cannot execute: invalid context");
Expand Down Expand Up @@ -205,7 +195,7 @@ public function validate() {
}

/**
* @return RunEvent
* @return \Civi\FlexMailer\Event\RunEvent
*/
public function fireRun() {
$event = new RunEvent($this->context);
Expand All @@ -215,7 +205,7 @@ public function fireRun() {

/**
* @param callable $onVisitBatch
* @return WalkBatchesEvent
* @return \Civi\FlexMailer\Event\WalkBatchesEvent
*/
public function fireWalkBatches($onVisitBatch) {
$event = new WalkBatchesEvent($this->context, $onVisitBatch);
Expand All @@ -225,7 +215,7 @@ public function fireWalkBatches($onVisitBatch) {

/**
* @param array<FlexMailerTask> $tasks
* @return ComposeBatchEvent
* @return \Civi\FlexMailer\Event\ComposeBatchEvent
*/
public function fireComposeBatch($tasks) {
// This isn't a great place for this, but it ensures consistent cleanup.
Expand All @@ -241,7 +231,7 @@ public function fireComposeBatch($tasks) {

/**
* @param array<FlexMailerTask> $tasks
* @return SendBatchEvent
* @return \Civi\FlexMailer\Event\SendBatchEvent
*/
public function fireSendBatch($tasks) {
$event = new SendBatchEvent($this->context, $tasks);
Expand Down
6 changes: 4 additions & 2 deletions src/Listener/Abdicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public static function isFlexmailPreferred($mailing) {
*/
public function onRun(RunEvent $e) {
if (self::isFlexmailPreferred($e->getMailing())) {
return; // OK, we'll continue running.
// OK, we'll continue running.
return;
}

// Nope, we'll abdicate.
Expand All @@ -98,7 +99,8 @@ public function onRun(RunEvent $e) {
*/
public function onCheckSendable($e) {
if (self::isFlexmailPreferred($e->getMailing())) {
return; // OK, we'll continue running.
// OK, we'll continue running.
return;
}

$e->stopPropagation();
Expand Down
3 changes: 1 addition & 2 deletions src/Listener/Attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace Civi\FlexMailer\Listener;

use Civi\FlexMailer\Event\ComposeBatchEvent;
use Civi\FlexMailer\FlexMailerTask;

class Attachments extends BaseListener {

Expand All @@ -42,7 +41,7 @@ public function onCompose(ComposeBatchEvent $e) {
}

foreach ($e->getTasks() as $task) {
/** @var FlexMailerTask $task */
/** @var \Civi\FlexMailer\FlexMailerTask $task */
$task->setMailParam('attachments', $e->getAttachments());
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Listener/BasicHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace Civi\FlexMailer\Listener;

use Civi\FlexMailer\Event\ComposeBatchEvent;
use Civi\FlexMailer\FlexMailerTask;

class BasicHeaders extends BaseListener {

Expand All @@ -44,7 +43,7 @@ public function onCompose(ComposeBatchEvent $e) {
$mailing = $e->getMailing();

foreach ($e->getTasks() as $task) {
/** @var FlexMailerTask $task */
/** @var \Civi\FlexMailer\FlexMailerTask $task */

if ($task->hasContent()) {
continue;
Expand Down
3 changes: 1 addition & 2 deletions src/Listener/BounceTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace Civi\FlexMailer\Listener;

use Civi\FlexMailer\Event\ComposeBatchEvent;
use Civi\FlexMailer\FlexMailerTask;

class BounceTracker extends BaseListener {

Expand All @@ -44,7 +43,7 @@ public function onCompose(ComposeBatchEvent $e) {
$mailing = $e->getMailing();

foreach ($e->getTasks() as $task) {
/** @var FlexMailerTask $task */
/** @var \Civi\FlexMailer\FlexMailerTask $task */
list($verp) = $mailing->getVerpAndUrlsAndHeaders(
$e->getJob()->id, $task->getEventQueueId(), $task->getHash(),
$task->getAddress());
Expand Down
16 changes: 8 additions & 8 deletions src/Listener/DefaultComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function onCompose(ComposeBatchEvent $e) {

$hasContent = FALSE;
foreach ($e->getTasks() as $key => $task) {
/** @var FlexMailerTask $task */
/** @var \Civi\FlexMailer\FlexMailerTask $task */
if (!$task->hasContent()) {
$tp->addRow()->context($this->createTokenRowContext($e, $task));
$hasContent = TRUE;
Expand All @@ -95,8 +95,8 @@ public function onCompose(ComposeBatchEvent $e) {
$tp->evaluate();

foreach ($tp->getRows() as $row) {
/** @var TokenRow $row */
/** @var FlexMailerTask $task */
/** @var \Civi\Token\TokenRow $row */
/** @var \Civi\FlexMailer\FlexMailerTask $task */
$task = $row->context['flexMailerTask'];
$task->setMailParams(array_merge(
$this->createMailParams($e, $task, $row),
Expand Down Expand Up @@ -126,7 +126,7 @@ public function createTokenProcessorContext(ComposeBatchEvent $e) {
* Create contextual data for a message recipient.
*
* @param \Civi\FlexMailer\Event\ComposeBatchEvent $e
* @param FlexMailerTask $task
* @param \Civi\FlexMailer\FlexMailerTask $task
* @return array
* Contextual data describing the recipient.
* Typical values are `contactId` or `mailingJobId`.
Expand All @@ -151,8 +151,8 @@ public function createTokenRowContext(
* For a given task, prepare the mailing.
*
* @param \Civi\FlexMailer\Event\ComposeBatchEvent $e
* @param FlexMailerTask $task
* @param TokenRow $row
* @param \Civi\FlexMailer\FlexMailerTask $task
* @param \Civi\Token\TokenRow $row
* @return array
* A list of email parameters, such as "Subject", "text", and/or "html".
* @see \CRM_Utils_Hook::alterMailParams
Expand All @@ -172,7 +172,7 @@ public function createMailParams(
/**
* Generate the message templates for use with token-processor.
*
* @param ComposeBatchEvent $e
* @param \Civi\FlexMailer\Event\ComposeBatchEvent $e
* @return array
* A list of templates. Some combination of:
* - subject: string
Expand All @@ -195,7 +195,7 @@ public function createMessageTemplates(ComposeBatchEvent $e) {
* via `cv debug:event-dispatcher', but it produces the expected
* interactions among tokens and click-tracking.
*
* @param ComposeBatchEvent $e
* @param \Civi\FlexMailer\Event\ComposeBatchEvent $e
* @param array $templates
* @return array
* Updated templates.
Expand Down
10 changes: 2 additions & 8 deletions src/Listener/DefaultSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@
*/
namespace Civi\FlexMailer\Listener;

use Civi\FlexMailer\Event\RunEvent;
use Civi\FlexMailer\Event\SendBatchEvent;
use Civi\FlexMailer\Event\WalkBatchesEvent;
use Civi\FlexMailer\FlexMailerTask;
use Civi\Token\TokenProcessor;
use Civi\Token\TokenRow;
use Symfony\Component\EventDispatcher\Event;

class DefaultSender extends BaseListener {
const BULK_MAIL_INSERT_COUNT = 10;
Expand All @@ -56,7 +50,7 @@ public function onSend(SendBatchEvent $e) {
$retryBatch = FALSE;

foreach ($e->getTasks() as $key => $task) {
/** @var FlexMailerTask $task */
/** @var \Civi\FlexMailer\FlexMailerTask $task */
/** @var \Mail_mime $message */
if (!$task->hasContent()) {
continue;
Expand Down Expand Up @@ -206,7 +200,7 @@ protected function isTemporaryError($message) {

/**
* @param \CRM_Mailing_BAO_MailingJob $job
* @param FlexMailerTask $task
* @param \Civi\FlexMailer\FlexMailerTask $task
* @param string $errorMessage
*/
protected function recordBounce($job, $task, $errorMessage) {
Expand Down
3 changes: 1 addition & 2 deletions src/Listener/HookAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace Civi\FlexMailer\Listener;

use Civi\FlexMailer\Event\ComposeBatchEvent;
use Civi\FlexMailer\FlexMailerTask;

class HookAdapter extends BaseListener {

Expand All @@ -42,7 +41,7 @@ public function onCompose(ComposeBatchEvent $e) {
}

foreach ($e->getTasks() as $task) {
/** @var FlexMailerTask $task */
/** @var \Civi\FlexMailer\FlexMailerTask $task */
$mailParams = $task->getMailParams();
if ($mailParams) {
\CRM_Utils_Hook::alterMailParams($mailParams, 'flexmailer');
Expand Down
3 changes: 1 addition & 2 deletions src/Listener/OpenTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace Civi\FlexMailer\Listener;

use Civi\FlexMailer\Event\ComposeBatchEvent;
use Civi\FlexMailer\FlexMailerTask;

class OpenTracker extends BaseListener {

Expand All @@ -44,7 +43,7 @@ public function onCompose(ComposeBatchEvent $e) {
$config = \CRM_Core_Config::singleton();

foreach ($e->getTasks() as $task) {
/** @var FlexMailerTask $task */
/** @var \Civi\FlexMailer\FlexMailerTask $task */
$mailParams = $task->getMailParams();

if (!empty($mailParams) && !empty($mailParams['html'])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Listener/RequiredFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RequiredFields extends BaseListener {
* RequiredFields constructor.
* @param array $fields
*/
public function __construct( $fields) {
public function __construct($fields) {
$this->fields = $fields;
}

Expand Down
6 changes: 2 additions & 4 deletions src/Listener/SimpleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
*/
namespace Civi\FlexMailer\Listener;

use Civi\Core\Resolver;
use Civi\FlexMailer\Event\ComposeBatchEvent;
use Civi\FlexMailer\FlexMailerTask;

/**
* Class SimpleFilter
Expand Down Expand Up @@ -58,7 +56,7 @@ class SimpleFilter {
*/
public static function byValue(ComposeBatchEvent $e, $field, $filter) {
foreach ($e->getTasks() as $task) {
/** @var FlexMailerTask $task */
/** @var \Civi\FlexMailer\FlexMailerTask $task */
$value = $task->getMailParam($field);
if ($value !== NULL) {
$task->setMailParam($field, call_user_func($filter, $value, $task, $e));
Expand Down Expand Up @@ -86,7 +84,7 @@ public static function byColumn(ComposeBatchEvent $e, $field, $filter) {
$values = array();

foreach ($tasks as $k => $task) {
/** @var FlexMailerTask $task */
/** @var \Civi\FlexMailer\FlexMailerTask $task */
$value = $task->getMailParam($field);
if ($value !== NULL) {
$values[$k] = $value;
Expand Down
3 changes: 1 addition & 2 deletions src/Listener/TestPrefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace Civi\FlexMailer\Listener;

use Civi\FlexMailer\Event\ComposeBatchEvent;
use Civi\FlexMailer\FlexMailerTask;

class TestPrefix extends BaseListener {

Expand All @@ -42,7 +41,7 @@ public function onCompose(ComposeBatchEvent $e) {
}

foreach ($e->getTasks() as $task) {
/** @var FlexMailerTask $task */
/** @var \Civi\FlexMailer\FlexMailerTask $task */
$subject = $task->getMailParam('Subject');
$subject = ts('[CiviMail Draft]') . ' ' . $subject;
$task->setMailParam('Subject', $subject);
Expand Down
Loading

0 comments on commit 52bd266

Please sign in to comment.