<commit_before><?php

namespace Contact\Utility;

use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberUtil;

class Phone
{

    protected static $formats = [
        'international' => PhoneNumberFormat::INTERNATIONAL,
        'national' => PhoneNumberFormat::NATIONAL,
        'uri' => PhoneNumberFormat::RFC3966,
        'short' => PhoneNumberFormat::E164,
    ];

    /**
     * format phone number :
     *
     * @param  string $text    phone number
     * @param  array  $options [ 'country' => 'FR', 'format' => 'international', ]
     *      'country' => 'FR',
     *      'format' => 'international',
     *  ]
     * @return formatted phone number
     */
    public static function format($text, $options = [])
    {
        if ((string)$text !== '') {
            $options = array_merge(
                [
                'country' => 'FR',
                'format' => 'international',
                ],
                $options
            );

            $LibPhone = PhoneNumberUtil::getInstance();

            $phone = $LibPhone->parse((string)$text, $options['country']);
            $text = $LibPhone->format($phone, self::$formats[$options['format']]);
        }

        return $text;
    }<commit_msg>only format viable phone numbers<commit_after><?php

namespace Contact\Utility;

use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberUtil;

class Phone
{

    protected static $formats = [
        'international' => PhoneNumberFormat::INTERNATIONAL,
        'national' => PhoneNumberFormat::NATIONAL,
        'uri' => PhoneNumberFormat::RFC3966,
        'short' => PhoneNumberFormat::E164,
    ];

    /**
     * format phone number :
     *
     * @param  string $text    phone number
     * @param  array  $options [ 'country' => 'FR', 'format' => 'international', ]
     *      'country' => 'FR',
     *      'format' => 'international',
     *  ]
     * @return formatted phone number
     */
    public static function format($text, $options = [])
    {
        if ($text !== '') {
            $options = array_merge(
                [
                'country' => 'FR',
                'format' => 'international',
                ],
                $options
            );

            $LibPhone = PhoneNumberUtil::getInstance();

            if ($LibPhone->isViablePhoneNumber($text)) {
                $phone = $LibPhone->parse($text, $options['country']);
                $text = $LibPhone->format($phone, self::$formats[$options['format']]);
            } else {
                $text = '';
            }
        }

        return $text;
    }
{'fraction_non_alphanumeric': 0.1475661172863166, 'fraction_numerical': 0.005366040628593331, 'mean_word_length': 1.9391891891891893, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2187078', 'n_tokens_mistral': 748, 'n_tokens_neox': 707, 'n_words': 142}