Fixing PHPCS and PHPMD errors

This commit is contained in:
Dan Cryer 2014-05-08 21:43:06 +01:00
parent cf2d93f71a
commit 8c1c02a22f
2 changed files with 20 additions and 20 deletions

View file

@ -104,14 +104,14 @@ class SessionController extends \PHPCI\Controller
$key = md5(date('Y-m-d') . $user->getHash()); $key = md5(date('Y-m-d') . $user->getHash());
$url = PHPCI_URL; $url = PHPCI_URL;
$name = $user->getName(); $name = $user->getName();
$id = $user->getId(); $userId = $user->getId();
$message = <<<MSG $message = <<<MSG
Hi {$name}, Hi {$name},
You have received this email because you, or someone else, has requested a password reset for PHPCI. You have received this email because you, or someone else, has requested a password reset for PHPCI.
If this was you, please click the following link to reset your password: {$url}session/reset-password/{$id}/{$key} If this was you, please click the following link to reset your password: {$url}session/reset-password/{$userId}/{$key}
Otherwise, please ignore this email and no action will be taken. Otherwise, please ignore this email and no action will be taken.
@ -122,7 +122,7 @@ MSG;
$email = new Email(); $email = new Email();
$email->setTo($user->getEmail(), $user->getName()); $email->setEmailTo($user->getEmail(), $user->getName());
$email->setSubject('Password reset'); $email->setSubject('Password reset');
$email->setBody($message); $email->setBody($message);
$email->send(); $email->send();
@ -133,9 +133,9 @@ MSG;
return $this->view->render(); return $this->view->render();
} }
public function resetPassword($id, $key) public function resetPassword($userId, $key)
{ {
$user = $this->userStore->getById($id); $user = $this->userStore->getById($userId);
$userKey = md5(date('Y-m-d') . $user->getHash()); $userKey = md5(date('Y-m-d') . $user->getHash());
if (empty($user) || $key != $userKey) { if (empty($user) || $key != $userKey) {
@ -154,7 +154,7 @@ MSG;
die; die;
} }
$this->view->id = $id; $this->view->id = $userId;
$this->view->key = $key; $this->view->key = $key;
return $this->view->render(); return $this->view->render();

View file

@ -9,8 +9,8 @@ class Email
{ {
const DEFAULT_FROM = 'PHPCI <no-reply@phptesting.org>'; const DEFAULT_FROM = 'PHPCI <no-reply@phptesting.org>';
protected $to = array(); protected $emailTo = array();
protected $cc = array(); protected $emailCc = array();
protected $subject = 'Email from PHPCI'; protected $subject = 'Email from PHPCI';
protected $body = ''; protected $body = '';
protected $isHtml = false; protected $isHtml = false;
@ -21,16 +21,16 @@ class Email
$this->config = Config::getInstance(); $this->config = Config::getInstance();
} }
public function setTo($email, $name = null) public function setEmailTo($email, $name = null)
{ {
$this->to[$email] = $name; $this->emailTo[$email] = $name;
return $this; return $this;
} }
public function addCc($email, $name = null) public function addCc($email, $name = null)
{ {
$this->cc[$email] = $name; $this->emailCc[$email] = $name;
return $this; return $this;
} }
@ -77,20 +77,20 @@ class Email
$headers .= 'From: ' . $this->getFrom() . PHP_EOL; $headers .= 'From: ' . $this->getFrom() . PHP_EOL;
$to = array(); $emailTo = array();
foreach ($this->to as $email => $name) { foreach ($this->emailTo as $email => $name) {
$thisTo = $email; $thisTo = $email;
if (!is_null($name)) { if (!is_null($name)) {
$thisTo = '"' . $name . '" <' . $thisTo . '>'; $thisTo = '"' . $name . '" <' . $thisTo . '>';
} }
$to[] = $thisTo; $emailTo[] = $thisTo;
} }
$to = implode(', ', $to); $emailTo = implode(', ', $emailTo);
return mail($to, $this->subject, $this->body, $headers); return mail($emailTo, $this->subject, $this->body, $headers);
} }
protected function sendViaSwiftMailer() protected function sendViaSwiftMailer()
@ -100,15 +100,15 @@ class Email
$message = \Swift_Message::newInstance($this->subject) $message = \Swift_Message::newInstance($this->subject)
->setFrom($this->getFrom()) ->setFrom($this->getFrom())
->setTo($this->to) ->setTo($this->emailTo)
->setBody($this->body); ->setBody($this->body);
if ($this->isHtml) { if ($this->isHtml) {
$message->setContentType('text/html'); $message->setContentType('text/html');
} }
if (is_array($this->cc) && count($this->cc)) { if (is_array($this->emailCc) && count($this->emailCc)) {
$message->setCc($this->cc); $message->setCc($this->emailCc);
} }
return $mailer->send($message); return $mailer->send($message);
@ -124,4 +124,4 @@ class Email
return $email; return $email;
} }
} }