<commit_before><?php

use Firefly\Helper\Controllers\AccountInterface as AI;
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;

/**
 * Class AccountController
 *
 * @SuppressWarnings(PHPMD.CamelCasePropertyName)
 */
class AccountController extends \BaseController
{

    protected $_repository;
    protected $_accounts;

    /**
     * @param ARI $repository
     * @param AI  $accounts
     */
    public function __construct(ARI $repository, AI $accounts)
    {
        $this->_accounts   = $accounts;
        $this->_repository = $repository;
        View::share('mainTitleIcon', 'fa-credit-card');
        View::share('title', 'Accounts');
    }

    /**
     * @return \Illuminate\View\View
     */
    public function create($what)
    {
        View::share('subTitleIcon', 'fa-money');

        return View::make('accounts.create')->with('subTitle', 'Create a new ' . $what . ' account')->with(
            'what', $what
        );
    }

    /**
     * @return $this
     */
    public function asset()
    {
        View::share('subTitleIcon','fa-money');

        $accounts = $this->_repository->getOfTypes(['Asset account', 'Default account']);

        return View::make('accounts.asset')->with('subTitle', 'Asset accounts')->with(
            'accounts', $accounts
        );
    }

    /**
     * @return $this
     */
    public function expense()
    {
        View::share('subTitleIcon','fa-shopping-cart');

        $accounts = $this->_repository->getOfTypes(['Expense account', 'Beneficiary account']);

        return View::make('accounts.expense')->with('subTitle', 'Expense accounts')->with(
            'accounts', $accounts
        );
    }

    /**
     * @return $this
     */
    public function revenue()
    {
        View::share('subTitleIcon','fa-download');

        $accounts = $this->_repository->getOfTypes(['Revenue account']);

        return View::make('accounts.revenue')->with('subTitle', 'Revenue accounts')->with(
            'accounts', $accounts
        );
    }

    /**
     * @param Account $account
     *
     * @return $this
     */
    public function delete(Account $account)
    {
        return View::make('accounts.delete')->with('account', $account)
            ->with('title', 'Accounts')->with(
                'subTitle', 'Delete ' . strtolower($account->accountType->type) . ' "' . $account->name . '"'
            );
    }

    /**
     * @param Account $account
     *
     * @return $this|\Illuminate\Http\RedirectResponse
     */
    public function destroy(Account $account)
    {
        $type = $account->accountType->type;
        $this->_repository->destroy($account);
        Session::flash('success', 'The account was deleted.');
        switch ($type) {
            case 'Asset account':
            case 'Default account':
                return Redirect::route('accounts.asset');
                break;
            case 'Expense account':
            case 'Beneficiary account':
                return Redirect::route('accounts.expense');
                break;
            case 'Revenue account':
                return Redirect::route('accounts.revenue');
                break;
        }


    }

