<commit_before><?php

namespace Good\Manners;


class StoreCompiler implements \Good\Rolemodel\Visitor
{
	// Compiler level data
	private $outputDir;
	private $dataTypes = array();
	private $output = null;
	private $varName = null;
	private $firstDateType = true;
	private $dataType = null;
	
	private $resolver = null;
	private $resolverVisit = null;
	
	public function __construct($outputDir)
	{
		$this->outputDir = $outputDir;
	}
	
	public function visitDataModel($dataModel)
	{
		// Start off the class 
		$this->output  = "abstract class GoodMannersStore implements \\Good\\Manners\\Store \n";
		$this->output .= "{\n";
		$this->output .= '	private $validationToken;' . "\n";
		$this->output .= "	\n";
		$this->output .= "	public function __construct()\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->validationToken = new \\Good\\Manners\\ValidationToken();' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
		$this->output .= "	public function __destruct()\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->flush();' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
		$this->output .= '	abstract public function visitReferenceProperty($name, ' .
								'$datatypeName, $dirty, $null, \\Good\\Manners\\Storable $value = null);' . "\n";
		$this->output .= '	abstract public function visitTextProperty($name, $dirty, ' .
																	'$null, $value);' . "\n";
		$this->output .= '	abstract public function visitIntProperty($name, $dirty, ' .
																	'$null, $value);' . "\n";
		$this->output .= '	abstract public function visitFloatProperty($name, $dirty, ' .
																	'$null, $value);' . "\n";
		$this->output .= '	abstract public function visitDatetimeProperty($name, $dirty, ' .
																	'$null, $value);' . "\n";
		$this->output .= "	\n";
		$this->output .= '	protected function invalidate()' . "\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->validationToken->invalidate();' . "\n";
		$this->output .= '		$this->validationToken = new \\Good\\Manners\\ValidationToken();' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
	}
	
	public function visitDataType($dataType)
	{
		if ($this->firstDateType)
		{
			$this->firstDateType = false;
		}
		else
		{
			$this->finishDataType();
		}
		$name = $dataType->getName();
		$this->dataType = $name;
		$this->dataTypes[] = $name;
		
		// ucfirst: upper case first (php builtin)
		$this->output .= '	abstract protected function doModifyAny' . \ucfirst($name) . 
							'(\\Good\\Manners\\Condition $condition, ' . $name . ' $modifications);' . "\n";
		$this->output .= '	abstract protected function doGet' . \ucfirst($name) .
							'Collection(\\Good\\Manners\\Condition $condition, ' . $name . 
															'Resolver $resolver);' . "\n";
		$this->output .= "	\n";
		$this->output .= '	abstract protected function saveNew' . \ucfirst($name) . 
																's(array $entries);' . "\n";
		$this->output .= '	abstract protected function save' . \ucfirst($name) . 
															'Modifications(array $entries);' . "\n";
		$this->output .= '	abstract protected function save' . \ucfirst($name) . 
															'Deletions(array $entries);' . "\n";
		$this->output .= "	\n";
		
		$this->output .= '	private $dirty' . \ucfirst($name) . 's = array();' . "\n";
		$this->output .= "	\n";
		$this->output .= '	public function dirty' . \ucfirst($name) . 
												'(' . $name . ' $storable)' . "\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->dirty' . \ucfirst($name) . 's[] = $storable;' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
		$this->output .= '	public function insert' . \ucfirst($name) . 
												'(' . $name . ' $storable)' . "\n";
		$this->output .= "	{\n";
		$this->output .= '		$storable->setStore($this);' . "\n";
		$this->output .= '		$storable->setValidationToken($this->validationToken);' . "\n";
		$this->output .= "		\n";
		$this->output .= '		$this->dirty' . \ucfirst($name) . 's[] = $storable;' . "\n";
		$this->output .= "	}\n";
		$this->output .= "\n";
		$this->output .= '	public function modifyAny' . \ucfirst($name) .'(\\Good\\Manners\\Condition ' .
													'$condition, ' . $name . ' $modifications)' . "\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->invalidate();' . "\n";
		$this->output .= "		\n";
		$this->output .= '		$this->doModifyAny' . \ucfirst($name) .'($condition, $modifications);' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
		$this->output .= '	public function get' . \ucfirst($name) . 'Collection(\\Good\\Manners\\Condition ' .
													 '$condition, ' . $name . 'Resolver $resolver)' . "\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->flush();' . "\n";
		$this->output .= '		return $this->doGet' . \ucfirst($name) . 
													'Collection($condition, $resolver);' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
		
		$this->resolver  = "<?php\n";
		$this->resolver .= "\n";
		$this->resolver .= 'class ' . $name . 'Resolver extends \\Good\\Manners\\AbstractResolver' . "\n";
		$this->resolver .= "{\n";
		
		$this->resolverVisit  = '	public function resolverAccept' . 
												'(\\Good\\Manners\\ResolverVisitor $visitor)' . "\n";
		$this->resolverVisit .= "	{\n";
	}
	
