<commit_before><?php
/**
 * Activation methods.
 *
 * @author <NAME>
 * @since  1.0
 */

/**
 * Get an activation.
 *
 * @since 1.0
 *
 * @param int $id
 *
 * @return \ITELIC\Activation
 */
function itelic_get_activation( $id ) {
	return \ITELIC\Activation::with_id( $id );
}

/**
 * Get an activation from data from the DB.
 *
 * @since 1.0
 *
 * @param stdClass $data
 *
 * @return \ITELIC\Activation
 */
function itelic_get_activation_from_data( stdClass $data ) {
	return new \ITELIC\Activation( $data );
}

/**
 * Get an activation record by its location
 *
 * @since 1.0
 *
 * @param string      $location
 * @param \ITELIC\Key $key
 *
 * @return \ITELIC\Activation|null
 */
function itelic_get_activation_by_location( $location, \ITELIC\Key $key ) {

	$query = new \ITELIC_API\Query\Activations( array(
		'location' => itelic_normalize_url( $location ),
		'key'      => $key->get_key()
	) );

	$keys = $query->get_results();

	if ( empty( $keys ) ) {
		return null;
	}

	return itelic_get_activation_from_data( reset( $keys ) );
}

/**
 * Check if a URL is a dev site.
 *
 * @since 1.0
 *
 * @param string $url
 *
 * @return bool
 */
function itelic_is_url_dev_site( $url ) {

	$is_dev = false;

	$white_listed = array(
		'localhost',
		'127.0.0.1',
		'192.168.50.4'
	);

	/**
	 * Filter the set of white listed domains and IPs.
	 *
	 * @since 1.0
	 *
	 * @param array $white_listed Set of white listed domains, or IPs
	 */
	$white_listed = apply_filters( 'itelic_is_url_dev_site_white_listed_urls', $white_listed );

	if ( in_array( $url, $white_listed, true ) ) {
		$is_dev = true;
	}

	$tlds = array( 'local' );

	/**
	 * Filter the white list of TLDs.
	 *
	 * @since 1.0
	 *
	 * @param array $tlds Set of top-level domains, without prefacing period.
	 */
	$tlds = apply_filters( 'itelic_is_url_dev_site_tlds', $tlds );

	foreach ( $tlds as $tld ) {
		if ( strpos( $url, ".$tld" ) !== false ) {
			$is_dev = true;

			break;
		}
	}

	/**
	 * Filter whether the passed URL belongs to a dev site.
	 *
	 * @since 1.0
	 */
	$is_dev = apply_filters( 'itelic_is_url_dev_site', $is_dev, $url );

	return $is_dev;
}

/**
 * Normalize URLs so they are all saved the same way.
 *
 * If passed an IP address, just saves the IP address, doesn't normalize.
 *
 * @since 1.0
 *
 * @param string $url
 *
 * @return string
 */
function itelic_normalize_url( $url ) {

	if ( filter_var( $url, FILTER_VALIDATE_IP ) !== false ) {
		return $url;
	}

	$normalizer = new URL\Normalizer( $url );

	return trailingslashit( esc_url_raw( $normalizer->normalize() ) );
}

/**
 * Activate a license key.
 *
 * @since 1.0
 *
 * @param \ITELIC\Key $key
 * @param string      $location
 * @param DateTime    $date
 * @param string      $status
 * @param string      $version
 *
 * @return \ITELIC\Activation
 *
 * @throws LogicException|\IronBound\DB\Exception
 */
function itelic_activate_license_key( \ITELIC\Key $key, $location, DateTime $date = null, $status = '', $version ) {

	$record = \ITELIC\Activation::create( $key, $location, $date, $status, $version );
	$key->log_activation( $record );

	return $record;
}<commit_msg>Make version optional in api method<commit_after><?php
/**
 * Activation methods.
 *
 * @author I<NAME>
 * @since  1.0
 */

/**
 * Get an activation.
 *
 * @since 1.0
 *
 * @param int $id
 *
 * @return \ITELIC\Activation
 */
function itelic_get_activation( $id ) {
	return \ITELIC\Activation::with_id( $id );
}

/**
 * Get an activation from data from the DB.
 *
 * @since 1.0
 *
 * @param stdClass $data
 *
 * @return \ITELIC\Activation
 */
function itelic_get_activation_from_data( stdClass $data ) {
	return new \ITELIC\Activation( $data );
}

/**
 * Get an activation record by its location
 *
 * @since 1.0
 *
 * @param string      $location
 * @param \ITELIC\Key $key
 *
 * @return \ITELIC\Activation|null
 */
function itelic_get_activation_by_location( $location, \ITELIC\Key $key ) {

	$query = new \ITELIC_API\Query\Activations( array(
		'location' => itelic_normalize_url( $location ),
		'key'      => $key->get_key()
	) );

	$keys = $query->get_results();

	if ( empty( $keys ) ) {
		return null;
	}

	return itelic_get_activation_from_data( reset( $keys ) );
}

/**
 * Check if a URL is a dev site.
 *
 * @since 1.0
 *
 * @param string $url
 *
 * @return bool
 */
function itelic_is_url_dev_site( $url ) {

	$is_dev = false;

	$white_listed = array(
		'localhost',
		'127.0.0.1',
		'192.168.50.4'
	);

	/**
	 * Filter the set of white listed domains and IPs.
	 *
	 * @since 1.0
	 *
	 * @param array $white_listed Set of white listed domains, or IPs
	 */
	$white_listed = apply_filters( 'itelic_is_url_dev_site_white_listed_urls', $white_listed );

	if ( in_array( $url, $white_listed, true ) ) {
		$is_dev = true;
	}

	$tlds = array( 'local' );

	/**
	 * Filter the white list of TLDs.
	 *
	 * @since 1.0
	 *
	 * @param array $tlds Set of top-level domains, without prefacing period.
	 */
	$tlds = apply_filters( 'itelic_is_url_dev_site_tlds', $tlds );

	foreach ( $tlds as $tld ) {
		if ( strpos( $url, ".$tld" ) !== false ) {
			$is_dev = true;

			break;
		}
	}

	/**
	 * Filter whether the passed URL belongs to a dev site.
	 *
	 * @since 1.0
	 */
	$is_dev = apply_filters( 'itelic_is_url_dev_site', $is_dev, $url );

	return $is_dev;
}

/**
 * Normalize URLs so they are all saved the same way.
 *
 * If passed an IP address, just saves the IP address, doesn't normalize.
 *
 * @since 1.0
 *
 * @param string $url
 *
 * @return string
 */
function itelic_normalize_url( $url ) {

	if ( filter_var( $url, FILTER_VALIDATE_IP ) !== false ) {
		return $url;
	}

	$normalizer = new URL\Normalizer( $url );

	return trailingslashit( esc_url_raw( $normalizer->normalize() ) );
}

/**
 * Activate a license key.
 *
 * @since 1.0
 *
 * @param \ITELIC\Key $key
 * @param string      $location
 * @param DateTime    $date
 * @param string      $status
 * @param string      $version
 *
 * @return \ITELIC\Activation
 *
 * @throws LogicException|\IronBound\DB\Exception
 */
function itelic_activate_license_key( \ITELIC\Key $key, $location, DateTime $date = null, $status = '', $version = '' ) {

	$record = \ITELIC\Activation::create( $key, $location, $date, $status, $version );
	$key->log_activation( $record );

	return $record;
}
{'fraction_non_alphanumeric': 0.15376, 'fraction_numerical': 0.0112, 'mean_word_length': 3.1728971962616823, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '2837782', 'n_tokens_mistral': 2489, 'n_tokens_neox': 2319, 'n_words': 593}