Skip to content

Commit

Permalink
Fix phpstan error courtesy of the laravel 11 upgrade (changed signatu…
Browse files Browse the repository at this point in the history
…res and return types)
  • Loading branch information
JC5 committed Apr 2, 2024
1 parent 87911c2 commit a17bc72
Show file tree
Hide file tree
Showing 73 changed files with 2,778 additions and 2,833 deletions.
6 changes: 3 additions & 3 deletions .ci/php-cs-fixer/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": {
"friendsofphp/php-cs-fixer": "^3.12"
}
"require": {
"friendsofphp/php-cs-fixer": "^3.12"
}
}
4 changes: 2 additions & 2 deletions .ci/phpmd/phpmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<ruleset name="pcsg-generated-ruleset"
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="pcsg-generated-ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>Firefly III ruleset.</description>
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/close-duplicates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "Issues - Command to close duplicate issues"
# the workflow to execute on is comments that are newly created
on:
issue_comment:
types: [created]
types: [ created ]

permissions:
issues: write
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/debug-info-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: 'Issues - Respond to hidden commands'
# the workflow to execute on is comments that are newly created
on:
issues:
types: [opened, edited]
types: [ opened, edited ]
issue_comment:
types: [created]
types: [ created ]

# permissions needed for reacting to IssueOps commands on issues and PRs
permissions:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/label-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: 'Issues - Reply to specific labels'

on:
issues:
types: [labeled, unlabeled]
types: [ labeled, unlabeled ]
pull_request_target:
types: [labeled, unlabeled]
types: [ labeled, unlabeled ]
discussion:
types: [labeled, unlabeled]
types: [ labeled, unlabeled ]

permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
required: true
default: 'develop'
schedule:
- cron: '0 3 * * MON,THU'
- cron: '0 3 * * MON,THU'

jobs:
build:
Expand Down
10 changes: 3 additions & 7 deletions app/Api/V1/Requests/Models/Rule/TestRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,13 @@ private function getPage(): int

private function getDate(string $field): ?Carbon
{
$value = $this->query($field);
$value = $this->query($field);
if (is_array($value)) {
return null;
}
$value = (string)$value;
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr($value, 0, 10));
if (false === $result) {
return null;
}
$value = (string)$value;

return $result;
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr($value, 0, 10));
}

private function getAccounts(): array
Expand Down
10 changes: 3 additions & 7 deletions app/Api/V1/Requests/Models/Rule/TriggerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ public function getTriggerParameters(): array

private function getDate(string $field): ?Carbon
{
$value = $this->query($field);
$value = $this->query($field);
if (is_array($value)) {
return null;
}
$value = (string)$value;
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr($value, 0, 10));
if (false === $result) {
return null;
}
$value = (string)$value;

return $result;
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr($value, 0, 10));
}

private function getAccounts(): array
Expand Down
10 changes: 3 additions & 7 deletions app/Api/V1/Requests/Models/RuleGroup/TestRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ public function getTestParameters(): array

private function getDate(string $field): ?Carbon
{
$value = $this->query($field);
$value = $this->query($field);
if (is_array($value)) {
return null;
}
$value = (string)$value;
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr($value, 0, 10));
if (false === $result) {
return null;
}
$value = (string)$value;

return $result;
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr($value, 0, 10));
}

private function getAccounts(): array
Expand Down
10 changes: 3 additions & 7 deletions app/Api/V1/Requests/Models/RuleGroup/TriggerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ public function getTriggerParameters(): array

private function getDate(string $field): ?Carbon
{
$value = $this->query($field);
$value = $this->query($field);
if (is_array($value)) {
return null;
}
$value = (string)$value;
$result = null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr($value, 0, 10));
if (false === $result) {
return null;
}
$value = (string)$value;

return $result;
return null === $this->query($field) ? null : Carbon::createFromFormat('Y-m-d', substr($value, 0, 10));
}

private function getAccounts(): array
Expand Down
2 changes: 1 addition & 1 deletion app/Api/V2/Controllers/Summary/BasicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private function getLeftToSpendInfo(Carbon $start, Carbon $end): array
app('log')->debug(sprintf('Amount left is %s', $left));

