Permalink
Browse files

Fixed reviews

  • Loading branch information...
iwalz committed Jan 7, 2013
1 parent 36511a8 commit b8a6aad9d03d586bd9be9bda74d4d085c71ca8e5
@@ -10,11 +10,11 @@
namespace Zend\Stdlib\Hydrator;
-use Zend\Stdlib\Exception,
- Zend\Stdlib\Hydrator\Filter\FilterComposite,
- Zend\Stdlib\Hydrator\Filter\IsFilter,
- Zend\Stdlib\Hydrator\Filter\GetFilter,
- Zend\Stdlib\Hydrator\Filter\HasFilter;
+use Zend\Stdlib\Exception;
+use Zend\Stdlib\Hydrator\Filter\FilterComposite;
+use Zend\Stdlib\Hydrator\Filter\GetFilter;
+use Zend\Stdlib\Hydrator\Filter\HasFilter;
+use Zend\Stdlib\Hydrator\Filter\IsFilter;
/**
* @category Zend
@@ -9,6 +9,7 @@
*/
namespace Zend\Stdlib\Hydrator\Filter;
+use ArrayObject;
use Zend\Stdlib\Exception\InvalidArgumentException;
/**
@@ -19,18 +20,20 @@
class FilterComposite implements FilterInterface
{
/**
- * @var \ArrayObject
+ * @var ArrayObject
*/
protected $orFilter;
+
/**
- * @var \ArrayObject
+ * @var ArrayObject
*/
protected $andFilter;
/**
* Constant to add with "or" conditition
*/
const CONDITION_OR = 1;
+
/**
* Constant to add with "and" conditition
*/
@@ -46,8 +49,8 @@ public function __construct($orFilter = array(), $andFilter = array())
array_walk($orFilter,
function($value, $key) {
if(
- !is_callable($value) &&
- !$value instanceof FilterInterface
+ !is_callable($value)
+ && !$value instanceof FilterInterface
) {
throw new InvalidArgumentException(
'The value of ' . $key . ' should be either a callable or ' .
@@ -60,8 +63,8 @@ function($value, $key) {
array_walk($andFilter,
function($value, $key) {
if(
- !is_callable($value) &&
- !$value instanceof FilterInterface
+ !is_callable($value)
+ && !$value instanceof FilterInterface
) {
throw new InvalidArgumentException(
'The value of ' . $key . ' should be either a callable or ' .
@@ -71,8 +74,8 @@ function($value, $key) {
}
);
- $this->orFilter = new \ArrayObject($orFilter);
- $this->andFilter = new \ArrayObject($andFilter);
+ $this->orFilter = new ArrayObject($orFilter);
+ $this->andFilter = new ArrayObject($andFilter);
}
/**
@@ -95,30 +98,31 @@ function($value, $key) {
* @param callable|FilterInterface $filter
* @param int $condition Can be either FilterComposite::CONDITION_OR or FilterComposite::CONDITION_AND
* @throws InvalidArgumentException
+ * @return FilterComposite
*/
public function addFilter($name, $filter, $condition = self::CONDITION_OR)
{
- if (
- is_callable($filter) ||
- $filter instanceof FilterInterface
- ) {
- if ($condition === self::CONDITION_OR) {
- $this->orFilter[$name] = $filter;
- } elseif ($condition === self::CONDITION_AND) {
- $this->andFilter[$name] = $filter;
- }
- } else {
+ if ( !is_callable($filter) && !($filter instanceof FilterInterface) ) {
throw new InvalidArgumentException(
'The value of ' . $name . ' should be either a callable or ' .
'an instance of Zend\Stdlib\Hydrator\Filter\FilterInterface'
);
}
+
+ if ($condition === self::CONDITION_OR) {
+ $this->orFilter[$name] = $filter;
+ } elseif ($condition === self::CONDITION_AND) {
+ $this->andFilter[$name] = $filter;
+ }
+
+ return $this;
}
/**
* Remove a filter from the composition
*
* @param $name string Identifier for the filter
+ * @return FilterComposite
*/
public function removeFilter($name)
{
@@ -129,6 +133,8 @@ public function removeFilter($name)
if( isset($this->andFilter[$name])) {
unset($this->andFilter[$name]);
}
+
+ return $this;
}
/**
@@ -139,8 +145,7 @@ public function removeFilter($name)
*/
public function hasFilter($name)
{
- return
- isset($this->orFilter[$name]) || isset($this->andFilter[$name]);
+ return isset($this->orFilter[$name]) || isset($this->andFilter[$name]);
}
/**
@@ -170,6 +175,7 @@ public function filter($property)
$returnValue = true;
break;
}
+ continue;
} else {
if ( $filter->filter($property) === true) {
$returnValue = true;
@@ -184,6 +190,7 @@ public function filter($property)
if( $filter($property) === false) {
return false;
}
+ continue;
} else {
if( $filter->filter($property) === false) {
return false;
@@ -274,7 +274,7 @@ public function testHydratorClassMethodsManipulateFilter()
$this->assertFalse(isset($datas['hasBar'])); //method is hasBar
}
- public function testHydratorClassMethodsWithCostumFilter()
+ public function testHydratorClassMethodsWithCustomFilter()
{
$hydrator = new ClassMethods(false);
$datas = $hydrator->extract($this->classMethodsCamelCase);

0 comments on commit b8a6aad

Please sign in to comment.