Fixing PHPCS and PHPMD errors

This commit is contained in:
Dan Cryer 2014-05-08 21:43:06 +01:00
parent 6b0d210344
commit 45b7dec478
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());
$url = PHPCI_URL;
$name = $user->getName();
$id = $user->getId();
$userId = $user->getId();
$message = <<<MSG
Hi {$name},
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.
@ -122,7 +122,7 @@ MSG;
$email = new Email();
$email->setTo($user->getEmail(), $user->getName());
$email->setEmailTo($user->getEmail(), $user->getName());
$email->setSubject('Password reset');
$email->setBody($message);
$email->send();
@ -133,9 +133,9 @@ MSG;
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());
if (empty($user) || $key != $userKey) {
@ -154,7 +154,7 @@ MSG;
die;
}
$this->view->id = $id;
$this->view->id = $userId;
$this->view->key = $key;
return $this->view->render();

View file

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