Experimental refactoring.

This commit is contained in:
James Cole 2023-10-30 07:27:43 +01:00
parent e9ef7d4144
commit 6790c318e2
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
3 changed files with 40 additions and 39 deletions

View File

@ -32,6 +32,7 @@ use FireflyIII\Support\Calendar\Periodicity;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Throwable; use Throwable;
use Illuminate\Support\Facades\Log;
/** /**
* Class Navigation. * Class Navigation.
@ -87,7 +88,7 @@ class Navigation
]; ];
if (!array_key_exists($repeatFreq, $functionMap)) { if (!array_key_exists($repeatFreq, $functionMap)) {
app('log')->error(sprintf( Log::error(sprintf(
'The periodicity %s is unknown. Choose one of available periodicity: %s', 'The periodicity %s is unknown. Choose one of available periodicity: %s',
$repeatFreq, $repeatFreq,
join(', ', array_keys($functionMap)) join(', ', array_keys($functionMap))
@ -110,12 +111,12 @@ class Navigation
try { try {
return $this->calculator->nextDateByInterval($epoch, $periodicity, $skipInterval); return $this->calculator->nextDateByInterval($epoch, $periodicity, $skipInterval);
} catch (IntervalException $exception) { } catch (IntervalException $exception) {
app('log')->warning($exception->getMessage(), ['exception' => $exception]); Log::warning($exception->getMessage(), ['exception' => $exception]);
} catch (Throwable $exception) { // @phpstan-ignore-line } catch (Throwable $exception) { // @phpstan-ignore-line
app('log')->error($exception->getMessage(), ['exception' => $exception]); Log::error($exception->getMessage(), ['exception' => $exception]);
} }
app('log')->debug( Log::debug(
'Any error occurred to calculate the next date.', 'Any error occurred to calculate the next date.',
['date' => $epoch, 'periodicity' => $periodicity->name, 'skipInterval' => $skipInterval] ['date' => $epoch, 'periodicity' => $periodicity->name, 'skipInterval' => $skipInterval]
); );
@ -241,7 +242,7 @@ class Navigation
if ('custom' === $repeatFreq) { if ('custom' === $repeatFreq) {
return $date; // the date is already at the start. return $date; // the date is already at the start.
} }
app('log')->error(sprintf('Cannot do startOfPeriod for $repeat_freq "%s"', $repeatFreq)); Log::error(sprintf('Cannot do startOfPeriod for $repeat_freq "%s"', $repeatFreq));
return $theDate; return $theDate;
} }
@ -317,7 +318,7 @@ class Navigation
if (!array_key_exists($repeatFreq, $functionMap)) { if (!array_key_exists($repeatFreq, $functionMap)) {
app('log')->error(sprintf('Cannot do endOfPeriod for $repeat_freq "%s"', $repeatFreq)); Log::error(sprintf('Cannot do endOfPeriod for $repeat_freq "%s"', $repeatFreq));
return $end; return $end;
} }
@ -350,7 +351,7 @@ class Navigation
*/ */
public function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int public function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int
{ {
app('log')->debug(sprintf( Log::debug(sprintf(
'diffInPeriods: %s (skip: %d), between %s and %s.', 'diffInPeriods: %s (skip: %d), between %s and %s.',
$period, $period,
$skip, $skip,
@ -366,7 +367,7 @@ class Navigation
'yearly' => 'floatDiffInYears', 'yearly' => 'floatDiffInYears',
]; ];
if (!array_key_exists($period, $map)) { if (!array_key_exists($period, $map)) {
app('log')->warning(sprintf('No diffInPeriods for period "%s"', $period)); Log::warning(sprintf('No diffInPeriods for period "%s"', $period));
return 1; return 1;
} }
$func = $map[$period]; $func = $map[$period];
@ -375,23 +376,23 @@ class Navigation
// then correct for quarterly or half-year // then correct for quarterly or half-year
if ('quarterly' === $period) { if ('quarterly' === $period) {
app('log')->debug(sprintf('Q: Corrected %f to %f', $diff, $diff / 3)); Log::debug(sprintf('Q: Corrected %f to %f', $diff, $diff / 3));
$diff = $diff / 3; $diff = $diff / 3;
} }
if ('half-year' === $period) { if ('half-year' === $period) {
app('log')->debug(sprintf('H: Corrected %f to %f', $diff, $diff / 6)); Log::debug(sprintf('H: Corrected %f to %f', $diff, $diff / 6));
$diff = $diff / 6; $diff = $diff / 6;
} }
// then do ceil() // then do ceil()
$diff = ceil($diff); $diff = ceil($diff);
app('log')->debug(sprintf('Diff is %f (%d)', $beginning->$func($end), $diff)); Log::debug(sprintf('Diff is %f (%d)', $beginning->$func($end), $diff));
if ($skip > 0) { if ($skip > 0) {
$parameter = $skip + 1; $parameter = $skip + 1;
$diff = ceil($diff / $parameter) * $parameter; $diff = ceil($diff / $parameter) * $parameter;
app('log')->debug(sprintf( Log::debug(sprintf(
'diffInPeriods: skip is %d, so param is %d, and diff becomes %d', 'diffInPeriods: skip is %d, so param is %d, and diff becomes %d',
$skip, $skip,
$parameter, $parameter,
@ -570,7 +571,7 @@ class Navigation
} }
// special formatter for quarter of year // special formatter for quarter of year
app('log')->error(sprintf('No date formats for frequency "%s"!', $repeatFrequency)); Log::error(sprintf('No date formats for frequency "%s"!', $repeatFrequency));
return $date->format('Y-m-d'); return $date->format('Y-m-d');
} }
@ -787,7 +788,7 @@ class Navigation
*/ */
public function updateEndDate(string $range, Carbon $start): Carbon public function updateEndDate(string $range, Carbon $start): Carbon
{ {
app('log')->debug(sprintf('updateEndDate("%s", "%s")', $range, $start->format('Y-m-d'))); Log::debug(sprintf('updateEndDate("%s", "%s")', $range, $start->format('Y-m-d')));
$functionMap = [ $functionMap = [
'1D' => 'endOfDay', '1D' => 'endOfDay',
'1W' => 'endOfWeek', '1W' => 'endOfWeek',
@ -833,7 +834,7 @@ class Navigation
if (in_array($range, $list, true)) { if (in_array($range, $list, true)) {
$end = today(config('app.timezone')); $end = today(config('app.timezone'));
$end->endOfDay(); $end->endOfDay();
app('log')->debug(sprintf('updateEndDate returns "%s"', $end->format('Y-m-d'))); Log::debug(sprintf('updateEndDate returns "%s"', $end->format('Y-m-d')));
return $end; return $end;
} }
@ -850,7 +851,7 @@ class Navigation
*/ */
public function updateStartDate(string $range, Carbon $start): Carbon public function updateStartDate(string $range, Carbon $start): Carbon
{ {
app('log')->debug(sprintf('updateStartDate("%s", "%s")', $range, $start->format('Y-m-d'))); Log::debug(sprintf('updateStartDate("%s", "%s")', $range, $start->format('Y-m-d')));
$functionMap = [ $functionMap = [
'1D' => 'startOfDay', '1D' => 'startOfDay',
'1W' => 'startOfWeek', '1W' => 'startOfWeek',

View File

@ -51,26 +51,26 @@ $mysql_ssl_verify = envNonEmpty('MYSQL_SSL_VERIFY_SERVER_CERT', null);
$mySqlSSLOptions = []; $mySqlSSLOptions = [];
$useSSL = envNonEmpty('MYSQL_USE_SSL', false); $useSSL = envNonEmpty('MYSQL_USE_SSL', false);
//if (false !== $useSSL && null !== $useSSL && '' !== $useSSL) { if (false !== $useSSL && null !== $useSSL && '' !== $useSSL) {
// if (null !== $mysql_ssl_ca_dir) { if (null !== $mysql_ssl_ca_dir) {
// $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CAPATH] = $mysql_ssl_ca_dir; $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CAPATH] = $mysql_ssl_ca_dir;
// } }
// if (null !== $mysql_ssl_ca_file) { if (null !== $mysql_ssl_ca_file) {
// $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CA] = $mysql_ssl_ca_file; $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CA] = $mysql_ssl_ca_file;
// } }
// if (null !== $mysql_ssl_cert) { if (null !== $mysql_ssl_cert) {
// $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CERT] = $mysql_ssl_cert; $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CERT] = $mysql_ssl_cert;
// } }
// if (null !== $mysql_ssl_key) { if (null !== $mysql_ssl_key) {
// $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_KEY] = $mysql_ssl_key; $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_KEY] = $mysql_ssl_key;
// } }
// if (null !== $mysql_ssl_ciphers) { if (null !== $mysql_ssl_ciphers) {
// $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CIPHER] = $mysql_ssl_ciphers; $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_CIPHER] = $mysql_ssl_ciphers;
// } }
// if (null !== $mysql_ssl_verify) { if (null !== $mysql_ssl_verify) {
// $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = $mysql_ssl_verify; $mySqlSSLOptions[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = $mysql_ssl_verify;
// } }
//} }
return [ return [
'default' => envNonEmpty('DB_CONNECTION', 'mysql'), 'default' => envNonEmpty('DB_CONNECTION', 'mysql'),

View File

@ -28,7 +28,7 @@ use FireflyIII\Enums\UserRoleEnum;
$result = []; $result = [];
//foreach (UserRoleEnum::cases() as $role) { foreach (UserRoleEnum::cases() as $role) {
// $result[$role->value] = []; $result[$role->value] = [];
//} }
return $result; return $result;