Fix phpstan issues.

This commit is contained in:
James Cole
2023-11-05 16:55:16 +01:00
parent 4edd9fe3da
commit a0564751d6
72 changed files with 110 additions and 138 deletions

View File

@@ -56,5 +56,5 @@ parameters:
# The level 8 is the highest level. original was 5 # The level 8 is the highest level. original was 5
# TODO: slowly up the level and fix the issues found. # TODO: slowly up the level and fix the issues found.
level: 3 level: 4

View File

@@ -50,7 +50,7 @@ class BudgetFactory
// first by ID: // first by ID:
if ($budgetId > 0) { if ($budgetId > 0) {
/** @var Budget $budget */ /** @var Budget|null $budget */
$budget = $this->user->budgets()->find($budgetId); $budget = $this->user->budgets()->find($budgetId);
if (null !== $budget) { if (null !== $budget) {
return $budget; return $budget;

View File

@@ -54,7 +54,7 @@ class CategoryFactory
} }
// first by ID: // first by ID:
if ($categoryId > 0) { if ($categoryId > 0) {
/** @var Category $category */ /** @var Category|null $category */
$category = $this->user->categories()->find($categoryId); $category = $this->user->categories()->find($categoryId);
if (null !== $category) { if (null !== $category) {
return $category; return $category;

View File

@@ -48,7 +48,7 @@ class PiggyBankFactory
} }
// first find by ID: // first find by ID:
if ($piggyBankId > 0) { if ($piggyBankId > 0) {
/** @var PiggyBank $piggyBank */ /** @var PiggyBank|null $piggyBank */
$piggyBank = $this->user->piggyBanks()->find($piggyBankId); $piggyBank = $this->user->piggyBanks()->find($piggyBankId);
if (null !== $piggyBank) { if (null !== $piggyBank) {
return $piggyBank; return $piggyBank;
@@ -57,7 +57,7 @@ class PiggyBankFactory
// then find by name: // then find by name:
if ('' !== $piggyBankName) { if ('' !== $piggyBankName) {
/** @var PiggyBank $piggyBank */ /** @var PiggyBank|null $piggyBank */
$piggyBank = $this->findByName($piggyBankName); $piggyBank = $this->findByName($piggyBankName);
if (null !== $piggyBank) { if (null !== $piggyBank) {
return $piggyBank; return $piggyBank;

View File

@@ -92,6 +92,7 @@ class TagFactory
'longitude' => null, 'longitude' => null,
'zoomLevel' => null, 'zoomLevel' => null,
]; ];
/** @var Tag|null $tag */
$tag = Tag::create($array); $tag = Tag::create($array);
if (null !== $tag && null !== $latitude && null !== $longitude) { if (null !== $tag && null !== $latitude && null !== $longitude) {
// create location object. // create location object.

View File

@@ -127,7 +127,9 @@ class TransactionFactory
); );
// do foreign currency thing: add foreign currency info to $one and $two if necessary. // do foreign currency thing: add foreign currency info to $one and $two if necessary.
if (null !== $this->foreignCurrency && null !== $foreignAmount && $this->foreignCurrency->id !== $this->currency->id && '' !== $foreignAmount) { if (null !== $this->foreignCurrency &&
null !== $foreignAmount &&
$this->foreignCurrency->id !== $this->currency->id) {
$result->foreign_currency_id = $this->foreignCurrency->id; $result->foreign_currency_id = $this->foreignCurrency->id;
$result->foreign_amount = $foreignAmount; $result->foreign_amount = $foreignAmount;
} }

View File

@@ -131,7 +131,7 @@ class UserEventHandler
$group = null; $group = null;
// create a new group. // create a new group.
while (true === $groupExists) { while (true === $groupExists) { /** @phpstan-ignore-line */
$groupExists = UserGroup::where('title', $groupTitle)->count() > 0; $groupExists = UserGroup::where('title', $groupTitle)->count() > 0;
if (false === $groupExists) { if (false === $groupExists) {
$group = UserGroup::create(['title' => $groupTitle]); $group = UserGroup::create(['title' => $groupTitle]);

View File

@@ -206,7 +206,7 @@ class AttachmentHelper implements AttachmentHelperInterface
Log::debug(sprintf('Now in saveAttachmentsForModel for model %s', get_class($model))); Log::debug(sprintf('Now in saveAttachmentsForModel for model %s', get_class($model)));
if (is_array($files)) { if (is_array($files)) {
Log::debug('$files is an array.'); Log::debug('$files is an array.');
/** @var UploadedFile $entry */ /** @var UploadedFile|null $entry */
foreach ($files as $entry) { foreach ($files as $entry) {
if (null !== $entry) { if (null !== $entry) {
$this->processFile($entry, $model); $this->processFile($entry, $model);

View File

@@ -158,7 +158,7 @@ class CreateController extends Controller
} }
// store attachment(s): // store attachment(s):
/** @var array $files */ /** @var array|null $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) { if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($account, $files); $this->attachments->saveAttachmentsForModel($account, $files);

View File

@@ -79,7 +79,7 @@ class ForgotPasswordController extends Controller
$this->validateEmail($request); $this->validateEmail($request);
// verify if the user is not a demo user. If so, we give him back an error. // verify if the user is not a demo user. If so, we give him back an error.
/** @var User $user */ /** @var User|null $user */
$user = User::where('email', $request->get('email'))->first(); $user = User::where('email', $request->get('email'))->first();
if (null !== $user && $repository->hasRole($user, 'demo')) { if (null !== $user && $repository->hasRole($user, 'demo')) {

View File

@@ -97,7 +97,7 @@ class LoginController extends Controller
// If the class is using the ThrottlesLogins trait, we can automatically throttle // If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and // the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application. // the IP address of the client making these requests into this application.
if (method_exists($this, 'hasTooManyLoginAttempts') && $this->hasTooManyLoginAttempts($request)) { if ($this->hasTooManyLoginAttempts($request)) {
Log::channel('audit')->info(sprintf('Login for user "%s" was locked out.', $request->get($this->username()))); Log::channel('audit')->info(sprintf('Login for user "%s" was locked out.', $request->get($this->username())));
app('log')->error(sprintf('Login for user "%s" was locked out.', $request->get($this->username()))); app('log')->error(sprintf('Login for user "%s" was locked out.', $request->get($this->username())));
$this->fireLockoutEvent($request); $this->fireLockoutEvent($request);

View File

@@ -114,7 +114,7 @@ class CreateController extends Controller
$request->session()->flash('success', (string)trans('firefly.stored_new_bill', ['name' => $bill->name])); $request->session()->flash('success', (string)trans('firefly.stored_new_bill', ['name' => $bill->name]));
app('preferences')->mark(); app('preferences')->mark();
/** @var array $files */ /** @var array|null $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) { if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($bill, $files); $this->attachments->saveAttachmentsForModel($bill, $files);

View File

@@ -128,7 +128,7 @@ class EditController extends Controller
$request->session()->flash('success', (string)trans('firefly.updated_bill', ['name' => $bill->name])); $request->session()->flash('success', (string)trans('firefly.updated_bill', ['name' => $bill->name]));
app('preferences')->mark(); app('preferences')->mark();
/** @var array $files */ /** @var array|null $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) { if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($bill, $files); $this->attachments->saveAttachmentsForModel($bill, $files);

View File

@@ -90,11 +90,7 @@ class ShowController extends Controller
return redirect(route('bills.show', [$bill->id])); return redirect(route('bills.show', [$bill->id]));
} }
$set = new Collection(); $set = $this->repository->getRulesForBill($bill);
if (true === $bill->active) {
$set = $this->repository->getRulesForBill($bill);
$total = 0;
}
if (0 === $set->count()) { if (0 === $set->count()) {
$request->session()->flash('error', (string)trans('firefly.no_rules_for_bill')); $request->session()->flash('error', (string)trans('firefly.no_rules_for_bill'));

View File

@@ -103,7 +103,7 @@ class CreateController extends Controller
app('preferences')->mark(); app('preferences')->mark();
// store attachment(s): // store attachment(s):
/** @var array $files */ /** @var array|null $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) { if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($piggyBank, $files); $this->attachments->saveAttachmentsForModel($piggyBank, $files);

View File

@@ -127,7 +127,7 @@ class EditController extends Controller
app('preferences')->mark(); app('preferences')->mark();
// store new attachment(s): // store new attachment(s):
/** @var array $files */ /** @var array|null $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) { if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($piggyBank, $files); $this->attachments->saveAttachmentsForModel($piggyBank, $files);

View File

@@ -241,7 +241,7 @@ class CreateController extends Controller
app('preferences')->mark(); app('preferences')->mark();
// store attachment(s): // store attachment(s):
/** @var array $files */ /** @var array|null $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) { if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($recurrence, $files); $this->attachments->saveAttachmentsForModel($recurrence, $files);

View File

@@ -327,7 +327,7 @@ class TagController extends Controller
app('preferences')->mark(); app('preferences')->mark();
// store attachment(s): // store attachment(s):
/** @var array $files */ /** @var array|null $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) { if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachmentsHelper->saveAttachmentsForModel($result, $files); $this->attachmentsHelper->saveAttachmentsForModel($result, $files);
@@ -366,7 +366,7 @@ class TagController extends Controller
app('preferences')->mark(); app('preferences')->mark();
// store new attachment(s): // store new attachment(s):
/** @var array $files */ /** @var array|null $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) { if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachmentsHelper->saveAttachmentsForModel($tag, $files); $this->attachmentsHelper->saveAttachmentsForModel($tag, $files);

View File

@@ -106,7 +106,7 @@ class MassController extends Controller
/** @var string $journalId */ /** @var string $journalId */
foreach ($ids as $journalId) { foreach ($ids as $journalId) {
app('log')->debug(sprintf('Searching for ID #%d', $journalId)); app('log')->debug(sprintf('Searching for ID #%d', $journalId));
/** @var TransactionJournal $journal */ /** @var TransactionJournal|null $journal */
$journal = $this->repository->find((int)$journalId); $journal = $this->repository->find((int)$journalId);
if (null !== $journal && (int)$journalId === (int)$journal->id) { if (null !== $journal && (int)$journalId === (int)$journal->id) {
$this->repository->destroyJournal($journal); $this->repository->destroyJournal($journal);

View File

@@ -122,7 +122,7 @@ class AccountFormRequest extends FormRequest
]; ];
$rules = Location::requestRules($rules); $rules = Location::requestRules($rules);
/** @var Account $account */ /** @var Account|null $account */
$account = $this->route()->parameter('account'); $account = $this->route()->parameter('account');
if (null !== $account) { if (null !== $account) {
// add rules: // add rules:

View File

@@ -65,7 +65,7 @@ class BudgetFormUpdateRequest extends FormRequest
{ {
$nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name'; $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name';
/** @var Budget $budget */ /** @var Budget|null $budget */
$budget = $this->route()->parameter('budget'); $budget = $this->route()->parameter('budget');
if (null !== $budget) { if (null !== $budget) {

View File

@@ -57,7 +57,7 @@ class CategoryFormRequest extends FormRequest
public function rules(): array public function rules(): array
{ {
$nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name'; $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name';
/** @var Category $category */ /** @var Category|null $category */
$category = $this->route()->parameter('category'); $category = $this->route()->parameter('category');
if (null !== $category) { if (null !== $category) {

View File

@@ -68,7 +68,7 @@ class CurrencyFormRequest extends FormRequest
'enabled' => 'in:0,1', 'enabled' => 'in:0,1',
]; ];
/** @var TransactionCurrency $currency */ /** @var TransactionCurrency|null $currency */
$currency = $this->route()->parameter('currency'); $currency = $this->route()->parameter('currency');
if (null !== $currency) { if (null !== $currency) {

View File

@@ -55,7 +55,7 @@ class ObjectGroupFormRequest extends FormRequest
*/ */
public function rules(): array public function rules(): array
{ {
/** @var ObjectGroup $objectGroup */ /** @var ObjectGroup|null $objectGroup */
$objectGroup = $this->route()->parameter('objectGroup'); $objectGroup = $this->route()->parameter('objectGroup');
$titleRule = 'required|between:1,255|uniqueObjectGroup'; $titleRule = 'required|between:1,255|uniqueObjectGroup';

View File

@@ -259,7 +259,7 @@ class RecurrenceFormRequest extends FormRequest
} }
// update some rules in case the user is editing a post: // update some rules in case the user is editing a post:
/** @var Recurrence $recurrence */ /** @var Recurrence|null $recurrence */
$recurrence = $this->route()->parameter('recurrence'); $recurrence = $this->route()->parameter('recurrence');
if ($recurrence instanceof Recurrence) { if ($recurrence instanceof Recurrence) {
$rules['id'] = 'required|numeric|exists:recurrences,id'; $rules['id'] = 'required|numeric|exists:recurrences,id';

View File

@@ -164,7 +164,7 @@ class RuleFormRequest extends FormRequest
'strict' => 'in:0,1', 'strict' => 'in:0,1',
]; ];
/** @var Rule $rule */ /** @var Rule|null $rule */
$rule = $this->route()->parameter('rule'); $rule = $this->route()->parameter('rule');
if (null !== $rule) { if (null !== $rule) {

View File

@@ -65,7 +65,7 @@ class RuleGroupFormRequest extends FormRequest
{ {
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title'; $titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title';
/** @var RuleGroup $ruleGroup */ /** @var RuleGroup|null $ruleGroup */
$ruleGroup = $this->route()->parameter('ruleGroup'); $ruleGroup = $this->route()->parameter('ruleGroup');
if (null !== $ruleGroup) { if (null !== $ruleGroup) {

View File

@@ -64,7 +64,7 @@ class TagFormRequest extends FormRequest
{ {
$idRule = ''; $idRule = '';
/** @var Tag $tag */ /** @var Tag|null $tag */
$tag = $this->route()->parameter('tag'); $tag = $this->route()->parameter('tag');
$tagRule = 'required|max:1024|min:1|uniqueObjectForUser:tags,tag'; $tagRule = 'required|max:1024|min:1|uniqueObjectForUser:tags,tag';
if (null !== $tag) { if (null !== $tag) {

View File

@@ -141,7 +141,7 @@ class Account extends Model
$accountId = (int)$value; $accountId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var Account $account */ /** @var Account|null $account */
$account = $user->accounts()->with(['accountType'])->find($accountId); $account = $user->accounts()->with(['accountType'])->find($accountId);
if (null !== $account) { if (null !== $account) {
return $account; return $account;

View File

@@ -111,7 +111,7 @@ class Attachment extends Model
$attachmentId = (int)$value; $attachmentId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var Attachment $attachment */ /** @var Attachment|null $attachment */
$attachment = $user->attachments()->find($attachmentId); $attachment = $user->attachments()->find($attachmentId);
if (null !== $attachment) { if (null !== $attachment) {
return $attachment; return $attachment;

View File

@@ -97,7 +97,7 @@ class AvailableBudget extends Model
$availableBudgetId = (int)$value; $availableBudgetId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var AvailableBudget $availableBudget */ /** @var AvailableBudget|null $availableBudget */
$availableBudget = $user->availableBudgets()->find($availableBudgetId); $availableBudget = $user->availableBudgets()->find($availableBudgetId);
if (null !== $availableBudget) { if (null !== $availableBudget) {
return $availableBudget; return $availableBudget;

View File

@@ -156,7 +156,7 @@ class Bill extends Model
$billId = (int)$value; $billId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var Bill $bill */ /** @var Bill|null $bill */
$bill = $user->bills()->find($billId); $bill = $user->bills()->find($billId);
if (null !== $bill) { if (null !== $bill) {
return $bill; return $bill;

View File

@@ -113,7 +113,7 @@ class Budget extends Model
$budgetId = (int)$value; $budgetId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var Budget $budget */ /** @var Budget|null $budget */
$budget = $user->budgets()->find($budgetId); $budget = $user->budgets()->find($budgetId);
if (null !== $budget) { if (null !== $budget) {
return $budget; return $budget;

View File

@@ -103,7 +103,7 @@ class Category extends Model
$categoryId = (int)$value; $categoryId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var Category $category */ /** @var Category|null $category */
$category = $user->categories()->find($categoryId); $category = $user->categories()->find($categoryId);
if (null !== $category) { if (null !== $category) {
return $category; return $category;

View File

@@ -77,7 +77,7 @@ class InvitedUser extends Model
{ {
if (auth()->check()) { if (auth()->check()) {
$attemptId = (int)$value; $attemptId = (int)$value;
/** @var InvitedUser $attempt */ /** @var InvitedUser|null $attempt */
$attempt = self::find($attemptId); $attempt = self::find($attemptId);
if (null !== $attempt) { if (null !== $attempt) {
return $attempt; return $attempt;

View File

@@ -89,7 +89,7 @@ class ObjectGroup extends Model
{ {
if (auth()->check()) { if (auth()->check()) {
$objectGroupId = (int)$value; $objectGroupId = (int)$value;
/** @var ObjectGroup $objectGroup */ /** @var ObjectGroup|null $objectGroup */
$objectGroup = self::where('object_groups.id', $objectGroupId) $objectGroup = self::where('object_groups.id', $objectGroupId)
->where('object_groups.user_id', auth()->user()->id)->first(); ->where('object_groups.user_id', auth()->user()->id)->first();
if (null !== $objectGroup) { if (null !== $objectGroup) {

View File

@@ -129,7 +129,7 @@ class Recurrence extends Model
$recurrenceId = (int)$value; $recurrenceId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var Recurrence $recurrence */ /** @var Recurrence|null $recurrence */
$recurrence = $user->recurrences()->find($recurrenceId); $recurrence = $user->recurrences()->find($recurrenceId);
if (null !== $recurrence) { if (null !== $recurrence) {
return $recurrence; return $recurrence;

View File

@@ -112,7 +112,7 @@ class Rule extends Model
$ruleId = (int)$value; $ruleId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var Rule $rule */ /** @var Rule|null $rule */
$rule = $user->rules()->find($ruleId); $rule = $user->rules()->find($ruleId);
if (null !== $rule) { if (null !== $rule) {
return $rule; return $rule;

View File

@@ -102,7 +102,7 @@ class RuleGroup extends Model
$ruleGroupId = (int)$value; $ruleGroupId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var RuleGroup $ruleGroup */ /** @var RuleGroup|null $ruleGroup */
$ruleGroup = $user->ruleGroups()->find($ruleGroupId); $ruleGroup = $user->ruleGroups()->find($ruleGroupId);
if (null !== $ruleGroup) { if (null !== $ruleGroup) {
return $ruleGroup; return $ruleGroup;

View File

@@ -113,7 +113,7 @@ class Tag extends Model
$tagId = (int)$value; $tagId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var Tag $tag */ /** @var Tag|null $tag */
$tag = $user->tags()->find($tagId); $tag = $user->tags()->find($tagId);
if (null !== $tag) { if (null !== $tag) {
return $tag; return $tag;

View File

@@ -97,7 +97,7 @@ class TransactionGroup extends Model
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
app('log')->debug(sprintf('User authenticated as %s', $user->email)); app('log')->debug(sprintf('User authenticated as %s', $user->email));
/** @var TransactionGroup $group */ /** @var TransactionGroup|null $group */
$group = $user->transactionGroups() $group = $user->transactionGroups()
->with(['transactionJournals', 'transactionJournals.transactions']) ->with(['transactionJournals', 'transactionJournals.transactions'])
->where('transaction_groups.id', $groupId)->first(['transaction_groups.*']); ->where('transaction_groups.id', $groupId)->first(['transaction_groups.*']);

View File

@@ -173,7 +173,7 @@ class TransactionJournal extends Model
$journalId = (int)$value; $journalId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var TransactionJournal $journal */ /** @var TransactionJournal|null $journal */
$journal = $user->transactionJournals()->where('transaction_journals.id', $journalId)->first(['transaction_journals.*']); $journal = $user->transactionJournals()->where('transaction_journals.id', $journalId)->first(['transaction_journals.*']);
if (null !== $journal) { if (null !== $journal) {
return $journal; return $journal;

View File

@@ -185,7 +185,7 @@ class Webhook extends Model
$webhookId = (int)$value; $webhookId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var Webhook $webhook */ /** @var Webhook|null $webhook */
$webhook = $user->webhooks()->find($webhookId); $webhook = $user->webhooks()->find($webhookId);
if (null !== $webhook) { if (null !== $webhook) {
return $webhook; return $webhook;

View File

@@ -78,7 +78,7 @@ class WebhookAttempt extends Model
$attemptId = (int)$value; $attemptId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var WebhookAttempt $attempt */ /** @var WebhookAttempt|null $attempt */
$attempt = self::find($attemptId); $attempt = self::find($attemptId);
if (null !== $attempt && $attempt->webhookMessage->webhook->user_id === $user->id) { if (null !== $attempt && $attempt->webhookMessage->webhook->user_id === $user->id) {
return $attempt; return $attempt;

View File

@@ -92,7 +92,7 @@ class WebhookMessage extends Model
$messageId = (int)$value; $messageId = (int)$value;
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
/** @var WebhookMessage $message */ /** @var WebhookMessage|null $message */
$message = self::find($messageId); $message = self::find($messageId);
if (null !== $message && $message->webhook->user_id === $user->id) { if (null !== $message && $message->webhook->user_id === $user->id) {
return $message; return $message;

View File

@@ -146,7 +146,7 @@ class OperationsRepository implements OperationsRepositoryInterface
if (null !== $budgets && $budgets->count() > 0) { if (null !== $budgets && $budgets->count() > 0) {
$collector->setBudgets($budgets); $collector->setBudgets($budgets);
} }
if (null === $budgets || (null !== $budgets && 0 === $budgets->count())) { if (null === $budgets || 0 === $budgets->count()) {
$collector->setBudgets($this->getBudgets()); $collector->setBudgets($this->getBudgets());
} }
$collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation(); $collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation();

View File

@@ -63,7 +63,7 @@ class OperationsRepository implements OperationsRepositoryInterface
if (null !== $categories && $categories->count() > 0) { if (null !== $categories && $categories->count() > 0) {
$collector->setCategories($categories); $collector->setCategories($categories);
} }
if (null === $categories || (null !== $categories && 0 === $categories->count())) { if (null === $categories || 0 === $categories->count()) {
$collector->setCategories($this->getCategories()); $collector->setCategories($this->getCategories());
} }
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation(); $collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
@@ -159,7 +159,7 @@ class OperationsRepository implements OperationsRepositoryInterface
if (null !== $categories && $categories->count() > 0) { if (null !== $categories && $categories->count() > 0) {
$collector->setCategories($categories); $collector->setCategories($categories);
} }
if (null === $categories || (null !== $categories && 0 === $categories->count())) { if (null === $categories || 0 === $categories->count()) {
$collector->setCategories($this->getCategories()); $collector->setCategories($this->getCategories());
} }
$collector->withCategoryInformation()->withAccountInformation(); $collector->withCategoryInformation()->withAccountInformation();
@@ -223,7 +223,7 @@ class OperationsRepository implements OperationsRepositoryInterface
if (null !== $categories && $categories->count() > 0) { if (null !== $categories && $categories->count() > 0) {
$collector->setCategories($categories); $collector->setCategories($categories);
} }
if (null === $categories || (null !== $categories && 0 === $categories->count())) { if (null === $categories || 0 === $categories->count()) {
$collector->setCategories($this->getCategories()); $collector->setCategories($this->getCategories());
} }
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation(); $collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
@@ -288,7 +288,7 @@ class OperationsRepository implements OperationsRepositoryInterface
if (null !== $categories && $categories->count() > 0) { if (null !== $categories && $categories->count() > 0) {
$collector->setCategories($categories); $collector->setCategories($categories);
} }
if (null === $categories || (null !== $categories && 0 === $categories->count())) { if (null === $categories || 0 === $categories->count()) {
$collector->setCategories($this->getCategories()); $collector->setCategories($this->getCategories());
} }
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation(); $collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
@@ -361,7 +361,7 @@ class OperationsRepository implements OperationsRepositoryInterface
if (null !== $accounts && $accounts->count() > 0) { if (null !== $accounts && $accounts->count() > 0) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);
} }
if (null === $categories || (null !== $categories && 0 === $categories->count())) { if (null === $categories || 0 === $categories->count()) {
$categories = $this->getCategories(); $categories = $this->getCategories();
} }
$collector->setCategories($categories); $collector->setCategories($categories);
@@ -405,7 +405,7 @@ class OperationsRepository implements OperationsRepositoryInterface
if (null !== $accounts && $accounts->count() > 0) { if (null !== $accounts && $accounts->count() > 0) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);
} }
if (null === $categories || (null !== $categories && 0 === $categories->count())) { if (null === $categories || 0 === $categories->count()) {
$categories = $this->getCategories(); $categories = $this->getCategories();
} }
$collector->setCategories($categories); $collector->setCategories($categories);
@@ -448,7 +448,7 @@ class OperationsRepository implements OperationsRepositoryInterface
if (null !== $accounts && $accounts->count() > 0) { if (null !== $accounts && $accounts->count() > 0) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);
} }
if (null === $categories || (null !== $categories && 0 === $categories->count())) { if (null === $categories || 0 === $categories->count()) {
$categories = $this->getCategories(); $categories = $this->getCategories();
} }
$collector->setCategories($categories); $collector->setCategories($categories);

View File

@@ -89,7 +89,7 @@ class JournalRepository implements JournalRepositoryInterface
*/ */
public function firstNull(): ?TransactionJournal public function firstNull(): ?TransactionJournal
{ {
/** @var TransactionJournal $entry */ /** @var TransactionJournal|null $entry */
$entry = $this->user->transactionJournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']); $entry = $this->user->transactionJournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
$result = null; $result = null;
if (null !== $entry) { if (null !== $entry) {

View File

@@ -347,7 +347,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
*/ */
public function switchLinkById(int $linkId): bool public function switchLinkById(int $linkId): bool
{ {
/** @var TransactionJournalLink $link */ /** @var TransactionJournalLink|null $link */
$link = TransactionJournalLink::find($linkId); $link = TransactionJournalLink::find($linkId);
if (null !== $link && $link->source->user->id === $this->user->id) { if (null !== $link && $link->source->user->id === $this->user->id) {
$this->switchLink($link); $this->switchLink($link);

View File

@@ -404,11 +404,8 @@ trait ModifiesPiggyBanks
return $piggyBank; return $piggyBank;
} }
// remove if name is empty. Should be overruled by ID. $piggyBank->objectGroups()->sync([]);
if ('' === $objectGroupTitle) { $piggyBank->save();
$piggyBank->objectGroups()->sync([]);
$piggyBank->save();
}
} }
// try also with ID: // try also with ID:

View File

@@ -67,7 +67,7 @@ class OperationsRepository implements OperationsRepositoryInterface
if (null !== $tags && $tags->count() > 0) { if (null !== $tags && $tags->count() > 0) {
$collector->setTags($tags); $collector->setTags($tags);
} }
if (null === $tags || (null !== $tags && 0 === $tags->count())) { if (null === $tags || 0 === $tags->count()) {
$collector->setTags($this->getTags()); $collector->setTags($this->getTags());
} }
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation()->withTagInformation(); $collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation()->withTagInformation();
@@ -166,7 +166,7 @@ class OperationsRepository implements OperationsRepositoryInterface
if (null !== $tags && $tags->count() > 0) { if (null !== $tags && $tags->count() > 0) {
$collector->setTags($tags); $collector->setTags($tags);
} }
if (null === $tags || (null !== $tags && 0 === $tags->count())) { if (null === $tags || 0 === $tags->count()) {
$collector->setTags($this->getTags()); $collector->setTags($this->getTags());
} }
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation()->withTagInformation(); $collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation()->withTagInformation();

View File

@@ -104,7 +104,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
$memberships = $this->user->groupMemberships()->get(); $memberships = $this->user->groupMemberships()->get();
/** @var GroupMembership $membership */ /** @var GroupMembership $membership */
foreach ($memberships as $membership) { foreach ($memberships as $membership) {
/** @var UserGroup $group */ /** @var UserGroup|null $group */
$group = $membership->userGroup()->first(); $group = $membership->userGroup()->first();
if (null !== $group) { if (null !== $group) {
$collection->push($group); $collection->push($group);
@@ -131,6 +131,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
$existingGroup = $this->findByName($groupName); $existingGroup = $this->findByName($groupName);
if (null === $existingGroup) { if (null === $existingGroup) {
$exists = false; $exists = false;
/** @var UserGroup|null $existingGroup */
$existingGroup = $this->store(['user' => $user, 'title' => $groupName]); $existingGroup = $this->store(['user' => $user, 'title' => $groupName]);
} }
if (null !== $existingGroup) { if (null !== $existingGroup) {

View File

@@ -161,7 +161,7 @@ class AccountDestroyService
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($account->transactions()->get() as $transaction) { foreach ($account->transactions()->get() as $transaction) {
app('log')->debug('Now at transaction #' . $transaction->id); app('log')->debug('Now at transaction #' . $transaction->id);
/** @var TransactionJournal $journal */ /** @var TransactionJournal|null $journal */
$journal = $transaction->transactionJournal()->first(); $journal = $transaction->transactionJournal()->first();
if (null !== $journal) { if (null !== $journal) {
app('log')->debug('Call for deletion of journal #' . $journal->id); app('log')->debug('Call for deletion of journal #' . $journal->id);

View File

@@ -137,7 +137,7 @@ trait AccountServiceTrait
$data['account_role'] = ''; $data['account_role'] = '';
} }
if ($account->accountType->type === AccountType::ASSET && array_key_exists('account_role', $data) && 'ccAsset' === $data['account_role']) { if ($account->accountType->type === AccountType::ASSET && 'ccAsset' === $data['account_role']) {
$fields = $this->validCCFields; $fields = $this->validCCFields;
} }
/** @var AccountMetaFactory $factory */ /** @var AccountMetaFactory $factory */

View File

@@ -461,10 +461,8 @@ trait JournalServiceTrait
return; return;
} }
if ('' === $notes && null !== $note) { // try to delete existing notes.
// try to delete existing notes. $note?->delete();
$note->delete();
}
} }
/** /**

View File

@@ -113,10 +113,8 @@ class BillUpdateService
return $bill; return $bill;
} }
// remove if name is empty. Should be overruled by ID. // remove if name is empty. Should be overruled by ID.
if ('' === $objectGroupTitle) { $bill->objectGroups()->sync([]);
$bill->objectGroups()->sync([]); $bill->save();
$bill->save();
}
} }
if (array_key_exists('object_group_id', $data)) { if (array_key_exists('object_group_id', $data)) {
// try also with ID: // try also with ID:
@@ -130,10 +128,8 @@ class BillUpdateService
return $bill; return $bill;
} }
if (0 === $objectGroupId) { $bill->objectGroups()->sync([]);
$bill->objectGroups()->sync([]); $bill->save();
$bill->save();
}
} }
return $bill; return $bill;

View File

@@ -105,7 +105,7 @@ class GroupCloneService
// add relation. // add relation.
// TODO clone ALL linked piggy banks // TODO clone ALL linked piggy banks
/** @var PiggyBankEvent $event */ /** @var PiggyBankEvent|null $event */
$event = $journal->piggyBankEvents()->first(); $event = $journal->piggyBankEvents()->first();
if (null !== $event) { if (null !== $event) {
$piggyBank = $event->piggyBank; $piggyBank = $event->piggyBank;

View File

@@ -497,9 +497,9 @@ class JournalUpdateService
{ {
$type = $this->transactionJournal->transactionType->type; $type = $this->transactionJournal->transactionType->type;
if (( if ((
array_key_exists('bill_id', $this->data) array_key_exists('bill_id', $this->data)
|| array_key_exists('bill_name', $this->data) || array_key_exists('bill_name', $this->data)
) )
&& TransactionType::WITHDRAWAL === $type && TransactionType::WITHDRAWAL === $type
) { ) {
$billId = (int)($this->data['bill_id'] ?? 0); $billId = (int)($this->data['bill_id'] ?? 0);
@@ -690,24 +690,22 @@ class JournalUpdateService
$currencyId = $this->data['currency_id'] ?? null; $currencyId = $this->data['currency_id'] ?? null;
$currencyCode = $this->data['currency_code'] ?? null; $currencyCode = $this->data['currency_code'] ?? null;
$currency = $this->currencyRepository->findCurrency($currencyId, $currencyCode); $currency = $this->currencyRepository->findCurrency($currencyId, $currencyCode);
if (null !== $currency) { // update currency everywhere.
// update currency everywhere. $this->transactionJournal->transaction_currency_id = $currency->id;
$this->transactionJournal->transaction_currency_id = $currency->id; $this->transactionJournal->save();
$this->transactionJournal->save();
$source = $this->getSourceTransaction(); $source = $this->getSourceTransaction();
$source->transaction_currency_id = $currency->id; $source->transaction_currency_id = $currency->id;
$source->save(); $source->save();
$dest = $this->getDestinationTransaction(); $dest = $this->getDestinationTransaction();
$dest->transaction_currency_id = $currency->id; $dest->transaction_currency_id = $currency->id;
$dest->save(); $dest->save();
// refresh transactions. // refresh transactions.
$this->sourceTransaction->refresh(); $this->sourceTransaction->refresh();
$this->destinationTransaction->refresh(); $this->destinationTransaction->refresh();
app('log')->debug(sprintf('Updated currency to #%d (%s)', $currency->id, $currency->code)); app('log')->debug(sprintf('Updated currency to #%d (%s)', $currency->id, $currency->code));
}
} }
/** /**

View File

@@ -55,11 +55,7 @@ class AutoBudgetCronjob extends AbstractCronjob
return; return;
} }
app('log')->info('Execution of the auto budget cron-job has been FORCED.');
// fire job regardless.
if (true === $this->force) {
app('log')->info('Execution of the auto budget cron-job has been FORCED.');
}
} }
if ($lastTime > 0 && $diff > 43200) { if ($lastTime > 0 && $diff > 43200) {

View File

@@ -65,10 +65,7 @@ class BillWarningCronjob extends AbstractCronjob
return; return;
} }
// fire job regardless. app('log')->info('Execution of the bill warning cron-job has been FORCED.');
if (true === $this->force) {
app('log')->info('Execution of the bill warning cron-job has been FORCED.');
}
} }
if ($lastTime > 0 && $diff > 43200) { if ($lastTime > 0 && $diff > 43200) {

View File

@@ -56,10 +56,7 @@ class ExchangeRatesCronjob extends AbstractCronjob
return; return;
} }
// fire job regardless. app('log')->info('Execution of the exchange rates cron-job has been FORCED.');
if (true === $this->force) {
app('log')->info('Execution of the exchange rates cron-job has been FORCED.');
}
} }
if ($lastTime > 0 && $diff > 43200) { if ($lastTime > 0 && $diff > 43200) {

View File

@@ -64,11 +64,7 @@ class RecurringCronjob extends AbstractCronjob
return; return;
} }
app('log')->info('Execution of the recurring transaction cron-job has been FORCED.');
// fire job regardless.
if (true === $this->force) {
app('log')->info('Execution of the recurring transaction cron-job has been FORCED.');
}
} }
if ($lastTime > 0 && $diff > 43200) { if ($lastTime > 0 && $diff > 43200) {

View File

@@ -104,7 +104,7 @@ trait FormSupport
protected function getHolderClasses(string $name): string protected function getHolderClasses(string $name): string
{ {
// Get errors from session: // Get errors from session:
/** @var MessageBag $errors */ /** @var MessageBag|null $errors */
$errors = session('errors'); $errors = session('errors');
$classes = 'form-group'; $classes = 'form-group';

View File

@@ -45,7 +45,7 @@ trait ChecksLogin
if (!$check) { if (!$check) {
return false; return false;
} }
if (!property_exists($this, 'acceptedRoles')) { if (!property_exists($this, 'acceptedRoles')) { // @phpstan-ignore-line
app('log')->debug('Request class has no acceptedRoles array'); app('log')->debug('Request class has no acceptedRoles array');
return true; // check for false already took place. return true; // check for false already took place.
} }

View File

@@ -166,7 +166,7 @@ trait ConvertsDataTypes
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
if (method_exists($this, 'validateUserGroup')) { if (method_exists($this, 'validateUserGroup')) { /** @phpstan-ignore-line */
$userGroup = $this->validateUserGroup($this); $userGroup = $this->validateUserGroup($this);
if (null !== $userGroup) { if (null !== $userGroup) {
$repository->setUserGroup($userGroup); $repository->setUserGroup($userGroup);

View File

@@ -68,7 +68,7 @@ class BillTransformer extends AbstractTransformer
$objectGroupId = null; $objectGroupId = null;
$objectGroupOrder = null; $objectGroupOrder = null;
$objectGroupTitle = null; $objectGroupTitle = null;
/** @var ObjectGroup $objectGroup */ /** @var ObjectGroup|null $objectGroup */
$objectGroup = $bill->objectGroups->first(); $objectGroup = $bill->objectGroups->first();
if (null !== $objectGroup) { if (null !== $objectGroup) {
$objectGroupId = (int)$objectGroup->id; $objectGroupId = (int)$objectGroup->id;

View File

@@ -76,7 +76,7 @@ class PiggyBankTransformer extends AbstractTransformer
$objectGroupId = null; $objectGroupId = null;
$objectGroupOrder = null; $objectGroupOrder = null;
$objectGroupTitle = null; $objectGroupTitle = null;
/** @var ObjectGroup $objectGroup */ /** @var ObjectGroup|null $objectGroup */
$objectGroup = $piggyBank->objectGroups->first(); $objectGroup = $piggyBank->objectGroups->first();
if (null !== $objectGroup) { if (null !== $objectGroup) {
$objectGroupId = (int)$objectGroup->id; $objectGroupId = (int)$objectGroup->id;

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Transformers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\CategoryFactory; use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Models\Account;
use FireflyIII\Models\Recurrence; use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceRepetition; use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Models\RecurrenceTransaction; use FireflyIII\Models\RecurrenceTransaction;
@@ -161,7 +162,9 @@ class RecurrenceTransformer extends AbstractTransformer
// get all transactions: // get all transactions:
/** @var RecurrenceTransaction $transaction */ /** @var RecurrenceTransaction $transaction */
foreach ($recurrence->recurrenceTransactions()->get() as $transaction) { foreach ($recurrence->recurrenceTransactions()->get() as $transaction) {
/** @var Account|null $sourceAccount */
$sourceAccount = $transaction->sourceAccount; $sourceAccount = $transaction->sourceAccount;
/** @var Account|null $destinationAccount */
$destinationAccount = $transaction->destinationAccount; $destinationAccount = $transaction->destinationAccount;
$foreignCurrencyCode = null; $foreignCurrencyCode = null;
$foreignCurrencySymbol = null; $foreignCurrencySymbol = null;

View File

@@ -43,7 +43,7 @@ class TagTransformer extends AbstractTransformer
public function transform(Tag $tag): array public function transform(Tag $tag): array
{ {
$date = $tag->date?->format('Y-m-d'); $date = $tag->date?->format('Y-m-d');
/** @var Location $location */ /** @var Location|null $location */
$location = $tag->locations()->first(); $location = $tag->locations()->first();
$latitude = null; $latitude = null;
$longitude = null; $longitude = null;

View File

@@ -59,7 +59,7 @@ trait GroupValidation
'source_number', 'source_number',
'destination_number', 'destination_number',
]; ];
/** @var array $transaction */ /** @var array|null $transaction */
foreach ($transactions as $index => $transaction) { foreach ($transactions as $index => $transaction) {
if (!is_array($transaction)) { if (!is_array($transaction)) {
throw new FireflyException('Invalid data submitted: transaction is not array.'); throw new FireflyException('Invalid data submitted: transaction is not array.');

View File

@@ -53,7 +53,7 @@ trait RecurrenceValidation
// grab model from parameter and try to set the transaction type from it // grab model from parameter and try to set the transaction type from it
if ('invalid' === $transactionType) { if ('invalid' === $transactionType) {
app('log')->debug('Type is invalid but we will search for it.'); app('log')->debug('Type is invalid but we will search for it.');
/** @var Recurrence $recurrence */ /** @var Recurrence|null $recurrence */
$recurrence = $this->route()->parameter('recurrence'); $recurrence = $this->route()->parameter('recurrence');
if (null !== $recurrence) { if (null !== $recurrence) {
app('log')->debug('There is a recurrence in the route.'); app('log')->debug('There is a recurrence in the route.');

View File

@@ -61,7 +61,7 @@ trait TransactionValidation
app('log')->debug(sprintf('Going to loop %d transaction(s)', count($transactions))); app('log')->debug(sprintf('Going to loop %d transaction(s)', count($transactions)));
/** /**
* @var int $index * @var int|null $index
* @var array $transaction * @var array $transaction
*/ */
foreach ($transactions as $index => $transaction) { foreach ($transactions as $index => $transaction) {
@@ -84,19 +84,13 @@ trait TransactionValidation
app('log')->debug('Now in getTransactionsArray'); app('log')->debug('Now in getTransactionsArray');
$data = $validator->getData(); $data = $validator->getData();
$transactions = []; $transactions = [];
if (is_array($data) && array_key_exists('transactions', $data) && is_array($data['transactions'])) { if (array_key_exists('transactions', $data) && is_array($data['transactions'])) {
app('log')->debug('Transactions key exists and is array.'); app('log')->debug('Transactions key exists and is array.');
$transactions = $data['transactions']; $transactions = $data['transactions'];
} }
if (is_array($data) && array_key_exists('transactions', $data) && !is_array($data['transactions'])) { if (array_key_exists('transactions', $data) && !is_array($data['transactions'])) {
app('log')->debug(sprintf('Transactions key exists but is NOT array, its a %s', gettype($data['transactions']))); app('log')->debug(sprintf('Transactions key exists but is NOT array, its a %s', gettype($data['transactions'])));
} }
// should be impossible to hit this:
if (!is_countable($transactions)) {
app('log')->error(sprintf('Transactions array is not countable, because its a %s', gettype($transactions)));
return [];
}
//app('log')->debug('Returning transactions.', $transactions);
return $transactions; return $transactions;
} }
@@ -383,7 +377,7 @@ trait TransactionValidation
$transactions = $this->getTransactionsArray($validator); $transactions = $this->getTransactionsArray($validator);
/** /**
* @var int $index * @var int|null $index
* @var array $transaction * @var array $transaction
*/ */
foreach ($transactions as $index => $transaction) { foreach ($transactions as $index => $transaction) {
@@ -783,13 +777,13 @@ trait TransactionValidation
if (0 === $journalId) { if (0 === $journalId) {
return $return; return $return;
} }
/** @var Transaction $source */ /** @var Transaction|null $source */
$source = Transaction::where('transaction_journal_id', $journalId)->where('amount', '<', 0)->with(['account'])->first(); $source = Transaction::where('transaction_journal_id', $journalId)->where('amount', '<', 0)->with(['account'])->first();
if (null !== $source) { if (null !== $source) {
$return['source_id'] = $source->account_id; $return['source_id'] = $source->account_id;
$return['source_name'] = $source->account->name; $return['source_name'] = $source->account->name;
} }
/** @var Transaction $destination */ /** @var Transaction|null $destination */
$destination = Transaction::where('transaction_journal_id', $journalId)->where('amount', '>', 0)->with(['account'])->first(); $destination = Transaction::where('transaction_journal_id', $journalId)->where('amount', '>', 0)->with(['account'])->first();
if (null !== $source) { if (null !== $source) {
$return['destination_id'] = $destination->account_id; $return['destination_id'] = $destination->account_id;