<commit_before><?php

class NoteController extends BaseController {

	private $_view = 'note/';

	public function index()
	{
		return View::make('hello');
	}

	public function create()
	{
		$item = new Note;

		return View::make($this->_view.'edit',
			array(
				'title' => 'Add note',
				'item' => $item,
				'projects' => Project::lists('title', 'id'),
				'frameworks' => Framework::lists('title', 'id'),
			)
		);
	}

	public function edit($id)
	{
		$item = Note::find($id);

		return View::make($this->_view.'edit',
			array(
				'title' => 'Edit note',
				'item' => $item,
				'projects' => Project::lists('title', 'id'),
				'frameworks' => Framework::lists('title', 'id'),
			)
		);
	}

	public function show($id)
	{
		return Redirect::action('NoteController@edit', array('id' => $id));
	}

	public function store()
	{
		$rules = array(
			'title' => 'required',
		);
		$info = Input::all();
		$validation = Validator::make($info, $rules);

		if ($validation->fails())
		{
			return Redirect::action('NoteController@create')->withInput()->withErrors($validation->messages());
		}
		else
		{
			if (trim($info['project']) != '')
			{
				$project = Project::whereTitle(Str::slug($info['project']))->first();

				if (is_null($project))
				{
					$project = Project::create(array(
						'title' => Str::slug($info['project']),
					));
				}
			}
			elseif (isset($info['project_id']))
			{
				$project = Project::find($info['project_id']);
			}

			if (trim($info['framework']) != '')
			{
				$framework = Framework::whereTitle(Str::slug($info['framework']))->first();

				if (is_null($framework))
				{
					$framework = Framework::create(array(
						'title' => Str::slug($info['framework']),
					));
				}
			}
			elseif (isset($info['framework_id']))
			{
				$framework = Framework::find($info['framework_id']);
			}

			$item = Note::create(array(
				'title' => $info['title'],
				'description' => $info['description'],
				'commits' => $info['commits'],
				'files' => $info['files'],
				'minutes' => (int) $info['minutes'],
				'cost' => (int) $info['cost'],
				'reference' => $info['reference'],
			));

			$item->project()->associate($project);
			$item->framework()->associate($framework);
			$item->save();

			Session::flash('success', 'New note added');

			return Redirect::action('NoteController@edit', array('id' => $item->id));
		}
	}

	public function update()
	{
		$rules = array(
			'title' => 'required',
		);
		$info = Input::all();
		$validation = Validator::make($info, $rules);

		if ($validation->fails())
		{
			return Redirect::action('NoteController@edit', array('id' => $info['id']))->withInput()->withErrors($validation->messages());
		}
		else
		{
			$item = Note::find($info['id']);

			$item->title = $info['title'];
			$item->description = $info['description'];
			$item->commits = $info['commits'];
			$item->files = $info['files'];
			$item->minutes = (int) $info['minutes'];
			$item->cost = (int) $info['cost'];
			$item->reference = $info['reference'];

			if (trim($info['project']) != '')
			{
				$project = Project::whereTitle(Str::slug($info['project']))->first();

				if (is_null($project))
				{
					$project = Project::create(array(
						'title' => Str::slug($info['project']),
					));
				}
			}
			elseif (isset($info['project_id']))
			{
				$project = Project::find($info['project_id']);
			}

			if (trim($info['framework']) != '')
			{
				$framework = Framework::whereTitle(Str::slug($info['framework']))->first();

				if (is_null($framework))
				{
					$framework = Framework::create(array(
						'title' => Str::slug($info['framework']),
					));
				}
			}
			elseif (isset($info['framework_id']))
			{
				$framework = Framework::find($info['framework_id'])->first();
			}

			$item->project()->associate($project);<commit_msg>Make use of firstOrCreate instead<commit_after><?php

class NoteController extends BaseController {

	private $_view = 'note/';

	public function index()
	{
		return View::make('hello');
	}

	public function create()
	{
		$item = new Note;

		return View::make($this->_view.'edit',
			array(
				'title' => 'Add note',
				'item' => $item,
				'projects' => Project::lists('title', 'id'),
				'frameworks' => Framework::lists('title', 'id'),
			)
		);
	}

	public function edit($id)
	{
		$item = Note::find($id);

		return View::make($this->_view.'edit',
			array(
				'title' => 'Edit note',
				'item' => $item,
				'projects' => Project::lists('title', 'id'),
				'frameworks' => Framework::lists('title', 'id'),
			)
		);
	}

	public function show($id)
	{
		return Redirect::action('NoteController@edit', array('id' => $id));
	}

	public function store()
	{
		$rules = array(
			'title' => 'required',
		);
		$info = Input::all();
		$validation = Validator::make($info, $rules);

		if ($validation->fails())
		{
			return Redirect::action('NoteController@create')->withInput()->withErrors($validation->messages());
		}
		else
		{
			if (trim($info['project']) != '')
			{
				$project = Project::firstOrCreate(array('title' => Str::slug($info['project'])));
			}
			elseif (isset($info['project_id']))
			{
				$project = Project::find($info['project_id']);
			}

			if (trim($info['framework']) != '')
			{
				$framework = Framework::firstOrCreate(array('title' => Str::slug($info['framework'])));
			}
			elseif (isset($info['framework_id']))
			{
				$framework = Framework::find($info['framework_id']);
			}

			$item = Note::create(array(
				'title' => $info['title'],
				'description' => $info['description'],
				'commits' => $info['commits'],
				'files' => $info['files'],
				'minutes' => (int) $info['minutes'],
				'cost' => (int) $info['cost'],
				'reference' => $info['reference'],
			));

			$item->project()->associate($project);
			$item->framework()->associate($framework);
			$item->save();

			Session::flash('success', 'New note added');

			return Redirect::action('NoteController@edit', array('id' => $item->id));
		}
	}

	public function update()
	{
		$rules = array(
			'title' => 'required',
		);
		$info = Input::all();
		$validation = Validator::make($info, $rules);

		if ($validation->fails())
		{
			return Redirect::action('NoteController@edit', array('id' => $info['id']))->withInput()->withErrors($validation->messages());
		}
		else
		{
			$item = Note::find($info['id']);

			$item->title = $info['title'];
			$item->description = $info['description'];
			$item->commits = $info['commits'];
			$item->files = $info['files'];
			$item->minutes = (int) $info['minutes'];
			$item->cost = (int) $info['cost'];
			$item->reference = $info['reference'];

			if (trim($info['project']) != '')
			{
				$project = Project::firstOrCreate(array('title' => Str::slug($info['project'])));
			}
			elseif (isset($info['project_id']))
			{
				$project = Project::find($info['project_id']);
			}

			if (trim($info['framework']) != '')
			{
				$framework = Framework::firstOrCreate(array('title' => Str::slug($info['framework'])));
			}
			elseif (isset($info['framework_id']))
			{
				$framework = Framework::find($info['framework_id'])->first();
			}

			$item->project()->associate($project);
{'fraction_non_alphanumeric': 0.23809523809523808, 'fraction_numerical': 0.0, 'mean_word_length': 3.983251919050942, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 107, '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': '3291176', 'n_tokens_mistral': 2857, 'n_tokens_neox': 2344, 'n_words': 381}