clean / assure
Data correction and validation
Installs: 21 657
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: 4.2.*
README
This package extends global namespace with assure method than can be used to correct and validate mixed data types.
Mainly used to support duck typing of primitive types in function parameters to simplify interface usage eg.:
class Foo { public function filterById($id) { assure($name, ['arrayOfIntegers']); // after assure we can trust that name is an array of integers // otherwise exception will be raised } } $foo = new Foo(); $foo->filterById(1) $foo->filterById('1') $foo->filterById(['1', 2])
Installation
via Composer
Example of Usage
// if value is not integer and cannot be transform to integer assure with throw exception // correct values: '1', 1, 1.3 // invalid values: 'a', NULL, false, array() assure($value, 'integer'); // if not integer OR string with integers separated by commas assure will throw exception // correct values: '1', '1,2,3,4,5'; // invalid values: 'a', '1,2,a,4,b'; assure($value, ['integer', 'commaSeparatedIntegers']);