mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Various code cleanup.
This commit is contained in:
parent
b0ccd26928
commit
ddb222cc72
@ -38,7 +38,6 @@ use Illuminate\Http\JsonResponse;
|
||||
*
|
||||
* Shows income information grouped or limited by date.
|
||||
* Ie. all income grouped by account + currency.
|
||||
* See reference nr. 75
|
||||
*/
|
||||
class AccountController extends Controller
|
||||
{
|
||||
@ -74,9 +73,6 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* See reference nr. 76
|
||||
* See reference nr. 77
|
||||
*
|
||||
* @param GenericRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
@ -104,8 +100,6 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* See reference nr. 78
|
||||
*
|
||||
* @param GenericRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
|
@ -35,7 +35,6 @@ use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class CategoryController
|
||||
* See reference nr. 79
|
||||
*/
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
|
@ -58,8 +58,6 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* See reference nr. 80
|
||||
* See reference nr. 81
|
||||
*
|
||||
* @param GenericRequest $request
|
||||
*
|
||||
|
@ -39,7 +39,6 @@ class TagController extends Controller
|
||||
|
||||
/**
|
||||
* TagController constructor.
|
||||
* See reference nr. 82
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -26,7 +26,6 @@ namespace FireflyIII\Api\V1\Controllers\Models\TransactionLink;
|
||||
|
||||
use FireflyIII\Api\V1\Controllers\Controller;
|
||||
use FireflyIII\Api\V1\Requests\Models\TransactionLink\UpdateRequest;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\TransactionJournalLink;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
|
||||
@ -71,8 +70,6 @@ class UpdateController extends Controller
|
||||
* @param TransactionJournalLink $journalLink
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
* See reference nr. 84
|
||||
*/
|
||||
public function update(UpdateRequest $request, TransactionJournalLink $journalLink): JsonResponse
|
||||
{
|
||||
|
@ -27,6 +27,7 @@ namespace FireflyIII\Api\V1\Controllers\User;
|
||||
use FireflyIII\Api\V1\Controllers\Controller;
|
||||
use FireflyIII\Api\V1\Requests\User\PreferenceStoreRequest;
|
||||
use FireflyIII\Api\V1\Requests\User\PreferenceUpdateRequest;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Transformers\PreferenceTransformer;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@ -47,13 +48,12 @@ class PreferencesController extends Controller
|
||||
* List all of them.
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
* @throws FireflyException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
// See reference nr. 83
|
||||
$collection = auth()->user()->preferences()->get();
|
||||
$collection = app('preferences')->all();
|
||||
$manager = $this->getManager();
|
||||
$count = $collection->count();
|
||||
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
|
||||
@ -119,7 +119,7 @@ class PreferencesController extends Controller
|
||||
* @param Preference $preference
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(PreferenceUpdateRequest $request, Preference $preference): JsonResponse
|
||||
{
|
||||
|
@ -23,8 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Helpers\Webhook;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\WebhookMessage;
|
||||
use JsonException;
|
||||
use Log;
|
||||
|
||||
|
||||
/**
|
||||
* Class Sha3SignatureGenerator
|
||||
@ -41,8 +44,11 @@ class Sha3SignatureGenerator implements SignatureGeneratorInterface
|
||||
try {
|
||||
$json = json_encode($message->message, JSON_THROW_ON_ERROR);
|
||||
} catch (JsonException $e) {
|
||||
// See reference nr. 87
|
||||
return sprintf('t=1,v%d=err-invalid-signature', $this->getVersion());
|
||||
Log::error('Could not generate hash.');
|
||||
Log::error(sprintf('JSON value: %s', $message->message));
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
throw new FireflyException('Could not generate JSON for SHA3 hash.', $e);
|
||||
}
|
||||
|
||||
// signature v1 is generated using the following structure:
|
||||
|
@ -149,21 +149,17 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
Log::debug(sprintf('Searching for account named "%s" (of user #%d) of the following type(s)', $name, $this->user->id), ['types' => $types]);
|
||||
|
||||
$accounts = $query->get(['accounts.*']);
|
||||
|
||||
// See reference nr. 10
|
||||
|
||||
$query->where('accounts.name', $name);
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
if ($account->name === $name) {
|
||||
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
|
||||
$account = $query->first(['accounts.*']);
|
||||
if (null === $account) {
|
||||
Log::debug(sprintf('There is no account with name "%s" of types', $name), $types);
|
||||
|
||||
return $account;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Log::debug(sprintf('There is no account with name "%s" of types', $name), $types);
|
||||
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
|
||||
|
||||
return null;
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,8 +99,6 @@ interface JournalRepositoryInterface
|
||||
public function getLast(): ?TransactionJournal;
|
||||
|
||||
/**
|
||||
* See reference nr. 4
|
||||
*
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return string
|
||||
|
@ -24,8 +24,6 @@ namespace FireflyIII\Repositories\LinkType;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Events\DestroyedTransactionLink;
|
||||
use FireflyIII\Events\StoredTransactionLink;
|
||||
use FireflyIII\Events\UpdatedTransactionLink;
|
||||
use FireflyIII\Models\LinkType;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@ -281,8 +279,6 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
// make note in noteable:
|
||||
$this->setNoteText($link, (string)$information['notes']);
|
||||
|
||||
event(new StoredTransactionLink($link));
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
@ -352,8 +348,6 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
$this->setNoteText($journalLink, $data['notes']);
|
||||
}
|
||||
|
||||
event(new UpdatedTransactionLink($journalLink));
|
||||
|
||||
return $journalLink;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,6 @@ use FireflyIII\Models\TransactionJournalMeta;
|
||||
|
||||
/**
|
||||
* Class GroupCloneService
|
||||
* See reference nr. 92
|
||||
*/
|
||||
class GroupCloneService
|
||||
{
|
||||
|
@ -32,7 +32,6 @@ use Log;
|
||||
|
||||
/**
|
||||
* Class GroupUpdateService
|
||||
* See reference nr. 91
|
||||
*/
|
||||
class GroupUpdateService
|
||||
{
|
||||
|
@ -48,7 +48,6 @@ use Log;
|
||||
* Class to centralise code that updates a journal given the input by system.
|
||||
*
|
||||
* Class JournalUpdateService
|
||||
* See reference nr. 93
|
||||
*/
|
||||
class JournalUpdateService
|
||||
{
|
||||
@ -163,8 +162,6 @@ class JournalUpdateService
|
||||
$this->updateAmount();
|
||||
$this->updateForeignAmount();
|
||||
|
||||
// See reference nr. 94
|
||||
|
||||
app('preferences')->mark();
|
||||
|
||||
$this->transactionJournal->refresh();
|
||||
|
@ -144,6 +144,19 @@ class Preferences
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function all(): Collection
|
||||
{
|
||||
$user = auth()->user();
|
||||
if(null === $user) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
return Preference::where('user_id', $user->id)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $name
|
||||
|
@ -28,7 +28,6 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Models\Webhook;
|
||||
@ -266,16 +265,8 @@ class FireflyValidator extends Validator
|
||||
if ('set_budget' === $actionType) {
|
||||
/** @var BudgetRepositoryInterface $repository */
|
||||
$repository = app(BudgetRepositoryInterface::class);
|
||||
$budgets = $repository->getBudgets();
|
||||
// count budgets, should have at least one
|
||||
// See reference nr. 102
|
||||
$count = $budgets->filter(
|
||||
function (Budget $budget) use ($value) {
|
||||
return $budget->name === $value;
|
||||
}
|
||||
)->count();
|
||||
|
||||
return 1 === $count;
|
||||
return null !== $repository->findByName($value);
|
||||
}
|
||||
|
||||
// if it's link to bill, verify the name of the bill.
|
||||
@ -450,16 +441,14 @@ class FireflyValidator extends Validator
|
||||
$type = AccountType::find($this->data['account_type_id'])->first();
|
||||
$value = $this->data['name'];
|
||||
|
||||
$set = $user->accounts()->where('account_type_id', $type->id)->get();
|
||||
// See reference nr. 103
|
||||
/** @var Account $entry */
|
||||
foreach ($set as $entry) {
|
||||
if ($entry->name === $value) {
|
||||
return false;
|
||||
$set = $user->accounts()->where('account_type_id', $type->id)->get();
|
||||
$result = $set->first(
|
||||
function (Account $account) use ($value) {
|
||||
return $account->name === $value;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
return null === $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -483,15 +472,13 @@ class FireflyValidator extends Validator
|
||||
$accountTypeIds = $accountTypes->pluck('id')->toArray();
|
||||
/** @var Collection $set */
|
||||
$set = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)->get();
|
||||
// See reference nr. 104
|
||||
/** @var Account $entry */
|
||||
foreach ($set as $entry) {
|
||||
if ($entry->name === $value) {
|
||||
return false;
|
||||
$result = $set->first(
|
||||
function (Account $account) use ($value) {
|
||||
return $account->name === $value;
|
||||
}
|
||||
}
|
||||
);
|
||||
return null === $result;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -507,16 +494,13 @@ class FireflyValidator extends Validator
|
||||
|
||||
/** @var Collection $set */
|
||||
$set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get();
|
||||
// See reference nr. 105
|
||||
/** @var Account $entry */
|
||||
foreach ($set as $entry) {
|
||||
// See reference nr. 106
|
||||
if ($entry->name === $value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
$result = $set->first(
|
||||
function (Account $account) use ($value) {
|
||||
return $account->name === $value;
|
||||
}
|
||||
);
|
||||
return null === $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -733,18 +717,8 @@ class FireflyValidator extends Validator
|
||||
if (null !== $exclude) {
|
||||
$query->where('piggy_banks.id', '!=', (int)$exclude);
|
||||
}
|
||||
$set = $query->get(['piggy_banks.*']);
|
||||
|
||||
/** @var PiggyBank $entry */
|
||||
foreach ($set as $entry) {
|
||||
|
||||
$fieldValue = $entry->name;
|
||||
if ($fieldValue === $value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
$query->where('piggy_banks.name',$value);
|
||||
return null === $query->first(['piggy_banks.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user