<commit_before><?php
namespace Asgard\Tester;

class Results {
	protected $results = [];

	public function add($id, $request, $response, $route) {
		$res = [
			'request' => $request,
			'response' => $response,
			'route' => $route,
			'coverage' => [],
		];
		$this->results[$id] = $res;

		return $this;
	}

	public function addCoverage($id, $coverage) {
		$this->results[$id]['coverage'] = new Coverage($coverage);
	}

	public function display() {
		
	}

	public function generate($name, $fixturesFile=null) {
		$tmp = [];

		foreach($this->results as $id=>$res) {
			$route = $res['route'];
			if(!$route)
				$tmp['Notfound'][''][] = $res;
			else
				$tmp[str_replace('\\', '', $route->getController())][$route->getAction()][] = $res;
		}

		#order same action's tests by coverage and request simplicity
		foreach($tmp as $controller=>$actions) {
			foreach($actions as $action=>$results) {
				usort($tmp[$controller][$action], function($a, $b) {
					if($a['coverage']->count() === $b['coverage']->count()) {
						$as = $a['request']->get->count() + $a['request']->post->count() + $a['request']->file->count() + $a['request']->cookie->count();
						$bs = $b['request']->get->count() + $b['request']->post->count() + $b['request']->file->count() + $b['request']->cookie->count();

						return $as > $bs;#todo sort by parameters if same simplicity
					}
					return $a['coverage']->count() < $b['coverage']->count();
				});
			}
		}

		$res = '<?php
class '.$name.' extends \Asgard\Http\Test {
	public static function setUpBeforeClass() {
		$container = \Asgard\Container\Container::singleton();'.($fixturesFile ? '
		require __DIR__.\'/'.$fixturesFile.'\';':'').'
	}
';<commit_msg>fixes<commit_after><?php
namespace Asgard\Tester;

class Results {
	protected $results = [];

	public function add($id, $request, $response, $route) {
		$res = [
			'request' => $request,
			'response' => $response,
			'route' => $route,
			'coverage' => [],
		];
		$this->results[$id] = $res;

		return $this;
	}

	public function addCoverage($id, $coverage) {
		$this->results[$id]['coverage'] = new Coverage($coverage);
	}

	public function display() {
		
	}

	public function generate($name, $fixturesFile=null) {
		$tmp = [];

		foreach($this->results as $id=>$res) {
			$route = $res['route'];
			if(!$route)
				$tmp['Notfound'][''][] = $res;
			else
				$tmp[str_replace('\\', '', $route->getController())][$route->getAction()][] = $res;
		}

		#order same action's tests by coverage and request simplicity
		foreach($tmp as $controller=>$actions) {
			foreach($actions as $action=>$results) {
				usort($tmp[$controller][$action], function($a, $b) {
					if($a['coverage']->count() === $b['coverage']->count()) {
						$as = $a['request']->get->count() + $a['request']->post->count() + $a['request']->file->count() + $a['request']->cookie->count();
						$bs = $b['request']->get->count() + $b['request']->post->count() + $b['request']->file->count() + $b['request']->cookie->count();

						return $as > $bs;
					}
					return $a['coverage']->count() < $b['coverage']->count();
				});
			}
		}

		$res = '<?php
class '.$name.' extends \Asgard\Http\Test {
	public static function setUpBeforeClass() {
		$container = \Asgard\Container\Container::singleton();'.($fixturesFile ? '
		require __DIR__.\'/'.$fixturesFile.'\';':'').'
	}
';
{'fraction_non_alphanumeric': 0.24722804914593946, 'fraction_numerical': 0.0, 'mean_word_length': 4.049924357034795, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 69, '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': '443943', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1156, 'n_words': 210}