First part of a large code cleanup commit.

This commit is contained in:
James Cole
2019-02-12 21:49:28 +01:00
parent b273af341c
commit e0d87aa11e
70 changed files with 336 additions and 354 deletions

View File

@@ -27,7 +27,6 @@ use Carbon\Carbon;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Tag;
@@ -38,8 +37,6 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
use Log;
use Throwable;
/**
* Trait AugumentData

View File

@@ -30,32 +30,6 @@ namespace FireflyIII\Support\Http\Controllers;
trait BasicDataSupport
{
/**
* Filters empty results from getBudgetPeriodReport.
*
* @param array $data
*
* @return array
*/
protected function filterPeriodReport(array $data): array // helper function for period overview.
{
/**
* @var int $entryId
* @var array $set
*/
foreach ($data as $entryId => $set) {
$sum = '0';
foreach ($set['entries'] as $amount) {
$sum = bcadd($amount, $sum);
}
$data[$entryId]['sum'] = $sum;
if (0 === bccomp('0', $sum)) {
unset($data[$entryId]);
}
}
return $data;
}
/**
* Sum up an array.
*
@@ -73,6 +47,33 @@ trait BasicDataSupport
return $sum;
}
/**
* Filters empty results from getBudgetPeriodReport.
*
* @param array $data
*
* @return array
*/
protected function filterPeriodReport(array $data): array // helper function for period overview.
{
/**
* @var int $entryId
* @var array $set
*/
foreach ($data as $entryId => $set) {
$sum = '0';
foreach ($set['entries'] as $amount) {
$sum = bcadd($amount, $sum);
}
$data[$entryId]['sum'] = $sum;
if (0 === bccomp('0', $sum)) {
unset($data[$entryId]);
}
}
return $data;
}
/**
* Find the ID in a given array. Return '0' of not there (amount).
*
@@ -83,10 +84,7 @@ trait BasicDataSupport
*/
protected function isInArray(array $array, int $entryId) // helper for data (math, calculations)
{
$result = '0';
if (isset($array[$entryId])) {
$result = $array[$entryId];
}
$result = $array[$entryId] ?? '0';
return $result;
}

View File

@@ -51,10 +51,7 @@ trait GetConfigurationData
E_ALL & ~E_NOTICE & ~E_STRICT => 'E_ALL & ~E_NOTICE & ~E_STRICT',
E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR => 'E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR',
];
$result = (string)$value;
if (isset($array[$value])) {
$result = $array[$value];
}
$result = $array[$value] ?? (string)$value;
return $result;
}
@@ -188,7 +185,7 @@ trait GetConfigurationData
$routeKey = '';
// user is on page with specific instructions:
if (\strlen($specificPage) > 0) {
if ('' !== $specificPage) {
$routeKey = str_replace('.', '_', $route);
$elements = config(sprintf('intro.%s', $routeKey . '_' . $specificPage));
if (\is_array($elements) && \count($elements) > 0) {

View File

@@ -351,7 +351,9 @@ trait PeriodOverview
/**
* This shows a period overview for a tag. It goes back in time and lists all relevant transactions and sums.
*
* @param Tag $tag
* @param Tag $tag
*
* @param Carbon $date
*
* @return Collection
*/

View File

@@ -305,8 +305,8 @@ trait RenderPartialViews
*/
protected function getCurrentTriggers(Rule $rule): array // get info from object and present.
{
$index = 0;
$triggers = [];
$index = 0;
$triggers = [];
// todo must be repos
$currentTriggers = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
/** @var RuleTrigger $entry */

View File

@@ -54,44 +54,6 @@ use Symfony\Component\HttpFoundation\ParameterBag;
*/
trait RequestInformation
{
/**
* Get info from old input.
*
* @param $array
* @param $old
*
* @return array
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function updateWithPrevious($array, $old): array // update object with new info
{
if (0 === \count($old) || !isset($old['transactions'])) {
return $array;
}
$old = $old['transactions'];
foreach ($old as $index => $row) {
if (isset($array[$index])) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$array[$index] = array_merge($array[$index], $row);
continue;
}
// take some info from first transaction, that should at least exist.
$array[$index] = $row;
$array[$index]['currency_id'] = $array[0]['currency_id'];
$array[$index]['currency_code'] = $array[0]['currency_code'] ?? '';
$array[$index]['currency_symbol'] = $array[0]['currency_symbol'] ?? '';
$array[$index]['foreign_amount'] = round($array[0]['foreign_destination_amount'] ?? '0', 12);
$array[$index]['foreign_currency_id'] = $array[0]['foreign_currency_id'];
$array[$index]['foreign_currency_code'] = $array[0]['foreign_currency_code'];
$array[$index]['foreign_currency_symbol'] = $array[0]['foreign_currency_symbol'];
}
return $array;
}
/**
* Create data-array from a journal.
*
@@ -104,7 +66,7 @@ trait RequestInformation
protected function arrayFromJournal(Request $request, TransactionJournal $journal): array // convert user input.
{
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$repository = app(JournalRepositoryInterface::class);
$sourceAccounts = $repository->getJournalSourceAccounts($journal);
$destinationAccounts = $repository->getJournalDestinationAccounts($journal);
$array = [
@@ -400,6 +362,44 @@ trait RequestInformation
return $attributes;
}
/**
* Get info from old input.
*
* @param $array
* @param $old
*
* @return array
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function updateWithPrevious($array, $old): array // update object with new info
{
if (0 === \count($old) || !isset($old['transactions'])) {
return $array;
}
$old = $old['transactions'];
foreach ($old as $index => $row) {
if (isset($array[$index])) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$array[$index] = array_merge($array[$index], $row);
continue;
}
// take some info from first transaction, that should at least exist.
$array[$index] = $row;
$array[$index]['currency_id'] = $array[0]['currency_id'];
$array[$index]['currency_code'] = $array[0]['currency_code'] ?? '';
$array[$index]['currency_symbol'] = $array[0]['currency_symbol'] ?? '';
$array[$index]['foreign_amount'] = round($array[0]['foreign_destination_amount'] ?? '0', 12);
$array[$index]['foreign_currency_id'] = $array[0]['foreign_currency_id'];
$array[$index]['foreign_currency_code'] = $array[0]['foreign_currency_code'];
$array[$index]['foreign_currency_symbol'] = $array[0]['foreign_currency_symbol'];
}
return $array;
}
/**
* Validate users new password.
*