Code cleanup

This commit is contained in:
James Cole
2018-04-02 14:50:17 +02:00
parent 379b104778
commit fa7ab45a40
100 changed files with 440 additions and 517 deletions

View File

@@ -101,7 +101,7 @@ class AccountTransformer extends TransformerAbstract
*/
public function includeTransactions(Account $account): FractalCollection
{
$pageSize = intval(app('preferences')->getForUser($account->user, 'listPageSize', 50)->data);
$pageSize = (int)app('preferences')->getForUser($account->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class);
@@ -112,7 +112,7 @@ class AccountTransformer extends TransformerAbstract
} else {
$collector->setOpposingAccounts(new Collection([$account]));
}
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -151,7 +151,7 @@ class AccountTransformer extends TransformerAbstract
if (strlen($role) === 0 || $type !== AccountType::ASSET) {
$role = null;
}
$currencyId = intval($this->repository->getMetaValue($account, 'currency_id'));
$currencyId = (int)$this->repository->getMetaValue($account, 'currency_id');
$currencyCode = null;
$decimalPlaces = 2;
if ($currencyId > 0) {
@@ -161,7 +161,7 @@ class AccountTransformer extends TransformerAbstract
}
$date = new Carbon;
if (!is_null($this->parameters->get('date'))) {
if (null !== $this->parameters->get('date')) {
$date = $this->parameters->get('date');
}
@@ -183,7 +183,7 @@ class AccountTransformer extends TransformerAbstract
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($account->user);
$amount = $repository->getOpeningBalanceAmount($account);
$openingBalance = is_null($amount) ? null : round($amount, $decimalPlaces);
$openingBalance = null === $amount ? null : round($amount, $decimalPlaces);
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
}
@@ -192,7 +192,7 @@ class AccountTransformer extends TransformerAbstract
'updated_at' => $account->updated_at->toAtomString(),
'created_at' => $account->created_at->toAtomString(),
'name' => $account->name,
'active' => intval($account->active) === 1,
'active' => (int)$account->active === 1,
'type' => $type,
'currency_id' => $currencyId,
'currency_code' => $currencyCode,

View File

