<commit_before><?php
	/**
	 * @package     Freemius Migration
	 * @copyright   Copyright (c) 2016, Freemius, Inc.
	 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
	 * @since       1.0.0
	 */

	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}

	/**
	 * Assumptions:
	 *  - Currently assumes that the download is a PLUGIN, not a THEME.
	 *
	 * Class FS_EDD_Download_Migration
	 */
	class FS_EDD_Download_Migration extends FS_Module_Migration_Abstract {
		/**
		 * @var EDD_Download
		 */
		private $_edd_download;

		/**
		 * @var array<int,array<string,mixed>>
		 */
		private $_edd_prices = array();

		/**
		 * @var int
		 */
		private $_edd_free_price_id;

		/**
		 * @var bool
		 */
		private $_edd_has_paid_plan = false;

		/**
		 * @var array
		 */
		private $_edd_paid_plan_pricing = array();

		#--------------------------------------------------------------------------------
		#region Init
		#--------------------------------------------------------------------------------

		function __construct(
			FS_Developer $developer,
			$module,
			EDD_Download $download
		) {
			$this->init( WP_FS__NAMESPACE_EDD, $developer, $module );

			$this->_edd_download = $download;

			if ( $download->has_variable_prices() ) {
				$this->_edd_prices = $download->get_prices();
			} else {
				if ( class_exists( 'EDD_Recurring' ) ) {
					$recurring = EDD_Recurring::is_recurring( $download->ID );
					$period    = EDD_Recurring::get_period_single( $download->ID );
				} else {
					$recurring = false;
					$period    = 'never';
				}

				$license_limit = get_post_meta( $download->ID, '_edd_sl_limit', true );

				$this->_edd_prices = array(
					// Set the EDD price ID as ZERO when the download doesn't have variable prices.
					0 => array(
						'recurring'     => $recurring ? 'yes' : 'no',
						'period'        => $period,
						'license_limit' => is_numeric( $license_limit ) ? $license_limit : 0,
						'amount'        => $download->get_price(),
					)
				);
			}

			$this->process_local_pricing();
		}

		#endregion

		#--------------------------------------------------------------------------------
		#region Helper Methods
		#--------------------------------------------------------------------------------

		/**
		 * Get billing cycle out of the variable price.
		 *
		 * @author <NAME> (@svovaf)
		 * @since  1.0.0
		 *
		 * @param array $edd_price
		 *
		 * @return string
		 */
		private function get_billing_cycle( $edd_price ) {
			$billing_cycle = 'lifetime';

			if ( ! empty( $edd_price['recurring'] ) &&
			     'yes' === $edd_price['recurring'] &&
			     ! empty( $edd_price['period'] ) &&
			     'never' !== $edd_price['period']
			) {
				switch ( $edd_price['period'] ) {
					case 'year':
						$billing_cycle = 'annual';
						break;
					case 'month':
						$billing_cycle = 'monthly';
						break;
					default:
						// @todo Throw an error when billing cycle is not supported.
						$billing_cycle = 'monthly';
						break;
				}
			}

			return $billing_cycle;
		}

		/**
		 * @author <NAME> (@svovaf)
		 * @since  1.0.0
		 *
		 * @param number $id
		 *
		 * @return string
		 */
		private function get_edd_unique_price_id( $id ) {<commit_msg>[edd] [bug-fix] [billing-cycle] Even if the Recurring Payments add-ons isn't installed, there are special fields setting up the billing cycle for the download. Use that instead of assuming it's a lifetime plans.<commit_after><?php
	/**
	 * @package     Freemius Migration
	 * @copyright   Copyright (c) 2016, Freemius, Inc.
	 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
	 * @since       1.0.0
	 */

	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}

	/**
	 * Assumptions:
	 *  - Currently assumes that the download is a PLUGIN, not a THEME.
	 *
	 * Class FS_EDD_Download_Migration
	 */
	class FS_EDD_Download_Migration extends FS_Module_Migration_Abstract {
		/**
		 * @var EDD_Download
		 */
		private $_edd_download;

		/**
		 * @var array<int,array<string,mixed>>
		 */
		private $_edd_prices = array();

		/**
		 * @var int
		 */
		private $_edd_free_price_id;

		/**
		 * @var bool
		 */
		private $_edd_has_paid_plan = false;

		/**
		 * @var array
		 */
		private $_edd_paid_plan_pricing = array();

		#--------------------------------------------------------------------------------
		#region Init
		#--------------------------------------------------------------------------------

		function __construct(
			FS_Developer $developer,
			$module,
			EDD_Download $download
		) {
			$this->init( WP_FS__NAMESPACE_EDD, $developer, $module );

			$this->_edd_download = $download;

			if ( $download->has_variable_prices() ) {
				$this->_edd_prices = $download->get_prices();
			} else {
				if ( class_exists( 'EDD_Recurring' ) ) {
					$recurring = EDD_Recurring::is_recurring( $download->ID );
					$period    = EDD_Recurring::get_period_single( $download->ID );
				} else {
					$recurring = false;
					$period    = 'never';
				}

				$license_limit = get_post_meta( $download->ID, '_edd_sl_limit', true );

				$this->_edd_prices = array(
					// Set the EDD price ID as ZERO when the download doesn't have variable prices.
					0 => array(
						'recurring'     => $recurring ? 'yes' : 'no',
						'period'        => $period,
						'license_limit' => is_numeric( $license_limit ) ? $license_limit : 0,
						'amount'        => $download->get_price(),
					)
				);
			}

			$this->process_local_pricing();
		}

		#endregion

		#--------------------------------------------------------------------------------
		#region Helper Methods
		#--------------------------------------------------------------------------------

		/**
		 * Get billing cycle out of the variable price.
		 *
		 * @author <NAME> (@svovaf)
		 * @since  1.0.0
		 *
		 * @param array $edd_price
		 *
		 * @return string
		 */
		private function get_billing_cycle( $edd_price ) {
			$billing_cycle = 'lifetime';

			if ( class_exists( 'EDD_Recurring' ) ) {
				if ( ! empty( $edd_price['recurring'] ) &&
				     'yes' === $edd_price['recurring'] &&
				     ! empty( $edd_price['period'] ) &&
				     'never' !== $edd_price['period']
				) {
					switch ( $edd_price['period'] ) {
						case 'year':
							$billing_cycle = 'annual';
							break;
						case 'month':
							$billing_cycle = 'monthly';
							break;
						default:
							// @todo Throw an error when billing cycle is not supported.
							$billing_cycle = 'monthly';
							break;
					}
				}
			} else {
				if ( ! empty( $edd_price['is_lifetime'] ) &&
				     $edd_price['is_lifetime']
				) {
					$billing_cycle = 'lifetime';
				} else {
					// Alias.
					$download_id = $this->_edd_download->ID;

					$is_limited = get_post_meta( $download_id, 'edd_sl_download_lifetime', true );
					$is_limited = empty( $is_limited );

					if ( $is_limited ) {
						$exp_unit   = get_post_meta( $download_id, '_edd_sl_exp_unit', true );
						$exp_length = get_post_meta( $download_id, '_edd_sl_exp_length', true );

						if ( 4 == $exp_length && 'weeks' === $exp_unit ) {
							$billing_cycle = 'monthly';
						} else if ( 12 == $exp_length && 'months' === $exp_unit ) {
							$billing_cycle = 'annual';
						} else {
							if ( 1 != $exp_length ) {
								// @todo Throw an error when billing cycle
							}

							switch ( $exp_unit ) {
								case 'years':
									$billing_cycle = 'annual';
									break;
								case 'months':
									$billing_cycle = 'monthly';
									break;
								default:
									// @todo Throw an error when billing cycle is not supported.
									$billing_cycle = 'monthly';
									break;
							}
						}
					}
				}
			}

			return $billing_cycle;
		}

		/**
		 * @author <NAME> (@svovaf)
		 * @since  1.0.0
		 *
		 * @param number $id
		 *
		 * @return string
		 */
		private function get_edd_unique_price_id( $id ) {
{'fraction_non_alphanumeric': 0.21430389412064138, 'fraction_numerical': 0.004835836090608297, 'mean_word_length': 1.8515965166908563, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 41, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '414434', 'n_tokens_mistral': 3308, 'n_tokens_neox': 2515, 'n_words': 541}