<commit_before><?php

/* vim: set noexpandtab tabstop=4 shiftwidth=4 foldmethod=marker: */

require_once 'Swat/SwatFloatEntry.php';

/**
 * A percentage entry widget
 *
 * @package    Swat
 * @copyright  2007 silverorange
 * @lisence    http://www.gnu.org/copyleft/lesser.html LGPL Lisence 2.1
 */
class SwatPercentageEntry extends SwatFloatEntry
{
	// {{{ protected function getDisplayValue()

	/**
	 * Returns a value for this widget
	 *
	 * The method returns a value to be displayed in the widget
	 *
	 * @return string the final percentage value
	 */
	protected function getDisplayValue($value)
	{
		if (is_numeric($value)) {
			$value = $value * 100;
			$value = parent::getDisplayValue($value);
			return $value.'%';
		} else {
			return parent::getDisplayValue($value);
		}
	}

	// }}}
	// {{{ protected function getNumericValue()

	/**
	 * Gets the float value of this widget
	 *
	 * This allows each widget to parse raw values and turn them into floats
	 *
	 * @param string $value the raw value to use to get the numeric value.
	 *
	 * @return mixed the numeric value of this entry widget or null if no
	 *							no numeric value is available.
	 */
	protected function getNumericValue($value)
	{
		$value = trim($value);
		$value = str_replace('%', '', $value);
		$value = parent::getNumericValue($value);
		if ($value !== null)
			$value = $value / 100;

		return $value;
	}
<commit_msg>coding conventions: for the most part, a single return point results in fewer bugs.<commit_after><?php

/* vim: set noexpandtab tabstop=4 shiftwidth=4 foldmethod=marker: */

require_once 'Swat/SwatFloatEntry.php';

/**
 * A percentage entry widget
 *
 * @package    Swat
 * @copyright  2007 silverorange
 * @lisence    http://www.gnu.org/copyleft/lesser.html LGPL Lisence 2.1
 */
class SwatPercentageEntry extends SwatFloatEntry
{
	// {{{ protected function getDisplayValue()

	/**
	 * Returns a value for this widget
	 *
	 * The method returns a value to be displayed in the widget
	 *
	 * @return string the final percentage value
	 */
	protected function getDisplayValue($value)
	{
		if (is_numeric($value)) {
			$value = $value * 100;
			$value = parent::getDisplayValue($value);
			$value = $value.'%';
		} else {
			$value = parent::getDisplayValue($value);
		}

		return $value;
	}

	// }}}
	// {{{ protected function getNumericValue()

	/**
	 * Gets the float value of this widget
	 *
	 * This allows each widget to parse raw values and turn them into floats
	 *
	 * @param string $value the raw value to use to get the numeric value.
	 *
	 * @return mixed the numeric value of this entry widget or null if no
	 *							no numeric value is available.
	 */
	protected function getNumericValue($value)
	{
		$value = trim($value);
		$value = str_replace('%', '', $value);
		$value = parent::getNumericValue($value);
		if ($value !== null)
			$value = $value / 100;

		return $value;
	}

{'fraction_non_alphanumeric': 0.12352941176470589, 'fraction_numerical': 0.009688581314878892, 'mean_word_length': 3.4070121951219514, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3280962', 'n_tokens_mistral': 992, 'n_tokens_neox': 871, 'n_words': 295}