mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Various phpstan fixes.
This commit is contained in:
parent
633d84449a
commit
dc45131f73
@ -55,7 +55,10 @@ class FixUnevenAmount extends Command
|
||||
/** @var stdClass $entry */
|
||||
foreach ($journals as $entry) {
|
||||
$sum = (string)$entry->the_sum;
|
||||
if (!is_numeric($sum) || 0 === strlen($sum) || str_contains($sum, 'e') || str_contains($sum, ',')) {
|
||||
if (!is_numeric($sum) ||
|
||||
0 === strlen($sum) || // @phpstan-ignore-line
|
||||
str_contains($sum, 'e') ||
|
||||
str_contains($sum, ',')) {
|
||||
$message = sprintf(
|
||||
'Journal #%d has an invalid sum ("%s"). No sure what to do.',
|
||||
$entry->transaction_journal_id,
|
||||
|
@ -480,8 +480,7 @@ class TransactionJournalFactory
|
||||
// return user's default:
|
||||
return app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
|
||||
}
|
||||
$result = ($preference ?? $currency)
|
||||
?? app('amount')->getSystemCurrency();
|
||||
$result = $preference ?? $currency;
|
||||
app('log')->debug(sprintf('Currency is now #%d (%s) because of account #%d (%s)', $result->id, $result->code, $account->id, $account->name));
|
||||
|
||||
return $result;
|
||||
|
@ -30,7 +30,12 @@ use FireflyIII\Models\Transaction;
|
||||
*/
|
||||
class TransactionObserver
|
||||
{
|
||||
public function deleting(Transaction $transaction): void
|
||||
/**
|
||||
* @param Transaction|null $transaction
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(?Transaction $transaction): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a transaction.');
|
||||
$transaction?->transactionJournal?->delete();
|
||||
|
@ -186,7 +186,7 @@ class ExpenseReportController extends Controller
|
||||
$newSet = [];
|
||||
foreach ($chartData as $key => $entry) {
|
||||
// TODO not sure, this is a bad comparison.
|
||||
if (0 === !array_sum($entry['entries'])) {
|
||||
if (array_sum($entry['entries']) > 0) {
|
||||
$newSet[$key] = $entry;
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ class BudgetController extends Controller
|
||||
// loop again to get percentages.
|
||||
foreach ($report as $budgetId => $data) {
|
||||
foreach ($data['currencies'] as $currencyId => $dataX) {
|
||||
$sum = $dataX['sum'] ?? '0';
|
||||
$sum = $dataX['sum'];
|
||||
$total = $sums[$currencyId]['sum'] ?? '0';
|
||||
$pct = '0';
|
||||
if (0 !== bccomp($sum, '0') && 0 !== bccomp($total, '9')) {
|
||||
|
@ -33,7 +33,6 @@ use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Services\Internal\Update\JournalUpdateService;
|
||||
use FireflyIII\Support\Http\Controllers\ModelInformation;
|
||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
@ -54,7 +53,6 @@ class ConvertController extends Controller
|
||||
use ModelInformation;
|
||||
|
||||
private AccountRepositoryInterface $accountRepository;
|
||||
private JournalRepositoryInterface $repository;
|
||||
|
||||
/**
|
||||
* ConvertController constructor.
|
||||
@ -68,7 +66,6 @@ class ConvertController extends Controller
|
||||
// some useful repositories:
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-exchange');
|
||||
|
@ -39,6 +39,7 @@ use FireflyIII\Services\Internal\Update\JournalUpdateService;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\View\View as IlluminateView;
|
||||
use InvalidArgumentException;
|
||||
|
||||
@ -251,7 +252,8 @@ class MassController extends Controller
|
||||
try {
|
||||
$carbon = Carbon::parse($value[$journalId]);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$e->getMessage();
|
||||
Log::warning(sprintf('Could not parse "%s" but dont mind',$value[$journalId]));
|
||||
Log::warning($e->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class ShowController extends Controller
|
||||
*/
|
||||
public function show(Request $request, TransactionGroup $transactionGroup)
|
||||
{
|
||||
/** @var TransactionJournal $first */
|
||||
/** @var TransactionJournal|null $first */
|
||||
$first = $transactionGroup->transactionJournals()->first(['transaction_journals.*']);
|
||||
$splits = $transactionGroup->transactionJournals()->count();
|
||||
|
||||
|
@ -109,7 +109,7 @@ class InterestingMessage
|
||||
$message = $request->get('message');
|
||||
|
||||
// send message about newly created transaction group.
|
||||
/** @var TransactionGroup $group */
|
||||
/** @var TransactionGroup|null $group */
|
||||
$group = auth()->user()->transactionGroups()->with(['transactionJournals', 'transactionJournals.transactionType'])->find((int)$transactionGroupId);
|
||||
|
||||
if (null === $group) {
|
||||
@ -118,7 +118,7 @@ class InterestingMessage
|
||||
|
||||
$count = $group->transactionJournals->count();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
/** @var TransactionJournal|null $journal */
|
||||
$journal = $group->transactionJournals->first();
|
||||
if (null === $journal) {
|
||||
return;
|
||||
@ -163,7 +163,7 @@ class InterestingMessage
|
||||
$accountId = $request->get('account_id');
|
||||
$message = $request->get('message');
|
||||
|
||||
/** @var Account $account */
|
||||
/** @var Account|null $account */
|
||||
$account = auth()->user()->accounts()->withTrashed()->find($accountId);
|
||||
|
||||
if (null === $account) {
|
||||
@ -203,7 +203,7 @@ class InterestingMessage
|
||||
$billId = $request->get('bill_id');
|
||||
$message = $request->get('message');
|
||||
|
||||
/** @var Bill $bill */
|
||||
/** @var Bill|null $bill */
|
||||
$bill = auth()->user()->bills()->withTrashed()->find($billId);
|
||||
|
||||
if (null === $bill) {
|
||||
@ -240,7 +240,7 @@ class InterestingMessage
|
||||
$webhookId = $request->get('webhook_id');
|
||||
$message = $request->get('message');
|
||||
|
||||
/** @var Webhook $webhook */
|
||||
/** @var Webhook|null $webhook */
|
||||
$webhook = auth()->user()->webhooks()->withTrashed()->find($webhookId);
|
||||
|
||||
if (null === $webhook) {
|
||||
@ -283,7 +283,7 @@ class InterestingMessage
|
||||
$code = $request->get('code');
|
||||
$message = $request->get('message');
|
||||
|
||||
/** @var TransactionCurrency $currency */
|
||||
/** @var TransactionCurrency|null $currency */
|
||||
$currency = TransactionCurrency::whereCode($code)->first();
|
||||
|
||||
if (null === $currency) {
|
||||
|
@ -43,7 +43,7 @@ class IsDemoUser
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
/** @var User $user */
|
||||
/** @var User|null $user */
|
||||
$user = $request->user();
|
||||
if (null === $user) {
|
||||
return $next($request);
|
||||
|
@ -185,7 +185,7 @@ class Account extends Model
|
||||
*/
|
||||
public function getAccountNumberAttribute(): string
|
||||
{
|
||||
/** @var AccountMeta $metaValue */
|
||||
/** @var AccountMeta|null $metaValue */
|
||||
$metaValue = $this->accountMeta()
|
||||
->where('name', 'account_number')
|
||||
->first();
|
||||
|
@ -189,9 +189,7 @@ class Transaction extends Model
|
||||
public static function isJoined(Builder $query, string $table): bool
|
||||
{
|
||||
$joins = $query->getQuery()->joins;
|
||||
if (null === $joins) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($joins as $join) {
|
||||
if ($join->table === $table) {
|
||||
return true;
|
||||
|
@ -330,9 +330,6 @@ class TransactionJournal extends Model
|
||||
public static function isJoined(Builder $query, string $table): bool
|
||||
{
|
||||
$joins = $query->getQuery()->joins;
|
||||
if (null === $joins) {
|
||||
return false;
|
||||
}
|
||||
foreach ($joins as $join) {
|
||||
if ($join->table === $table) {
|
||||
return true;
|
||||
|
@ -108,7 +108,7 @@ class UserGroup extends Model
|
||||
$userGroupId = (int)$value;
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
/** @var UserGroup $userGroup */
|
||||
/** @var UserGroup|null $userGroup */
|
||||
$userGroup = UserGroup::find($userGroupId);
|
||||
if (null === $userGroup) {
|
||||
throw new NotFoundHttpException();
|
||||
|
@ -167,7 +167,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
app('log')->debug(sprintf('Searching for account named "%s" (of user #%d) of the following type(s)', $name, $this->user->id), ['types' => $types]);
|
||||
|
||||
$query->where('accounts.name', $name);
|
||||
/** @var Account $account */
|
||||
/** @var Account|null $account */
|
||||
$account = $query->first(['accounts.*']);
|
||||
if (null === $account) {
|
||||
app('log')->debug(sprintf('There is no account with name "%s" of types', $name), $types);
|
||||
@ -434,11 +434,12 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
/** @var AccountType $type */
|
||||
$type = AccountType::where('type', AccountType::RECONCILIATION)->first();
|
||||
|
||||
/** @var Account|null $current */
|
||||
$current = $this->user->accounts()->where('account_type_id', $type->id)
|
||||
->where('name', $name)
|
||||
->first();
|
||||
|
||||
/** @var Account $current */
|
||||
if (null !== $current) {
|
||||
return $current;
|
||||
}
|
||||
|
@ -284,13 +284,10 @@ class BillRepository implements BillRepositoryInterface
|
||||
*/
|
||||
public function getNoteText(Bill $bill): string
|
||||
{
|
||||
/** @var Note $note */
|
||||
/** @var Note|null $note */
|
||||
$note = $bill->notes()->first();
|
||||
if (null !== $note) {
|
||||
return (string)$note->text;
|
||||
}
|
||||
return (string)$note?->text;
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -452,7 +449,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
/** @var Transaction $transaction */
|
||||
/** @var Transaction|null $transaction */
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
if (null === $transaction) {
|
||||
continue;
|
||||
|
@ -401,7 +401,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
app('log')->debug(sprintf('Found %d budget limits.', $limits));
|
||||
|
||||
// there might be a budget limit for these dates:
|
||||
/** @var BudgetLimit $limit */
|
||||
/** @var BudgetLimit|null $limit */
|
||||
$limit = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
|
||||
|
@ -81,7 +81,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
|
||||
return $rate;
|
||||
}
|
||||
/** @var CurrencyExchangeRate $rate */
|
||||
/** @var CurrencyExchangeRate|null $rate */
|
||||
$rate = $this->user->currencyExchangeRates()
|
||||
->where('from_currency_id', $fromCurrency->id)
|
||||
->where('to_currency_id', $toCurrency->id)
|
||||
|
@ -104,7 +104,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
*/
|
||||
public function getDestinationAccount(TransactionJournal $journal): Account
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
/** @var Transaction|null $transaction */
|
||||
$transaction = $journal->transactions()->with('account')->where('amount', '>', 0)->first();
|
||||
if (null === $transaction) {
|
||||
throw new FireflyException(sprintf('Your administration is broken. Transaction journal #%d has no destination transaction.', $journal->id));
|
||||
@ -142,7 +142,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
*/
|
||||
public function getLast(): ?TransactionJournal
|
||||
{
|
||||
/** @var TransactionJournal $entry */
|
||||
/** @var TransactionJournal|null $entry */
|
||||
$entry = $this->user->transactionJournals()->orderBy('date', 'DESC')->first(['transaction_journals.*']);
|
||||
$result = null;
|
||||
if (null !== $entry) {
|
||||
@ -159,13 +159,9 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
*/
|
||||
public function getLinkNoteText(TransactionJournalLink $link): string
|
||||
{
|
||||
/** @var Note $note */
|
||||
/** @var Note|null $note */
|
||||
$note = $link->notes()->first();
|
||||
if (null !== $note) {
|
||||
return $note->text ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
return (string)$note?->text;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,106 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* ValidatesAdministrationAccess.php
|
||||
* Copyright (c) 2023 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Validation\Administration;
|
||||
|
||||
use FireflyIII\Enums\UserRoleEnum;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Trait ValidatesAdministrationAccess
|
||||
*/
|
||||
trait ValidatesAdministrationAccess
|
||||
{
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param array $allowedRoles
|
||||
*
|
||||
* @return void
|
||||
* @throws AuthenticationException
|
||||
* @throws FireflyException
|
||||
* @deprecated
|
||||
*/
|
||||
protected function validateAdministration(Validator $validator, array $allowedRoles): void
|
||||
{
|
||||
throw new FireflyException('deprecated method, must be done through user.');
|
||||
app('log')->debug('Now in validateAdministration()');
|
||||
if (!auth()->check()) {
|
||||
app('log')->error('User is not authenticated.');
|
||||
throw new AuthenticationException('No access to validateAdministration() method.');
|
||||
}
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
// get data from request:
|
||||
$data = $validator->getData();
|
||||
// check if user is part of this administration
|
||||
$administrationId = (int)($data['administration_id'] ?? $user->getAdministrationId());
|
||||
// safety catch:
|
||||
if (0 === $administrationId) {
|
||||
app('log')->error('validateAdministration ran into empty administration ID.');
|
||||
throw new AuthenticationException('Cannot validate administration.');
|
||||
}
|
||||
// grab the group:
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
|
||||
// collect the user's roles in this group:
|
||||
$array = $repository->getRolesInGroup($user, $administrationId);
|
||||
if (0 === count($array)) {
|
||||
app('log')->error(sprintf('User #%d ("%s") has no membership in group #%d.', $user->id, $user->email, $administrationId));
|
||||
$validator->errors()->add('administration', (string)trans('validation.no_access_user_group'));
|
||||
return;
|
||||
}
|
||||
if (in_array(UserRoleEnum::OWNER->value, $array, true)) {
|
||||
app('log')->debug('User is owner of this administration.');
|
||||
return;
|
||||
}
|
||||
if (in_array(UserRoleEnum::OWNER->value, $array, true)) {
|
||||
app('log')->debug('User has full access to this administration.');
|
||||
return;
|
||||
}
|
||||
$access = true;
|
||||
foreach ($allowedRoles as $allowedRole) {
|
||||
if (!in_array($allowedRole, $array, true)) {
|
||||
$access = false;
|
||||
}
|
||||
}
|
||||
if (false === $access) {
|
||||
app('log')->error(
|
||||
sprintf(
|
||||
'User #%d has memberships [%s] to group #%d but needs [%s].',
|
||||
$user->id,
|
||||
join(', ', $array),
|
||||
$administrationId,
|
||||
join(', ', $allowedRoles)
|
||||
)
|
||||
);
|
||||
$validator->errors()->add('administration', (string)trans('validation.no_access_user_group'));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user