<commit_before><?php
/**
 * This file is part of ResMan library.
 *
 * Copyright (c) 2015 DTForce, s.r.o. (http://www.dtforce.com)
 *
 * For the full copyright and license information, please view
 * the file LICENSE that was distributed with this source code.
 */

namespace DTForce\ResMan\Generator;

use DirectoryIterator;
use PhpParser\Node\Const_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassConst;


final class Helper
{

	/**
	 * @param array $data
	 *
	 * @return Const_[]
	 */
	public static function createStringConstants(array $data)
	{
		$consts = [];
		foreach ($data as $key => $value) {
			$consts[] = new ClassConst([new Const_($key, new String_($value))]);
		}
		return $consts;
	}


	/**
	 * @param array $data
	 *
	 * @return Const_[]
	 */
	public static function createIntConstants(array $data)
	{
		$consts = [];
		foreach ($data as $key => $value) {
			$consts[] = new Const_($key, new LNumber($value));
		}
		return $consts;
	}


	/**
	 * @param array $data
	 *
	 * @return Array_
	 */
	public static function createArray(array $data)
	{
		$items = [];
		foreach ($data as $key => $value) {
			if (is_array($value)) {
				$items[] = new ArrayItem(self::createArray($value), new String_($key));
			} else {
				$items[] = new ArrayItem(new String_($value), new String_($key));
			}

		}
		return new Array_($items);
	}


	/**
	 * @param string $file
	 *
	 * @return array
	 */
	public static function readCsvValues($file)
	{
		$csv = array_map('str_getcsv', file($file));<commit_msg>Use double quoted string to allow newlines.<commit_after><?php
/**
 * This file is part of ResMan library.
 *
 * Copyright (c) 2015 DTForce, s.r.o. (http://www.dtforce.com)
 *
 * For the full copyright and license information, please view
 * the file LICENSE that was distributed with this source code.
 */

namespace DTForce\ResMan\Generator;

use DirectoryIterator;
use PhpParser\Node\Const_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassConst;


final class Helper
{

	/**
	 * @param array $data
	 *
	 * @return Const_[]
	 */
	public static function createStringConstants(array $data)
	{
		$consts = [];
		foreach ($data as $key => $value) {
			$consts[] = new ClassConst([new Const_($key, new String_($value))]);
		}
		return $consts;
	}


	/**
	 * @param array $data
	 *
	 * @return Const_[]
	 */
	public static function createIntConstants(array $data)
	{
		$consts = [];
		foreach ($data as $key => $value) {
			$consts[] = new Const_($key, new LNumber($value));
		}
		return $consts;
	}


	/**
	 * @param array $data
	 *
	 * @return Array_
	 */
	public static function createArray(array $data)
	{
		$items = [];
		foreach ($data as $key => $value) {
			if (is_array($value)) {
				$items[] = new ArrayItem(self::createArray($value), new String_($key));
			} else {
				$items[] = new ArrayItem(new String_($value, ['kind' => String_::KIND_DOUBLE_QUOTED]), new String_($key));
			}

		}
		return new Array_($items);
	}


	/**
	 * @param string $file
	 *
	 * @return array
	 */
	public static function readCsvValues($file)
	{
		$csv = array_map('str_getcsv', file($file));
{'fraction_non_alphanumeric': 0.15639097744360902, 'fraction_numerical': 0.002406015037593985, 'mean_word_length': 3.600276625172891, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7453406', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1118, 'n_words': 295}