<commit_before><?php

class BugzillaParser implements ProviderParser
{
	public static function setHook( Parser $parser )
	{
		$parser->setHook('bugzilla', __CLASS__ . '::parseTag');

		return true;
	}

	public static function parseTag( $input, array $args, Parser $parser, PPFrame $frame )
	{
		$jsonQuery = FormatJson::decode( $input );

		if ( !is_null( $jsonQuery ) ) {
			$url = 'https://bugzilla.mozilla.org/bzapi/bug?' . http_build_query( $jsonQuery );

			$jsonObject = FormatJson::decode( HttpRest::get( $url ) );

			$output = '[[ Query returned ' . count($jsonObject->bugs) . ' bugs ]]';
		} else {
			$output = 'BAD JSON!';
		}

		return htmlentities( $output );
	}
}

/* vim:set ts=4 sw=4 sts=4 noexpandtab: */<commit_msg>Factor out functionality of parseTag().<commit_after><?php

class BugzillaParser implements ProviderParser
{
	public static function setHook( Parser $parser )
	{
		$parser->setHook('bugzilla', __CLASS__ . '::parseTag');

		return true;
	}

	public static function parseTag( $input, array $args, Parser $parser, PPFrame $frame )
	{
		$jsonQuery = self::buildQuery( $input );

		$jsonResult = self::sendRequest( $jsonQuery );

		return self::formatResult( $jsonResult );
	}

	protected static function decodeInput( $input )
	{
		return FormatJson::decode( $input );
	}

	protected static function buildQuery( $input )
	{
		$decodedInput = self::decodeInput( $input );

		if ( is_null( $decodedInput ) ) {
			return false;
		}

		return $decodedInput;
	}

	protected static function sendRequest( $jsonQuery )
	{
		if ( $jsonQuery === false ) {
			return false;
		}

		$url = 'https://bugzilla.mozilla.org/bzapi/bug?' . http_build_query( $jsonQuery );

		$jsonResult = self::buildResult( HttpRest::get( $url ) );

		return $jsonResult;
	}

	protected static function buildResult( $request )
	{
		if ( !$request ) {
			return false;
		}

		return FormatJson::decode( $request );
	}

	protected static function formatResult( $jsonResult )
	{
		if ( !$jsonResult ) {
			return 'BAD JSON!';
		}

		$output = '[[ Query returned ' . count( $jsonResult->bugs ) . ' bugs ]]';

		return htmlentities( $output );
	}
}

/* vim:set ts=4 sw=4 sts=4 noexpandtab: */
{'fraction_non_alphanumeric': 0.15038972948188903, 'fraction_numerical': 0.002751031636863824, 'mean_word_length': 3.9144144144144146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '3498912', 'n_tokens_mistral': 803, 'n_tokens_neox': 724, 'n_words': 177}