diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8efe890e..7bd2c948 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,7 +20,7 @@ jobs: - name: Set up PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' - name: Install Composer dependencies run: composer install --no-interaction - name: Run PHPCS @@ -40,7 +40,7 @@ jobs: - name: Set up PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' - uses: actions/setup-node@v3 with: node-version: 18 diff --git a/README.md b/README.md index af3f31f6..945303d9 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ You can use Budget by hosting it yourself, or using [the instance hosted by us]( ## Requirements -* PHP 8.1 or higher +* PHP 8.2 or higher * HTTP server (for example Apache or NGINX) * MySQL * Composer diff --git a/app/Http/Controllers/Api/RecurringController.php b/app/Http/Controllers/Api/RecurringController.php index f0b37d87..2a0d1ddc 100644 --- a/app/Http/Controllers/Api/RecurringController.php +++ b/app/Http/Controllers/Api/RecurringController.php @@ -33,7 +33,7 @@ public function store(Request $request) 'space_id' => $space->id, 'type' => $request->input('type'), 'interval' => $request->input('interval'), - 'day' => (int) ltrim($request->input('day'), 0), + 'day' => (int) ltrim((string) $request->input('day'), 0), 'starts_on' => $request->input('start'), 'ends_on' => $request->input('end'), 'tag_id' => $request->input('tag_id'), diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php index 9f1e992c..3c54aefa 100644 --- a/app/Http/Controllers/AttachmentController.php +++ b/app/Http/Controllers/AttachmentController.php @@ -10,11 +10,8 @@ class AttachmentController extends Controller { - private $attachmentRepository; - - public function __construct(AttachmentRepository $attachmentRepository) + public function __construct(private readonly AttachmentRepository $attachmentRepository) { - $this->attachmentRepository = $attachmentRepository; } public function store(Request $request) diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index d169827d..01c0e550 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -12,13 +12,8 @@ class BudgetController extends Controller { - private $budgetRepository; - private $tagRepository; - - public function __construct(BudgetRepository $budgetRepository, TagRepository $tagRepository) + public function __construct(private readonly BudgetRepository $budgetRepository, private readonly TagRepository $tagRepository) { - $this->budgetRepository = $budgetRepository; - $this->tagRepository = $tagRepository; } public function index() diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 5d2d69d7..98017767 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -8,13 +8,8 @@ class DashboardController extends Controller { - private $dashboardRepository; - private $tagRepository; - - public function __construct(DashboardRepository $dashboardRepository, TagRepository $tagRepository) + public function __construct(private readonly DashboardRepository $dashboardRepository, private readonly TagRepository $tagRepository) { - $this->dashboardRepository = $dashboardRepository; - $this->tagRepository = $tagRepository; } public function __invoke(Request $request) diff --git a/app/Http/Controllers/EarningController.php b/app/Http/Controllers/EarningController.php index 09ead9dd..da1cc891 100644 --- a/app/Http/Controllers/EarningController.php +++ b/app/Http/Controllers/EarningController.php @@ -11,15 +11,8 @@ class EarningController extends Controller { - private $earningRepository; - private $conversionRateRepository; - - public function __construct( - EarningRepository $earningRepository, - ConversionRateRepository $conversionRateRepository - ) { - $this->earningRepository = $earningRepository; - $this->conversionRateRepository = $conversionRateRepository; + public function __construct(private readonly EarningRepository $earningRepository, private readonly ConversionRateRepository $conversionRateRepository) + { } public function show(Request $request, Earning $earning) diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index e2579680..f31f6564 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -11,11 +11,8 @@ class ImportController extends Controller { - private $spendingRepository; - - public function __construct(SpendingRepository $spendingRepository) + public function __construct(private readonly SpendingRepository $spendingRepository) { - $this->spendingRepository = $spendingRepository; } public function index() diff --git a/app/Http/Controllers/LoginController.php b/app/Http/Controllers/LoginController.php index 9461ca3e..32f2416d 100644 --- a/app/Http/Controllers/LoginController.php +++ b/app/Http/Controllers/LoginController.php @@ -10,11 +10,8 @@ class LoginController extends Controller { - private $loginAttemptRepository; - - public function __construct(LoginAttemptRepository $loginAttemptRepository) + public function __construct(private readonly LoginAttemptRepository $loginAttemptRepository) { - $this->loginAttemptRepository = $loginAttemptRepository; } public function index() diff --git a/app/Http/Controllers/RecurringController.php b/app/Http/Controllers/RecurringController.php index 161a09aa..110ac944 100644 --- a/app/Http/Controllers/RecurringController.php +++ b/app/Http/Controllers/RecurringController.php @@ -11,11 +11,8 @@ class RecurringController extends Controller { - private $recurringRepository; - - public function __construct(RecurringRepository $recurringRepository) + public function __construct(private readonly RecurringRepository $recurringRepository) { - $this->recurringRepository = $recurringRepository; } public function index() @@ -54,7 +51,7 @@ public function store(Request $request) session('space_id'), $request->type, $request->interval, - (int) ltrim($request->input('day'), 0), + (int) ltrim((string) $request->input('day'), 0), $request->start, $request->input('end', null), $request->input('tag', null), diff --git a/app/Http/Controllers/RegisterController.php b/app/Http/Controllers/RegisterController.php index d6d39bf4..ca5e343b 100644 --- a/app/Http/Controllers/RegisterController.php +++ b/app/Http/Controllers/RegisterController.php @@ -16,15 +16,8 @@ class RegisterController extends Controller { - private $spaceRepository; - private $loginAttemptRepository; - - public function __construct( - SpaceRepository $spaceRepository, - LoginAttemptRepository $loginAttemptRepository - ) { - $this->spaceRepository = $spaceRepository; - $this->loginAttemptRepository = $loginAttemptRepository; + public function __construct(private readonly SpaceRepository $spaceRepository, private readonly LoginAttemptRepository $loginAttemptRepository) + { } public function index() diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index fad9632b..8d8d54cf 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -9,13 +9,8 @@ class ReportController extends Controller { - private $transactionRepository; - private $tagRepository; - - public function __construct(TransactionRepository $transactionRepository, TagRepository $tagRepository) + public function __construct(private readonly TransactionRepository $transactionRepository, private readonly TagRepository $tagRepository) { - $this->transactionRepository = $transactionRepository; - $this->tagRepository = $tagRepository; } public function index() diff --git a/app/Http/Controllers/ResendVerificationMailController.php b/app/Http/Controllers/ResendVerificationMailController.php index 00430561..32592820 100644 --- a/app/Http/Controllers/ResendVerificationMailController.php +++ b/app/Http/Controllers/ResendVerificationMailController.php @@ -16,9 +16,9 @@ public function __invoke(Request $request) (new SendVerificationMailAction())->execute(Auth::user()->id); $request->session()->flash('verification_mail_status', 'success'); - } catch (UserAlreadyVerifiedException $e) { + } catch (UserAlreadyVerifiedException) { $request->session()->flash('verification_mail_status', 'already_verified'); - } catch (VerificationMailRateLimitException $e) { + } catch (VerificationMailRateLimitException) { $request->session()->flash('verification_mail_status', 'rate_limited'); } diff --git a/app/Http/Controllers/ResetPasswordController.php b/app/Http/Controllers/ResetPasswordController.php index cb673a3c..67d749ae 100644 --- a/app/Http/Controllers/ResetPasswordController.php +++ b/app/Http/Controllers/ResetPasswordController.php @@ -12,11 +12,8 @@ class ResetPasswordController extends Controller { - private $passwordResetRepository; - - public function __construct(PasswordResetRepository $passwordResetRepository) + public function __construct(private readonly PasswordResetRepository $passwordResetRepository) { - $this->passwordResetRepository = $passwordResetRepository; } public function get(Request $request) diff --git a/app/Http/Controllers/SpaceController.php b/app/Http/Controllers/SpaceController.php index f2838551..252be2cd 100644 --- a/app/Http/Controllers/SpaceController.php +++ b/app/Http/Controllers/SpaceController.php @@ -95,11 +95,11 @@ public function invite(Request $request, Space $space) $authenticatedUser->id, $request->role ); - } catch (SpaceInviteInviteeAlreadyPresentException $e) { + } catch (SpaceInviteInviteeAlreadyPresentException) { return redirect() ->route('spaces.edit', ['space' => $space->id]) ->with('inviteStatus', 'present'); - } catch (SpaceInviteAlreadyExistsException $e) { + } catch (SpaceInviteAlreadyExistsException) { return redirect() ->route('spaces.edit', ['space' => $space->id]) ->with('inviteStatus', 'exists'); diff --git a/app/Http/Controllers/SpendingController.php b/app/Http/Controllers/SpendingController.php index 8045a12e..4404d93e 100644 --- a/app/Http/Controllers/SpendingController.php +++ b/app/Http/Controllers/SpendingController.php @@ -12,15 +12,8 @@ class SpendingController extends Controller { - private $spendingRepository; - private $conversionRateRepository; - - public function __construct( - SpendingRepository $spendingRepository, - ConversionRateRepository $conversionRateRepository - ) { - $this->spendingRepository = $spendingRepository; - $this->conversionRateRepository = $conversionRateRepository; + public function __construct(private readonly SpendingRepository $spendingRepository, private readonly ConversionRateRepository $conversionRateRepository) + { } public function create() @@ -60,7 +53,6 @@ public function store(Request $request) $this->spendingRepository->create( session('space_id'), null, - null, $request->input('tag_id'), $request->input('date'), $request->input('description'), diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index cf21f37a..0a3b9c7f 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -8,11 +8,8 @@ class TagController extends Controller { - private $tagRepository; - - public function __construct(TagRepository $tagRepository) + public function __construct(private readonly TagRepository $tagRepository) { - $this->tagRepository = $tagRepository; } public function index() diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index ca5a8333..f28a1463 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -12,17 +12,12 @@ class TransactionController extends Controller { - private $currencyRepository; - private $recurringRepository; - public function __construct( TransactionRepository $transactionRepository, - CurrencyRepository $currencyRepository, - RecurringRepository $recurringRepository + private readonly CurrencyRepository $currencyRepository, + private readonly RecurringRepository $recurringRepository ) { $this->repository = $transactionRepository; - $this->currencyRepository = $currencyRepository; - $this->recurringRepository = $recurringRepository; } public function index(Request $request) @@ -30,7 +25,7 @@ public function index(Request $request) $filterBy = []; if ($request->get('filterBy')) { - $filterBy = explode('-', $request->get('filterBy')); + $filterBy = explode('-', (string) $request->get('filterBy')); } return view('transactions.index', [ diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index ad8bbb95..51f81221 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -10,7 +10,7 @@ class TransactionResource extends JsonResource { public function toArray(Request $request): array { - $isEarning = get_class($this->resource) === Earning::class; + $isEarning = $this->resource::class === Earning::class; return [ 'id' => $this->id, diff --git a/app/Jobs/FetchConversionRate.php b/app/Jobs/FetchConversionRate.php index 77432baf..184e5d17 100644 --- a/app/Jobs/FetchConversionRate.php +++ b/app/Jobs/FetchConversionRate.php @@ -60,7 +60,7 @@ public function handle( $decoded_response = json_decode($response->getBody(), true); $rate = $decoded_response[$baseCurrency->iso_lowercased][$targetCurrency->iso_lowercased]; - } catch (Exception $e) { + } catch (Exception) { continue; } diff --git a/app/Jobs/ProcessRecurrings.php b/app/Jobs/ProcessRecurrings.php index fe90c943..b57b54db 100644 --- a/app/Jobs/ProcessRecurrings.php +++ b/app/Jobs/ProcessRecurrings.php @@ -83,22 +83,22 @@ public function handle( switch ($recurring->interval) { case 'daily': - $cursorDate = date('Y-m-d', strtotime('+1 day', strtotime($cursorDate))); + $cursorDate = date('Y-m-d', strtotime('+1 day', strtotime((string) $cursorDate))); break; case 'weekly': - $cursorDate = date('Y-m-d', strtotime('+1 week', strtotime($cursorDate))); + $cursorDate = date('Y-m-d', strtotime('+1 week', strtotime((string) $cursorDate))); break; case 'biweekly': - $cursorDate = date('Y-m-d', strtotime('+2 weeks', strtotime($cursorDate))); + $cursorDate = date('Y-m-d', strtotime('+2 weeks', strtotime((string) $cursorDate))); break; // Monthly is a different story, because of the different lengths of the months // See below case 'yearly': - $cursorDate = date('Y-m-d', strtotime('+1 year', strtotime($cursorDate))); + $cursorDate = date('Y-m-d', strtotime('+1 year', strtotime((string) $cursorDate))); break; } @@ -115,8 +115,8 @@ public function handle( * Hence why this next piece of code exists :shrug: */ if ($recurring->interval === 'monthly') { - $year = date('Y', strtotime($cursorDate)); - $month = date('n', strtotime($cursorDate)); + $year = date('Y', strtotime((string) $cursorDate)); + $month = date('n', strtotime((string) $cursorDate)); $day = date('j', strtotime($startingDate)); $month++; @@ -147,12 +147,12 @@ public function handle( if ($recurring->type === 'spending') { $this->spendingRepository->create( $recurring->space_id, - null, $recurring->id, $recurring->tag_id, $occuranceDate, $recurring->description, - $amount + $amount, + null ); } diff --git a/app/Models/Recurring.php b/app/Models/Recurring.php index 8eeff469..f34ee0a0 100644 --- a/app/Models/Recurring.php +++ b/app/Models/Recurring.php @@ -51,9 +51,7 @@ protected function dueDays(): Attribute protected function status(): Attribute { - return Attribute::make(function () { - return $this->starts_on <= date('Y-m-d') && ($this->ends_on >= date('Y-m-d') || !$this->ends_on); - }); + return Attribute::make(fn() => $this->starts_on <= date('Y-m-d') && ($this->ends_on >= date('Y-m-d') || !$this->ends_on)); } // Relations diff --git a/app/Models/Widget.php b/app/Models/Widget.php index c8162520..49fa268b 100644 --- a/app/Models/Widget.php +++ b/app/Models/Widget.php @@ -39,7 +39,7 @@ protected function properties(): Attribute */ return Attribute::make( - get: fn ($value) => json_decode($value), + get: fn ($value) => json_decode((string) $value), set: fn ($value) => json_encode($value, JSON_FORCE_OBJECT), ); } diff --git a/app/Repositories/SpendingRepository.php b/app/Repositories/SpendingRepository.php index 373301d3..7f960a9f 100644 --- a/app/Repositories/SpendingRepository.php +++ b/app/Repositories/SpendingRepository.php @@ -20,12 +20,12 @@ public function getValidationRules(): array public function create( int $spaceId, - ?int $importId = null, ?int $recurringId, ?int $tagId, string $date, string $description, - int $amount + int $amount, + ?int $importId = null ): Spending { return Spending::create([ 'space_id' => $spaceId, diff --git a/app/Repositories/TransactionRepository.php b/app/Repositories/TransactionRepository.php index 0e083f73..2509617a 100644 --- a/app/Repositories/TransactionRepository.php +++ b/app/Repositories/TransactionRepository.php @@ -86,9 +86,7 @@ public function getTransactionsByYearMonth(array $filterBy = []) // Sort transactions foreach ($yearMonths as &$yearMonth) { - usort($yearMonth, function ($a, $b) { - return $a->happened_on < $b->happened_on; - }); + usort($yearMonth, fn($a, $b) => $a->happened_on < $b->happened_on); } // Sort yearMonths diff --git a/app/Widgets/Spent.php b/app/Widgets/Spent.php index b3cd78a5..de7784af 100644 --- a/app/Widgets/Spent.php +++ b/app/Widgets/Spent.php @@ -8,11 +8,8 @@ class Spent { - private $properties; - - public function __construct(object $properties) + public function __construct(private readonly object $properties) { - $this->properties = $properties; } public function render() diff --git a/composer.json b/composer.json index d6d63ce9..0cd5d3c1 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "license": "MIT", "type": "project", "require": { - "php": "^8.1", + "php": "^8.2", "ext-calendar": "*", "doctrine/dbal": "^3.0", "guzzlehttp/guzzle": "^7.0.1", diff --git a/composer.lock b/composer.lock index 458de902..22f5e0da 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "542613d7062068b3b8abd065c9500796", + "content-hash": "b18816a490a2ba471b7788f52df82000", "packages": [ { "name": "brick/math", @@ -8551,7 +8551,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^8.1", + "php": "^8.2", "ext-calendar": "*" }, "platform-dev": [], diff --git a/docker/Dockerfile b/docker/Dockerfile index 5bd6bb5c..32c0ff28 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM php:8.1-fpm-bullseye +FROM php:8.2-fpm-bullseye # Grab magical script that brings back balance throughout earth COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ diff --git a/phpcs.xml b/phpcs.xml index 3d044652..a3e8b7a8 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -4,7 +4,9 @@ ./config ./tests - + + +