public static function isValidNie(string $nie): bool
    {
        if (!preg_match(self::NIE_REGEX, $nie, $matches)) {
            return false;
        }

        $nieType = strpos(self::NIE_TYPES, $matches['type']);
        $nie = $nieType . $matches['number'];

        return self::DNINIE_CHECK_TABLE[$nie % 23] === $matches['check'];
    }