File "TrackingData.php"

Full Path: /home/jlklyejr/public_html/post-date/wp-content/plugins/flexible-shipping/src/WPDesk/FS/ProFeatures/Tracker/TrackingData.php
File size: 1.26 KB
MIME-type: text/x-php
Charset: utf-8

<?php
/**
 * Class TrackingData
 */

namespace WPDesk\FS\ProFeatures\Tracker;

/**
 * Can provide pro features tracking data.
 */
class TrackingData {

	const OPTION_NAME = 'fs-pro-features-tracking-data';
	const SHOW_COUNT  = 'show_count';
	const HIDE_COUNT  = 'hide_count';

	/**
	 * @return void
	 */
	public function increase_show_count(): void {
		$this->increase_value( self::SHOW_COUNT );
	}

	/**
	 * @return void
	 */
	public function increase_hide_count(): void {
		$this->increase_value( self::HIDE_COUNT );
	}

	/**
	 * @return int[]
	 */
	public function get_tracking_data(): array {
		$tracking_data = get_option( self::OPTION_NAME, [] );

		$tracking_data[ self::SHOW_COUNT ] = (int) ( $tracking_data[ self::SHOW_COUNT ] ?? 0 );
		$tracking_data[ self::HIDE_COUNT ] = (int) ( $tracking_data[ self::HIDE_COUNT ] ?? 0 );

		return $tracking_data;
	}

	/**
	 * @param string $option .
	 *
	 * @return void
	 */
	private function increase_value( string $option ): void {
		$tracking_data = $this->get_tracking_data();
		$tracking_data[ $option ]++;
		$this->save_tracking_data( $tracking_data );
	}

	/**
	 * @param int[] $tracking_data .
	 */
	private function save_tracking_data( array $tracking_data ): void {
		update_option( self::OPTION_NAME, $tracking_data, false );
	}
}