rsporteman / validator
provides a set of commonly needed validators
dev-main
2022-04-27 21:36 UTC
Requires
- php: ^7.3 || ~8.0.0 || ~8.1.0
- laminas/laminas-validator: ^2.17
Requires (Dev)
- phpunit/php-code-coverage: ^9.2
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-04-28 02:21:59 UTC
README
rsporteman/validator
Introduction
Code for cpf and a cnpj validation, use like Laminas validators.
Installation using Composer
$ composer require rsporteman/validator
Example
<?php use rsporteman\Validator\Cpf; use rsporteman\Validator\Cnpj; $post['cpf'] = '313.734.531/68'; // it is valid $validatorCpf = new Cpf(); $isValidCpf = $validatorCpf->isValid($post['cpf']); //output: true $post['cnpj'] = '1364679'; //it is invalid $validatorCnpj = new Cnpj(); $isValidCnpj = $validatorCnpj->isValid($post['cnpj']); //output: false //Get Error messages //return array empty because cpf is valid $errorCnpjMsg = $validatorCpf->getMessages(); //output: [] //return array with errors messages because cnpj is invalid $errorCpfMsg = $validatorCnpj->getMessages(); var_dump($errorCpfMsg);// output: ['cnpjLength' => string 'The input contains an invalid amount of characters']
Ambience and Tests
#up docker container docker-compose up #enter on container docker exec -it rsporteman-validator bash #install dependencies composer install #run tests vendor/bin/phpunit #generate coverage, files will be generate inside .phpunit.cache composer test:coverage composer test:coverage-html