<commit_before><?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\base;

use Yii;
use DateTime;
use yii\helpers\HtmlPurifier;
use yii\helpers\Html;

/**
 * Formatter provides a set of commonly used data formatting methods.
 *
 * The formatting methods provided by Formatter are all named in the form of `asXyz()`.
 * The behavior of some of them may be configured via the properties of Formatter. For example,
 * by configuring [[dateFormat]], one may control how [[asDate()]] formats the value into a date string.
 *
 * @author <NAME> <<EMAIL>>
 * @since 2.0
 */
class Formatter extends Component
{
	/**
	 * @var string the default format string to be used to format a date using PHP date() function.
	 */
	public $dateFormat = 'Y/m/d';
	/**
	 * @var string the default format string to be used to format a time using PHP date() function.
	 */
	public $timeFormat = 'h:i:s A';
	/**
	 * @var string the default format string to be used to format a date and time using PHP date() function.
	 */
	public $datetimeFormat = 'Y/m/d h:i:s A';
	/**
	 * @var string the text to be displayed when formatting a null. Defaults to '(not set)'.
	 */
	public $nullDisplay;
	/**
	 * @var array the text to be displayed when formatting a boolean value. The first element corresponds
	 * to the text display for false, the second element for true. Defaults to `array('No', 'Yes')`.
	 */
	public $booleanFormat;
	/**
	 * @var string the character displayed as the decimal point when formatting a number.
	 * If not set, "." will be used.
	 */
	public $decimalSeparator;
	/**
	 * @var string the character displayed as the thousands separator character when formatting a number.
	 * If not set, "," will be used.
	 */
	public $thousandSeparator;


	/**
	 * Initializes the component.
	 */
	public function init()
	{
		if (empty($this->booleanFormat)) {
			$this->booleanFormat = array(Yii::t('yii', 'No'), Yii::t('yii', 'Yes'));
		}
		if ($this->nullDisplay === null) {
			$this->nullDisplay = Yii::t('yii', '(not set)');
		}
	}

	/**
	 * Formats the value as is without any formatting.
	 * This method simply returns back the parameter without any format.
	 * @param mixed $value the value to be formatted
	 * @return string the formatted result
	 */
	public function asRaw($value)
	{
		if ($value === null) {
			return $this->nullDisplay;
		}
		return $value;
	}

	/**
	 * Formats the value as an HTML-encoded plain text.
	 * @param mixed $value the value to be formatted
	 * @return string the formatted result
	 */
	public function asText($value)
	{<commit_msg>Added Formatter::format().<commit_after><?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\base;

use Yii;
use DateTime;
use yii\helpers\HtmlPurifier;
use yii\helpers\Html;

/**
 * Formatter provides a set of commonly used data formatting methods.
 *
 * The formatting methods provided by Formatter are all named in the form of `asXyz()`.
 * The behavior of some of them may be configured via the properties of Formatter. For example,
 * by configuring [[dateFormat]], one may control how [[asDate()]] formats the value into a date string.
 *
 * @author <NAME> <<EMAIL>>
 * @since 2.0
 */
class Formatter extends Component
{
	/**
	 * @var string the default format string to be used to format a date using PHP date() function.
	 */
	public $dateFormat = 'Y/m/d';
	/**
	 * @var string the default format string to be used to format a time using PHP date() function.
	 */
	public $timeFormat = 'h:i:s A';
	/**
	 * @var string the default format string to be used to format a date and time using PHP date() function.
	 */
	public $datetimeFormat = 'Y/m/d h:i:s A';
	/**
	 * @var string the text to be displayed when formatting a null. Defaults to '(not set)'.
	 */
	public $nullDisplay;
	/**
	 * @var array the text to be displayed when formatting a boolean value. The first element corresponds
	 * to the text display for false, the second element for true. Defaults to `array('No', 'Yes')`.
	 */
	public $booleanFormat;
	/**
	 * @var string the character displayed as the decimal point when formatting a number.
	 * If not set, "." will be used.
	 */
	public $decimalSeparator;
	/**
	 * @var string the character displayed as the thousands separator character when formatting a number.
	 * If not set, "," will be used.
	 */
	public $thousandSeparator;


	/**
	 * Initializes the component.
	 */
	public function init()
	{
		if (empty($this->booleanFormat)) {
			$this->booleanFormat = array(Yii::t('yii', 'No'), Yii::t('yii', 'Yes'));
		}
		if ($this->nullDisplay === null) {
			$this->nullDisplay = Yii::t('yii', '(not set)');
		}
	}

	/**
	 * Formats the value based on the give type.
	 * This method will call one of the "as" methods available in this class to do the formatting.
	 * For type "xyz", the method "asXyz" will be used. For example, if the type is "html",
	 * then [[asHtml()]] will be used. Type names are case insensitive.
	 * @param mixed $value the value to be formatted
	 * @param string $type the type of the value, e.g., "html", "text".
	 * @return string the formatting result
	 * @throws InvalidParamException if the type is not supported by this class.
	 */
	public function format($value, $type)
	{
		$method = 'as' . $type;
		if (method_exists($this, $method)) {
			return $this->$method($value);
		} else {
			throw new InvalidParamException("Unknown type: $type");
		}
	}

	/**
	 * Formats the value as is without any formatting.
	 * This method simply returns back the parameter without any format.
	 * @param mixed $value the value to be formatted
	 * @return string the formatted result
	 */
	public function asRaw($value)
	{
		if ($value === null) {
			return $this->nullDisplay;
		}
		return $value;
	}

	/**
	 * Formats the value as an HTML-encoded plain text.
	 * @param mixed $value the value to be formatted
	 * @return string the formatted result
	 */
	public function asText($value)
	{
{'fraction_non_alphanumeric': 0.12372992461488037, 'fraction_numerical': 0.0019665683382497543, 'mean_word_length': 3.451495258935084, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3375649', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1782, 'n_words': 763}