	public function visitEnd()
	{<commit_msg>Removed necessity for flush before modifyAny<commit_after><?php

namespace Good\Manners;


class StoreCompiler implements \Good\Rolemodel\Visitor
{
	// Compiler level data
	private $outputDir;
	private $dataTypes = array();
	private $output = null;
	private $varName = null;
	private $firstDateType = true;
	private $dataType = null;
	
	private $resolver = null;
	private $resolverVisit = null;
	
	public function __construct($outputDir)
	{
		$this->outputDir = $outputDir;
	}
	
	public function visitDataModel($dataModel)
	{
		// Start off the class 
		$this->output  = "abstract class GoodMannersStore implements \\Good\\Manners\\Store \n";
		$this->output .= "{\n";
		$this->output .= '	private $validationToken;' . "\n";
		$this->output .= "	\n";
		$this->output .= "	public function __construct()\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->validationToken = new \\Good\\Manners\\ValidationToken();' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
		$this->output .= "	public function __destruct()\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->flush();' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
		$this->output .= '	abstract public function visitReferenceProperty($name, ' .
								'$datatypeName, $dirty, $null, \\Good\\Manners\\Storable $value = null);' . "\n";
		$this->output .= '	abstract public function visitTextProperty($name, $dirty, ' .
																	'$null, $value);' . "\n";
		$this->output .= '	abstract public function visitIntProperty($name, $dirty, ' .
																	'$null, $value);' . "\n";
		$this->output .= '	abstract public function visitFloatProperty($name, $dirty, ' .
																	'$null, $value);' . "\n";
		$this->output .= '	abstract public function visitDatetimeProperty($name, $dirty, ' .
																	'$null, $value);' . "\n";
		$this->output .= "	\n";
		$this->output .= '	protected function invalidate()' . "\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->validationToken->invalidate();' . "\n";
		$this->output .= '		$this->validationToken = new \\Good\\Manners\\ValidationToken();' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
	}
	
	public function visitDataType($dataType)
	{
		if ($this->firstDateType)
		{
			$this->firstDateType = false;
		}
		else
		{
			$this->finishDataType();
		}
		$name = $dataType->getName();
		$this->dataType = $name;
		$this->dataTypes[] = $name;
		
		// ucfirst: upper case first (php builtin)
		$this->output .= '	abstract protected function doModifyAny' . \ucfirst($name) . 
							'(\\Good\\Manners\\Condition $condition, ' . $name . ' $modifications);' . "\n";
		$this->output .= '	abstract protected function doGet' . \ucfirst($name) .
							'Collection(\\Good\\Manners\\Condition $condition, ' . $name . 
															'Resolver $resolver);' . "\n";
		$this->output .= "	\n";
		$this->output .= '	abstract protected function saveNew' . \ucfirst($name) . 
																's(array $entries);' . "\n";
		$this->output .= '	abstract protected function save' . \ucfirst($name) . 
															'Modifications(array $entries);' . "\n";
		$this->output .= '	abstract protected function save' . \ucfirst($name) . 
															'Deletions(array $entries);' . "\n";
		$this->output .= "	\n";
		
		$this->output .= '	private $dirty' . \ucfirst($name) . 's = array();' . "\n";
		$this->output .= "	\n";
		$this->output .= '	public function dirty' . \ucfirst($name) . 
												'(' . $name . ' $storable)' . "\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->dirty' . \ucfirst($name) . 's[] = $storable;' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
		$this->output .= '	public function insert' . \ucfirst($name) . 
												'(' . $name . ' $storable)' . "\n";
		$this->output .= "	{\n";
		$this->output .= '		$storable->setStore($this);' . "\n";
		$this->output .= '		$storable->setValidationToken($this->validationToken);' . "\n";
		$this->output .= "		\n";
		$this->output .= '		$this->dirty' . \ucfirst($name) . 's[] = $storable;' . "\n";
		$this->output .= "	}\n";
		$this->output .= "\n";
		$this->output .= '	public function modifyAny' . \ucfirst($name) .'(\\Good\\Manners\\Condition ' .
													'$condition, ' . $name . ' $modifications)' . "\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->flush();' . "\n";
		$this->output .= '		$this->invalidate();' . "\n";
		$this->output .= "		\n";
		$this->output .= '		$this->doModifyAny' . \ucfirst($name) .'($condition, $modifications);' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
		$this->output .= '	public function get' . \ucfirst($name) . 'Collection(\\Good\\Manners\\Condition ' .
													 '$condition, ' . $name . 'Resolver $resolver)' . "\n";
		$this->output .= "	{\n";
		$this->output .= '		$this->flush();' . "\n";
		$this->output .= '		return $this->doGet' . \ucfirst($name) . 
													'Collection($condition, $resolver);' . "\n";
		$this->output .= "	}\n";
		$this->output .= "	\n";
		
		$this->resolver  = "<?php\n";
		$this->resolver .= "\n";
		$this->resolver .= 'class ' . $name . 'Resolver extends \\Good\\Manners\\AbstractResolver' . "\n";
		$this->resolver .= "{\n";
		
		$this->resolverVisit  = '	public function resolverAccept' . 
												'(\\Good\\Manners\\ResolverVisitor $visitor)' . "\n";
		$this->resolverVisit .= "	{\n";
	}
	
	public function visitEnd()
	{
{'fraction_non_alphanumeric': 0.23571161748225625, 'fraction_numerical': 0.0, 'mean_word_length': 2.615462525320729, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 181, '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': '3804449', 'n_tokens_mistral': 4345, 'n_tokens_neox': 3727, 'n_words': 744}