@@ -93,7 +93,7 @@ class BillTransformer extends TransformerAbstract
*/
public function includeTransactions(Bill $bill): FractalCollection
{
$pageSize = intval(app('preferences')->getForUser($bill->user, 'listPageSize', 50)->data);
$pageSize = (int)app('preferences')->getForUser($bill->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class);
@@ -101,7 +101,7 @@ class BillTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setBills(new Collection([$bill]));
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -145,8 +145,8 @@ class BillTransformer extends TransformerAbstract
'date' => $bill->date->format('Y-m-d'),
'repeat_freq' => $bill->repeat_freq,
'skip' => (int)$bill->skip,
'automatch' => intval($bill->automatch) === 1,
'active' => intval($bill->active) === 1,
'automatch' => (int)$bill->automatch === 1,
'active' => (int)$bill->active === 1,
'attachments_count' => $bill->attachments()->count(),
'pay_dates' => $payDates,
'paid_dates' => $paidData['paid_dates'],
@@ -161,7 +161,7 @@ class BillTransformer extends TransformerAbstract
];
/** @var Note $note */
$note = $bill->notes()->first();
if (!is_null($note)) {
if (null !== $note) {
$data['notes'] = $note->text;
}
@@ -222,7 +222,7 @@ class BillTransformer extends TransformerAbstract
protected function paidData(Bill $bill): array
{
Log::debug(sprintf('Now in paidData for bill #%d', $bill->id));
if (is_null($this->parameters->get('start')) || is_null($this->parameters->get('end'))) {
if (null === $this->parameters->get('start') || null === $this->parameters->get('end')) {
Log::debug('parameters are NULL, return empty array');
return [
@@ -267,7 +267,7 @@ class BillTransformer extends TransformerAbstract
*/
protected function payDates(Bill $bill): array
{
if (is_null($this->parameters->get('start')) || is_null($this->parameters->get('end'))) {
if (null === $this->parameters->get('start') || null === $this->parameters->get('end')) {
return [];
}
$set = new Collection;

View File

@@ -75,7 +75,7 @@ class BudgetTransformer extends TransformerAbstract
*/
public function includeTransactions(Budget $budget): FractalCollection
{
$pageSize = intval(app('preferences')->getForUser($budget->user, 'listPageSize', 50)->data);
$pageSize = (int)app('preferences')->getForUser($budget->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class);
@@ -83,7 +83,7 @@ class BudgetTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
$collector->setAllAssetAccounts();
$collector->setBudgets(new Collection([$budget]));
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -118,7 +118,7 @@ class BudgetTransformer extends TransformerAbstract
'id' => (int)$budget->id,
'updated_at' => $budget->updated_at->toAtomString(),
'created_at' => $budget->created_at->toAtomString(),
'active' => intval($budget->active) === 1,
'active' => (int)$budget->active === 1,
'name' => $budget->name,
'links' => [
[

View File

@@ -75,7 +75,7 @@ class CategoryTransformer extends TransformerAbstract
*/
public function includeTransactions(Category $category): FractalCollection
{
$pageSize = intval(app('preferences')->getForUser($category->user, 'listPageSize', 50)->data);
$pageSize = (int)app('preferences')->getForUser($category->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class);
@@ -83,7 +83,7 @@ class CategoryTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts();
$collector->setCategories(new Collection([$category]));
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));

View File

@@ -75,7 +75,7 @@ class JournalMetaTransformer extends TransformerAbstract
public function includeTransactions(TransactionJournalMeta $meta): FractalCollection
{
$journal = $meta->transactionJournal;
$pageSize = intval(app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data);
$pageSize = (int)app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class);
@@ -83,7 +83,7 @@ class JournalMetaTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts();
$collector->setJournals(new Collection([$journal]));
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));

View File

@@ -91,7 +91,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
public function includeTransaction(PiggyBankEvent $event): Item
{
$journal = $event->transactionJournal;
$pageSize = intval(app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data);
$pageSize = (int)app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class);
@@ -99,7 +99,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts();
$collector->setJournals(new Collection([$journal]));
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -118,7 +118,7 @@ class PiggyBankEventTransformer extends TransformerAbstract
public function transform(PiggyBankEvent $event): array
{
$account = $event->piggyBank->account;
$currencyId = intval($account->getMeta('currency_id'));
$currencyId = (int)$account->getMeta('currency_id');
$decimalPlaces = 2;
if ($currencyId > 0) {
/** @var CurrencyRepositoryInterface $repository */

View File

@@ -117,7 +117,7 @@ class PiggyBankTransformer extends TransformerAbstract
public function transform(PiggyBank $piggyBank): array
{
$account = $piggyBank->account;
$currencyId = intval($account->getMeta('currency_id'));
$currencyId = (int)$account->getMeta('currency_id');
$decimalPlaces = 2;
if ($currencyId > 0) {
/** @var CurrencyRepositoryInterface $repository */
@@ -133,8 +133,8 @@ class PiggyBankTransformer extends TransformerAbstract
$piggyRepos->setUser($account->user);
$currentAmount = round($piggyRepos->getCurrentAmount($piggyBank), $decimalPlaces);
$startDate = is_null($piggyBank->startdate) ? null : $piggyBank->startdate->format('Y-m-d');
$targetDate = is_null($piggyBank->targetdate) ? null : $piggyBank->targetdate->format('Y-m-d');
$startDate = null === $piggyBank->startdate ? null : $piggyBank->startdate->format('Y-m-d');
$targetDate = null === $piggyBank->targetdate ? null : $piggyBank->targetdate->format('Y-m-d');
$targetAmount = round($piggyBank->targetamount, $decimalPlaces);
$data = [
'id' => (int)$piggyBank->id,
@@ -146,7 +146,7 @@ class PiggyBankTransformer extends TransformerAbstract
'startdate' => $startDate,
'targetdate' => $targetDate,
'order' => (int)$piggyBank->order,
'active' => intval($piggyBank->active) === 1,
'active' => (int)$piggyBank->active === 1,
'notes' => null,
'links' => [
[
@@ -157,7 +157,7 @@ class PiggyBankTransformer extends TransformerAbstract
];
/** @var Note $note */
$note = $piggyBank->notes()->first();
if (!is_null($note)) {
if (null !== $note) {
$data['notes'] = $note->text;
}

View File

@@ -74,7 +74,7 @@ class TagTransformer extends TransformerAbstract
*/
public function includeTransactions(Tag $tag): FractalCollection
{
$pageSize = intval(app('preferences')->getForUser($tag->user, 'listPageSize', 50)->data);
$pageSize = (int)app('preferences')->getForUser($tag->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters.
$collector = app(JournalCollectorInterface::class);
@@ -82,7 +82,7 @@ class TagTransformer extends TransformerAbstract
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts();
$collector->setTag($tag);
if (!is_null($this->parameters->get('start')) && !is_null($this->parameters->get('end'))) {
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
@@ -113,7 +113,7 @@ class TagTransformer extends TransformerAbstract
*/
public function transform(Tag $tag): array
{
$date = is_null($tag->date) ? null : $tag->date->format('Y-m-d');
$date = null === $tag->date ? null : $tag->date->format('Y-m-d');
$data = [
'id' => (int)$tag->id,
'updated_at' => $tag->updated_at->toAtomString(),

View File

@@ -157,21 +157,21 @@ class TransactionTransformer extends TransformerAbstract
$categoryName = null;
$budgetId = null;
$budgetName = null;
$categoryId = is_null($transaction->transaction_category_id) ? $transaction->transaction_journal_category_id
$categoryId = null === $transaction->transaction_category_id ? $transaction->transaction_journal_category_id
: $transaction->transaction_category_id;
$categoryName = is_null($transaction->transaction_category_name) ? $transaction->transaction_journal_category_name
$categoryName = null === $transaction->transaction_category_name ? $transaction->transaction_journal_category_name
: $transaction->transaction_category_name;
if ($transaction->transaction_type_type === TransactionType::WITHDRAWAL) {
$budgetId = is_null($transaction->transaction_budget_id) ? $transaction->transaction_journal_budget_id
$budgetId = null === $transaction->transaction_budget_id ? $transaction->transaction_journal_budget_id
: $transaction->transaction_budget_id;
$budgetName = is_null($transaction->transaction_budget_name) ? $transaction->transaction_journal_budget_name
$budgetName = null === $transaction->transaction_budget_name ? $transaction->transaction_journal_budget_name
: $transaction->transaction_budget_name;
}
/** @var Note $dbNote */
$dbNote = $transaction->transactionJournal->notes()->first();
$notes = null;
if (!is_null($dbNote)) {
if (null !== $dbNote) {
$notes = $dbNote->text;
}
@@ -186,7 +186,7 @@ class TransactionTransformer extends TransformerAbstract
'identifier' => $transaction->identifier,
'journal_id' => (int)$transaction->journal_id,
'reconciled' => (bool)$transaction->reconciled,
'amount' => round($transaction->transaction_amount, intval($transaction->transaction_currency_dp)),
'amount' => round($transaction->transaction_amount, (int)$transaction->transaction_currency_dp),
'currency_id' => $transaction->transaction_currency_id,
'currency_code' => $transaction->transaction_currency_code,
'currency_symbol' => $transaction->transaction_currency_symbol,
@@ -212,8 +212,8 @@ class TransactionTransformer extends TransformerAbstract
];
// expand foreign amount:
if (!is_null($transaction->transaction_foreign_amount)) {
$data['foreign_amount'] = round($transaction->transaction_foreign_amount, intval($transaction->foreign_currency_dp));
if (null !== $transaction->transaction_foreign_amount) {
$data['foreign_amount'] = round($transaction->transaction_foreign_amount, (int)$transaction->foreign_currency_dp);
}
// switch on type for consistency
@@ -251,7 +251,7 @@ class TransactionTransformer extends TransformerAbstract
}
// expand description.
if (strlen(strval($transaction->transaction_description)) > 0) {
if (strlen((string)$transaction->transaction_description) > 0) {
$data['description'] = $transaction->transaction_description . ' (' . $transaction->description . ')';
}

View File

@@ -184,7 +184,7 @@ class UserTransformer extends TransformerAbstract
{
/** @var Role $role */
$role = $user->roles()->first();
if (!is_null($role)) {
if (null !== $role) {
$role = $role->name;
}
@@ -193,7 +193,7 @@ class UserTransformer extends TransformerAbstract
'updated_at' => $user->updated_at->toAtomString(),
'created_at' => $user->created_at->toAtomString(),
'email' => $user->email,
'blocked' => intval($user->blocked) === 1,
'blocked' => (int)$user->blocked === 1,
'blocked_code' => $user->blocked_code,
'role' => $role,
'links' => [