<?php

namespace Planaday\Platform\WordpressConfig\Migrations;

use Planaday\Utility\PluginData;

class MigrationHelper {

	/** @var PluginData */
	public $pluginData;

	public function __construct(PluginData $pluginData) {
		$this->pluginData = $pluginData;
	}

	public function getBool($toBeTested):?bool {
		if ($toBeTested === '' || $toBeTested === null) return null;
		return $toBeTested === "1" ||
		       strtolower((string)$toBeTested) === "ja" ||
		       $toBeTested === 1 ||
		       $toBeTested === true;
	}

	public function getInt($toBeConverted):?int {
		if ( $toBeConverted == "" || !filter_var($toBeConverted, FILTER_VALIDATE_INT)) return null;

		return (int)$toBeConverted;
	}

	public function getString($toBeConverted):?string {
		if ($toBeConverted == "") return null;

		return "" . $toBeConverted;
	}

	public function checkIfEmail($toBeChecked):bool {
		return (is_string($toBeChecked) && filter_var($toBeChecked, FILTER_VALIDATE_EMAIL));
	}
}