Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00%
0 / 1
0.00%
0 / 1
CRAP
0.00%
0 / 9
NullableDbInteger
0.00%
0 / 1
0.00%
0 / 1
12
0.00%
0 / 9
 filter($value)
0.00%
0 / 1
12
0.00%
0 / 9
<?php
/**
* Dewdrop
*
* @link https://github.com/DeltaSystems/dewdrop
* @copyright Delta Systems (http://deltasys.com)
* @license https://github.com/DeltaSystems/dewdrop/LICENSE
*/
namespace Dewdrop\Filter;
use Zend\Filter\AbstractFilter;
/**
* This filter is intended to assist with DB integer fields that are allowed to
* be nullable.
*/
class NullableDbInteger extends AbstractFilter
{
/**
* For empty strings (think HTTP requests, where everything is a string), or
* actual nulls, we return null. If not, we return the value cast to an int.
*
* @param mixed $value
* @return int|null
*/
public function filter($value)
{
if (null === $value || '' === $value) {
$out = null;
} else {
$out = (int) $value;
}
return $out;
}
}