Code cleanup for scrutinizer.

This commit is contained in:
James Cole 2017-11-25 08:54:52 +01:00
parent f2cf0ed446
commit f7b1168e7c
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
36 changed files with 53 additions and 179 deletions

View File

@ -105,7 +105,7 @@ final class Entry
*
* @return Entry
*/
public static function fromTransaction(Transaction $transaction): self
public static function fromTransaction(Transaction $transaction): Entry
{
$entry = new self();
$entry->journal_id = $transaction->journal_id;

View File

@ -168,8 +168,8 @@ class JournalCollector implements JournalCollectorInterface
$q1->where(
function (EloquentBuilder $q2) use ($amount) {
// amount < 0 and .amount > -$amount
$amount = bcmul($amount, '-1');
$q2->where('transactions.amount', '<', 0)->where('transactions.amount', '>', $amount);
$invertedAmount = bcmul($amount, '-1');
$q2->where('transactions.amount', '<', 0)->where('transactions.amount', '>', $invertedAmount);
}
)
->orWhere(
@ -196,8 +196,8 @@ class JournalCollector implements JournalCollectorInterface
$q1->where(
function (EloquentBuilder $q2) use ($amount) {
// amount < 0 and .amount < -$amount
$amount = bcmul($amount, '-1');
$q2->where('transactions.amount', '<', 0)->where('transactions.amount', '<', $amount);
$invertedAmount = bcmul($amount, '-1');
$q2->where('transactions.amount', '<', 0)->where('transactions.amount', '<', $invertedAmount);
}
)
->orWhere(

View File

@ -74,9 +74,9 @@ class LoginController extends Controller
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @param Request $request
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse
* @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response|void
*/
public function login(Request $request)
{
@ -109,9 +109,10 @@ class LoginController extends Controller
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @param Request $request
* @param CookieJar $cookieJar
*
* @return \Illuminate\Http\Response
* @return $this
*/
public function logout(Request $request, CookieJar $cookieJar)
{
@ -127,11 +128,10 @@ class LoginController extends Controller
* Show the application's login form.
*
* @param Request $request
* @param CookieJar $cookieJar
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function showLoginForm(Request $request, CookieJar $cookieJar)
public function showLoginForm(Request $request)
{
// check for presence of tables:
$hasTable = Schema::hasTable('users');
@ -166,6 +166,6 @@ class LoginController extends Controller
$email = $request->old('email');
$remember = $request->old('remember');
return view('auth.login', compact('allowRegistration', 'email', 'remember')); //->withCookie($cookie);
return view('auth.login', compact('allowRegistration', 'email', 'remember'));
}
}

View File

@ -85,7 +85,7 @@ class BudgetController extends Controller
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
$budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount);
if (0 === $amount) {
if (bccomp($amount,'0') === 0) {
$budgetLimit = null;
}

View File

@ -88,6 +88,7 @@ class BankController extends Controller
$remoteAccounts = array_keys($remoteAccounts);
$class = config(sprintf('firefly.import_pre.%s', $bank));
// get import file
unset($remoteAccounts, $class);
// get import config
}

View File

@ -1,90 +0,0 @@
<?php
/**
* TransactionController.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* 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\Controllers\Json;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Support\SingleCacheProperties;
use Illuminate\Http\Request;
use Response;
class TransactionController extends Controller
{
public function amounts(Request $request, JournalRepositoryInterface $repository)
{
$ids = $request->get('transactions');
$cache = new SingleCacheProperties;
$cache->addProperty('json-reconcile-amounts');
$cache->addProperty($ids);
if ($cache->has()) {
return Response::json($cache->get());
}
$totals = [];
// for each transaction, get amount(s)
foreach ($ids as $transactionId) {
$transaction = $repository->findTransaction(intval($transactionId));
$transactionType = $transaction->transactionJournal->transactionType->type;
// default amount:
$currencyId = $transaction->transaction_currency_id;
if (!isset($totals[$currencyId])) {
$totals[$currencyId] = [
'amount' => '0',
'currency' => $transaction->transactionCurrency,
'type' => $transactionType,
];
}
// add default amount:
$totals[$currencyId]['amount'] = bcadd($totals[$currencyId]['amount'], app('steam')->positive($transaction->amount));
// foreign amount:
if (null !== $transaction->foreign_amount) {
$currencyId = $transaction->foreign_currency_id;
if (!isset($totals[$currencyId])) {
$totals[$currencyId] = [
'amount' => '0',
'currency' => $transaction->foreignCurrency,
'type' => $transactionType,
];
}
// add foreign amount:
$totals[$currencyId]['amount'] = bcadd($totals[$currencyId]['amount'], app('steam')->positive($transaction->foreign_amount));
}
}
$entries = [];
foreach ($totals as $entry) {
$amount = $entry['amount'];
if (TransactionType::WITHDRAWAL === $entry['type']) {
$amount = bcmul($entry['amount'], '-1');
}
$entries[] = app('amount')->formatAnything($entry['currency'], $amount, false);
}
$result = ['amounts' => join(' / ', $entries)];
$cache->store($result);
return Response::json($result);
}
}

View File

@ -34,6 +34,7 @@ use FireflyIII\Models\Preference;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Hash;
use Illuminate\Contracts\Auth\Guard;
use Log;
use Preferences;
use Session;
@ -41,6 +42,8 @@ use View;
/**
* Class ProfileController.
*
* @method Guard guard()
*/
class ProfileController extends Controller
{

View File

@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers;
use FireflyIII\Support\CacheProperties;
use FireflyIII\Support\Search\SearchInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Response;
use View;
@ -70,8 +71,8 @@ class SearchController extends Controller
public function search(Request $request, SearchInterface $searcher)
{
$fullQuery = strval($request->get('query'));
$fullQuery = strval($request->get('query'));
$transactions = new Collection;
// cache
$cache = new CacheProperties;
$cache->addProperty('search');

View File

@ -143,7 +143,7 @@ class LinkController extends Controller
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function switch(LinkTypeRepositoryInterface $repository, TransactionJournalLink $link)
public function switchLink(LinkTypeRepositoryInterface $repository, TransactionJournalLink $link)
{
$repository->switchLink($link);

View File

@ -31,19 +31,6 @@ use Illuminate\Session\Middleware\StartSession;
*/
class StartFireflySession extends StartSession
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param Closure $next
*
* @return mixed
*/
// public function handle($request, Closure $next)
// {
// return parent::handle($request, $next); // defer to the right stuff
// }
/**
* Store the current URL for the request if necessary.
*

View File

@ -53,7 +53,7 @@ class TrustProxies extends Middleware
/**
* The trusted proxies for this application.
*
* @var array
* @var array|string
*/
protected $proxies;

View File

@ -115,7 +115,7 @@ class Account extends Model
*
* @return Account
*/
public static function routeBinder(self $value)
public static function routeBinder(Account $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {

View File

@ -56,7 +56,7 @@ class Attachment extends Model
*
* @return Attachment
*/
public static function routeBinder(self $value)
public static function routeBinder(Attachment $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {

View File

@ -64,7 +64,7 @@ class Bill extends Model
*
* @return Bill
*/
public static function routeBinder(self $value)
public static function routeBinder(Bill $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {

View File

@ -88,7 +88,7 @@ class Budget extends Model
*
* @return Budget
*/
public static function routeBinder(self $value)
public static function routeBinder(Budget $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {

View File

@ -87,7 +87,7 @@ class Category extends Model
*
* @return Category
*/
public static function routeBinder(self $value)
public static function routeBinder(Category $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {

View File

@ -65,7 +65,7 @@ class PiggyBank extends Model
*
* @return PiggyBank
*/
public static function routeBinder(self $value)
public static function routeBinder(PiggyBank $value)
{
if (auth()->check()) {
if (intval($value->account->user_id) === auth()->user()->id) {

View File

@ -53,7 +53,7 @@ class Rule extends Model
*
* @return Rule
*/
public static function routeBinder(self $value)
public static function routeBinder(Rule $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {

View File

@ -53,7 +53,7 @@ class RuleGroup extends Model
*
* @return RuleGroup
*/
public static function routeBinder(self $value)
public static function routeBinder(RuleGroup $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {

View File

@ -91,7 +91,7 @@ class Tag extends Model
*
* @return Tag
*/
public static function routeBinder(self $value)
public static function routeBinder(Tag $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {

View File

@ -257,4 +257,11 @@ trait FindAccountsTrait
return $account;
}
/**
* @param array $data
*
* @return Account
*/
abstract protected function storeAccount(array $data): Account;
}

View File

@ -487,7 +487,7 @@ class BillRepository implements BillRepositoryInterface
$wordMatch = $this->doWordMatch($matches, $description);
$amountMatch = $this->doAmountMatch($journal->amountPositive(), $bill->amount_min, $bill->amount_max);
// If both, update!
// when both, update!
if ($wordMatch && $amountMatch) {
$journal->bill()->associate($bill);
$journal->save();

View File

@ -210,7 +210,7 @@ interface BudgetRepositoryInterface
* @param Budget $budget
* @param Carbon $start
* @param Carbon $end
* @param int $amount
* @param string $amount
*
* @return BudgetLimit
*/

View File

@ -34,5 +34,6 @@ class NotificationFilter extends BunqObject
*/
public function __construct(array $data)
{
unset($data);
}
}

View File

@ -42,7 +42,6 @@ class FixerIO implements ExchangeRateInterface
{
$uri = sprintf('https://api.fixer.io/%s?base=%s&symbols=%s', $date->format('Y-m-d'), $fromCurrency->code, $toCurrency->code);
$statusCode = -1;
$body = '';
try {
$result = Requests::get($uri);
$statusCode = $result->status_code;

View File

@ -238,8 +238,6 @@ class Navigation
'1W' => trans('config.week_in_year'),
'week' => trans('config.week_in_year'),
'weekly' => trans('config.week_in_year'),
//'3M' => trans('config.quarter_of_year'),
//'quarter' => trans('config.quarter_of_year'),
'1M' => trans('config.month'),
'month' => trans('config.month'),
'monthly' => trans('config.month'),

View File

@ -22,7 +22,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Twig\Extension;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\Transaction as TransactionModel;
use FireflyIII\Models\TransactionJournal as JournalModel;
use FireflyIII\Models\TransactionType;
use FireflyIII\Support\SingleCacheProperties;
@ -48,7 +48,7 @@ class TransactionJournal extends Twig_Extension
$transactions = $journal->transactions()->where('amount', '>', 0)->get();
$totals = [];
$type = $journal->transactionType->type;
/** @var Transaction $transaction */
/** @var TransactionModel $transaction */
foreach ($transactions as $transaction) {
$currencyId = $transaction->transaction_currency_id;
$currency = $transaction->transactionCurrency;

View File

@ -18,6 +18,8 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** global: overviewUri, transactionsUri, indexUri,accounting */
var balanceDifference = 0;
var difference = 0;
var selectedAmount = 0;
@ -101,14 +103,11 @@ function storeReconcile() {
function checkReconciledBox(e) {
var el = $(e.target);
var amount = parseFloat(el.val());
console.log('Amount is ' + amount);
// if checked, add to selected amount
if (el.prop('checked') === true && el.data('younger') === false) {
console.log("Sum is: " + selectedAmount + " - " + amount + " = " + (selectedAmount - amount));
selectedAmount = selectedAmount - amount;
}
if (el.prop('checked') === false && el.data('younger') === false) {
console.log("Sum is: " + selectedAmount + " + " + amount + " = " + (selectedAmount + amount));
selectedAmount = selectedAmount + amount;
}
difference = balanceDifference - selectedAmount;

View File

@ -18,8 +18,7 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** global: spent, budgeted, available, currencySymbol, budgetIndexUri, updateIncomeUri, periodStart, periodEnd, budgetAmountUri, accounting */
/** global: infoIncomeUri, spent, budgeted, available, currencySymbol, budgetIndexUri, updateIncomeUri, periodStart, periodEnd, budgetAmountUri, accounting */
/**
*
*/
@ -150,9 +149,6 @@ function updateBudgetedAmounts(e) {
link.attr('href', 'budgets/show/' + id + '/' + data.limit);
}
});
return;
}
/**

View File

@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** global: Chart, defaultChartOptions, accounting, defaultPieOptions, noDataForChart */
/** global: Chart, defaultChartOptions, accounting, defaultPieOptions, noDataForChart, todayText */
var allCharts = {};
@ -131,7 +131,6 @@ function lineChart(URI, container) {
function lineChartWithDay(URI, container, today) {
"use strict";
console.log('in lineChartWithDay');
var colorData = true;
var options = $.extend(true, {}, defaultChartOptions);
var chartType = 'line';
@ -342,7 +341,6 @@ function drawAChart(URI, container, chartType, options, colorData, today) {
};
if (today >= 0) {
chartOpts.lineAtIndex.push(today - 1);
console.log('push opt');
}
allCharts[container] = new Chart(ctx, chartOpts);
}

View File

@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** global: moment, dateRangeMeta,dateRangeConfig, accountingConfig, accounting, currencySymbol, mon_decimal_point, frac_digits, showFullList, showOnlyTop, mon_thousands_sep */
/** global: moment, token, dateRangeMeta,dateRangeConfig, accountingConfig, accounting, currencySymbol, mon_decimal_point, frac_digits, showFullList, showOnlyTop, mon_thousands_sep */
$(function () {

View File

@ -18,7 +18,7 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** global: accountFrontpageUri, token, billCount, accountExpenseUri, accountRevenueUri */
/** global: accountFrontpageUri, today, piggyInfoUri, token, billCount, accountExpenseUri, accountRevenueUri */
$(function () {
"use strict";

View File

@ -18,7 +18,7 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** global: routeForTour, routeStepsUri, routeForFinishedTour, forceDemoOff */
/** global: routeForTour, token, routeStepsUri, routeForFinishedTour, forceDemoOff */
$(function () {
"use strict";

View File

@ -18,7 +18,7 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** global: zoomLevel, latitude, longitude, google, doPlaceMarker */
/** global: zoomLevel, latitude, longitude, L, mapboxToken, doPlaceMarker */
/*
Some vars as prep for the map:

View File

@ -156,29 +156,6 @@ function countChecked() {
}
}
function getAmounts() {
$('.mass_reconcile span').html(reconcile_selected_txt + ' (<i class="fa fa-spinner fa-spin "></i>)');
var checked = $('.select_all_single:checked');
var ids = [];
$.each(checked, function (i, v) {
ids.push(parseInt($(v).data('transaction')));
});
// go to specially crafted URL:
var bases = document.getElementsByTagName('base');
var baseHref = null;
if (bases.length > 0) {
baseHref = bases[0].href;
}
$.getJSON(baseHref + 'json/transactions/amount', {transactions: ids}).done(function (data) {
$('.mass_reconcile span').text(reconcile_selected_txt + ' (' + data.amounts + ')');
console.log(data);
});
return;
}
/**
*
*/

View File

@ -473,9 +473,6 @@ Route::group(
// frontpage
Route::get('frontpage/piggy-banks', ['uses' => 'Json\FrontpageController@piggyBanks', 'as' => 'fp.piggy-banks']);
// amount reconciliation
Route::get('transactions/amount', ['uses' => 'Json\TransactionController@amounts', 'as' => 'transactions.amounts']);
// currency conversion:
Route::get('rate/{fromCurrencyCode}/{toCurrencyCode}/{date}', ['uses' => 'Json\ExchangeController@getRate', 'as' => 'rate']);
@ -774,7 +771,7 @@ Route::group(
Route::post('store/{tj}', ['uses' => 'LinkController@store', 'as' => 'store']);
Route::get('delete/{journalLink}', ['uses' => 'LinkController@delete', 'as' => 'delete']);
Route::get('switch/{journalLink}', ['uses' => 'LinkController@switch', 'as' => 'switch']);
Route::get('switch/{journalLink}', ['uses' => 'LinkController@switchLink', 'as' => 'switch']);
Route::post('destroy/{journalLink}', ['uses' => 'LinkController@destroy', 'as' => 'destroy']);
}