<commit_before><?php

namespace App\Validation\Rules;

use Illuminate\Support\Facades\Validator;

class MaxLengthWithoutHtmlRule
{
	/**
	 * The max length to accept.
	 *
	 * @var int
	 */
	protected $max_length;

	/**
	 * Require a certain number of parameters to be present (if set).
	 *
	 * @param  array  $parameters
	 * @return void
	 *
	 * @throws \InvalidArgumentException
	 */
	public function __construct($parameters = null)
	{
		if (!is_null($parameters) && count($parameters) < 1) {
			throw new \InvalidArgumentException(
				'"max_length_plaintext" validation rule requires at least 1 parameter.'
			);
		}

		$this->max_length = is_null($parameters[0]) ? 0 : (int) $parameters[0];
	}

	/**
	 * Determine if the length of the string is too large once stripped of HTML.
	 *
	 * @param  string  $attribute The name of the attribute being validated
	 * @param  string  $value  The value of the attribute
	 * @return bool
	 */
	public function passes($attribute, $value)
	{
		// Our length has to be multibyte "safe" to be consistent with the client-side
		return mb_strlen(
			// We decode html entities so things like &nbsp; don't count as several chars
			html_entity_decode(
				// Strip all HTML before decoding the HTML entities
				strip_tags($value),
				ENT_QUOTES | ENT_HTML5,
				'UTF-8'
			)<commit_msg>Ensure the length parameter supplied to our max length rule is a positive integer.<commit_after><?php

namespace App\Validation\Rules;

use Illuminate\Support\Facades\Validator;

class MaxLengthWithoutHtmlRule
{
	/**
	 * The max length to accept.
	 *
	 * @var int
	 */
	protected $max_length;

	/**
	 * Require a certain number of parameters to be present (if set).
	 *
	 * @param  array  $parameters
	 * @return void
	 *
	 * @throws \InvalidArgumentException
	 */
	public function __construct($parameters = null)
	{
		if (!is_null($parameters) && count($parameters) < 1) {
			throw new \InvalidArgumentException(
				'"max_length_plaintext" validation rule requires at least 1 parameter.'
			);
		}

		$length = is_null($parameters) ? 0 : $parameters[0];

		if(
			filter_var($length, FILTER_VALIDATE_INT) === false ||
			// FILTER_VALIDATE_INT has stupid result if var is true
			$length === true ||
			$length < 0
		) {
			throw new \InvalidArgumentException(
				'"max_length_plaintext" validation rule parameter must be a positive integer.' . " ($length supplied)"
			);
		}

		$this->max_length = (int) $length;
	}

	/**
	 * Determine if the length of the string is too large once stripped of HTML.
	 *
	 * @param  string  $attribute The name of the attribute being validated
	 * @param  string  $value  The value of the attribute
	 * @return bool
	 */
	public function passes($attribute, $value)
	{
		// Our length has to be multibyte "safe" to be consistent with the client-side
		return mb_strlen(
			// We decode html entities so things like &nbsp; don't count as several chars
			html_entity_decode(
				// Strip all HTML before decoding the HTML entities
				strip_tags($value),
				ENT_QUOTES | ENT_HTML5,
				'UTF-8'
			)
{'fraction_non_alphanumeric': 0.10235448005232178, 'fraction_numerical': 0.004578155657292348, 'mean_word_length': 3.376251788268956, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, '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': '247841', 'n_tokens_mistral': 1032, 'n_tokens_neox': 890, 'n_words': 319}