<commit_before><?php
/**
 * Main Plugin Functions
 *
 * @author <NAME>
 * @since  1.0
 */

/**
 * Generate license keys for a transaction.
 *
 * @since 1.0
 *
 * @param IT_Exchange_Transaction $transaction
 * @param string                  $status Default ITELIC_Key::ACTIVE
 *
 * @return boolean
 */
function itelic_generate_keys_for_transaction( IT_Exchange_Transaction $transaction, $status = '' ) {

	$result = false;

	foreach ( $transaction->get_products() as $product ) {

		if ( it_exchange_product_has_feature( $product['product_id'], 'licensing' ) ) {

			$product  = it_exchange_get_product( $product['product_id'] );
			$customer = it_exchange_get_transaction_customer( $transaction );

			$factory = new ITELIC_Key_Factory( $product, $customer, $transaction );
			$key     = $factory->make();

			$max = it_exchange_get_product_feature( $product->ID, 'licensing', array( 'field' => 'limit' ) );

			ITELIC_Key::create( $key, $transaction, $product, $customer, $max, $status );

			$result = true;
		}
	}

	return $result;
}<commit_msg>Add expiry date when generating keys from a transaction.<commit_after><?php
/**
 * Main Plugin Functions
 *
 * @author <NAME>
 * @since  1.0
 */

/**
 * Generate license keys for a transaction.
 *
 * @since 1.0
 *
 * @param IT_Exchange_Transaction $transaction
 * @param string                  $status Default ITELIC_Key::ACTIVE
 *
 * @return boolean
 */
function itelic_generate_keys_for_transaction( IT_Exchange_Transaction $transaction, $status = '' ) {

	$result = false;

	foreach ( $transaction->get_products() as $product ) {

		if ( it_exchange_product_has_feature( $product['product_id'], 'licensing' ) ) {

			$product = it_exchange_get_product( $product['product_id'] );

			if ( itelic_generate_key_for_transaction_product( $transaction, $product, $status ) ) {
				$result = true;
			} else {
				$result = false;
			}
		}
	}

	return $result;
}

/**
 * Generate a key for a certain transaction product.
 *
 * @since 1.0
 *
 * @param IT_Exchange_Transaction $transaction
 * @param IT_Exchange_Product     $product
 * @param string                  $status
 *
 * @return ITELIC_Key
 */
function itelic_generate_key_for_transaction_product( IT_Exchange_Transaction $transaction, IT_Exchange_Product $product, $status = '' ) {

	$customer = it_exchange_get_transaction_customer( $transaction );

	$factory = new ITELIC_Key_Factory( $product, $customer, $transaction );
	$key     = $factory->make();

	$max = it_exchange_get_product_feature( $product->ID, 'licensing', array( 'field' => 'limit' ) );

	if ( ! it_exchange_product_has_feature( $product->ID, 'recurring-payments' ) ) {
		$expires = null;
	} else {

		$type  = it_exchange_get_product_feature( $product->ID, 'recurring-payments', array( 'setting' => 'interval' ) );
		$count = it_exchange_get_product_feature( $product->ID, 'recurring-payments', array( 'setting' => 'interval-count' ) );

		$interval = itelic_convert_rp_to_date_interval( $type, $count );

		$expires = new DateTime( 'now', new DateTimeZone( get_option( 'timezone_string' ) ) );
		$expires->add( $interval );
	}

	ITELIC_Key::create( $key, $transaction, $product, $customer, $max, $expires, $status );
}

/**
 * Convert a recurring payments interval to a DateInterval object.
 *
 * @since 1.0
 *
 * @param string $type
 * @param int    $count
 *
 * @return DateInterval
 *
 * @throws Exception if invalid interval spec.
 */
function itelic_convert_rp_to_date_interval( $type, $count ) {

	$count = absint( $count );

	switch ( $type ) {
		case 'day':
			$period_designator = 'D';
			break;
		case 'week':
			$period_designator = 'W';
			break;
		case 'month':
			$period_designator = 'M';
			break;
		case 'year':
			$period_designator = 'Y';
			break;
	}

	if ( isset( $period_designator ) ) {
		$interval_spec = $count . $period_designator;
	} else {

		/**
		 * Filters the interval spec if the period designator is unknown.
		 *
		 * @see   http://php.net/manual/en/dateinterval.construct.php#refsect1-dateinterval.construct-parameters
		 *
		 * @since 1.0
		 *
		 * @param string|null $interval_spec Conforms to PHP date interval_spec without the P prefix.
		 * @param string      $type          Raw recurring payments type.
		 * @param int         $count         Recurrence count.
		 */
		$interval_spec = apply_filters( 'itelic_convert_rp_to_date_interval_unknown_designator', null, $type, $count );
	}

	return new DateInterval( "P$interval_spec" );
}
{'fraction_non_alphanumeric': 0.13649651450416012, 'fraction_numerical': 0.0033730604902181245, 'mean_word_length': 3.887912087912088, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '719160', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1421, 'n_words': 335}