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;
use BrenoRoosevelt\Validation\AbstractValidation;
use Throwable;
abstract class Document extends AbstractValidation
{
public function __construct(private bool $mask = true, ?string $message = 'Invalid document')
parent::__construct($message);
}
public function evaluate($input, array $context = []): bool
try {
$document = (string) $input;
} catch (Throwable) {
catch (\Throwable)
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.
return
die
exit
function fx() { try { doSomething(); return true; } catch (\Exception $e) { return false; } return false; }
In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.
return false
return false;
if ($this->mask) {
if (!$this->isValidMask($document)) {
$document = $this->unmaskNumber($document);
$document = $this->adjustZeroPadding($document);
return $this->isValidDocument($document);
public function isValidMask(string $input): bool
return preg_match($this->maskPattern(), $input) === 1;
public function unmaskNumber(string $input): string
return preg_replace('/\D/', '', $input);
public function adjustZeroPadding(string $input): string
return $input;
public function validateNumbersWithCorrectLength(string $unmaskedInput): bool
$numericWithSize = '/^\d{' . $this->unmaskedLength() . '}$/';
return preg_match($numericWithSize, $unmaskedInput) === 1;
abstract public function isValidDocument(string $input): bool;
abstract public function maskPattern(): string;
abstract public function unmaskedLength(): int;
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.