Skip to content

Commit cf426dc

Browse files
author
ndm2
committed
Cleanup - The aftermath
Cleaning up the mess I made (and some other stuff). Also made sure that unsetting the email pattern, respectively validating using `filter_var()` works properly.
1 parent 72770e5 commit cf426dc

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

src/Network/Email/Email.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,13 @@ public function headerCharset($charset = null) {
579579
/**
580580
* EmailPattern setter/getter
581581
*
582-
* @param string $regex for email address validation
582+
* @param string|bool|null $regex The pattern to use for email address validation,
583+
* null to unset the pattern and make use of filter_var() instead, false or
584+
* nothing to return the current value
583585
* @return string|$this
584586
*/
585-
public function emailPattern($regex = null) {
586-
if ($regex === null) {
587+
public function emailPattern($regex = false) {
588+
if ($regex === false) {
587589
return $this->_emailPattern;
588590
}
589591
$this->_emailPattern = $regex;
@@ -629,10 +631,11 @@ protected function _setEmail($varName, $email, $name) {
629631
* @throws \InvalidArgumentException If email address does not validate
630632
*/
631633
protected function _validateEmail($email) {
632-
if ($this->_emailPattern === null && filter_var($email, FILTER_VALIDATE_EMAIL)) {
633-
return;
634-
}
635-
if (preg_match($this->_emailPattern, $email)) {
634+
if ($this->_emailPattern === null) {
635+
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
636+
return;
637+
}
638+
} elseif (preg_match($this->_emailPattern, $email)) {
636639
return;
637640
}
638641
throw new InvalidArgumentException(sprintf('Invalid email: "%s"', $email));

src/Network/Session/CacheSession.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ public function destroy($id) {
104104
* Helper function called on gc for cache sessions.
105105
*
106106
* @param string $maxlifetime Sessions that have not updated for the last maxlifetime seconds will be removed.
107-
* @return void
107+
* @return bool True (irrespective of whether or not the garbage is being successfully collected)
108108
*/
109109
public function gc($maxlifetime) {
110110
Cache::gc($this->_options['config'], time() - $maxlifetime);
111+
return true;
111112
}
112113

113114
}

src/View/JsonView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function render($view = null, $layout = null) {
138138
/**
139139
* Serialize view vars
140140
*
141-
* @param array|string $serialize The viewVars that need to be serialized
141+
* @param array|string $serialize The name(s) of the view variable(s) that need(s) to be serialized
142142
* @return string The serialized data
143143
*/
144144
protected function _serialize($serialize) {

src/View/XmlView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function render($view = null, $layout = null) {
122122
/**
123123
* Serialize view vars.
124124
*
125-
* @param array|string $serialize The viewVars that need to be serialized.
125+
* @param array|string $serialize The name(s) of the view variable(s) that need(s) to be serialized
126126
* @return string The serialized data
127127
*/
128128
protected function _serialize($serialize) {

tests/TestCase/Network/Email/EmailTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,25 @@ public function testCustomEmailValidation() {
333333
), $this->CakeEmail->to());
334334
}
335335

336+
/**
337+
* Tests that it is possible to unset the email pattern and make use of filter_var() instead.
338+
*
339+
* @return void
340+
*
341+
* @expectedException \InvalidArgumentException
342+
* @expectedExceptionMessage Invalid email: "fail.@example.com"
343+
*/
344+
public function testUnsetEmailPattern() {
345+
$email = new Email();
346+
$this->assertSame(Email::EMAIL_PATTERN, $email->emailPattern());
347+
348+
$email->emailPattern(null);
349+
$this->assertNull($email->emailPattern());
350+
351+
$email->to('pass@example.com');
352+
$email->to('fail.@example.com');
353+
}
354+
336355
/**
337356
* testFormatAddress method
338357
*

0 commit comments

Comments
 (0)