<commit_before><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2009, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\util\reflection;

/**
 * A source code doc block parser.
 *
 * This parser may be used as the basis for a variety of secondary tools, including
 * a reflection-based API generator, a code metrics analyzer, and various other possible
 * use cases.
 */
class Docblock extends \lithium\core\StaticObject {

	/**
	 * Parses a doc block into its major components of `description`, `text` and `tags`.
	 *
	 * @param string $description The doc block string to be parsed
	 * @return array An associative array of the parsed comment, whose keys are `description`,
	 *         `text` and `tags`
	 * @todo Implement text
	 */
	public static function comment($description) {
		$text = null;
		$tags = array();
		$description = trim(preg_replace('/^(\s*\/\*\*|\s*\*\/|\s+\* ?)/m', '', $description));

		if (!(preg_match_all('/\n@(\w+)\s+/', $description, $tagNames))) {
			return compact('description', 'text', 'tags');
		}
		$tagContents = preg_split('/\n@\w+\s+/ms', $description);

		foreach (array_values(array_slice($tagContents, 1)) as $i => $desc) {
			$description = trim(str_replace("@{$tagNames[1][$i]} {$desc}", '', $description));
			$tag = $tagNames[1][$i];

			if (isset($tags[$tag])) {
				$tags[$tag] = (array)$tags[$tag];
				$tags[$tag][] = $desc;
			} else {
				$tags[$tag] = $desc;
			}
		}

		if (isset($tags['param'])) {
			$params = $tags['param'];
			$tags['params'] = array();<commit_msg>Fixing regex for stripping docblock prefix.<commit_after><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2009, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\util\reflection;

/**
 * A source code doc block parser.
 *
 * This parser may be used as the basis for a variety of secondary tools, including
 * a reflection-based API generator, a code metrics analyzer, and various other possible
 * use cases.
 */
class Docblock extends \lithium\core\StaticObject {

	/**
	 * Parses a doc block into its major components of `description`, `text` and `tags`.
	 *
	 * @param string $description The doc block string to be parsed
	 * @return array An associative array of the parsed comment, whose keys are `description`,
	 *         `text` and `tags`
	 * @todo Implement text
	 */
	public static function comment($description) {
		$text = null;
		$tags = array();
		$description = trim(preg_replace('/^(\s*\/\*\*|\s*\*\/|\s*\* ?)/m', '', $description));

		if (!(preg_match_all('/\n@(\w+)\s+/', $description, $tagNames))) {
			return compact('description', 'text', 'tags');
		}
		$tagContents = preg_split('/\n@\w+\s+/ms', $description);

		foreach (array_values(array_slice($tagContents, 1)) as $i => $desc) {
			$description = trim(str_replace("@{$tagNames[1][$i]} {$desc}", '', $description));
			$tag = $tagNames[1][$i];

			if (isset($tags[$tag])) {
				$tags[$tag] = (array)$tags[$tag];
				$tags[$tag][] = $desc;
			} else {
				$tags[$tag] = $desc;
			}
		}

		if (isset($tags['param'])) {
			$params = $tags['param'];
			$tags['params'] = array();
{'fraction_non_alphanumeric': 0.1862214199759326, 'fraction_numerical': 0.00421179302045728, 'mean_word_length': 3.6633941093969145, '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': '3512376', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1038, 'n_words': 308}