<commit_before><?php
/**
 * SplitJournalFormRequest.php
 * Copyright (c) 2017 <EMAIL>
 *
 * This file is part of Firefly III.
 *
 * Firefly III is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Firefly III is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
 */
declare(strict_types=1);

namespace FireflyIII\Http\Requests;

use Illuminate\Validation\Validator;

/**
 * Class SplitJournalFormRequest.
 */
class SplitJournalFormRequest extends Request
{
    /**
     * @return bool
     */
    public function authorize(): bool
    {
        // Only allow logged in users
        return auth()->check();
    }

    /**
     * @return array
     */
    public function getAll(): array
    {
        $data = [
            'description'     => $this->string('journal_description'),
            'type'            => $this->string('what'),
            'date'            => $this->date('date'),
            'tags'            => explode(',', $this->string('tags')),
            'bill_id'         => null,
            'bill_name'       => null,
            'piggy_bank_id'   => null,
            'piggy_bank_name' => null,
            'notes'           => $this->string('notes'),
            'transactions'    => [],
        ];
        // switch type to get correct source / destination info:
        $sourceId        = null;
        $sourceName      = null;
        $destinationId   = null;
        $destinationName = null;

        foreach ($this->get('transactions') as $index => $transaction) {
            switch ($data['type']) {
                case 'withdrawal':
                    $sourceId        = $this->integer('journal_source_account_id');
                    $destinationName = $transaction['destination_name'] ?? '';
                    break;
                case 'deposit':
                    $sourceName    = $transaction['source_name'] ?? '';
                    $destinationId = $this->integer('journal_destination_account_id');
                    break;
                case 'transfer':
                    $sourceId      = $this->integer('journal_source_account_id');
                    $destinationId = $this->integer('journal_destination_account_id');
                    break;
            }
            $foreignAmount          = $transaction['foreign_amount'] ?? null;
            $foreignCurrencyId      = (int)($transaction['foreign_currency_id'] ?? 0.0);
            $set                    = [
                'source_id'             => $sourceId,
                'source_name'           => $sourceName,
                'destination_id'        => $destinationId,
                'destination_name'      => $destinationName,
                'foreign_amount'        => $foreignAmount,
                'foreign_currency_id'   => $foreignCurrencyId,
                'foreign_currency_code' => null,
                'reconciled'            => false,
                'identifier'            => $index,
                'currency_id'           => $this->integer('journal_currency_id'),
                'currency_code'         => null,
                'description'           => $transaction['transaction_description'] ?? '',
                'amount'                => $transaction['amount'],
                'budget_id'             => (int)($transaction['budget_id'] ?? 0.0),<commit_msg>Prevent index error<commit_after><?php
/**
 * SplitJournalFormRequest.php
 * Copyright (c) 2017 <EMAIL>
 *
 * This file is part of Firefly III.
 *
 * Firefly III is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Firefly III is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
 */
declare(strict_types=1);

namespace FireflyIII\Http\Requests;

use Illuminate\Validation\Validator;

/**
 * Class SplitJournalFormRequest.
 */
class SplitJournalFormRequest extends Request
{
    /**
     * @return bool
     */
    public function authorize(): bool
    {
        // Only allow logged in users
        return auth()->check();
    }

    /**
     * @return array
     */
    public function getAll(): array
    {
        $data = [
            'description'     => $this->string('journal_description'),
            'type'            => $this->string('what'),
            'date'            => $this->date('date'),
            'tags'            => explode(',', $this->string('tags')),
            'bill_id'         => null,
            'bill_name'       => null,
            'piggy_bank_id'   => null,
            'piggy_bank_name' => null,
            'notes'           => $this->string('notes'),
            'transactions'    => [],
        ];
        // switch type to get correct source / destination info:
        $sourceId        = null;
        $sourceName      = null;
        $destinationId   = null;
        $destinationName = null;

        foreach ($this->get('transactions') as $index => $transaction) {
            switch ($data['type']) {
                case 'withdrawal':
                    $sourceId        = $this->integer('journal_source_account_id');
                    $destinationName = $transaction['destination_name'] ?? '';
                    break;
                case 'deposit':
                    $sourceName    = $transaction['source_name'] ?? '';
                    $destinationId = $this->integer('journal_destination_account_id');
                    break;
                case 'transfer':
                    $sourceId      = $this->integer('journal_source_account_id');
                    $destinationId = $this->integer('journal_destination_account_id');
                    break;
            }
            $foreignAmount          = $transaction['foreign_amount'] ?? null;
            $foreignCurrencyId      = (int)($transaction['foreign_currency_id'] ?? 0.0);
            $set                    = [
                'source_id'             => $sourceId,
                'source_name'           => $sourceName,
                'destination_id'        => $destinationId,
                'destination_name'      => $destinationName,
                'foreign_amount'        => $foreignAmount,
                'foreign_currency_id'   => $foreignCurrencyId,
                'foreign_currency_code' => null,
                'reconciled'            => false,
                'identifier'            => $index,
                'currency_id'           => $this->integer('journal_currency_id'),
                'currency_code'         => null,
                'description'           => $transaction['transaction_description'] ?? '',
                'amount'                => $transaction['amount'] ?? '',
                'budget_id'             => (int)($transaction['budget_id'] ?? 0.0),
{'fraction_non_alphanumeric': 0.12003138075313807, 'fraction_numerical': 0.002615062761506276, 'mean_word_length': 1.7037822552138564, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6637401', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1879, 'n_words': 487}