<commit_before><?php

namespace ASF;

class Mailer
{
	public static $template = null;
	private static $params = array();

	public static function setTemplate ($template, $params = array())
	{
		$file = __DIR__ . '/../View/Emails/' . $template . '.html';

		if (!file_exists($file))
		{
			return false;
		}

		self::$template = file_get_contents($file);
		self::$params = $params;

		return true;
	}

	public static function send ($to, $from, $subject)
	{
		if (self::$template === null) 
		{
			return false;
		}

		self::compile();

		$headers = "From: " . $from . "\r\n";
		$headers .= "Reply-To: ". $from . "\r\n";
		$headers .= "MIME-Version: 1.0\r\n";
		$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

		try
		{
			mail($to, $from, self::$template, $headers);
		}
		catch (\Exception $e)
		{
			throw new \Exception('Failed to send mail');
		}

		return true;
	}

	public static function compile ()
	{
		$params = self::$params;

		foreach ($params as $key => $param)
		{
			self::$template = str_replace('{{ ' . $key . ' }}', $param, self::$template);
		}
	}
}<commit_msg>added comments to mailer class<commit_after><?php

namespace ASF;

/**
 * A wrapper class for sending emails
 */
class Mailer
{
	/**
	 * The template html
	 * @var string
	 */
	public static $template = null;

	/**
	 * Key value replacements for template html
	 * @var array
	 */
	private static $params = array();

	/**
	 * Sets the template
	 * @param string $template
	 * @param array  $params An array of parameters to replace in template html
	 */
	public static function setTemplate ($template, $params = array())
	{
		$file = __DIR__ . '/../View/Emails/' . $template . '.html';

		if (!file_exists($file))
		{
			return false;
		}

		self::$template = file_get_contents($file);
		self::$params = $params;

		return true;
	}

	/**
	 * Sends the compiled email
	 * @param  string $to      
	 * @param  string $from    
	 * @param  string $subject 
	 * @return boolean          
	 */
	public static function send ($to, $from, $subject)
	{
		if (self::$template === null) 
		{
			return false;
		}

		self::compile();

		$headers = "From: " . $from . "\r\n";
		$headers .= "Reply-To: ". $from . "\r\n";
		$headers .= "MIME-Version: 1.0\r\n";
		$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

		try
		{
			mail($to, $from, self::$template, $headers);
		}
		catch (\Exception $e)
		{
			throw new \Exception('Failed to send mail');
		}

		return true;
	}

	/**
	 * Compiles the template
	 * @return void
	 */
	public static function compile ()
	{
		$params = self::$params;

		foreach ($params as $key => $param)
		{
			self::$template = str_replace('{{ ' . $key . ' }}', $param, self::$template);
		}
	}
}
{'fraction_non_alphanumeric': 0.18138337012509198, 'fraction_numerical': 0.0051508462104488595, 'mean_word_length': 2.8403954802259888, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '465446', 'n_tokens_mistral': 1048, 'n_tokens_neox': 933, 'n_words': 251}