// how much left per day?
$days = (int) $today->diffInDays($end, true) + 1;
$days = (int)$today->diffInDays($end, true) + 1;
$perDay = '0';
$perDayNative = '0';
if (0 !== $days && bccomp($left, '0') > -1) {
Expand Down
16 changes: 8 additions & 8 deletions app/Api/V2/Controllers/UserGroup/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ function ($request, $next) {
);
}

public function useUserGroup(UserGroup $userGroup): JsonResponse
{
// group validation is already in place, so can just update the user.
$this->repository->useUserGroup($userGroup);

return response()->json([], 204);
}

public function update(UpdateRequest $request, UserGroup $userGroup): JsonResponse
{
$all = $request->getAll();
Expand All @@ -87,4 +79,12 @@ public function updateMembership(UpdateMembershipRequest $request, UserGroup $us
->header('Content-Type', self::CONTENT_TYPE)
;
}

public function useUserGroup(UserGroup $userGroup): JsonResponse
{
// group validation is already in place, so can just update the user.
$this->repository->useUserGroup($userGroup);

return response()->json([], 204);
}
}
14 changes: 2 additions & 12 deletions app/Console/Commands/Correction/MigratePreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,10 @@

class MigratePreferences extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:migrate-preferences';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Give Firefly III preferences a user group ID so they can be made administration specific.';

protected $signature = 'firefly-iii:migrate-preferences';

