mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 20:16:22 +00:00
Clean up code and comments.
This commit is contained in:
@@ -62,15 +62,6 @@ class RemoteUserGuard implements Guard
|
||||
$this->user = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function viaRemember(): bool
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -189,4 +180,13 @@ class RemoteUserGuard implements Guard
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
throw new FireflyException('Did not implement RemoteUserGuard::validate()');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function viaRemember(): bool
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Chart\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||
|
@@ -828,6 +828,14 @@ class ExportDataGenerator
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
@@ -997,6 +1005,14 @@ class ExportDataGenerator
|
||||
return implode(',', $smol);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function has(mixed $key): mixed
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $end
|
||||
*/
|
||||
@@ -1084,20 +1100,4 @@ class ExportDataGenerator
|
||||
{
|
||||
$this->start = $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function has(mixed $key): mixed
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Facades;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
|
||||
* Class AccountForm.
|
||||
*
|
||||
*/
|
||||
|
@@ -29,7 +29,6 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
|
||||
* Class Amount.
|
||||
*
|
||||
* @method string formatAnything(TransactionCurrency $format, string $amount, bool $coloured = true)
|
||||
|
@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Facades;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
|
||||
* Class CurrencyForm.
|
||||
*
|
||||
*/
|
||||
|
@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Facades;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
|
||||
* Class ExpandedForm.
|
||||
*/
|
||||
class ExpandedForm extends Facade
|
||||
|
@@ -27,7 +27,6 @@ use FireflyIII\Models\Configuration;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
|
||||
* Class FireflyConfig.
|
||||
* @method null|Configuration get($name, $default = null)
|
||||
* @method Configuration set(string $name, $value)
|
||||
|
@@ -27,7 +27,6 @@ use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
|
||||
* Class Navigation.
|
||||
*
|
||||
* @method Carbon addPeriod(Carbon $theDate, string $repeatFreq, int $skip)
|
||||
|
@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Facades;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
|
||||
* Class PiggyBankForm.
|
||||
*
|
||||
*/
|
||||
|
@@ -29,7 +29,6 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
|
||||
* Class Preferences.
|
||||
*
|
||||
* @method Collection beginsWith(User $user, string $search)
|
||||
|
@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Facades;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
|
||||
* Class RuleForm.
|
||||
*
|
||||
*/
|
||||
|
@@ -74,60 +74,6 @@ trait ConvertsExchangeRates
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a sum of entries, get the exchange rate to the native currency of
|
||||
* the user.
|
||||
* @param array $entries
|
||||
* @return array
|
||||
*/
|
||||
public function cerSum(array $entries): array
|
||||
{
|
||||
if (null === $this->enabled) {
|
||||
$this->getPreference();
|
||||
}
|
||||
|
||||
// if false, return the same array without conversion info
|
||||
if (false === $this->enabled) {
|
||||
$return = [];
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$entry['converted'] = false;
|
||||
$return[] = $entry;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/** @var TransactionCurrency $native */
|
||||
$native = app('amount')->getDefaultCurrency();
|
||||
$return = [];
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$currency = $this->getCurrency((int)$entry['id']);
|
||||
if ($currency->id !== $native->id) {
|
||||
$amount = $this->convertAmount($entry['sum'], $currency, $native);
|
||||
$entry['converted'] = true;
|
||||
$entry['native_sum'] = $amount;
|
||||
$entry['native_id'] = (string)$native->id;
|
||||
$entry['native_name'] = $native->name;
|
||||
$entry['native_symbol'] = $native->symbol;
|
||||
$entry['native_code'] = $native->code;
|
||||
$entry['native_decimal_places'] = $native->decimal_places;
|
||||
}
|
||||
if ($currency->id === $native->id) {
|
||||
$entry['converted'] = false;
|
||||
$entry['native_sum'] = $entry['sum'];
|
||||
$entry['native_id'] = (string)$native->id;
|
||||
$entry['native_name'] = $native->name;
|
||||
$entry['native_symbol'] = $native->symbol;
|
||||
$entry['native_code'] = $native->code;
|
||||
$entry['native_decimal_places'] = $native->decimal_places;
|
||||
}
|
||||
$return[] = $entry;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -149,15 +95,6 @@ trait ConvertsExchangeRates
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function convertAmount(string $amount, TransactionCurrency $from, TransactionCurrency $to, ?Carbon $date = null): string
|
||||
{
|
||||
Log::debug(sprintf('Converting %s from %s to %s', $amount, $from->code, $to->code));
|
||||
$date = $date ?? today(config('app.timezone'));
|
||||
$rate = $this->getRate($from, $to, $date);
|
||||
|
||||
return bcmul($amount, $rate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $from
|
||||
* @param TransactionCurrency $to
|
||||
@@ -260,4 +197,67 @@ trait ConvertsExchangeRates
|
||||
Log::debug(sprintf('No rate for %s to EUR.', $currency->code));
|
||||
return '0';
|
||||
}
|
||||
|
||||
/**
|
||||
* For a sum of entries, get the exchange rate to the native currency of
|
||||
* the user.
|
||||
* @param array $entries
|
||||
* @return array
|
||||
*/
|
||||
public function cerSum(array $entries): array
|
||||
{
|
||||
if (null === $this->enabled) {
|
||||
$this->getPreference();
|
||||
}
|
||||
|
||||
// if false, return the same array without conversion info
|
||||
if (false === $this->enabled) {
|
||||
$return = [];
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$entry['converted'] = false;
|
||||
$return[] = $entry;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/** @var TransactionCurrency $native */
|
||||
$native = app('amount')->getDefaultCurrency();
|
||||
$return = [];
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
$currency = $this->getCurrency((int)$entry['id']);
|
||||
if ($currency->id !== $native->id) {
|
||||
$amount = $this->convertAmount($entry['sum'], $currency, $native);
|
||||
$entry['converted'] = true;
|
||||
$entry['native_sum'] = $amount;
|
||||
$entry['native_id'] = (string)$native->id;
|
||||
$entry['native_name'] = $native->name;
|
||||
$entry['native_symbol'] = $native->symbol;
|
||||
$entry['native_code'] = $native->code;
|
||||
$entry['native_decimal_places'] = $native->decimal_places;
|
||||
}
|
||||
if ($currency->id === $native->id) {
|
||||
$entry['converted'] = false;
|
||||
$entry['native_sum'] = $entry['sum'];
|
||||
$entry['native_id'] = (string)$native->id;
|
||||
$entry['native_name'] = $native->name;
|
||||
$entry['native_symbol'] = $native->symbol;
|
||||
$entry['native_code'] = $native->code;
|
||||
$entry['native_decimal_places'] = $native->decimal_places;
|
||||
}
|
||||
$return[] = $entry;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
private function convertAmount(string $amount, TransactionCurrency $from, TransactionCurrency $to, ?Carbon $date = null): string
|
||||
{
|
||||
Log::debug(sprintf('Converting %s from %s to %s', $amount, $from->code, $to->code));
|
||||
$date = $date ?? today(config('app.timezone'));
|
||||
$rate = $this->getRate($from, $to, $date);
|
||||
|
||||
return bcmul($amount, $rate);
|
||||
}
|
||||
}
|
||||
|
@@ -70,7 +70,6 @@ trait ModelInformation
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
*
|
||||
* @return string[]
|
||||
*
|
||||
@@ -95,7 +94,6 @@ trait ModelInformation
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* @return array
|
||||
*/
|
||||
protected function getRoles(): array
|
||||
|
@@ -200,7 +200,6 @@ trait PeriodOverview
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
|
||||
*/
|
||||
private function filterTransferredIn(Account $account, array $journals): array
|
||||
{
|
||||
@@ -219,7 +218,6 @@ trait PeriodOverview
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
|
||||
*/
|
||||
private function groupByCurrency(array $journals): array
|
||||
{
|
||||
|
@@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Exceptions\ValidationException;
|
||||
use FireflyIII\Helpers\Help\HelpInterface;
|
||||
use FireflyIII\Http\Requests\RuleFormRequest;
|
||||
@@ -219,7 +218,6 @@ trait RequestInformation
|
||||
* @param array $data
|
||||
*
|
||||
* @return ValidatorContract
|
||||
|
||||
*/
|
||||
final protected function validator(array $data): ValidatorContract
|
||||
{
|
||||
|
@@ -330,6 +330,37 @@ class Navigation
|
||||
return $currentEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user's view range and if necessary, corrects the dynamic view
|
||||
* range to a normal range.
|
||||
* @param bool $correct
|
||||
* @return string
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getViewRange(bool $correct): string
|
||||
{
|
||||
$range = (string)app('preferences')->get('viewRange', '1M')?->data ?? '1M';
|
||||
if (!$correct) {
|
||||
return $range;
|
||||
}
|
||||
switch ($range) {
|
||||
default:
|
||||
return $range;
|
||||
case 'last7':
|
||||
return '1W';
|
||||
case 'last30':
|
||||
case 'MTD':
|
||||
return '1M';
|
||||
case 'last90':
|
||||
case 'QTD':
|
||||
return '3M';
|
||||
case 'last365':
|
||||
case 'YTD':
|
||||
return '1Y';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
@@ -430,37 +461,6 @@ class Navigation
|
||||
return $date->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user's view range and if necessary, corrects the dynamic view
|
||||
* range to a normal range.
|
||||
* @param bool $correct
|
||||
* @return string
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getViewRange(bool $correct): string
|
||||
{
|
||||
$range = (string)app('preferences')->get('viewRange', '1M')?->data ?? '1M';
|
||||
if (!$correct) {
|
||||
return $range;
|
||||
}
|
||||
switch ($range) {
|
||||
default:
|
||||
return $range;
|
||||
case 'last7':
|
||||
return '1W';
|
||||
case 'last30':
|
||||
case 'MTD':
|
||||
return '1M';
|
||||
case 'last90':
|
||||
case 'QTD':
|
||||
return '3M';
|
||||
case 'last365':
|
||||
case 'YTD':
|
||||
return '1Y';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the date difference between start and end is less than a month, method returns trans(config.month_and_day). If the difference is less than a year,
|
||||
* method returns "config.month". If the date difference is larger, method returns "config.year".
|
||||
|
@@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support;
|
||||
|
||||
use Cache;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\User;
|
||||
|
@@ -32,25 +32,6 @@ use Log;
|
||||
*/
|
||||
trait ConvertsDataTypes
|
||||
{
|
||||
/**
|
||||
* Abstract method that always exists in the Request classes that use this
|
||||
* trait, OR a stub needs to be added by any other class that uses this train.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed|null $default
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function get(string $key, mixed $default = null): mixed;
|
||||
|
||||
/**
|
||||
* Abstract method that always exists in the Request classes that use this
|
||||
* trait, OR a stub needs to be added by any other class that uses this train.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function has($key);
|
||||
|
||||
/**
|
||||
* Return integer value.
|
||||
*
|
||||
@@ -63,6 +44,16 @@ trait ConvertsDataTypes
|
||||
return (int)$this->get($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method that always exists in the Request classes that use this
|
||||
* trait, OR a stub needs to be added by any other class that uses this train.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed|null $default
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function get(string $key, mixed $default = null): mixed;
|
||||
|
||||
/**
|
||||
* Return string value.
|
||||
*
|
||||
@@ -285,6 +276,15 @@ trait ConvertsDataTypes
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method that always exists in the Request classes that use this
|
||||
* trait, OR a stub needs to be added by any other class that uses this train.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function has($key);
|
||||
|
||||
/**
|
||||
* Return date or NULL.
|
||||
*
|
||||
|
@@ -63,6 +63,7 @@ use TypeError;
|
||||
*/
|
||||
class OperatorQuerySearch implements SearchInterface
|
||||
{
|
||||
protected Carbon $date;
|
||||
private AccountRepositoryInterface $accountRepository;
|
||||
private BillRepositoryInterface $billRepository;
|
||||
private BudgetRepositoryInterface $budgetRepository;
|
||||
@@ -73,9 +74,6 @@ class OperatorQuerySearch implements SearchInterface
|
||||
private int $limit;
|
||||
private Collection $operators;
|
||||
private int $page;
|
||||
protected Carbon $date;
|
||||
|
||||
|
||||
private array $prohibitedWords;
|
||||
private float $startTime;
|
||||
private TagRepositoryInterface $tagRepository;
|
||||
@@ -1993,6 +1991,14 @@ class OperatorQuerySearch implements SearchInterface
|
||||
return $this->words;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*/
|
||||
public function setDate(Carbon $date): void
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -2027,12 +2033,4 @@ class OperatorQuerySearch implements SearchInterface
|
||||
$this->limit = $limit;
|
||||
$this->collector->setLimit($this->limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
*/
|
||||
public function setDate(Carbon $date): void
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
}
|
||||
|
@@ -428,6 +428,21 @@ class Steam
|
||||
return str_replace($search, '', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $ipAddress
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getHostName(string $ipAddress): string
|
||||
{
|
||||
try {
|
||||
$hostName = gethostbyaddr($ipAddress);
|
||||
} catch (Exception $e) { // intentional generic exception
|
||||
throw new FireflyException($e->getMessage(), 0, $e);
|
||||
}
|
||||
return $hostName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accounts
|
||||
*
|
||||
@@ -668,19 +683,4 @@ class Steam
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $ipAddress
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getHostName(string $ipAddress): string
|
||||
{
|
||||
try {
|
||||
$hostName = gethostbyaddr($ipAddress);
|
||||
} catch (Exception $e) { // intentional generic exception
|
||||
throw new FireflyException($e->getMessage(), 0, $e);
|
||||
}
|
||||
return $hostName;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user