Skip to content

Commit

Permalink
general code style fixes (PHPMailer#1241)
Browse files Browse the repository at this point in the history
* use instanceof instead of is_a

is_a is deprecated since 5.0.0 in favour of instanceof operator
http://php.net/is_a

this allows using class aliases instead of strings

* do not assign null to class properties

that is default behaviour of php engine

* use stripos instead of stristr

* use faster $array[]= $value instead of array_push

* add SuspiciousAssignmentsInspection noinspection to shut up ide

* use call_user_func with defined args

* avoid overwriting $error parameter

* apply more yoda-style
  • Loading branch information
glensc authored and Synchro committed Nov 17, 2017
1 parent 2f874e6 commit 0d5cb18
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/OAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class OAuth
*
* @var AbstractProvider
*/
protected $provider = null;
protected $provider;

/**
* The current OAuth access token.
*
* @var AccessToken
*/
protected $oauthToken = null;
protected $oauthToken;

/**
* The user's email address, usually used as the login ID
Expand Down
43 changes: 22 additions & 21 deletions src/PHPMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PHPMailer
*
* @var int
*/
public $Priority = null;
public $Priority;

/**
* The character set of the message.
Expand Down Expand Up @@ -314,7 +314,7 @@ class PHPMailer
*
* @var OAuth
*/
protected $oauth = null;
protected $oauth;

/**
* The SMTP server timeout in seconds.
Expand Down Expand Up @@ -504,7 +504,7 @@ class PHPMailer
*
* @var SMTP
*/
protected $smtp = null;
protected $smtp;

/**
* The array of 'to' names and addresses.
Expand Down Expand Up @@ -786,7 +786,7 @@ protected function edebug($str)
return;
}
//Is this a PSR-3 logger?
if (is_a($this->Debugoutput, 'Psr\Log\LoggerInterface')) {
if ($this->Debugoutput instanceof \Psr\Log\LoggerInterface) {
$this->Debugoutput->debug($str);

return;
Expand Down Expand Up @@ -866,7 +866,7 @@ public function isSendmail()
{
$ini_sendmail_path = ini_get('sendmail_path');

if (!stristr($ini_sendmail_path, 'sendmail')) {
if (false === stripos($ini_sendmail_path, 'sendmail')) {
$this->Sendmail = '/usr/sbin/sendmail';
} else {
$this->Sendmail = $ini_sendmail_path;
Expand All @@ -881,7 +881,7 @@ public function isQmail()
{
$ini_sendmail_path = ini_get('sendmail_path');

if (!stristr($ini_sendmail_path, 'qmail')) {
if (false === stripos($ini_sendmail_path, 'qmail')) {
$this->Sendmail = '/var/qmail/bin/qmail-inject';
} else {
$this->Sendmail = $ini_sendmail_path;
Expand Down Expand Up @@ -1039,7 +1039,7 @@ protected function addAnAddress($kind, $address, $name = '')
}
if ('Reply-To' != $kind) {
if (!array_key_exists(strtolower($address), $this->all_recipients)) {
array_push($this->$kind, [$address, $name]);
$this->{$kind}[] = [$address, $name];
$this->all_recipients[strtolower($address)] = true;

return true;
Expand Down Expand Up @@ -1890,7 +1890,7 @@ public function smtpConnect($options = null)
// * we have openssl extension
// * we are not already using SSL
// * the server offers STARTTLS
if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
if ($this->SMTPAutoTLS and $sslext and 'ssl' != $secure and $this->smtp->getServerExt('STARTTLS')) {
$tls = true;
}
if ($tls) {
Expand Down Expand Up @@ -2089,7 +2089,7 @@ public function wrapText($message, $length, $qp_mode = false)
}
// If utf-8 encoding is used, we will need to make sure we don't
// split multibyte characters when we wrap
$is_utf8 = (strtolower($this->CharSet) == 'utf-8');
$is_utf8 = 'utf-8' == strtolower($this->CharSet);
$lelen = strlen(static::$LE);
$crlflen = strlen(static::$LE);

Expand All @@ -2115,9 +2115,9 @@ public function wrapText($message, $length, $qp_mode = false)
$len = $space_left;
if ($is_utf8) {
$len = $this->utf8CharBoundary($word, $len);
} elseif (substr($word, $len - 1, 1) == '=') {
} elseif ('=' == substr($word, $len - 1, 1)) {
--$len;
} elseif (substr($word, $len - 2, 1) == '=') {
} elseif ('=' == substr($word, $len - 2, 1)) {
$len -= 2;
}
$part = substr($word, 0, $len);
Expand All @@ -2136,9 +2136,9 @@ public function wrapText($message, $length, $qp_mode = false)
$len = $length;
if ($is_utf8) {
$len = $this->utf8CharBoundary($word, $len);
} elseif (substr($word, $len - 1, 1) == '=') {
} elseif ('=' == substr($word, $len - 1, 1)) {
--$len;
} elseif (substr($word, $len - 2, 1) == '=') {
} elseif ('=' == substr($word, $len - 2, 1)) {
$len -= 2;
}
$part = substr($word, 0, $len);
Expand All @@ -2157,7 +2157,7 @@ public function wrapText($message, $length, $qp_mode = false)
}
$buf .= $word;

if (strlen($buf) > $length and $buf_o != '') {
if (strlen($buf) > $length and '' != $buf_o) {
$message .= $buf_o . $soft_break;
$buf = $word;
}
Expand Down Expand Up @@ -3202,6 +3202,7 @@ public function encodeQ($str, $position = 'text')
default:
// RFC 2047 section 5.1
// Replace every high ascii, control, =, ? and _ characters
/** @noinspection SuspiciousAssignmentsInspection */
$pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
break;
}
Expand Down Expand Up @@ -3381,7 +3382,7 @@ protected function cidExists($cid)
public function inlineImageExists()
{
foreach ($this->attachment as $attachment) {
if ($attachment[6] == 'inline') {
if ('inline' == $attachment[6]) {
return true;
}
}
Expand All @@ -3397,7 +3398,7 @@ public function inlineImageExists()
public function attachmentExists()
{
foreach ($this->attachment as $attachment) {
if ($attachment[6] == 'attachment') {
if ('attachment' == $attachment[6]) {
return true;
}
}
Expand Down Expand Up @@ -3691,7 +3692,7 @@ public function msgHTML($message, $basedir = '', $advanced = false)
{
preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
if (array_key_exists(2, $images)) {
if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
if (strlen($basedir) > 1 && '/' != substr($basedir, -1)) {
// Ensure $basedir has a trailing /
$basedir .= '/';
}
Expand Down Expand Up @@ -3726,7 +3727,7 @@ public function msgHTML($message, $basedir = '', $advanced = false)
// Ignore URLs containing parent dir traversal (..)
and (strpos($url, '..') === false)
// Do not change urls that are already inline images
and substr($url, 0, 4) !== 'cid:'
and 0 !== strpos($url, 'cid:')
// Do not change absolute URLs, including anonymous protocol
and !preg_match('#^[a-z][a-z0-9+.-]*:?//#i', $url)
) {
Expand All @@ -3736,10 +3737,10 @@ public function msgHTML($message, $basedir = '', $advanced = false)
$directory = '';
}
$cid = hash('sha256', $url) . '@phpmailer.0'; // RFC2392 S 2
if (strlen($basedir) > 1 and substr($basedir, -1) != '/') {
if (strlen($basedir) > 1 and '/' != substr($basedir, -1)) {
$basedir .= '/';
}
if (strlen($directory) > 1 and substr($directory, -1) != '/') {
if (strlen($directory) > 1 and '/' != substr($directory, -1)) {
$directory .= '/';
}
if ($this->addEmbeddedImage(
Expand Down Expand Up @@ -4378,7 +4379,7 @@ public function getAllRecipientAddresses()
protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from, $extra)
{
if (!empty($this->action_function) and is_callable($this->action_function)) {
call_user_func_array($this->action_function, [$isSent, $to, $cc, $bcc, $subject, $body, $from, $extra]);
call_user_func($this->action_function, $isSent, $to, $cc, $bcc, $subject, $body, $from, $extra);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/POP3.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ protected function setError($error)
$this->errors[] = $error;
if ($this->do_debug >= 1) {
echo '<pre>';
foreach ($this->errors as $error) {
print_r($error);
foreach ($this->errors as $e) {
print_r($e);
}
echo '</pre>';
}
Expand Down
2 changes: 1 addition & 1 deletion src/SMTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ protected function edebug($str, $level = 0)
return;
}
//Is this a PSR-3 logger?
if (is_a($this->Debugoutput, 'Psr\Log\LoggerInterface')) {
if ($this->Debugoutput instanceof \Psr\Log\LoggerInterface) {
$this->Debugoutput->debug($str);

return;
Expand Down

0 comments on commit 0d5cb18

Please sign in to comment.