From a2ab29fe8301a896d29cf842bcbeef25d11ce8ae Mon Sep 17 00:00:00 2001
From: Nejc <nejc.koporec@agiledrop.com>
Date: Fri, 2 Mar 2018 09:24:54 +0100
Subject: [PATCH] Fix coding standards

---
 smtp.install                                |   3 +-
 smtp.module                                 |  19 ++-
 src/Form/SMTPConfigForm.php                 |  26 ++--
 src/Plugin/Exception/PHPMailerException.php |  10 +-
 src/Plugin/Mail/SMTPMailSystem.php          | 197 +++++++++++++---------------
 src/Tests/SmtpTest.php                      |   9 +-
 6 files changed, 136 insertions(+), 128 deletions(-)

diff --git a/smtp.install b/smtp.install
index 389f250..d21f030 100644
--- a/smtp.install
+++ b/smtp.install
@@ -16,8 +16,7 @@ function smtp_uninstall() {
   $default_system_mail = 'php_mail';
   $mail_config = $config->getEditable('system.mail');
   $default_interface = (!$smtp_config->get('prev_mail_system')) ? $smtp_config->get('prev_mail_system') : $default_system_mail;
-  $mail_config ->set('interface.default', $default_interface)
-    ->save();
+  $mail_config->set('interface.default', $default_interface)->save();
 
   // Cleaning garbage.
   $smtp_config->delete();
diff --git a/smtp.module b/smtp.module
index 2e69241..0dc950c 100644
--- a/smtp.module
+++ b/smtp.module
@@ -50,30 +50,36 @@ function smtp_mail($key, &$message, $params) {
 }
 
 /**
- * Implementation of hook_queue_info().
+ * Implements hook_queue_info().
  */
 function smtp_queue_info() {
   $queues['smtp_send_queue'] = array(
     'worker callback' => 'smtp_send_queue_runner',
     'cron' => array(
-      'time' => 60, // This is the max run time per cron run in seconds.
+      'time' => 60,
     ),
   );
   return $queues;
 }
 
 /**
- * smtp_send_queue queuer.
+ * Smtp_send_queue queuer function.
  */
 function smtp_send_queue($mailerObj) {
   $queue = Drupal::queue('smtp_send_queue');
   $queue->createItem($mailerObj);
 }
 
+/**
+ * Smtp_send_queue queue runner function.
+ */
 function smtp_send_queue_runner($variables) {
   _smtp_mailer_send($variables);
 }
 
+/**
+ * Smtp mailer send function.
+ */
 function _smtp_mailer_send($variables) {
   $mailer = $variables['mailer'];
   $to = $variables['to'];
@@ -86,7 +92,12 @@ function _smtp_mailer_send($variables) {
 
   // Try to send e-mail. If it fails, set watchdog entry.
   if (!$mailer->Send()) {
-    $logger->error('Error sending e-mail from @from to @to: @error_message', array('@from' => $from, '@to' => $to, '@error_message' => $mailer->ErrorInfo));
+    $logger->error('Error sending e-mail from @from to @to: @error_message',
+      array(
+        '@from' => $from,
+        '@to' => $to,
+        '@error_message' => $mailer->ErrorInfo,
+      ));
     return FALSE;
   }
 
diff --git a/src/Form/SMTPConfigForm.php b/src/Form/SMTPConfigForm.php
index c8c2f4c..2631a03 100644
--- a/src/Form/SMTPConfigForm.php
+++ b/src/Form/SMTPConfigForm.php
@@ -4,7 +4,6 @@ namespace Drupal\smtp\Form;
 
 use Drupal\Core\Form\ConfigFormBase;
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\smtp\Plugin\Mail\SMTPMailSystem;
 
 /**
  * Implements the SMTP admin settings form.
@@ -12,14 +11,14 @@ use Drupal\smtp\Plugin\Mail\SMTPMailSystem;
 class SMTPConfigForm extends ConfigFormBase {
 
   /**
-   * {@inheritdoc}.
+   * Set the form id.
    */
-  public function getFormID() {
+  public function getFormId() {
     return 'smtp_admin_settings';
   }
 
   /**
-   * {@inheritdoc}.
+   * Build config form.
    */
   public function buildForm(array $form, FormStateInterface $form_state) {
     $config = $this->configFactory->get('smtp.settings');
@@ -61,7 +60,7 @@ class SMTPConfigForm extends ConfigFormBase {
       '#type' => 'textfield',
       '#title' => t('SMTP backup server'),
       '#default_value' => $config->get('smtp_hostbackup'),
-      '#description' => t('The address of your outgoing SMTP backup server. If the primary server can\'t be found this one will be tried. This is optional.'),
+      '#description' => t("The address of your outgoing SMTP backup server. If the primary server can\'t be found this one will be tried. This is optional."),
       '#disabled' => $this->isOverridden('smtp_hostbackup'),
     );
     $form['server']['smtp_port'] = array(
@@ -114,7 +113,7 @@ class SMTPConfigForm extends ConfigFormBase {
       '#type' => 'password',
       '#title' => t('Password'),
       '#default_value' => $config->get('smtp_password'),
-      '#description' => t('SMTP password. If you have already entered your password before, you should leave this field blank, unless you want to change the stored password. Please note that this password will be stored as plain-text inside Drupal\'s core configuration variables.'),
+      '#description' => t("SMTP password. If you have already entered your password before, you should leave this field blank, unless you want to change the stored password. Please note that this password will be stored as plain-text inside Drupal\'s core configuration variables."),
       '#disabled' => $this->isOverridden('smtp_password'),
     );
 
@@ -193,9 +192,10 @@ class SMTPConfigForm extends ConfigFormBase {
    * Check if config variable is overridden by the settings.php.
    *
    * @param string $name
-   *  STMP settings key.
+   *    STMP settings key.
    *
    * @return bool
+   *    Returns bool result.
    */
   protected function isOverridden($name) {
     $original = $this->configFactory->getEditable('smtp.settings')->get($name);
@@ -225,12 +225,15 @@ class SMTPConfigForm extends ConfigFormBase {
       $form_state->setErrorByName('smtp_test_address', $this->t('The provided test e-mail address is not valid.'));
     }
 
-    // If username is set empty, we must set both username/password empty as well.
+    // If username is set empty,
+    // we must set both username/password empty as well.
     if (empty($values['smtp_username'])) {
       $values['smtp_password'] = '';
     }
-    // A little hack. When form is presented, the password is not shown (Drupal way of doing).
-    // So, if user submits the form without changing the password, we must prevent it from being reset.
+    // A little hack. When form is presented,
+    // the password is not shown (Drupal way of doing).
+    // So, if user submits the form without changing the password,
+    // we must prevent it from being reset.
     elseif (empty($values['smtp_password'])) {
       $form_state->unsetValue('smtp_password');
     }
@@ -292,7 +295,8 @@ class SMTPConfigForm extends ConfigFormBase {
       $params['subject'] = t('Drupal SMTP test e-mail');
       $params['body'] = array(t('If you receive this message it means your site is capable of using SMTP to send e-mail.'));
       $account = \Drupal::currentUser();
-      // If module is off, send the test message with SMTP by temporarily overriding.
+      // If module is off,
+      // send the test message with SMTP by temporarily overriding.
       if (!$config->get('smtp_on')) {
         $original = $mail_config->get('interface');
         $mail_system = 'SMTPMailSystem';
diff --git a/src/Plugin/Exception/PHPMailerException.php b/src/Plugin/Exception/PHPMailerException.php
index 0ba1185..59ec963 100644
--- a/src/Plugin/Exception/PHPMailerException.php
+++ b/src/Plugin/Exception/PHPMailerException.php
@@ -2,9 +2,17 @@
 
 namespace Drupal\smtp\Plugin\Exception;
 
-class phpmailerException extends \Exception {
+/**
+ * Class PHPMailerException.
+ */
+class PHPMailerException extends \Exception {
+
+  /**
+   * Returns error message.
+   */
   public function errorMessage() {
     $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
     return $errorMsg;
   }
+
 }
diff --git a/src/Plugin/Mail/SMTPMailSystem.php b/src/Plugin/Mail/SMTPMailSystem.php
index 6d5302a..5f8f37a 100644
--- a/src/Plugin/Mail/SMTPMailSystem.php
+++ b/src/Plugin/Mail/SMTPMailSystem.php
@@ -13,7 +13,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Modify the drupal mail system to use smtp when sending emails.
- * Include the option to choose between plain text or HTML
+ *
+ * Include the option to choose between plain text or HTML.
  *
  * @Mail(
  *   id = "SMTPMailSystem",
@@ -26,17 +27,23 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
   protected $smtpConfig;
 
   /**
-   * Logger
+   * Logger.
+   *
    * @var LoggerInterface
    */
   protected $logger;
 
   /**
    * Constructs a SMPTMailSystem object.
+   *
    * @param array $configuration
-   * @param $plugin_id
+   *    Array of configurations.
+   * @param int $plugin_id
+   *    Plugin id.
    * @param $plugin_definition
-   * @param \Psr\Log\LoggerInterface $logger
+   *    Plugin definition.
+   * @param LoggerChannelFactoryInterface $logger
+   *    LoggerInterface.
    */
   public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelFactoryInterface $logger) {
     $this->smtpConfig = \Drupal::config('smtp.settings');
@@ -63,13 +70,12 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
   }
 
   /**
-   * Concatenate and wrap the e-mail body for either
-   * plain-text or HTML emails.
+   * Concatenate and wrap the e-mail body for either plain-text or HTML emails.
    *
-   * @param $message
+   * @param array $message
    *   A message array, as described in hook_mail_alter().
    *
-   * @return
+   * @return array
    *   The formatted $message.
    */
   public function format(array $message) {
@@ -87,13 +93,6 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
 
   /**
    * Send the e-mail message.
-   *
-   * @see drupal_mail()
-   *
-   * @param $message
-   *   A message array, as described in hook_mail_alter().
-   * @return
-   *   TRUE if the mail was successfully accepted, otherwise FALSE.
    */
   public function mail(array $message) {
     $to = $message['to'];
@@ -119,10 +118,10 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
 
     // Set SMTP module email from.
     if (\Drupal::service('email.validator')->isValid($this->smtpConfig->get('smtp_from'))) {
-        $from = $this->smtpConfig->get('smtp_from');
-        $headers['Sender'] = $from;
-        $headers['Return-Path'] = $from;
-        $headers['Reply-To'] = $from;
+      $from = $this->smtpConfig->get('smtp_from');
+      $headers['Sender'] = $from;
+      $headers['Return-Path'] = $from;
+      $headers['Reply-To'] = $from;
     }
 
     // Defines the From value to what we expect.
@@ -143,30 +142,31 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
     // Create the list of 'To:' recipients.
     $torecipients = explode(',', $to);
     foreach ($torecipients as $torecipient) {
-      $to_comp = $this->_get_components($torecipient);
+      $to_comp = $this->getComponents($torecipient);
       $mailer->AddAddress($to_comp['email'], $to_comp['name']);
     }
 
     // Parse the headers of the message and set the PHPMailer object's settings
     // accordingly.
     foreach ($headers as $key => $value) {
-      //watchdog('error', 'Key: ' . $key . ' Value: ' . $value);
+      // watchdog('error', 'Key: ' . $key . ' Value: ' . $value).
       switch (strtolower($key)) {
         case 'from':
           if ($from == NULL or $from == '') {
             // If a from value was already given, then set based on header.
             // Should be the most common situation since drupal_mail moves the
             // from to headers.
-            $from           = $value;
-            $mailer->From     = $value;
-            // then from can be out of sync with from_name !
+            $from = $value;
+            $mailer->From = $value;
+            // Then from can be out of sync with from_name !
             $mailer->FromName = '';
             $mailer->Sender   = $value;
           }
           break;
+
         case 'content-type':
-          // Parse several values on the Content-type header, storing them in an array like
-          // key=value -> $vars['key']='value'
+          // Parse several values on the Content-type header,
+          // storing them in an array like key=value -> $vars['key']='value'.
           $vars = explode(';', $value);
           foreach ($vars as $i => $var) {
             if ($cut = strpos($var, '=')) {
@@ -176,10 +176,12 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
               $vars[$new_key] = $new_var;
             }
           }
-          // Set the charset based on the provided value, otherwise set it to UTF-8 (which is Drupals internal default).
+          // Set the charset based on the provided value,
+          // otherwise set it to UTF-8 (which is Drupals internal default).
           $mailer->CharSet = isset($vars['charset']) ? $vars['charset'] : 'UTF-8';
-          // If $vars is empty then set an empty value at index 0 to avoid a PHP warning in the next statement
-          $vars[0] = isset($vars[0])?$vars[0]:'';
+          // If $vars is empty then set an empty value at index 0
+          // to avoid a PHP warning in the next statement.
+          $vars[0] = isset($vars[0]) ? $vars[0] : '';
 
           switch ($vars[0]) {
             case 'text/plain':
@@ -187,32 +189,37 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
               $mailer->IsHTML(FALSE);
               $content_type = 'text/plain';
               break;
+
             case 'text/html':
               // The message includes only an HTML part.
               $mailer->IsHTML(TRUE);
               $content_type = 'text/html';
               break;
+
             case 'multipart/related':
               // Get the boundary ID from the Content-Type header.
-              $boundary = $this->_get_substring($value, 'boundary', '"', '"');
+              $boundary = $this->getSubString($value, 'boundary', '"', '"');
 
               // The message includes an HTML part w/inline attachments.
               $mailer->ContentType = $content_type = 'multipart/related; boundary="' . $boundary . '"';
-            break;
+              break;
+
             case 'multipart/alternative':
               // The message includes both a plain text and an HTML part.
               $mailer->ContentType = $content_type = 'multipart/alternative';
 
               // Get the boundary ID from the Content-Type header.
-              $boundary = $this->_get_substring($value, 'boundary', '"', '"');
-            break;
+              $boundary = $this->getSubString($value, 'boundary', '"', '"');
+              break;
+
             case 'multipart/mixed':
               // The message includes one or more attachments.
               $mailer->ContentType = $content_type = 'multipart/mixed';
 
               // Get the boundary ID from the Content-Type header.
-              $boundary = $this->_get_substring($value, 'boundary', '"', '"');
-            break;
+              $boundary = $this->getSubString($value, 'boundary', '"', '"');
+              break;
+
             default:
               // Everything else is unsuppored by PHPMailer.
               drupal_set_message(t('The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', array('%header' => "Content-Type: $value")), 'error');
@@ -227,7 +234,7 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
         case 'reply-to':
           // Only add a "reply-to" if it's not the same as "return-path".
           if ($value != $headers['Return-Path']) {
-            $reply_to_comp = $this->_get_components($value);
+            $reply_to_comp = $this->getComponents($value);
             $mailer->AddReplyTo($reply_to_comp['email'], $reply_to_comp['name']);
           }
           break;
@@ -252,7 +259,7 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
         case 'cc':
           $ccrecipients = explode(',', $value);
           foreach ($ccrecipients as $ccrecipient) {
-            $cc_comp = $this->_get_components($ccrecipient);
+            $cc_comp = $this->getComponents($ccrecipient);
             $mailer->AddCC($cc_comp['email'], $cc_comp['name']);
           }
           break;
@@ -260,7 +267,7 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
         case 'bcc':
           $bccrecipients = explode(',', $value);
           foreach ($bccrecipients as $bccrecipient) {
-            $bcc_comp = $this->_get_components($bccrecipient);
+            $bcc_comp = $this->getComponents($bccrecipient);
             $mailer->AddBCC($bcc_comp['email'], $bcc_comp['name']);
           }
           break;
@@ -271,7 +278,7 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
       }
     }
 
-    /**
+    /*
      * TODO
      * Need to figure out the following.
      *
@@ -298,19 +305,19 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
 
       case 'multipart/alternative':
         // Split the body based on the boundary ID.
-        $body_parts = $this->_boundary_split($body, $boundary);
+        $body_parts = $this->boundarySplit($body, $boundary);
         foreach ($body_parts as $body_part) {
           // If plain/text within the body part, add it to $mailer->AltBody.
           if (strpos($body_part, 'text/plain')) {
             // Clean up the text.
-            $body_part = trim($this->_remove_headers(trim($body_part)));
+            $body_part = trim($this->removeHeaders(trim($body_part)));
             // Include it as part of the mail object.
             $mailer->AltBody = $body_part;
           }
           // If plain/html within the body part, add it to $mailer->Body.
           elseif (strpos($body_part, 'text/html')) {
             // Clean up the text.
-            $body_part = trim($this->_remove_headers(trim($body_part)));
+            $body_part = trim($this->removeHeaders(trim($body_part)));
             // Include it as part of the mail object.
             $mailer->Body = $body_part;
           }
@@ -319,9 +326,10 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
 
       case 'multipart/mixed':
         // Split the body based on the boundary ID.
-        $body_parts = $this->_boundary_split($body, $boundary);
+        $body_parts = $this->boundarySplit($body, $boundary);
 
-        // Determine if there is an HTML part for when adding the plain text part.
+        // Determine if there is an HTML part
+        // for when adding the plain text part.
         $text_plain = FALSE;
         $text_html  = FALSE;
         foreach ($body_parts as $body_part) {
@@ -339,17 +347,17 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
           // also a text/html part ot not.
           if (strpos($body_part, 'multipart/alternative')) {
             // Get boundary ID from the Content-Type header.
-            $boundary2 = $this->_get_substring($body_part, 'boundary', '"', '"');
+            $boundary2 = $this->getSubString($body_part, 'boundary', '"', '"');
             // Clean up the text.
-            $body_part = trim($this->_remove_headers(trim($body_part)));
+            $body_part = trim($this->removeHeaders(trim($body_part)));
             // Split the body based on the boundary ID.
-            $body_parts2 = $this->_boundary_split($body_part, $boundary2);
+            $body_parts2 = $this->boundarySplit($body_part, $boundary2);
 
             foreach ($body_parts2 as $body_part2) {
               // If plain/text within the body part, add it to $mailer->AltBody.
               if (strpos($body_part2, 'text/plain')) {
                 // Clean up the text.
-                $body_part2 = trim($this->_remove_headers(trim($body_part2)));
+                $body_part2 = trim($this->removeHeaders(trim($body_part2)));
                 // Include it as part of the mail object.
                 $mailer->AltBody = $body_part2;
                 $mailer->ContentType = 'multipart/mixed';
@@ -357,9 +365,9 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
               // If plain/html within the body part, add it to $mailer->Body.
               elseif (strpos($body_part2, 'text/html')) {
                 // Get the encoding.
-                $body_part2_encoding = $this->_get_substring($body_part2, 'Content-Transfer-Encoding', ' ', "\n");
+                $body_part2_encoding = $this->getSubString($body_part2, 'Content-Transfer-Encoding', ' ', "\n");
                 // Clean up the text.
-                $body_part2 = trim($this->_remove_headers(trim($body_part2)));
+                $body_part2 = trim($this->removeHeaders(trim($body_part2)));
                 // Check whether the encoding is base64, and if so, decode it.
                 if (Unicode::strtolower($body_part2_encoding) == 'base64') {
                   // Include it as part of the mail object.
@@ -378,7 +386,7 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
           // If text/plain within the body part, add it to $mailer->Body.
           elseif (strpos($body_part, 'text/plain')) {
             // Clean up the text.
-            $body_part = trim($this->_remove_headers(trim($body_part)));
+            $body_part = trim($this->removeHeaders(trim($body_part)));
 
             if ($text_html) {
               $mailer->AltBody = $body_part;
@@ -394,7 +402,7 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
           // If text/html within the body part, add it to $mailer->Body.
           elseif (strpos($body_part, 'text/html')) {
             // Clean up the text.
-            $body_part = trim($this->_remove_headers(trim($body_part)));
+            $body_part = trim($this->removeHeaders(trim($body_part)));
             // Include it as part of the mail object.
             $mailer->Body = $body_part;
             $mailer->IsHTML(TRUE);
@@ -402,10 +410,10 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
           }
           // Add the attachment.
           elseif (strpos($body_part, 'Content-Disposition: attachment;') && !isset($message['params']['attachments'])) {
-            $file_path     = $this->_get_substring($body_part, 'filename=', '"', '"');
-            $file_name     = $this->_get_substring($body_part, ' name=', '"', '"');
-            $file_encoding = $this->_get_substring($body_part, 'Content-Transfer-Encoding', ' ', "\n");
-            $file_type     = $this->_get_substring($body_part, 'Content-Type', ' ', ';');
+            $file_path     = $this->getSubString($body_part, 'filename=', '"', '"');
+            $file_name     = $this->getSubString($body_part, ' name=', '"', '"');
+            $file_encoding = $this->getSubString($body_part, 'Content-Transfer-Encoding', ' ', "\n");
+            $file_type     = $this->getSubString($body_part, 'Content-Type', ' ', ';');
 
             if (file_exists($file_path)) {
               if (!$mailer->AddAttachment($file_path, $file_name, $file_encoding, $file_type)) {
@@ -414,7 +422,7 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
             }
             else {
               // Clean up the text.
-              $body_part = trim($this->_remove_headers(trim($body_part)));
+              $body_part = trim($this->removeHeaders(trim($body_part)));
 
               if (Unicode::strtolower($file_encoding) == 'base64') {
                 $attachment = base64_decode($body_part);
@@ -510,15 +518,8 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
    *
    * Swiped from Mail::MimeDecode, with modifications based on Drupal's coding
    * standards and this bug report: http://pear.php.net/bugs/bug.php?id=6495
-   *
-   * @param input
-   *   A string containing the body text to parse.
-   * @param boundary
-   *   A string with the boundary string to parse on.
-   * @return
-   *   An array containing the resulting mime parts
    */
-  protected function _boundary_split($input, $boundary) {
+  protected function boundarySplit($input, $boundary) {
     $parts       = array();
     $bs_possible = substr($boundary, 2, -2);
     $bs_check    = '\"' . $bs_possible . '\"';
@@ -536,68 +537,57 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
     }
 
     return $parts;
-  }  //  End of _smtp_boundary_split().
+  }  //  End of boundarySplit().
 
   /**
    * Strips the headers from the body part.
-   *
-   * @param input
-   *   A string containing the body part to strip.
-   * @return
-   *   A string with the stripped body part.
    */
-  protected function _remove_headers($input) {
+  protected function removeHeaders($input) {
     $part_array = explode("\n", $input);
 
-    // will strip these headers according to RFC2045
-    $headers_to_strip = array( 'Content-Type', 'Content-Transfer-Encoding', 'Content-ID', 'Content-Disposition');
+    // Will strip these headers according to RFC2045.
+    $headers_to_strip = array(
+      'Content-Type',
+      'Content-Transfer-Encoding',
+      'Content-ID',
+      'Content-Disposition',
+    );
     $pattern = '/^(' . implode('|', $headers_to_strip) . '):/';
 
     while (count($part_array) > 0) {
 
-      // ignore trailing spaces/newlines
+      // Ignore trailing spaces/newlines.
       $line = rtrim($part_array[0]);
 
-      // if the line starts with a known header string
+      // If the line starts with a known header string.
       if (preg_match($pattern, $line)) {
         $line = rtrim(array_shift($part_array));
-        // remove line containing matched header.
-
-        // if line ends in a ';' and the next line starts with four spaces, it's a continuation
-        // of the header split onto the next line. Continue removing lines while we have this condition.
+        // Remove line containing matched header.
+        // If line ends in a ';' and the next line starts with four spaces,
+        // it's a continuation.
+        // of the header split onto the next line.
+        // Continue removing lines while we have this condition.
         while (substr($line, -1) == ';' && count($part_array) > 0 && substr($part_array[0], 0, 4) == '    ') {
           $line = rtrim(array_shift($part_array));
         }
       }
       else {
-        // no match header, must be past headers; stop searching.
+        // No match header, must be past headers; stop searching.
         break;
       }
     }
 
     $output = implode("\n", $part_array);
     return $output;
-  }  //  End of _smtp_remove_headers().
+  }  //  End of removeHeaders().
 
   /**
    * Returns a string that is contained within another string.
    *
    * Returns the string from within $source that is some where after $target
    * and is between $beginning_character and $ending_character.
-   *
-   * @param $source
-   *   A string containing the text to look through.
-   * @param $target
-   *   A string containing the text in $source to start looking from.
-   * @param $beginning_character
-   *   A string containing the character just before the sought after text.
-   * @param $ending_character
-   *   A string containing the character just after the sought after text.
-   * @return
-   *   A string with the text found between the $beginning_character and the
-   *   $ending_character.
    */
-  protected function _get_substring($source, $target, $beginning_character, $ending_character) {
+  protected function getSubString($source, $target, $beginning_character, $ending_character) {
     $search_start     = strpos($source, $target) + 1;
     $first_character  = strpos($source, $beginning_character, $search_start) + 1;
     $second_character = strpos($source, $ending_character, $first_character) + 1;
@@ -609,18 +599,12 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
     }
 
     return $substring;
-  }  //  End of _smtp_get_substring().
+  }  //  End of getSubString().
 
   /**
    * Returns an array of name and email address from a string.
-   *
-   * @param $input
-   *  A string that contains different possible combinations of names and
-   *  email address.
-   * @return
-   *  An array containing a name and an email address.
    */
-  protected function _get_components($input) {
+  protected function getComponents($input) {
     $components = array(
       'input' => $input,
       'name' => '',
@@ -635,9 +619,9 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
     }
 
     // Check if $input has one of the following formats, extract what we can:
-    //  some name <address@example.com>
-    //  "another name" <address@example.com>
-    //  <address@example.com>
+    // some name <address@example.com>
+    // "another name" <address@example.com>
+    // <address@example.com>.
     if (preg_match('/^"?([^"\t\n]*)"?\s*<([^>\t\n]*)>$/', trim($input), $matches)) {
       $components['name'] = trim($matches[1]);
       $components['email'] = trim($matches[2]);
@@ -645,4 +629,5 @@ class SMTPMailSystem implements MailInterface, ContainerFactoryPluginInterface {
 
     return $components;
   }
+
 }
diff --git a/src/Tests/SmtpTest.php b/src/Tests/SmtpTest.php
index 0a5edb2..4fceadd 100644
--- a/src/Tests/SmtpTest.php
+++ b/src/Tests/SmtpTest.php
@@ -5,31 +5,32 @@ namespace Drupal\smtp\Tests;
 use Drupal\simpletest\WebTestBase;
 
 /**
- * Tests the Drupal 8 SMTP module functionality
+ * Tests the Drupal 8 SMTP module functionality.
  *
  * @group SMTP
  */
 class SmtpTest extends WebTestBase {
 
   /**
-   * Modules to install
+   * Modules to install.
    *
    * @var array
    */
   public static $modules = array('smtp');
 
   /**
-   * Perform any initial set up tasks that run before every test method
+   * Perform any initial set up tasks that run before every test method.
    */
   public function setUp() {
     parent::setUp();
   }
 
   /**
-   * Tests that the '/' path returns 200
+   * Tests that the '/' path returns 200.
    */
   public function testSiteIsLive() {
     $this->drupalGet('');
     $this->assertResponse(200);
   }
+
 }
-- 
2.15.1

