Code for cpf and a cnpj validation, use like Laminas validators.
$ composer require rsporteman/validator<?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