Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 72 changed files with 383 additions and 384 deletions.
27 changes: 19 additions & 8 deletions src/BaseName.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,30 @@ class BaseName extends AbstractFilter
/**
* Defined by Zend\Filter\FilterInterface
*
* Returns basename($value)
* Returns basename($value).
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)) {
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

return basename((string) $value);
Expand Down
25 changes: 18 additions & 7 deletions src/Digits.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,28 @@ class Digits extends AbstractFilter
*
* Returns the string $value, removing all but digit characters
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)) {
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

if (!StringUtils::hasPcreUnicodeSupport()) {
Expand Down
27 changes: 19 additions & 8 deletions src/HtmlEntities.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,29 @@ public function setDoubleQuote($doubleQuote)
* Returns the string $value, converting characters to their corresponding HTML entity
* equivalents where they exist
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @throws Exception\DomainException
* @return string
* @return string|mixed
* @throws Exception\DomainException on encoding mismatches
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)) {
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

$filtered = htmlentities((string) $value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote());
Expand Down
25 changes: 18 additions & 7 deletions src/Int.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,28 @@ class Int extends AbstractFilter
*
* Returns (int) $value
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return int
* @return int|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)) {
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

return (int) ((string) $value);
Expand Down
25 changes: 18 additions & 7 deletions src/RealPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,28 @@ public function getExists()
*
* Returns realpath($value)
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)) {
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

$path = (string) $value;
Expand Down
25 changes: 18 additions & 7 deletions src/StringToLower.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,28 @@ public function __construct($encodingOrOptions = null)
*
* Returns the string $value, converting characters to lowercase as necessary
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)) {
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

if ($this->options['encoding'] !== null) {
Expand Down
27 changes: 19 additions & 8 deletions src/StringToUpper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,30 @@ public function __construct($encodingOrOptions = null)
/**
* Defined by Zend\Filter\FilterInterface
*
* Returns the string $value, converting characters to lowercase as necessary
* Returns the string $value, converting characters to uppercase as necessary
*
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)) {
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

if ($this->options['encoding'] !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/StripNewlines.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class StripNewlines extends AbstractFilter
* @param string $value
* @return string
*/
public function filter ($value)
public function filter($value)
{
return str_replace(array("\n", "\r"), '', $value);
}
Expand Down
26 changes: 18 additions & 8 deletions src/StripTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,29 @@ public function setAttributesAllowed($attributesAllowed)
/**
* Defined by Zend\Filter\FilterInterface
*
* @todo improve docblock descriptions
* If the value provided is non-scalar, the value will remain unfiltered
* and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @todo improve docblock descriptions
* @param string $value
* @return string
* @return string|mixed
*/
public function filter($value)
{
if(!is_scalar($value)){
throw new Exception\InvalidArgumentException(sprintf(
'%s expects parameter to be scalar, "%s" given',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
if (null === $value) {
return null;
}

if (!is_scalar($value)) {
trigger_error(
sprintf(
'%s expects parameter to be scalar, "%s" given; cannot filter',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
),
E_USER_WARNING
);
return $value;
}

$value = (string) $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Word/CamelCaseToSeparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function filter($value)
$pattern = array('#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#', '#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#');
$replacement = array($this->separator . '\1', $this->separator . '\1');
} else {
$pattern = array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#');
$pattern = array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][a-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#');
$replacement = array('\1' . $this->separator . '\2', $this->separator . '\1');
}

Expand Down
31 changes: 19 additions & 12 deletions test/BaseNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Filter
*/

namespace ZendTest\Filter;

use Zend\Filter\BaseName as BaseNameFilter;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
* @package Zend_Filter
* @subpackage UnitTests
* @group Zend_Filter
*/
class BaseNameTest extends \PHPUnit_Framework_TestCase
Expand All @@ -38,21 +35,31 @@ public function testBasic()
}

/**
* Ensures that an InvalidArgumentException is raised if array is used
* Ensures that a warning is raised if array is used
*
* @return void
*/
public function testExceptionRaisedIfArrayUsed()
public function testWarningIsRaisedIfArrayUsed()
{
$filter = new BaseNameFilter();
$input = array('/path/to/filename', '/path/to/filename.ext');

try {
$filter->filter($input);
} catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
return;
}
ErrorHandler::start(E_USER_WARNING);
$filtered = $filter->filter($input);
$err = ErrorHandler::stop();

$this->assertEquals($input, $filtered);
$this->assertInstanceOf('ErrorException', $err);
$this->assertContains('cannot filter', $err->getMessage());
}

$this->fail('An expected InvalidArgumentException has not been raised.');
/**
* @return void
*/
public function testReturnsNullIfNullIsUsed()
{
$filter = new BaseNameFilter();
$filtered = $filter->filter(null);
$this->assertNull($filtered);
}
}
4 changes: 0 additions & 4 deletions test/BooleanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Filter
*/

namespace ZendTest\Filter;

use Zend\Filter\Boolean as BooleanFilter;

/**
* @category Zend
* @package Zend_Filter
* @subpackage UnitTests
* @group Zend_Filter
*/
class BooleanTest extends \PHPUnit_Framework_TestCase
Expand Down
Loading

0 comments on commit 163cb93

Please sign in to comment.