Clean up code and comments.

This commit is contained in:
James Cole
2023-02-22 18:14:14 +01:00
parent e6dc881f56
commit e421b29b01
249 changed files with 647 additions and 1044 deletions

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Facades;
use Illuminate\Support\Facades\Facade;
/**
* Class AccountForm.
*
*/

View File

@@ -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)

View File

@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Facades;
use Illuminate\Support\Facades\Facade;
/**
* Class CurrencyForm.
*
*/

View File

@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Facades;
use Illuminate\Support\Facades\Facade;
/**
* Class ExpandedForm.
*/
class ExpandedForm extends Facade

View File

@@ -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)

View File

@@ -27,7 +27,6 @@ use Carbon\Carbon;
use Illuminate\Support\Facades\Facade;
/**
* Class Navigation.
*
* @method Carbon addPeriod(Carbon $theDate, string $repeatFreq, int $skip)

View File

@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Facades;
use Illuminate\Support\Facades\Facade;
/**
* Class PiggyBankForm.
*
*/

View File

@@ -29,7 +29,6 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Facade;
/**
* Class Preferences.
*
* @method Collection beginsWith(User $user, string $search)

View File

@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Facades;
use Illuminate\Support\Facades\Facade;
/**
* Class RuleForm.
*
*/

View File

@@ -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);
}
}

View File

@@ -70,7 +70,6 @@ trait ModelInformation
}
/**
*
* @return string[]
*
@@ -95,7 +94,6 @@ trait ModelInformation
}
/**
* @return array
*/
protected function getRoles(): array

View File

@@ -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
{

View File

@@ -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
{

View File

@@ -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".

View File

@@ -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;

View File

@@ -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.
*

View File

@@ -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;
}
}

View File

@@ -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;
}
}