diff --git a/.ci/php-cs-fixer/composer.lock b/.ci/php-cs-fixer/composer.lock index b1c40622d6..14cc84dcb3 100644 --- a/.ci/php-cs-fixer/composer.lock +++ b/.ci/php-cs-fixer/composer.lock @@ -379,16 +379,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.21.1", + "version": "v3.22.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "229b55b3eae4729a8e2a321441ba40fcb3720b86" + "reference": "92b019f6c8d79aa26349d0db7671d37440dc0ff3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/229b55b3eae4729a8e2a321441ba40fcb3720b86", - "reference": "229b55b3eae4729a8e2a321441ba40fcb3720b86", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/92b019f6c8d79aa26349d0db7671d37440dc0ff3", + "reference": "92b019f6c8d79aa26349d0db7671d37440dc0ff3", "shasum": "" }, "require": { @@ -398,7 +398,7 @@ "doctrine/lexer": "^2 || ^3", "ext-json": "*", "ext-tokenizer": "*", - "php": "^8.0.1", + "php": "^7.4 || ^8.0", "sebastian/diff": "^4.0 || ^5.0", "symfony/console": "^5.4 || ^6.0", "symfony/event-dispatcher": "^5.4 || ^6.0", @@ -412,6 +412,7 @@ "symfony/stopwatch": "^5.4 || ^6.0" }, "require-dev": { + "facile-it/paraunit": "^1.3 || ^2.0", "justinrainbow/json-schema": "^5.2", "keradus/cli-executor": "^2.0", "mikey179/vfsstream": "^1.6.11", @@ -463,7 +464,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.21.1" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.22.0" }, "funding": [ { @@ -471,7 +472,7 @@ "type": "github" } ], - "time": "2023-07-05T21:50:25+00:00" + "time": "2023-07-16T23:08:06+00:00" }, { "name": "psr/cache", diff --git a/app/Api/V2/Controllers/Model/Budget/ShowController.php b/app/Api/V2/Controllers/Model/Budget/ShowController.php index a75966497b..b9b5ea1229 100644 --- a/app/Api/V2/Controllers/Model/Budget/ShowController.php +++ b/app/Api/V2/Controllers/Model/Budget/ShowController.php @@ -44,7 +44,8 @@ class ShowController extends Controller /** * */ - public function __construct() { + public function __construct() + { parent::__construct(); $this->middleware( function ($request, $next) { @@ -60,7 +61,8 @@ class ShowController extends Controller * TODO add URL * */ - public function budgeted(DateRequest $request, Budget $budget): JsonResponse { + public function budgeted(DateRequest $request, Budget $budget): JsonResponse + { $data = $request->getAll(); $result = $this->repository->budgetedInPeriodForBudget($budget, $data['start'], $data['end']); $converted = $this->cerSum(array_values($result)); @@ -73,7 +75,8 @@ class ShowController extends Controller * TODO add URL * */ - public function spent(DateRequest $request, Budget $budget): JsonResponse { + public function spent(DateRequest $request, Budget $budget): JsonResponse + { $data = $request->getAll(); $result = $this->repository->spentInPeriodForBudget($budget, $data['start'], $data['end']); $converted = $this->cerSum(array_values($result)); diff --git a/app/Console/Commands/ShowsFriendlyMessages.php b/app/Console/Commands/ShowsFriendlyMessages.php index 8b9d2b9129..bc40b466d1 100644 --- a/app/Console/Commands/ShowsFriendlyMessages.php +++ b/app/Console/Commands/ShowsFriendlyMessages.php @@ -35,7 +35,8 @@ trait ShowsFriendlyMessages * * @return void */ - public function friendlyError(string $message): void { + public function friendlyError(string $message): void + { $this->error(sprintf(' [x] %s', trim($message))); } @@ -44,7 +45,8 @@ trait ShowsFriendlyMessages * * @return void */ - public function friendlyInfo(string $message): void { + public function friendlyInfo(string $message): void + { $this->friendlyNeutral($message); } @@ -53,7 +55,8 @@ trait ShowsFriendlyMessages * * @return void */ - public function friendlyNeutral(string $message): void { + public function friendlyNeutral(string $message): void + { $this->line(sprintf(' [i] %s', trim($message))); } @@ -62,7 +65,8 @@ trait ShowsFriendlyMessages * * @return void */ - public function friendlyLine(string $message): void { + public function friendlyLine(string $message): void + { $this->line(sprintf(' %s', trim($message))); } @@ -71,7 +75,8 @@ trait ShowsFriendlyMessages * * @return void */ - public function friendlyPositive(string $message): void { + public function friendlyPositive(string $message): void + { $this->info(sprintf(' [✓] %s', trim($message))); } @@ -80,7 +85,8 @@ trait ShowsFriendlyMessages * * @return void */ - public function friendlyWarning(string $message): void { + public function friendlyWarning(string $message): void + { $this->warn(sprintf(' [!] %s', trim($message))); } diff --git a/app/Events/Model/BudgetLimit/Created.php b/app/Events/Model/BudgetLimit/Created.php index e3dc88a3a7..e0133a3f21 100644 --- a/app/Events/Model/BudgetLimit/Created.php +++ b/app/Events/Model/BudgetLimit/Created.php @@ -41,7 +41,8 @@ class Created extends Event /** * @param BudgetLimit $budgetLimit */ - public function __construct(BudgetLimit $budgetLimit) { + public function __construct(BudgetLimit $budgetLimit) + { $this->budgetLimit = $budgetLimit; } } diff --git a/app/Events/Model/BudgetLimit/Deleted.php b/app/Events/Model/BudgetLimit/Deleted.php index eb57cc4545..059d594ab5 100644 --- a/app/Events/Model/BudgetLimit/Deleted.php +++ b/app/Events/Model/BudgetLimit/Deleted.php @@ -41,7 +41,8 @@ class Deleted extends Event /** * @param BudgetLimit $budgetLimit */ - public function __construct(BudgetLimit $budgetLimit) { + public function __construct(BudgetLimit $budgetLimit) + { $this->budgetLimit = $budgetLimit; } } diff --git a/app/Events/Model/BudgetLimit/Updated.php b/app/Events/Model/BudgetLimit/Updated.php index 08032b96aa..828ae98a07 100644 --- a/app/Events/Model/BudgetLimit/Updated.php +++ b/app/Events/Model/BudgetLimit/Updated.php @@ -41,7 +41,8 @@ class Updated extends Event /** * @param BudgetLimit $budgetLimit */ - public function __construct(BudgetLimit $budgetLimit) { + public function __construct(BudgetLimit $budgetLimit) + { $this->budgetLimit = $budgetLimit; } } diff --git a/app/Handlers/Events/Model/BudgetLimitHandler.php b/app/Handlers/Events/Model/BudgetLimitHandler.php index 0233056b07..145c7e9b4b 100644 --- a/app/Handlers/Events/Model/BudgetLimitHandler.php +++ b/app/Handlers/Events/Model/BudgetLimitHandler.php @@ -49,7 +49,8 @@ class BudgetLimitHandler * * @return void */ - public function created(Created $event): void { + public function created(Created $event): void + { Log::debug(sprintf('BudgetLimitHandler::created(#%s)', $event->budgetLimit->id)); $this->updateAvailableBudget($event->budgetLimit); } @@ -59,7 +60,8 @@ class BudgetLimitHandler * * @return void */ - private function updateAvailableBudget(BudgetLimit $budgetLimit): void { + private function updateAvailableBudget(BudgetLimit $budgetLimit): void + { Log::debug(sprintf('Now in updateAvailableBudget(#%d)', $budgetLimit->id)); // based on the view range of the user (month week quarter etc) the budget limit could @@ -145,7 +147,8 @@ class BudgetLimitHandler * * @return void */ - private function calculateAmount(AvailableBudget $availableBudget): void { + private function calculateAmount(AvailableBudget $availableBudget): void + { $repository = app(BudgetLimitRepositoryInterface::class); $repository->setUser($availableBudget->user); $newAmount = '0'; @@ -173,8 +176,8 @@ class BudgetLimitHandler ); // overlap in days: $limitPeriod = Period::make( - $budgetLimit->start_date, - $budgetLimit->end_date, + $budgetLimit->start_date, + $budgetLimit->end_date, precision : Precision::DAY(), boundaries: Boundaries::EXCLUDE_NONE() ); @@ -210,13 +213,14 @@ class BudgetLimitHandler * * @return string */ - private function getDailyAmount(BudgetLimit $budgetLimit): string { + private function getDailyAmount(BudgetLimit $budgetLimit): string + { if (0 === (int)$budgetLimit->id) { return '0'; } $limitPeriod = Period::make( - $budgetLimit->start_date, - $budgetLimit->end_date, + $budgetLimit->start_date, + $budgetLimit->end_date, precision : Precision::DAY(), boundaries: Boundaries::EXCLUDE_NONE() ); @@ -233,7 +237,8 @@ class BudgetLimitHandler * * @return void */ - public function deleted(Deleted $event): void { + public function deleted(Deleted $event): void + { Log::debug(sprintf('BudgetLimitHandler::deleted(#%s)', $event->budgetLimit->id)); $budgetLimit = $event->budgetLimit; $budgetLimit->id = null; @@ -245,7 +250,8 @@ class BudgetLimitHandler * * @return void */ - public function updated(Updated $event): void { + public function updated(Updated $event): void + { Log::debug(sprintf('BudgetLimitHandler::updated(#%s)', $event->budgetLimit->id)); $this->updateAvailableBudget($event->budgetLimit); } diff --git a/app/Http/Requests/TriggerRecurrenceRequest.php b/app/Http/Requests/TriggerRecurrenceRequest.php index 04ce8ce576..205141f368 100644 --- a/app/Http/Requests/TriggerRecurrenceRequest.php +++ b/app/Http/Requests/TriggerRecurrenceRequest.php @@ -42,7 +42,8 @@ class TriggerRecurrenceRequest extends FormRequest * * @return array */ - public function getAll(): array { + public function getAll(): array + { return [ 'date' => $this->getCarbonDate('date'), ]; @@ -53,7 +54,8 @@ class TriggerRecurrenceRequest extends FormRequest * * @return array */ - public function rules(): array { + public function rules(): array + { return [ 'date' => 'required|date', ]; diff --git a/app/Notifications/Admin/TestNotification.php b/app/Notifications/Admin/TestNotification.php index 79877f08a2..aa4a954d3a 100644 --- a/app/Notifications/Admin/TestNotification.php +++ b/app/Notifications/Admin/TestNotification.php @@ -97,6 +97,10 @@ class TestNotification extends Notification */ public function via($notifiable) { - return ['mail', 'slack']; + $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data; + if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) { + return ['mail', 'slack']; + } + return ['mail']; } } diff --git a/app/Notifications/Admin/UserInvitation.php b/app/Notifications/Admin/UserInvitation.php index 6e4ebb071f..a5a9f67c7d 100644 --- a/app/Notifications/Admin/UserInvitation.php +++ b/app/Notifications/Admin/UserInvitation.php @@ -100,6 +100,10 @@ class UserInvitation extends Notification */ public function via($notifiable) { - return ['mail', 'slack']; + $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data; + if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) { + return ['mail', 'slack']; + } + return ['mail']; } } diff --git a/app/Notifications/Admin/UserRegistration.php b/app/Notifications/Admin/UserRegistration.php index b57b4f5cec..b195bd4ff5 100644 --- a/app/Notifications/Admin/UserRegistration.php +++ b/app/Notifications/Admin/UserRegistration.php @@ -98,6 +98,10 @@ class UserRegistration extends Notification */ public function via($notifiable) { - return ['mail', 'slack']; + $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data; + if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) { + return ['mail', 'slack']; + } + return ['mail']; } } diff --git a/app/Notifications/Admin/VersionCheckResult.php b/app/Notifications/Admin/VersionCheckResult.php index c0d97abdb8..2323bf7289 100644 --- a/app/Notifications/Admin/VersionCheckResult.php +++ b/app/Notifications/Admin/VersionCheckResult.php @@ -87,14 +87,14 @@ class VersionCheckResult extends Notification public function toSlack($notifiable) { // return (new SlackMessage())->text($this->message) -// ->sectionBlock(function (SectionBlock $block) { -// $button = new ButtonElement('Button'); -// $button->url('https://github.com/firefly-iii/firefly-iii/releases'); -// $block->accessory($button); -// }); -//// ->attachment(function ($attachment) { -//// $attachment->title('Firefly III @ GitHub', 'https://github.com/firefly-iii/firefly-iii/releases'); -//// }); + // ->sectionBlock(function (SectionBlock $block) { + // $button = new ButtonElement('Button'); + // $button->url('https://github.com/firefly-iii/firefly-iii/releases'); + // $block->accessory($button); + // }); + //// ->attachment(function ($attachment) { + //// $attachment->title('Firefly III @ GitHub', 'https://github.com/firefly-iii/firefly-iii/releases'); + //// }); return (new SlackMessage())->content($this->message) @@ -112,6 +112,10 @@ class VersionCheckResult extends Notification */ public function via($notifiable) { - return ['mail', 'slack']; + $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data; + if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) { + return ['mail', 'slack']; + } + return ['mail']; } } diff --git a/app/Notifications/User/BillReminder.php b/app/Notifications/User/BillReminder.php index 7f756aa819..827517b7ab 100644 --- a/app/Notifications/User/BillReminder.php +++ b/app/Notifications/User/BillReminder.php @@ -118,6 +118,10 @@ class BillReminder extends Notification */ public function via($notifiable) { - return ['mail', 'slack']; + $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data; + if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) { + return ['mail', 'slack']; + } + return ['mail']; } } diff --git a/app/Notifications/User/NewAccessToken.php b/app/Notifications/User/NewAccessToken.php index e57c719047..c35e5dc96b 100644 --- a/app/Notifications/User/NewAccessToken.php +++ b/app/Notifications/User/NewAccessToken.php @@ -94,6 +94,10 @@ class NewAccessToken extends Notification */ public function via($notifiable) { - return ['mail', 'slack']; + $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data; + if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) { + return ['mail', 'slack']; + } + return ['mail']; } } diff --git a/app/Notifications/User/UserLogin.php b/app/Notifications/User/UserLogin.php index c4ff10025a..22a56cde73 100644 --- a/app/Notifications/User/UserLogin.php +++ b/app/Notifications/User/UserLogin.php @@ -122,6 +122,10 @@ class UserLogin extends Notification */ public function via($notifiable) { - return ['mail', 'slack']; + $slackUrl = (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data; + if (str_starts_with($slackUrl, 'https://hooks.slack.com/services/')) { + return ['mail', 'slack']; + } + return ['mail']; } } diff --git a/app/Repositories/Administration/Account/AccountRepository.php b/app/Repositories/Administration/Account/AccountRepository.php index c269734037..8f056c73dd 100644 --- a/app/Repositories/Administration/Account/AccountRepository.php +++ b/app/Repositories/Administration/Account/AccountRepository.php @@ -38,7 +38,8 @@ class AccountRepository implements AccountRepositoryInterface /** * @inheritDoc */ - public function searchAccount(string $query, array $types, int $limit): Collection { + public function searchAccount(string $query, array $types, int $limit): Collection + { // search by group, not by user $dbQuery = $this->userGroup->accounts() ->where('active', true) diff --git a/app/Support/Calendar/Calculator.php b/app/Support/Calendar/Calculator.php index 7ad3a3f164..b09ba58c59 100644 --- a/app/Support/Calendar/Calculator.php +++ b/app/Support/Calendar/Calculator.php @@ -46,7 +46,8 @@ class Calculator * @return Carbon * @throws IntervalException */ - public function nextDateByInterval(Carbon $epoch, Periodicity $periodicity, int $skipInterval = 0): Carbon { + public function nextDateByInterval(Carbon $epoch, Periodicity $periodicity, int $skipInterval = 0): Carbon + { if (!self::isAvailablePeriodicity($periodicity)) { throw IntervalException::unavailable($periodicity, self::$intervals); } @@ -62,7 +63,8 @@ class Calculator * * @return bool */ - public function isAvailablePeriodicity(Periodicity $periodicity): bool { + public function isAvailablePeriodicity(Periodicity $periodicity): bool + { return self::containsInterval($periodicity); } @@ -71,14 +73,16 @@ class Calculator * * @return bool */ - private static function containsInterval(Periodicity $periodicity): bool { + private static function containsInterval(Periodicity $periodicity): bool + { return self::loadIntervalMap()->contains($periodicity); } /** * @return SplObjectStorage */ - private static function loadIntervalMap(): SplObjectStorage { + private static function loadIntervalMap(): SplObjectStorage + { if (self::$intervalMap != null) { return self::$intervalMap; } @@ -96,7 +100,8 @@ class Calculator * * @return int */ - private function skipInterval(int $skip): int { + private function skipInterval(int $skip): int + { return self::DEFAULT_INTERVAL + $skip; } diff --git a/app/Support/Calendar/Exceptions/IntervalException.php b/app/Support/Calendar/Exceptions/IntervalException.php index eb75706585..6192dcc51e 100644 --- a/app/Support/Calendar/Exceptions/IntervalException.php +++ b/app/Support/Calendar/Exceptions/IntervalException.php @@ -36,7 +36,7 @@ final class IntervalException extends Exception { public readonly array $availableIntervals; public readonly Periodicity $periodicity; - protected $message = 'The periodicity %s is unknown. Choose one of available periodicity: %s'; + protected $message = 'The periodicity %s is unknown. Choose one of available periodicity: %s'; /** * @param Periodicity $periodicity diff --git a/app/Support/Calendar/Periodicity/Daily.php b/app/Support/Calendar/Periodicity/Daily.php index 7346019147..5b9a661322 100644 --- a/app/Support/Calendar/Periodicity/Daily.php +++ b/app/Support/Calendar/Periodicity/Daily.php @@ -38,7 +38,8 @@ final class Daily extends Interval * * @return Carbon */ - public function nextDate(Carbon $date, int $interval = 1): Carbon { + public function nextDate(Carbon $date, int $interval = 1): Carbon + { return ($date->clone())->addDays($this->skip($interval)); } } diff --git a/app/Support/Calendar/Periodicity/Interval.php b/app/Support/Calendar/Periodicity/Interval.php index 5bda217906..c3a3a06805 100644 --- a/app/Support/Calendar/Periodicity/Interval.php +++ b/app/Support/Calendar/Periodicity/Interval.php @@ -37,7 +37,8 @@ abstract class Interval implements Interspacable * * @return int */ - public function skip(int $skip): int { + public function skip(int $skip): int + { return static::INTERVAL * $skip; } } diff --git a/app/Support/Calendar/Periodicity/Monthly.php b/app/Support/Calendar/Periodicity/Monthly.php index 25935c5fc7..983383ab90 100644 --- a/app/Support/Calendar/Periodicity/Monthly.php +++ b/app/Support/Calendar/Periodicity/Monthly.php @@ -38,7 +38,8 @@ class Monthly extends Interval * * @return Carbon */ - public function nextDate(Carbon $date, int $interval = 1): Carbon { + public function nextDate(Carbon $date, int $interval = 1): Carbon + { return ($date->clone())->addMonthsNoOverflow($this->skip($interval)); } } diff --git a/app/Support/Calendar/Periodicity/Weekly.php b/app/Support/Calendar/Periodicity/Weekly.php index 4f0c375a34..54e33408a6 100644 --- a/app/Support/Calendar/Periodicity/Weekly.php +++ b/app/Support/Calendar/Periodicity/Weekly.php @@ -38,7 +38,8 @@ class Weekly extends Interval * * @return Carbon */ - public function nextDate(Carbon $date, int $interval = 1): Carbon { + public function nextDate(Carbon $date, int $interval = 1): Carbon + { return ($date->clone())->addWeeks($this->skip($interval)); } } diff --git a/app/Support/Calendar/Periodicity/Yearly.php b/app/Support/Calendar/Periodicity/Yearly.php index 25e0d163ab..794bc111dd 100644 --- a/app/Support/Calendar/Periodicity/Yearly.php +++ b/app/Support/Calendar/Periodicity/Yearly.php @@ -38,7 +38,8 @@ final class Yearly extends Interval * * @return Carbon */ - public function nextDate(Carbon $date, int $interval = 1): Carbon { + public function nextDate(Carbon $date, int $interval = 1): Carbon + { return ($date->clone())->addYearsNoOverflow($this->skip($interval)); } } diff --git a/app/Support/Repositories/Administration/AdministrationTrait.php b/app/Support/Repositories/Administration/AdministrationTrait.php index c425cbf7e9..315288d5fd 100644 --- a/app/Support/Repositories/Administration/AdministrationTrait.php +++ b/app/Support/Repositories/Administration/AdministrationTrait.php @@ -43,7 +43,8 @@ trait AdministrationTrait /** * @return int */ - public function getAdministrationId(): int { + public function getAdministrationId(): int + { return $this->administrationId; } @@ -52,7 +53,8 @@ trait AdministrationTrait * * @throws FireflyException */ - public function setAdministrationId(int $administrationId): void { + public function setAdministrationId(int $administrationId): void + { $this->administrationId = $administrationId; $this->refreshAdministration(); } @@ -61,7 +63,8 @@ trait AdministrationTrait * @return void * @throws FireflyException */ - private function refreshAdministration(): void { + private function refreshAdministration(): void + { if (null !== $this->administrationId) { $memberships = GroupMembership::where('user_id', $this->user->id) ->where('user_group_id', $this->administrationId) @@ -80,7 +83,8 @@ trait AdministrationTrait * * @return void */ - public function setUser(Authenticatable | User | null $user): void { + public function setUser(Authenticatable | User | null $user): void + { if (null !== $user) { $this->user = $user; } diff --git a/app/User.php b/app/User.php index 12b76044a9..3796626366 100644 --- a/app/User.php +++ b/app/User.php @@ -53,7 +53,6 @@ use FireflyIII\Notifications\Admin\TestNotification; use FireflyIII\Notifications\Admin\UserInvitation; use FireflyIII\Notifications\Admin\UserRegistration; use FireflyIII\Notifications\Admin\VersionCheckResult; -use FireflyIII\Notifications\User\NewAccessToken; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -487,9 +486,6 @@ class User extends Authenticatable if ($notification instanceof VersionCheckResult) { return app('fireflyconfig')->get('slack_webhook_url', '')->data; } - if ($notification instanceof NewAccessToken) { - return app('fireflyconfig')->get('slack_webhook_url', '')->data; - } if ($notification instanceof UserInvitation) { return app('fireflyconfig')->get('slack_webhook_url', '')->data; } diff --git a/app/Validation/Administration/ValidatesAdministrationAccess.php b/app/Validation/Administration/ValidatesAdministrationAccess.php index 25762eb327..a03d35c248 100644 --- a/app/Validation/Administration/ValidatesAdministrationAccess.php +++ b/app/Validation/Administration/ValidatesAdministrationAccess.php @@ -46,7 +46,8 @@ trait ValidatesAdministrationAccess * @throws AuthenticationException * @throws FireflyException */ - protected function validateAdministration(Validator $validator, array $allowedRoles): void { + protected function validateAdministration(Validator $validator, array $allowedRoles): void + { Log::debug('Now in validateAdministration()'); if (!auth()->check()) { Log::error('User is not authenticated.'); diff --git a/tests/unit/Support/Calendar/CalculatorProvider.php b/tests/unit/Support/Calendar/CalculatorProvider.php index 0e82aad341..50b39a315c 100644 --- a/tests/unit/Support/Calendar/CalculatorProvider.php +++ b/tests/unit/Support/Calendar/CalculatorProvider.php @@ -37,14 +37,16 @@ readonly class CalculatorProvider public Periodicity $periodicity; public int $skip; - private function __construct(IntervalProvider $intervalProvider, Periodicity $periodicity, int $skip = 0) { + private function __construct(IntervalProvider $intervalProvider, Periodicity $periodicity, int $skip = 0) + { $this->skip = $skip; $this->intervalProvider = $intervalProvider; $this->periodicity = $periodicity; $this->label = "{$periodicity->name} {$intervalProvider->label}"; } - public static function providePeriodicityWithSkippedIntervals(): Generator { + public static function providePeriodicityWithSkippedIntervals(): Generator + { $intervals = [ CalculatorProvider::from(Periodicity::Daily, new IntervalProvider(Carbon::now(), Carbon::now()->addDays(2)), 1), CalculatorProvider::from(Periodicity::Daily, new IntervalProvider(Carbon::now(), Carbon::now()->addDays(3)), 2), @@ -117,15 +119,18 @@ readonly class CalculatorProvider } } - public static function from(Periodicity $periodicity, IntervalProvider $interval, int $skip = 0): CalculatorProvider { + public static function from(Periodicity $periodicity, IntervalProvider $interval, int $skip = 0): CalculatorProvider + { return new self($interval, $periodicity, $skip); } - public function epoch(): Carbon { + public function epoch(): Carbon + { return $this->intervalProvider->epoch; } - public function expected(): Carbon { + public function expected(): Carbon + { return $this->intervalProvider->expected; } } diff --git a/tests/unit/Support/Calendar/CalculatorTest.php b/tests/unit/Support/Calendar/CalculatorTest.php index 0d0aaf9da5..3c0e265002 100644 --- a/tests/unit/Support/Calendar/CalculatorTest.php +++ b/tests/unit/Support/Calendar/CalculatorTest.php @@ -48,7 +48,8 @@ use Tests\unit\Support\Calendar\Periodicity\YearlyTest; */ class CalculatorTest extends TestCase { - public static function provideAllPeriodicity(): Generator { + public static function provideAllPeriodicity(): Generator + { $intervals = []; $intervals = array_merge($intervals, self::convert(Periodicity::Daily, DailyTest::provideIntervals())); $intervals = array_merge($intervals, self::convert(Periodicity::Weekly, WeeklyTest::provideIntervals())); @@ -65,7 +66,8 @@ class CalculatorTest extends TestCase } } - private static function convert(Periodicity $periodicity, array $intervals): array { + private static function convert(Periodicity $periodicity, array $intervals): array + { $periodicityIntervals = []; /** @var IntervalProvider $interval */ foreach ($intervals as $index => $interval) { @@ -76,7 +78,8 @@ class CalculatorTest extends TestCase return $periodicityIntervals; } - public static function provideSkippedIntervals(): Generator { + public static function provideSkippedIntervals(): Generator + { return CalculatorProvider::providePeriodicityWithSkippedIntervals(); } @@ -84,7 +87,8 @@ class CalculatorTest extends TestCase * @dataProvider provideAllPeriodicity * @throws IntervalException */ - public function testGivenADailyPeriodicityWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider) { + public function testGivenADailyPeriodicityWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider) + { $calculator = new Calculator(); $period = $calculator->nextDateByInterval($provider->epoch(), $provider->periodicity); $this->assertEquals($provider->expected()->toDateString(), $period->toDateString()); @@ -94,7 +98,8 @@ class CalculatorTest extends TestCase * @dataProvider provideSkippedIntervals * @throws IntervalException */ - public function testGivenAnEpochWithSkipIntervalNumberWhenCallTheNextDateBySkippedIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider) { + public function testGivenAnEpochWithSkipIntervalNumberWhenCallTheNextDateBySkippedIntervalMethodThenReturnsTheExpectedDateSuccessful(CalculatorProvider $provider) + { $calculator = new Calculator(); $period = $calculator->nextDateByInterval($provider->epoch(), $provider->periodicity, $provider->skip); $this->assertEquals($provider->expected()->toDateString(), $period->toDateString()); diff --git a/tests/unit/Support/Calendar/Periodicity/MonthlyTest.php b/tests/unit/Support/Calendar/Periodicity/MonthlyTest.php index 7edc3ab95a..fcc81f4690 100644 --- a/tests/unit/Support/Calendar/Periodicity/MonthlyTest.php +++ b/tests/unit/Support/Calendar/Periodicity/MonthlyTest.php @@ -37,11 +37,13 @@ use FireflyIII\Support\Calendar\Periodicity\Interval; */ class MonthlyTest extends IntervalTestCase { - public static function factory(): Interval { + public static function factory(): Interval + { return new Periodicity\Monthly(); } - public static function provideIntervals(): array { + public static function provideIntervals(): array + { return [ new IntervalProvider(Carbon::now(), Carbon::now()->addMonth(1)), new IntervalProvider(Carbon::parse('2019-01-01'), Carbon::parse('2019-02-01')), diff --git a/tests/unit/Support/Calendar/Periodicity/QuarterlyTest.php b/tests/unit/Support/Calendar/Periodicity/QuarterlyTest.php index c8ce3a2e1c..3d4b010e7f 100644 --- a/tests/unit/Support/Calendar/Periodicity/QuarterlyTest.php +++ b/tests/unit/Support/Calendar/Periodicity/QuarterlyTest.php @@ -37,11 +37,13 @@ use FireflyIII\Support\Calendar\Periodicity\Interval; */ class QuarterlyTest extends IntervalTestCase { - public static function factory(): Interval { + public static function factory(): Interval + { return new Periodicity\Quarterly(); } - public static function provideIntervals(): array { + public static function provideIntervals(): array + { return [ new IntervalProvider(Carbon::now(), Carbon::now()->addMonths(3)), new IntervalProvider(Carbon::parse('2019-01-29'), Carbon::parse('2019-04-29')), diff --git a/tests/unit/Support/Calendar/Periodicity/WeeklyTest.php b/tests/unit/Support/Calendar/Periodicity/WeeklyTest.php index 69d2f36ca8..b076ff8c46 100644 --- a/tests/unit/Support/Calendar/Periodicity/WeeklyTest.php +++ b/tests/unit/Support/Calendar/Periodicity/WeeklyTest.php @@ -37,11 +37,13 @@ use FireflyIII\Support\Calendar\Periodicity\Interval; */ class WeeklyTest extends IntervalTestCase { - public static function factory(): Interval { + public static function factory(): Interval + { return new Periodicity\Weekly(); } - public static function provideIntervals(): array { + public static function provideIntervals(): array + { return [ new IntervalProvider(Carbon::now(), Carbon::now()->addWeek()), new IntervalProvider(Carbon::parse('2023-01-31'), Carbon::parse('2023-02-07')), diff --git a/tests/unit/Support/Calendar/Periodicity/YearlyTest.php b/tests/unit/Support/Calendar/Periodicity/YearlyTest.php index 9479faadb0..11143238f5 100644 --- a/tests/unit/Support/Calendar/Periodicity/YearlyTest.php +++ b/tests/unit/Support/Calendar/Periodicity/YearlyTest.php @@ -37,11 +37,13 @@ use FireflyIII\Support\Calendar\Periodicity\Interval; */ class YearlyTest extends IntervalTestCase { - public static function factory(): Interval { + public static function factory(): Interval + { return new Periodicity\Yearly(); } - public static function provideIntervals(): array { + public static function provideIntervals(): array + { return [ new IntervalProvider(Carbon::now(), Carbon::now()->addYears(1)), new IntervalProvider(Carbon::parse('2019-01-29'), Carbon::parse('2020-01-29')), diff --git a/tests/unit/Support/NavigationAddPeriodTest.php b/tests/unit/Support/NavigationAddPeriodTest.php index 0f192496ed..a087637920 100644 --- a/tests/unit/Support/NavigationAddPeriodTest.php +++ b/tests/unit/Support/NavigationAddPeriodTest.php @@ -39,12 +39,14 @@ class NavigationAddPeriodTest extends TestCase { private Navigation $navigation; - public function __construct(string $name) { + public function __construct(string $name) + { parent::__construct($name); $this->navigation = new Navigation(); } - public static function provideFrequencies(): array { + public static function provideFrequencies(): array + { return [ Periodicity::Daily->name => ['periodicity' => Periodicity::Daily, 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()], Periodicity::Weekly->name => ['periodicity' => Periodicity::Weekly, 'from' => Carbon::now(), 'expected' => Carbon::now()->addWeeks(1)], @@ -71,7 +73,8 @@ class NavigationAddPeriodTest extends TestCase ]; } - public static function provideMonthPeriods(): array { + public static function provideMonthPeriods(): array + { return [ '1M' => ['frequency' => '1M', 'from' => Carbon::parse('2023-06-25'), 'expected' => Carbon::parse('2023-06-25')->addMonths(1)], 'month' => ['frequency' => 'month', 'from' => Carbon::parse('2023-06-25'), 'expected' => Carbon::parse('2023-06-25')->addMonths(1)], @@ -86,7 +89,8 @@ class NavigationAddPeriodTest extends TestCase ]; } - public static function providePeriods(): array { + public static function providePeriods(): array + { return [ '1D' => ['frequency' => '1D', 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()], 'daily' => ['frequency' => 'daily', 'from' => Carbon::now(), 'expected' => Carbon::tomorrow()], @@ -111,7 +115,8 @@ class NavigationAddPeriodTest extends TestCase ]; } - public static function providePeriodsWithSkippingParam(): Generator { + public static function providePeriodsWithSkippingParam(): Generator + { $intervals = [ '2019-01-31 to 2019-02-11' => ['skip' => 10, 'frequency' => 'daily', 'from' => Carbon::parse('2019-01-31'), 'expected' => Carbon::parse('2019-02-11')], '1D' => ['skip' => 1, 'frequency' => '1D', 'from' => Carbon::now(), 'expected' => Carbon::now()->addDays(2)], @@ -155,7 +160,8 @@ class NavigationAddPeriodTest extends TestCase /** * @dataProvider providePeriodsWithSkippingParam */ - public function testGivenAFrequencyAndSkipIntervalWhenCalculateTheDateThenReturnsTheSkippedDateSuccessful(int $skip, string $frequency, Carbon $from, Carbon $expected) { + public function testGivenAFrequencyAndSkipIntervalWhenCalculateTheDateThenReturnsTheSkippedDateSuccessful(int $skip, string $frequency, Carbon $from, Carbon $expected) + { $period = $this->navigation->addPeriod($from, $frequency, $skip); $this->assertEquals($expected->toDateString(), $period->toDateString()); } @@ -163,7 +169,8 @@ class NavigationAddPeriodTest extends TestCase /** * @dataProvider providePeriods */ - public function testGivenAFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected) { + public function testGivenAFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected) + { $period = $this->navigation->addPeriod($from, $frequency, 0); $this->assertEquals($expected->toDateString(), $period->toDateString()); } @@ -171,7 +178,8 @@ class NavigationAddPeriodTest extends TestCase /** * @dataProvider provideFrequencies */ - public function testGivenAIntervalWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(Periodicity $periodicity, Carbon $from, Carbon $expected) { + public function testGivenAIntervalWhenCallTheNextDateByIntervalMethodThenReturnsTheExpectedDateSuccessful(Periodicity $periodicity, Carbon $from, Carbon $expected) + { $period = $this->navigation->nextDateByInterval($from, $periodicity); $this->assertEquals($expected->toDateString(), $period->toDateString()); } @@ -179,7 +187,8 @@ class NavigationAddPeriodTest extends TestCase /** * @dataProvider provideMonthPeriods */ - public function testGivenAMonthFrequencyWhenCalculateTheDateThenReturnsTheLastDayOfMonthSuccessful(string $frequency, Carbon $from, Carbon $expected) { + public function testGivenAMonthFrequencyWhenCalculateTheDateThenReturnsTheLastDayOfMonthSuccessful(string $frequency, Carbon $from, Carbon $expected) + { $period = $this->navigation->addPeriod($from, $frequency, 0); $this->assertEquals($expected->toDateString(), $period->toDateString()); } diff --git a/tests/unit/Support/NavigationStartOfPeriodTest.php b/tests/unit/Support/NavigationStartOfPeriodTest.php index c7e638a3e9..ca92a8d9ba 100644 --- a/tests/unit/Support/NavigationStartOfPeriodTest.php +++ b/tests/unit/Support/NavigationStartOfPeriodTest.php @@ -38,12 +38,14 @@ class NavigationStartOfPeriodTest extends TestCase { private Navigation $navigation; - public function __construct(string $name) { + public function __construct(string $name) + { parent::__construct($name); $this->navigation = new Navigation(); } - public static function provideDates(): array { + public static function provideDates(): array + { return [ 'custom' => ['frequency' => 'custom', 'from' => Carbon::now(), 'expected' => Carbon::now()], '1D' => ['frequency' => '1D', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()], @@ -72,7 +74,8 @@ class NavigationStartOfPeriodTest extends TestCase ]; } - public static function provideUnknownFrequencies(): array { + public static function provideUnknownFrequencies(): array + { return [ '1day' => ['frequency' => '1day', 'from' => Carbon::now(), 'expected' => Carbon::now()], 'unknown' => ['frequency' => 'unknown', 'from' => Carbon::now(), 'expected' => Carbon::now()->startOfDay()], @@ -83,7 +86,8 @@ class NavigationStartOfPeriodTest extends TestCase /** * @dataProvider provideDates */ - public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected) { + public function testGivenADateAndFrequencyWhenCalculateTheDateThenReturnsTheExpectedDateSuccessful(string $frequency, Carbon $from, Carbon $expected) + { $period = $this->navigation->startOfPeriod($from, $frequency); $this->assertEquals($expected->toDateString(), $period->toDateString()); } @@ -91,7 +95,8 @@ class NavigationStartOfPeriodTest extends TestCase /** * @dataProvider provideUnknownFrequencies */ - public function testGivenADateAndUnknownFrequencyWhenCalculateTheDateThenReturnsTheSameDateSuccessful(string $frequency, Carbon $from, Carbon $expected) { + public function testGivenADateAndUnknownFrequencyWhenCalculateTheDateThenReturnsTheSameDateSuccessful(string $frequency, Carbon $from, Carbon $expected) + { Log::shouldReceive('error') ->with(sprintf('Cannot do startOfPeriod for $repeat_freq "%s"', $frequency)) ->andReturnNull();