Skip to content

Commit

Permalink
Upgrade to PHP 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
range-of-motion committed Aug 31, 2024
1 parent 0bf9ba4 commit 7e42cbb
Show file tree
Hide file tree
Showing 30 changed files with 50 additions and 115 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/RecurringController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/AttachmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions app/Http/Controllers/BudgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 1 addition & 6 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 2 additions & 9 deletions app/Http/Controllers/EarningController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 2 additions & 5 deletions app/Http/Controllers/RecurringController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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),
Expand Down
11 changes: 2 additions & 9 deletions app/Http/Controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 1 addition & 6 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/ResendVerificationMailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/SpaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
12 changes: 2 additions & 10 deletions app/Http/Controllers/SpendingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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'),
Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 3 additions & 8 deletions app/Http/Controllers/TransactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,20 @@

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)
{
$filterBy = [];

if ($request->get('filterBy')) {
$filterBy = explode('-', $request->get('filterBy'));
$filterBy = explode('-', (string) $request->get('filterBy'));
}

return view('transactions.index', [
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/TransactionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/FetchConversionRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 8 additions & 8 deletions app/Jobs/ProcessRecurrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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++;
Expand Down Expand Up @@ -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
);
}

Expand Down
4 changes: 1 addition & 3 deletions app/Models/Recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Repositories/SpendingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 7e42cbb

Please sign in to comment.