/**
* Execute the console command.
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Export/ExportData.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private function getDateParameter(string $field): Carbon
$this->friendlyError(sprintf('%s date "%s" must be formatted YYYY-MM-DD. Field will be ignored.', $field, $this->option('start')));
$error = true;
}
if (false === $date) {
if (null === $date) {
$this->friendlyError(sprintf('%s date "%s" must be formatted YYYY-MM-DD.', $field, $this->option('start')));

throw new FireflyException(sprintf('%s date "%s" must be formatted YYYY-MM-DD.', $field, $this->option('start')));
Expand Down
15 changes: 2 additions & 13 deletions app/Console/Commands/System/LaravelPassportKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,13 @@ class LaravelPassportKeys extends Command
{
use ShowsFriendlyMessages;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:laravel-passport-keys';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Calls the Laravel "passport:keys" but doesn\'t exit 1.';
protected $signature = 'firefly-iii:laravel-passport-keys';

/**
* Execute the console command.
*/
public function handle()
public function handle(): int
{
Artisan::call('passport:keys --no-interaction', []);
$result = Artisan::output();
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Tools/ApplyRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private function verifyInputDates(): void
if (null !== $endString && '' !== $endString) {
$inputEnd = Carbon::createFromFormat('Y-m-d', $endString);
}
if (false === $inputEnd || false === $inputStart) {
if (null === $inputEnd || null === $inputStart) {
Log::error('Could not parse start or end date in verifyInputDate().');

return;
Expand Down
2 changes: 1 addition & 1 deletion app/Handlers/Events/UserEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public function storeUserIPAddress(ActuallyLoggedIn $event): void
}
// clean up old entries (6 months)
$carbon = Carbon::createFromFormat('Y-m-d H:i:s', $preference[$index]['time']);
if (false !== $carbon && $carbon->diffInMonths(today(), true) > 6) {
if (null !== $carbon && $carbon->diffInMonths(today(), true) > 6) {
app('log')->debug(sprintf('Entry for %s is very old, remove it.', $row['ip']));
unset($preference[$index]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Budget/BudgetLimitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function store(Request $request): JsonResponse|RedirectResponse
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));

if (false === $start || false === $end) {
if (null === $start || null === $end) {
return response()->json([]);
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public function dateRange(Request $request): JsonResponse
app('log')->error(sprintf('End could not parse date string "%s" so ignore it.', $stringEnd));
$end = Carbon::now()->endOfMonth();
}
if (false === $start) {
if (null === $start) {
$start = Carbon::now()->startOfMonth();
}
if (false === $end) {
if (null === $end) {
$end = Carbon::now()->endOfMonth();
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Json/BoxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static function (AvailableBudget $availableBudget) use ($currency) { // @phpstan
$boxTitle = (string)trans('firefly.left_to_spend');
$activeDaysLeft = $this->activeDaysLeft($start, $end); // see method description.
$display = 1; // not overspent
$leftPerDayAmount = 0 === (int) $activeDaysLeft ? $leftToSpendAmount : bcdiv($leftToSpendAmount, (string)$activeDaysLeft);
$leftPerDayAmount = 0 === $activeDaysLeft ? $leftToSpendAmount : bcdiv($leftToSpendAmount, (string)$activeDaysLeft);
app('log')->debug(sprintf('Left to spend per day is %s', $leftPerDayAmount));
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Json/RecurrenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function events(Request $request): JsonResponse
$skip = $skip < 0 || $skip > 31 ? 0 : $skip;
$weekend = $weekend < 1 || $weekend > 4 ? 1 : $weekend;

if (false === $start || false === $end || false === $firstDate || false === $endDate) {
if (null === $start || null === $end || null === $firstDate || null === $endDate) {
return response()->json();
}

Expand Down Expand Up @@ -112,7 +112,7 @@ public function events(Request $request): JsonResponse
$actualEnd = clone $end;

if ('until_date' === $endsAt) {
$actualEnd = $endDate ?? clone $end;
$actualEnd = $endDate;
$occurrences = $this->recurring->getOccurrencesInRange($repetition, $actualStart, $actualEnd);
}
if ('times' === $endsAt) {
Expand Down Expand Up @@ -155,7 +155,7 @@ public function suggest(Request $request): JsonResponse
} catch (InvalidFormatException $e) {
$date = Carbon::today(config('app.timezone'));
}
if (false === $date) {
if (null === $date) {
return response()->json();
}
$date->startOfDay();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/PreferencesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ public function postIndex(Request $request)

// same for locale:
if (!auth()->user()->hasRole('demo')) {
/** @var Preference $locale */
$locale = $request->get('locale');
$locale = (string) $request->get('locale');
$locale = '' === $locale ? null : $locale;
app('preferences')->set('locale', $locale);
}

Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

namespace FireflyIII\Http\Controllers;

use Auth;
use FireflyIII\Events\UserChangedEmail;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Exceptions\ValidationException;
Expand Down Expand Up @@ -467,9 +466,7 @@ public function postCode(TokenFormRequest $request)
if (is_array($secret)) {
$secret = null;
}
if (is_int($secret)) {
$secret = (string)$secret;
}
$secret = (string)$secret;

$repository->setMFACode($user, $secret);

Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/DownloadExchangeRates.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private function downloadRates(TransactionCurrency $currency): void
return;
}
$date = Carbon::createFromFormat('Y-m-d', $json['date'], config('app.timezone'));
if (false === $date) {
if (null === $date) {
return;
}
$this->saveRates($currency, $date, $json['rates']);
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/WarnAboutBills.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function getDiff(Bill $bill, string $field): int
$today = clone $this->date;
$carbon = clone $bill->{$field};

return (int) $today->diffInDays($carbon);
return (int)$today->diffInDays($carbon);
}

private function sendWarning(Bill $bill, string $field): void
Expand Down
14 changes: 7 additions & 7 deletions app/Models/Preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
/**
* FireflyIII\Models\Preference
*
* @property int $id
* @property null|Carbon $created_at
* @property null|Carbon $updated_at
* @property int $user_id
* @property string $name
* @property null|array|int|string $data
* @property User $user
* @property int $id
* @property null|Carbon $created_at
* @property null|Carbon $updated_at
* @property int $user_id
* @property string $name
* @property null|array|bool|int|string $data
* @property User $user
*
* @method static Builder|Preference newModelQuery()
* @method static Builder|Preference newQuery()
Expand Down
Loading

0 comments on commit a17bc72

Please sign in to comment.