<commit_before><?php

namespace Tools\IdeHelper\Generator\Task;

use Cake\Core\Configure;
use Cake\View\View;
use IdeHelper\Generator\Directive\ExpectedArguments;
use IdeHelper\Generator\Task\TaskInterface;
use Tools\View\Helper\FormatHelper;

class FormatIconTask implements TaskInterface {

	const CLASS_FORMAT_HELPER = FormatHelper::class;

	/**
	 * @return \IdeHelper\Generator\Directive\BaseDirective[]
	 */
	public function collect() {
		$result = [];

		$icons = $this->collectIcons();
		$list = [];
		foreach ($icons as $icon) {
			$list[$icon] = '\'' . $icon . '\'';
		}

		ksort($list);

		$method = '\\' . static::CLASS_FORMAT_HELPER . '::icon()';
		$directive = new ExpectedArguments($method, 0, $list);
		$result[$directive->key()] = $directive;

		return $result;
	}

	/**
	 * Fontawesome v4 using .../scss/_variables.scss
	 *
	 * @return string[]
	 */
	protected function collectIcons() {
		$helper = new FormatHelper(new View());
		$configured = $helper->getConfig('fontIcons');

		$fontFile = Configure::readOrFail('Format.fontPath');
		$icons = [];
		if ($fontFile && file_exists($fontFile)) {
			$content = file_get_contents($fontFile);
			preg_match_all('/\$fa-var-([0-9a-z-]+):/', $content, $matches);
			$icons = !empty($matches[1]) ? $matches[1] : [];
		}

		$icons = array_merge($configured, $icons);
		sort($icons);

		return $icons;<commit_msg>Fix font icon parsing.<commit_after><?php

namespace Tools\IdeHelper\Generator\Task;

use Cake\Core\Configure;
use Cake\View\View;
use IdeHelper\Generator\Directive\ExpectedArguments;
use IdeHelper\Generator\Task\TaskInterface;
use Tools\View\Helper\FormatHelper;

class FormatIconTask implements TaskInterface {

	const CLASS_FORMAT_HELPER = FormatHelper::class;

	/**
	 * @return \IdeHelper\Generator\Directive\BaseDirective[]
	 */
	public function collect() {
		$result = [];

		$icons = $this->collectIcons();
		$list = [];
		foreach ($icons as $icon) {
			$list[$icon] = '\'' . $icon . '\'';
		}

		ksort($list);

		$method = '\\' . static::CLASS_FORMAT_HELPER . '::icon()';
		$directive = new ExpectedArguments($method, 0, $list);
		$result[$directive->key()] = $directive;

		return $result;
	}

	/**
	 * Fontawesome v4 using .../scss/_variables.scss
	 *
	 * @return string[]
	 */
	protected function collectIcons() {
		$helper = new FormatHelper(new View());
		$configured = $helper->getConfig('fontIcons');
		$configured = array_keys($configured);

		$fontFile = Configure::readOrFail('Format.fontPath');
		$icons = [];
		if ($fontFile && file_exists($fontFile)) {
			$content = file_get_contents($fontFile);
			preg_match_all('/\$fa-var-([0-9a-z-]+):/', $content, $matches);
			$icons = !empty($matches[1]) ? $matches[1] : [];
		}

		$icons = array_merge($configured, $icons);
		sort($icons);

		return $icons;
{'fraction_non_alphanumeric': 0.18530465949820787, 'fraction_numerical': 0.004301075268817204, 'mean_word_length': 4.306083650190114, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3130606', 'n_tokens_mistral': 1037, 'n_tokens_neox': 937, 'n_words': 170}