for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace BrenoRoosevelt\Validation\Rules\Brazilian;
use Attribute;
use BrenoRoosevelt\Validation\AbstractRule;
use Throwable;
#[Attribute(Attribute::TARGET_PROPERTY)]
class FoneComDDD extends AbstractRule
{
const MASK = '/^\([0-9]{2}\)[0-9]{4,5}-[0-9]{4}$/';
const UNMASK = '/^\[0-9]{10,11}$/';
public function __construct(private bool $mask = true, ?string $message = 'Telefone inválido')
parent::__construct($message);
}
public function isValid($input, array $context = []): bool
if (!is_string($input) || !is_numeric($input)) {
return false;
$pattern = $this->mask ? self::MASK : self::UNMASK;
return preg_match($pattern, (string) $input) === 1;