mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
Fix various phpstan issues.
This commit is contained in:
@@ -74,8 +74,8 @@ class Range
|
|||||||
}
|
}
|
||||||
|
|
||||||
$today = today(config('app.timezone'));
|
$today = today(config('app.timezone'));
|
||||||
$start = app('navigation')->updateStartDate($viewRange, $today);
|
$start = app('navigation')->updateStartDate((string) $viewRange, $today);
|
||||||
$end = app('navigation')->updateEndDate($viewRange, $start);
|
$end = app('navigation')->updateEndDate((string) $viewRange, $start);
|
||||||
|
|
||||||
app('session')->put('start', $start);
|
app('session')->put('start', $start);
|
||||||
app('session')->put('end', $end);
|
app('session')->put('end', $end);
|
||||||
|
@@ -25,12 +25,13 @@ namespace FireflyIII\Models;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Eloquent;
|
use Eloquent;
|
||||||
|
use FireflyIII\Support\Models\ReturnsIntegerIdTrait;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Database\Query\Builder;
|
use Illuminate\Database\Query\Builder;
|
||||||
use FireflyIII\Support\Models\ReturnsIntegerIdTrait;
|
|
||||||
/**
|
/**
|
||||||
* FireflyIII\Models\RecurrenceRepetition
|
* FireflyIII\Models\RecurrenceRepetition
|
||||||
*
|
*
|
||||||
@@ -38,11 +39,11 @@ use FireflyIII\Support\Models\ReturnsIntegerIdTrait;
|
|||||||
* @property Carbon|null $created_at
|
* @property Carbon|null $created_at
|
||||||
* @property Carbon|null $updated_at
|
* @property Carbon|null $updated_at
|
||||||
* @property Carbon|null $deleted_at
|
* @property Carbon|null $deleted_at
|
||||||
* @property int $recurrence_id
|
* @property int $recurrence_id
|
||||||
* @property string $repetition_type
|
* @property string $repetition_type
|
||||||
* @property string $repetition_moment
|
* @property string $repetition_moment
|
||||||
* @property int|string $repetition_skip
|
* @property int $repetition_skip
|
||||||
* @property int|string $weekend
|
* @property int $weekend
|
||||||
* @property-read Recurrence $recurrence
|
* @property-read Recurrence $recurrence
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceRepetition newModelQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceRepetition newModelQuery()
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceRepetition newQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceRepetition newQuery()
|
||||||
@@ -104,4 +105,24 @@ class RecurrenceRepetition extends Model
|
|||||||
get: static fn($value) => (int)$value,
|
get: static fn($value) => (int)$value,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Attribute
|
||||||
|
*/
|
||||||
|
protected function repetitionSkip(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: static fn($value) => (int)$value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Attribute
|
||||||
|
*/
|
||||||
|
protected function weekend(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: static fn($value) => (int)$value,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -95,7 +95,7 @@ class TransactionJournalMeta extends Model
|
|||||||
{
|
{
|
||||||
$data = json_encode($value);
|
$data = json_encode($value);
|
||||||
$this->attributes['data'] = $data;
|
$this->attributes['data'] = $data;
|
||||||
$this->attributes['hash'] = (string) hash('sha256', $data);
|
$this->attributes['hash'] = hash('sha256',(string) $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -653,7 +653,7 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
return $this->user->bills()
|
return $this->user->bills()
|
||||||
->where('active', true)
|
->where('active', true)
|
||||||
->orderBy('bills.name', 'ASC')
|
->orderBy('bills.name', 'ASC')
|
||||||
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]);
|
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]); // @phpstan-ignore-line
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -201,7 +201,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
|||||||
{
|
{
|
||||||
$query = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
$query = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
->groupBy('transaction_journals.id');
|
->groupBy('transaction_journals.id');
|
||||||
$result = $query->get(['transaction_journals.id as id', DB::raw('count(transactions.id) as transaction_count')]);
|
$result = $query->get(['transaction_journals.id as id', DB::raw('count(transactions.id) as transaction_count')]); // @phpstan-ignore-line
|
||||||
$journalIds = [];
|
$journalIds = [];
|
||||||
/** @var stdClass $row */
|
/** @var stdClass $row */
|
||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
|
@@ -69,9 +69,9 @@ class RecurringRepository implements RecurringRepositoryInterface
|
|||||||
// if not, loop set and try to read the recurrence_date. If it matches start or end, return it as well.
|
// if not, loop set and try to read the recurrence_date. If it matches start or end, return it as well.
|
||||||
$set
|
$set
|
||||||
= TransactionJournalMeta::where(static function (Builder $q1) use ($recurrence) {
|
= TransactionJournalMeta::where(static function (Builder $q1) use ($recurrence) {
|
||||||
$q1->where('name', 'recurrence_id');
|
$q1->where('name', 'recurrence_id');
|
||||||
$q1->where('data', json_encode((string)$recurrence->id));
|
$q1->where('data', json_encode((string)$recurrence->id));
|
||||||
})->get(['journal_meta.transaction_journal_id']);
|
})->get(['journal_meta.transaction_journal_id']);
|
||||||
|
|
||||||
// there are X journals made for this recurrence. Any of them meant for today?
|
// there are X journals made for this recurrence. Any of them meant for today?
|
||||||
foreach ($set as $journalMeta) {
|
foreach ($set as $journalMeta) {
|
||||||
@@ -495,6 +495,10 @@ class RecurringRepository implements RecurringRepositoryInterface
|
|||||||
/** @var Preference $pref */
|
/** @var Preference $pref */
|
||||||
$pref = app('preferences')->getForUser($this->user, 'language', config('firefly.default_language', 'en_US'));
|
$pref = app('preferences')->getForUser($this->user, 'language', config('firefly.default_language', 'en_US'));
|
||||||
$language = $pref->data;
|
$language = $pref->data;
|
||||||
|
if (is_array($language)) {
|
||||||
|
$language = 'en_US';
|
||||||
|
}
|
||||||
|
$language = (string)$language;
|
||||||
if ('daily' === $repetition->repetition_type) {
|
if ('daily' === $repetition->repetition_type) {
|
||||||
return (string)trans('firefly.recurring_daily', [], $language);
|
return (string)trans('firefly.recurring_daily', [], $language);
|
||||||
}
|
}
|
||||||
@@ -532,6 +536,9 @@ class RecurringRepository implements RecurringRepositoryInterface
|
|||||||
//
|
//
|
||||||
$today = today(config('app.timezone'))->endOfYear();
|
$today = today(config('app.timezone'))->endOfYear();
|
||||||
$repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment);
|
$repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment);
|
||||||
|
if(false === $repDate) {
|
||||||
|
$repDate = clone $today;
|
||||||
|
}
|
||||||
$diffInYears = $today->diffInYears($repDate);
|
$diffInYears = $today->diffInYears($repDate);
|
||||||
$repDate->addYears($diffInYears); // technically not necessary.
|
$repDate->addYears($diffInYears); // technically not necessary.
|
||||||
$string = $repDate->isoFormat((string)trans('config.month_and_day_no_year_js'));
|
$string = $repDate->isoFormat((string)trans('config.month_and_day_no_year_js'));
|
||||||
|
@@ -206,12 +206,15 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
|||||||
{
|
{
|
||||||
$owner = UserRole::whereTitle(UserRoleEnum::OWNER)->first();
|
$owner = UserRole::whereTitle(UserRoleEnum::OWNER)->first();
|
||||||
app('log')->debug('in update membership');
|
app('log')->debug('in update membership');
|
||||||
|
/** @var User|null $user */
|
||||||
$user = null;
|
$user = null;
|
||||||
if (array_key_exists('id', $data)) {
|
if (array_key_exists('id', $data)) {
|
||||||
|
/** @var User|null $user */
|
||||||
$user = User::find($data['id']);
|
$user = User::find($data['id']);
|
||||||
app('log')->debug('Found user by ID');
|
app('log')->debug('Found user by ID');
|
||||||
}
|
}
|
||||||
if (array_key_exists('email', $data) && '' !== (string)$data['email']) {
|
if (array_key_exists('email', $data) && '' !== (string)$data['email']) {
|
||||||
|
/** @var User|null $user */
|
||||||
$user = User::whereEmail($data['email'])->first();
|
$user = User::whereEmail($data['email'])->first();
|
||||||
app('log')->debug('Found user by email');
|
app('log')->debug('Found user by email');
|
||||||
}
|
}
|
||||||
|
@@ -123,10 +123,15 @@ class UpdateRequest implements UpdateRequestInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parse response a bit. No message yet.
|
// parse response a bit. No message yet.
|
||||||
$response = $json['firefly_iii'][$channel];
|
$response = $json['firefly_iii'][$channel];
|
||||||
|
$date = Carbon::createFromFormat('Y-m-d', $response['date']);
|
||||||
|
if (false === $date) {
|
||||||
|
$date = today(config('app.timezone'));
|
||||||
|
}
|
||||||
$return['version'] = $response['version'];
|
$return['version'] = $response['version'];
|
||||||
$return['level'] = 'success';
|
$return['level'] = 'success';
|
||||||
$return['date'] = Carbon::createFromFormat('Y-m-d', $response['date'])->startOfDay();
|
$return['date'] = $date->startOfDay();
|
||||||
|
|
||||||
app('log')->info('Response from update server', $response);
|
app('log')->info('Response from update server', $response);
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
@@ -118,7 +118,7 @@ class AccountDestroyService
|
|||||||
|
|
||||||
$collection = Transaction::groupBy('transaction_journal_id', 'account_id')
|
$collection = Transaction::groupBy('transaction_journal_id', 'account_id')
|
||||||
->where('account_id', $moveTo->id)
|
->where('account_id', $moveTo->id)
|
||||||
->get(['transaction_journal_id', 'account_id', DB::raw('count(*) as the_count')]);
|
->get(['transaction_journal_id', 'account_id', DB::raw('count(*) as the_count')]); // @phpstan-ignore-line
|
||||||
if (0 === $collection->count()) {
|
if (0 === $collection->count()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -224,7 +224,11 @@ trait AccountServiceTrait
|
|||||||
protected function createOBGroup(Account $account, array $data): TransactionGroup
|
protected function createOBGroup(Account $account, array $data): TransactionGroup
|
||||||
{
|
{
|
||||||
app('log')->debug('Now going to create an OB group.');
|
app('log')->debug('Now going to create an OB group.');
|
||||||
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
||||||
|
if (is_array($language)) {
|
||||||
|
$language = 'en_US';
|
||||||
|
}
|
||||||
|
$language = (string)$language;
|
||||||
$sourceId = null;
|
$sourceId = null;
|
||||||
$sourceName = null;
|
$sourceName = null;
|
||||||
$destId = null;
|
$destId = null;
|
||||||
@@ -478,6 +482,10 @@ trait AccountServiceTrait
|
|||||||
}
|
}
|
||||||
|
|
||||||
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
||||||
|
if (is_array($language)) {
|
||||||
|
$language = 'en_US';
|
||||||
|
}
|
||||||
|
$language = (string)$language;
|
||||||
|
|
||||||
// set source and/or destination based on whether the amount is positive or negative.
|
// set source and/or destination based on whether the amount is positive or negative.
|
||||||
// first, assume the amount is positive and go from there:
|
// first, assume the amount is positive and go from there:
|
||||||
@@ -686,6 +694,10 @@ trait AccountServiceTrait
|
|||||||
{
|
{
|
||||||
app('log')->debug('Now going to create an OB group.');
|
app('log')->debug('Now going to create an OB group.');
|
||||||
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
$language = app('preferences')->getForUser($account->user, 'language', 'en_US')->data;
|
||||||
|
if (is_array($language)) {
|
||||||
|
$language = 'en_US';
|
||||||
|
}
|
||||||
|
$language= (string)$language;
|
||||||
$sourceId = null;
|
$sourceId = null;
|
||||||
$sourceName = null;
|
$sourceName = null;
|
||||||
$destId = null;
|
$destId = null;
|
||||||
|
@@ -338,6 +338,9 @@ class AccountUpdateService
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$array = $preference->data;
|
$array = $preference->data;
|
||||||
|
if(!is_array($array)) {
|
||||||
|
$array = [$array];
|
||||||
|
}
|
||||||
app('log')->debug('Old array is: ', $array);
|
app('log')->debug('Old array is: ', $array);
|
||||||
app('log')->debug(sprintf('Must remove : %d', $account->id));
|
app('log')->debug(sprintf('Must remove : %d', $account->id));
|
||||||
$removeAccountId = $account->id;
|
$removeAccountId = $account->id;
|
||||||
|
@@ -77,7 +77,7 @@ class Amount
|
|||||||
$fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, $symbol);
|
$fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, $symbol);
|
||||||
$fmt->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces);
|
$fmt->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, $decimalPlaces);
|
||||||
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);
|
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);
|
||||||
$result = $fmt->format((float)$rounded); // intentional float
|
$result = (string) $fmt->format((float)$rounded); // intentional float
|
||||||
|
|
||||||
if (true === $coloured) {
|
if (true === $coloured) {
|
||||||
if (1 === bccomp($rounded, '0')) {
|
if (1 === bccomp($rounded, '0')) {
|
||||||
|
@@ -55,7 +55,7 @@ trait RequestInformation
|
|||||||
$url = url()->to('/');
|
$url = url()->to('/');
|
||||||
$parts = parse_url($url);
|
$parts = parse_url($url);
|
||||||
|
|
||||||
return $parts['host'];
|
return $parts['host'] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,7 +129,9 @@ trait RequestInformation
|
|||||||
*/
|
*/
|
||||||
final protected function getSpecificPageName(): string // get request info
|
final protected function getSpecificPageName(): string // get request info
|
||||||
{
|
{
|
||||||
return null === RouteFacade::current()->parameter('objectType') ? '' : '_' . RouteFacade::current()->parameter('objectType');
|
/** @var string|null $param */
|
||||||
|
$param = RouteFacade::current()->parameter('objectType');
|
||||||
|
return null === $param ? '' : sprintf('_%s', $param);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,20 +172,25 @@ trait RequestInformation
|
|||||||
$attributes['location'] = $attributes['location'] ?? '';
|
$attributes['location'] = $attributes['location'] ?? '';
|
||||||
$attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', []));
|
$attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', []));
|
||||||
try {
|
try {
|
||||||
$attributes['startDate'] = Carbon::createFromFormat('Ymd', $attributes['startDate'])->startOfDay();
|
$date = Carbon::createFromFormat('Ymd', $attributes['startDate']);
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
app('log')->debug(sprintf('Not important error message: %s', $e->getMessage()));
|
app('log')->debug(sprintf('Not important error message: %s', $e->getMessage()));
|
||||||
$date = today(config('app.timezone'))->startOfMonth();
|
$date = today(config('app.timezone'));
|
||||||
$attributes['startDate'] = $date;
|
|
||||||
}
|
}
|
||||||
|
$date->startOfMonth();
|
||||||
|
$attributes['startDate'] = $date;
|
||||||
|
unset($date);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$attributes['endDate'] = Carbon::createFromFormat('Ymd', $attributes['endDate'])->endOfDay();
|
$date2 = Carbon::createFromFormat('Ymd', $attributes['endDate']);
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
app('log')->debug(sprintf('Not important error message: %s', $e->getMessage()));
|
app('log')->debug(sprintf('Not important error message: %s', $e->getMessage()));
|
||||||
$date = today(config('app.timezone'))->startOfMonth();
|
$date2 = today(config('app.timezone'));
|
||||||
$attributes['endDate'] = $date;
|
|
||||||
}
|
}
|
||||||
|
$date2->endOfDay();
|
||||||
|
$attributes['endDate'] = $date2;
|
||||||
|
|
||||||
|
|
||||||
return $attributes;
|
return $attributes;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user