    /**
     * @param Account $account
     *
     * @return $this
     */
    public function edit(Account $account)
    {
        $openingBalance = $this->_accounts->openingBalanceTransaction($account);
        return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)
            ->with('title', 'Accounts')
            ->with('subTitle', 'Edit ' . strtolower($account->accountType->type) . ' "' . $account->name . '"');
    }

    /**
     * @return $this
     */
    public function index()
    {
        return View::make('error')->with('message', 'This view has been disabled');
//        $accounts = $this->_repository->get();
//        $set      = [
//            'personal'      => [],
//            'beneficiaries' => []
//        ];
//        foreach ($accounts as $account) {
//            switch ($account->accounttype->type) {
//                case 'Default account':
//                    $set['personal'][] = $account;
//                    break;
//                case 'Beneficiary account':
//                    $set['beneficiaries'][] = $account;
//                    break;
//            }
//        }
//
//        return View::make('accounts.index')->with('accounts', $set)->with('title', 'All your accounts');
    }

    /**
     * @param Account $account
     *
     * @return $this
     */
    public function show(Account $account)
    {
        $data = $this->_accounts->show($account, 40);

        return View::make('accounts.show')->with('account', $account)->with('show', $data)->with(
            'subTitle',
            'Details for ' . strtolower($account->accountType->type) . ' "' . $account->name . '"'
        )->with('title', 'Accounts');
    }

    /**
     * @return $this|\Illuminate\Http\RedirectResponse
     */
    public function store()
    {

        $data         = Input::all();
        $data['what'] = isset($data['what']) && $data['what'] != '' ? $data['what'] : 'asset';<commit_msg>Cleanup account controller.<commit_after><?php

use Firefly\Helper\Controllers\AccountInterface as AI;
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;

/**
 * Class AccountController
 *
 * @SuppressWarnings(PHPMD.CamelCasePropertyName)
 */
class AccountController extends \BaseController
{

    protected $_repository;
    protected $_accounts;

    /**
     * @param ARI $repository
     * @param AI  $accounts
     */
    public function __construct(ARI $repository, AI $accounts)
    {
        $this->_accounts   = $accounts;
        $this->_repository = $repository;
        View::share('mainTitleIcon', 'fa-credit-card');
        View::share('title', 'Accounts');
    }

    /**
     * @return \Illuminate\View\View
     */
    public function create($what)
    {
        View::share('subTitleIcon', 'fa-money');

        return View::make('accounts.create')->with('subTitle', 'Create a new ' . $what . ' account')->with(
            'what', $what
        );
    }

    /**
     * @return $this
     */
    public function asset()
    {
        View::share('subTitleIcon','fa-money');

        $accounts = $this->_repository->getOfTypes(['Asset account', 'Default account']);

        return View::make('accounts.asset')->with('subTitle', 'Asset accounts')->with(
            'accounts', $accounts
        );
    }

    /**
     * @return $this
     */
    public function expense()
    {
        View::share('subTitleIcon','fa-shopping-cart');

        $accounts = $this->_repository->getOfTypes(['Expense account', 'Beneficiary account']);

        return View::make('accounts.expense')->with('subTitle', 'Expense accounts')->with(
            'accounts', $accounts
        );
    }

    /**
     * @return $this
     */
    public function revenue()
    {
        View::share('subTitleIcon','fa-download');

        $accounts = $this->_repository->getOfTypes(['Revenue account']);

        return View::make('accounts.revenue')->with('subTitle', 'Revenue accounts')->with(
            'accounts', $accounts
        );
    }

    /**
     * @param Account $account
     *
     * @return $this
     */
    public function delete(Account $account)
    {
        return View::make('accounts.delete')->with('account', $account)
            ->with(
                'subTitle', 'Delete ' . strtolower($account->accountType->type) . ' "' . $account->name . '"'
            );
    }

    /**
     * @param Account $account
     *
     * @return $this|\Illuminate\Http\RedirectResponse
     */
    public function destroy(Account $account)
    {
        $type = $account->accountType->type;
        $this->_repository->destroy($account);
        Session::flash('success', 'The account was deleted.');
        switch ($type) {
            case 'Asset account':
            case 'Default account':
                return Redirect::route('accounts.asset');
                break;
            case 'Expense account':
            case 'Beneficiary account':
                return Redirect::route('accounts.expense');
                break;
            case 'Revenue account':
                return Redirect::route('accounts.revenue');
                break;
        }


    }

    /**
     * @param Account $account
     *
     * @return $this
     */
    public function edit(Account $account)
    {
        $openingBalance = $this->_accounts->openingBalanceTransaction($account);
        return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)

            ->with('subTitle', 'Edit ' . strtolower($account->accountType->type) . ' "' . $account->name . '"');
    }

    /**
     * @return $this
     */
    public function index()
    {
        return View::make('error')->with('message', 'This view has been disabled');
//        $accounts = $this->_repository->get();
//        $set      = [
//            'personal'      => [],
//            'beneficiaries' => []
//        ];
//        foreach ($accounts as $account) {
//            switch ($account->accounttype->type) {
//                case 'Default account':
//                    $set['personal'][] = $account;
//                    break;
//                case 'Beneficiary account':
//                    $set['beneficiaries'][] = $account;
//                    break;
//            }
//        }
//
//        return View::make('accounts.index')->with('accounts', $set)->with('title', 'All your accounts');
    }

    /**
     * @param Account $account
     *
     * @return $this
     */
    public function show(Account $account)
    {
        $data = $this->_accounts->show($account, 40);

        return View::make('accounts.show')->with('account', $account)->with('show', $data)->with(
            'subTitle',
            'Details for ' . strtolower($account->accountType->type) . ' "' . $account->name . '"'
        );
    }

    /**
     * @return $this|\Illuminate\Http\RedirectResponse
     */
    public function store()
    {

        $data         = Input::all();
        $data['what'] = isset($data['what']) && $data['what'] != '' ? $data['what'] : 'asset';
{'fraction_non_alphanumeric': 0.17165124208475402, 'fraction_numerical': 0.0003896736483195324, 'mean_word_length': 2.0247495580436063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 106, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4107570', 'n_tokens_mistral': 2907, 'n_tokens_neox': 2828, 'n_words': 522}