<commit_before><?php

namespace ReliQArts\Mardin\Http\Controllers;

use Carbon\Carbon;
use League\Fractal;
use Illuminate\Http\Request;
use ReliQArts\Mardin\Contracts\User;
use ReliQArts\Mardin\Contracts\Thread;
use ReliQArts\Mardin\Contracts\Message;
use ReliQArts\Mardin\Events\NewMessage;
// use ReliQArts\Mardin\Events\NewMessage;
use ReliQArts\Mardin\Contracts\Participant;
use Illuminate\Routing\Controller as BaseController;
use ReliQArts\Mardin\Transformers\ThreadTransformer;
use ReliQArts\Mardin\Transformers\MessageTransformer;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class MessagesController extends BaseController
{
    use AuthorizesRequests, ValidatesRequests;

    /**
     * Thread model.
     * @var Thread
     */
    protected $threads;

    /**
     * Message model.
     * @var Message
     */
    protected $messages;

    /**
     * Participant model.
     * @var Participant
     */
    protected $participants;

    /**
     * User model.
     * @var User
     */
    protected $users;

    /**
     * Fractal manager instance.
     * @var Fractal\Manager
     */
    protected $fractal;

    /**
     * Constructor.
     */
    public function __construct(Thread $threads, Message $messages, User $users, Participant $participants)
    {
        $this->threads = $threads;
        $this->messages = $messages;
        $this->users = $users;
        $this->participants = $participants;
        $this->fractal = new Fractal\Manager;
    }

    /**
     * Show all of the message threads to the user.
     *
     * @return mixed
     */
    public function index()
    {
        $this->authorize('receive', resolve(Message::class));

        $currentUserId = auth()->user()->id;
        $title = 'Inbox';

        // All threads that user is participating in
        $threads = $this->threads->forUser($currentUserId)->get();

        return view(config('mardin.views.wrappers.index'), compact('threads', 'currentUserId', 'title'));
    }

    /**
     * Shows a message thread.
     *
     * @param Thread $thread
     * @return mixed
     */
    public function show(Thread $thread)
    {
        $this->authorize('receive', resolve(Message::class));

        // don't show the current user in list
        $userId = auth()->user()->id;
        $otherUsersIds = array_except($thread->participantsUserIds(), [$userId]);
        $users = $this->users->whereIn('id', $otherUsersIds)->get();
        $title = "{$thread->subject} &mdash; Inbox";

        if (!$users->count()) {
            $errorMessage = 'Could not load thread. Participants error.';
            return redirect()->back()->with([
                'message' => $errorMessage,
                'error' => $errorMessage,
                'status' => $errorMessage,
            ]);
        }

        $thread->markAsRead($userId);
        unset($thread->deleted_at);

        return view(config('mardin.views.wrappers.show'), compact('thread', 'users', 'title'));
    }

    /**
     * Creates a new message thread.
     *
     * @return mixed
     */
    public function create(Request $request)
    {
        $this->authorize('send', resolve(Message::class));
<commit_msg>Apply fixes from StyleCI (#10)<commit_after><?php

namespace ReliQArts\Mardin\Http\Controllers;

use Carbon\Carbon;
use League\Fractal;
use Illuminate\Http\Request;
use ReliQArts\Mardin\Contracts\User;
use ReliQArts\Mardin\Contracts\Thread;
use ReliQArts\Mardin\Contracts\Message;
use ReliQArts\Mardin\Events\NewMessage;
// use ReliQArts\Mardin\Events\NewMessage;
use ReliQArts\Mardin\Contracts\Participant;
use Illuminate\Routing\Controller as BaseController;
use ReliQArts\Mardin\Transformers\ThreadTransformer;
use ReliQArts\Mardin\Transformers\MessageTransformer;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class MessagesController extends BaseController
{
    use AuthorizesRequests, ValidatesRequests;

    /**
     * Thread model.
     * @var Thread
     */
    protected $threads;

    /**
     * Message model.
     * @var Message
     */
    protected $messages;

    /**
     * Participant model.
     * @var Participant
     */
    protected $participants;

    /**
     * User model.
     * @var User
     */
    protected $users;

    /**
     * Fractal manager instance.
     * @var Fractal\Manager
     */
    protected $fractal;

    /**
     * Constructor.
     */
    public function __construct(Thread $threads, Message $messages, User $users, Participant $participants)
    {
        $this->threads = $threads;
        $this->messages = $messages;
        $this->users = $users;
        $this->participants = $participants;
        $this->fractal = new Fractal\Manager;
    }

    /**
     * Show all of the message threads to the user.
     *
     * @return mixed
     */
    public function index()
    {
        $this->authorize('receive', resolve(Message::class));

        $currentUserId = auth()->user()->id;
        $title = 'Inbox';

        // All threads that user is participating in
        $threads = $this->threads->forUser($currentUserId)->get();

        return view(config('mardin.views.wrappers.index'), compact('threads', 'currentUserId', 'title'));
    }

    /**
     * Shows a message thread.
     *
     * @param Thread $thread
     * @return mixed
     */
    public function show(Thread $thread)
    {
        $this->authorize('receive', resolve(Message::class));

        // don't show the current user in list
        $userId = auth()->user()->id;
        $otherUsersIds = array_except($thread->participantsUserIds(), [$userId]);
        $users = $this->users->whereIn('id', $otherUsersIds)->get();
        $title = "{$thread->subject} &mdash; Inbox";

        if (! $users->count()) {
            $errorMessage = 'Could not load thread. Participants error.';

            return redirect()->back()->with([
                'message' => $errorMessage,
                'error' => $errorMessage,
                'status' => $errorMessage,
            ]);
        }

        $thread->markAsRead($userId);
        unset($thread->deleted_at);

        return view(config('mardin.views.wrappers.show'), compact('thread', 'users', 'title'));
    }

    /**
     * Creates a new message thread.
     *
     * @return mixed
     */
    public function create(Request $request)
    {
        $this->authorize('send', resolve(Message::class));

{'fraction_non_alphanumeric': 0.13862760215882808, 'fraction_numerical': 0.00030840400925212025, 'mean_word_length': 2.5269168026101143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '5515994', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1938, 'n_words': 400}