<commit_before><?php

namespace FluxBB\Controllers;

use FluxBB\Models\Post;
use FluxBB\Repositories\Topics;
use FluxBB\Services\CreateReply;
use FluxBB\Services\CreateReplyObserver;
use Illuminate\Support\MessageBag;
use Auth;
use Input;
use Redirect;

class PostsController extends BaseController implements
    CreateReplyObserver
{
    public function postReply($tid)
    {
        $topic = $this->topics->find($tid); // TODO: 404?

        $service = new CreateReply($this, $this->topics);
        return $service->createReply($topic, Auth::user(), Input::get('req_message'));
    }

    public function replyCreated(Post $post)
    {
        return Redirect::route('viewpost', array('id' => $post->id));
    }

    public function replyValidationFailed(Post $post, MessageBag $errors)
    {
        return Redirect::route('posting@reply', array($post->topic_id))
                       ->withInput()
                       ->withErrors($errors);
    }
}<commit_msg>Throw exception if topic cannot be found.<commit_after><?php

namespace FluxBB\Controllers;

use FluxBB\Models\Post;
use FluxBB\Repositories\Topics;
use FluxBB\Services\CreateReply;
use FluxBB\Services\CreateReplyObserver;
use Illuminate\Support\MessageBag;
use Auth;
use Input;
use Redirect;

class PostsController extends BaseController implements
    CreateReplyObserver
{
    public function postReply($tid)
    {
        $topic = $this->topics->findOrFail($tid);

        $service = new CreateReply($this, $this->topics);
        return $service->createReply($topic, Auth::user(), Input::get('req_message'));
    }

    public function replyCreated(Post $post)
    {
        return Redirect::route('viewpost', array('id' => $post->id));
    }

    public function replyValidationFailed(Post $post, MessageBag $errors)
    {
        return Redirect::route('posting@reply', array($post->topic_id))
                       ->withInput()
                       ->withErrors($errors);
    }
}
{'fraction_non_alphanumeric': 0.1289500509683996, 'fraction_numerical': 0.0015290519877675841, 'mean_word_length': 3.3719376391982183, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '3095243', 'n_tokens_mistral': 573, 'n_tokens_neox': 564, 'n_words': 123}