<commit_before><?php

namespace vakata\intl;

use \MessageFormatter as MF;

// https://www.sitepoint.com/localization-demystified-understanding-php-intl/

/**
 * Translator class using \MessageFormatter
 */
class Intl
{
    protected $code = 'en_US';
    protected $data = [];

    /**
     * Create a new instance
     * @method __construct
     * @param  string      $code the locale code to use, defaults to `en_US`
     */
    public function __construct(string $code = 'en_US')
    {
        $this->code = $code;
    }

    /**
     * Get the locale code
     * @method getCode
     * @param  bool|boolean $short if `true` return a short (`en`), otherwise a full code (`en_US`), defaults to `false`
     * @return string the code
     */
    public function getCode(bool $short = false) : string
    {
        return $short ? explode('_', $this->code)[0] : $this->code;
    }

    /**
     * Load all translations from an array
     * @method fromArray
     * @param  array     $data the translations
     * @return self
     */
    public function fromArray(array $data) : Intl
    {
        $this->data = array_replace_recursive($this->data, $data);
        return $this;
    }
    /**
     * Load all translations from a file - can be a JSON or INI file.
     * @method fromFile
     * @param  string   $location the file location
     * @param  string   $format   the file format (defaults to 'json')
     * @return self
     */
    public function fromFile(string $location, string $format = 'json') : Intl
    {
        if (!is_file($location)) {
            throw new IntlException('Invalid file');
        }
        $data = [];
        switch (strtolower($format)) {
            case 'ini':
                $data = parse_ini_file($location, true);
                break;
            case 'json':
                $data = @json_decode(file_get_contents($location), true);
                break;
            default:
                throw new IntlException('Invalid file format');
        }
        if (!$data) {
            throw new IntlException('Invalid file contents');
        }
        return $this->fromArray($data);
    }

    /**
     * Get all translations as an array
     * @method toArray
     * @return array  the translations
     */
    public function toArray() : array
    {
        return $this->data;
    }
    /**<commit_msg>added proper check<commit_after><?php

namespace vakata\intl;

use \MessageFormatter as MF;

// https://www.sitepoint.com/localization-demystified-understanding-php-intl/

/**
 * Translator class using \MessageFormatter
 */
class Intl
{
    protected $code = 'en_US';
    protected $data = [];

    /**
     * Create a new instance
     * @method __construct
     * @param  string      $code the locale code to use, defaults to `en_US`
     */
    public function __construct(string $code = 'en_US')
    {
        $this->code = $code;
    }

    /**
     * Get the locale code
     * @method getCode
     * @param  bool|boolean $short if `true` return a short (`en`), otherwise a full code (`en_US`), defaults to `false`
     * @return string the code
     */
    public function getCode(bool $short = false) : string
    {
        return $short ? explode('_', $this->code)[0] : $this->code;
    }

    /**
     * Load all translations from an array
     * @method fromArray
     * @param  array     $data the translations
     * @return self
     */
    public function fromArray(array $data) : Intl
    {
        $this->data = array_replace_recursive($this->data, $data);
        return $this;
    }
    /**
     * Load all translations from a file - can be a JSON or INI file.
     * @method fromFile
     * @param  string   $location the file location
     * @param  string   $format   the file format (defaults to 'json')
     * @return self
     */
    public function fromFile(string $location, string $format = 'json') : Intl
    {
        if (!is_file($location)) {
            throw new IntlException('Invalid file');
        }
        $data = [];
        switch (strtolower($format)) {
            case 'ini':
                $data = parse_ini_file($location, true);
                break;
            case 'json':
                $data = @json_decode(file_get_contents($location), true);
                break;
            default:
                throw new IntlException('Invalid file format');
        }
        if (!is_array($data)) {
            throw new IntlException('Invalid file contents');
        }
        return $this->fromArray($data);
    }

    /**
     * Get all translations as an array
     * @method toArray
     * @return array  the translations
     */
    public function toArray() : array
    {
        return $this->data;
    }
    /**
{'fraction_non_alphanumeric': 0.11968703742863185, 'fraction_numerical': 0.00042292239374074856, 'mean_word_length': 1.9767149150409062, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1245617', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1347, 'n_words': 402}