Skip to content

Firefly III: a personal finances manager

PHP7 type declarations.

James Colef0f47530bf98
diff --git a/app/Handlers/Events/FireRulesForStore.php b/app/Handlers/Events/FireRulesForStore.php
index e7aeb8ddf1..754e112013 100644
--- a/app/Handlers/Events/FireRulesForStore.php
+++ b/app/Handlers/Events/FireRulesForStore.php
@@ -58,10 +58,11 @@ class FireRulesForStore
$processor->handleTransactionJournal($event->journal);
if ($rule->stop_processing) {
- break;
+ return true;
}
}
}
+ return true;
}
}
diff --git a/app/Helpers/Collection/BalanceEntry.php b/app/Helpers/Collection/BalanceEntry.php
index f916cbeba2..baa2f3d17c 100644
--- a/app/Helpers/Collection/BalanceEntry.php
+++ b/app/Helpers/Collection/BalanceEntry.php
@@ -25,7 +25,7 @@ class BalanceEntry
/**
* @return AccountModel
*/
- public function getAccount()
+ public function getAccount(): AccountModel
{
return $this->account;
}
@@ -41,7 +41,7 @@ class BalanceEntry
/**
* @return string
*/
- public function getLeft()
+ public function getLeft(): string
{
return $this->left;
}
@@ -57,7 +57,7 @@ class BalanceEntry
/**
* @return string
*/
- public function getSpent()
+ public function getSpent(): string
{
return $this->spent;
}
diff --git a/app/Helpers/Collection/BalanceHeader.php b/app/Helpers/Collection/BalanceHeader.php
index 55ba9b4f4d..60ed221f7b 100644
--- a/app/Helpers/Collection/BalanceHeader.php
+++ b/app/Helpers/Collection/BalanceHeader.php
@@ -37,7 +37,7 @@ class BalanceHeader
/**
* @return Collection
*/
- public function getAccounts()
+ public function getAccounts(): Collection
{
return $this->accounts;
}
diff --git a/app/Helpers/Collection/BalanceLine.php b/app/Helpers/Collection/BalanceLine.php
index 5df4350aba..d1035ac3ab 100644
--- a/app/Helpers/Collection/BalanceLine.php
+++ b/app/Helpers/Collection/BalanceLine.php
@@ -34,6 +34,7 @@ class BalanceLine
public function __construct()
{
$this->balanceEntries = new Collection;
+
}
/**
@@ -47,7 +48,7 @@ class BalanceLine
/**
* @return Collection
*/
- public function getBalanceEntries()
+ public function getBalanceEntries(): Collection
{
return $this->balanceEntries;
}
@@ -63,9 +64,9 @@ class BalanceLine
/**
* @return BudgetModel
*/
- public function getBudget()
+ public function getBudget(): BudgetModel
{
- return $this->budget;
+ return $this->budget ?? new BudgetModel;
}
/**
@@ -79,7 +80,7 @@ class BalanceLine
/**
* @return int
*/
- public function getRole()
+ public function getRole(): int
{
return $this->role;
}
@@ -95,9 +96,9 @@ class BalanceLine
/**
* @return string
*/
- public function getTitle()
+ public function getTitle(): string
{
- if ($this->getBudget() instanceof BudgetModel) {
+ if ($this->getBudget() instanceof BudgetModel && !is_null($this->getBudget()->id)) {
return $this->getBudget()->name;
}
if ($this->getRole() == self::ROLE_DEFAULTROLE) {
@@ -121,7 +122,7 @@ class BalanceLine
*
* @return string
*/
- public function leftOfRepetition()
+ public function leftOfRepetition(): string
{
bcscale(2);
$start = $this->budget->amount ?? '0';
diff --git a/app/Helpers/Collection/Bill.php b/app/Helpers/Collection/Bill.php
index 95a30bbc79..f5b58b36ec 100644
--- a/app/Helpers/Collection/Bill.php
+++ b/app/Helpers/Collection/Bill.php
@@ -38,7 +38,7 @@ class Bill
/**
* @return Collection
*/
- public function getBills()
+ public function getBills(): Collection
{
$set = $this->bills->sortBy(
function (BillLine $bill) {
diff --git a/app/Helpers/Collection/BillLine.php b/app/Helpers/Collection/BillLine.php
index 2d12f55da5..4f29e85a64 100644
--- a/app/Helpers/Collection/BillLine.php
+++ b/app/Helpers/Collection/BillLine.php
@@ -33,7 +33,7 @@ class BillLine
/**
* @return string
*/
- public function getAmount()
+ public function getAmount(): string
{
return $this->amount;
}
@@ -49,7 +49,7 @@ class BillLine
/**
* @return BillModel
*/
- public function getBill()
+ public function getBill(): BillModel
{
return $this->bill;
}
@@ -65,7 +65,7 @@ class BillLine
/**
* @return string
*/
- public function getMax()
+ public function getMax(): string
{
return $this->max;
}
@@ -81,7 +81,7 @@ class BillLine
/**
* @return string
*/
- public function getMin()
+ public function getMin(): string
{
return $this->min;
}
@@ -113,7 +113,7 @@ class BillLine
/**
* @return boolean
*/
- public function isActive()
+ public function isActive(): bool
{
return $this->active;
}
@@ -129,7 +129,7 @@ class BillLine
/**
* @return boolean
*/
- public function isHit()
+ public function isHit(): bool
{
return $this->hit;
}
diff --git a/app/Helpers/Collection/Budget.php b/app/Helpers/Collection/Budget.php
index a5139d7093..7569f3eeb1 100644
--- a/app/Helpers/Collection/Budget.php
+++ b/app/Helpers/Collection/Budget.php
@@ -83,7 +83,7 @@ class Budget
/**
* @return \Illuminate\Support\Collection
*/
- public function getBudgetLines()
+ public function getBudgetLines(): Collection
{
return $this->budgetLines;
}
@@ -91,7 +91,7 @@ class Budget
/**
* @return string
*/
- public function getBudgeted()
+ public function getBudgeted(): string
{
return $this->budgeted;
}
@@ -107,7 +107,7 @@ class Budget
/**
* @return string
*/
- public function getLeft()
+ public function getLeft(): string
{
return $this->left;
}
@@ -123,7 +123,7 @@ class Budget
/**
* @return string
*/
- public function getOverspent()
+ public function getOverspent(): string
{
return $this->overspent;
}
@@ -139,7 +139,7 @@ class Budget
/**
* @return string
*/
- public function getSpent()
+ public function getSpent(): string
{
return $this->spent;
}
diff --git a/app/Helpers/Collection/Category.php b/app/Helpers/Collection/Category.php
index 1225c05ee6..644656a00f 100644
--- a/app/Helpers/Collection/Category.php
+++ b/app/Helpers/Collection/Category.php
@@ -54,7 +54,7 @@ class Category
/**
* @return Collection
*/
- public function getCategories()
+ public function getCategories(): Collection
{
$set = $this->categories->sortBy(
function (CategoryModel $category) {
@@ -69,7 +69,7 @@ class Category
/**
* @return string
*/
- public function getTotal()
+ public function getTotal(): string
{
return strval(round($this->total, 2));
}
diff --git a/app/Helpers/Collection/Expense.php b/app/Helpers/Collection/Expense.php
index b380bfc134..25441b493b 100644
--- a/app/Helpers/Collection/Expense.php
+++ b/app/Helpers/Collection/Expense.php
@@ -80,7 +80,7 @@ class Expense
/**
* @return Collection
*/
- public function getExpenses()
+ public function getExpenses(): Collection
{
$set = $this->expenses->sortBy(
function (stdClass $object) {
@@ -94,7 +94,7 @@ class Expense
/**
* @return string
*/
- public function getTotal()
+ public function getTotal(): string
{
return strval(round($this->total, 2));
}
diff --git a/app/Helpers/Collection/Income.php b/app/Helpers/Collection/Income.php
index e2d306f310..fc3cf45814 100644
--- a/app/Helpers/Collection/Income.php
+++ b/app/Helpers/Collection/Income.php
@@ -66,7 +66,7 @@ class Income
/**
* @return Collection
*/
- public function getIncomes()
+ public function getIncomes(): Collection
{
$set = $this->incomes->sortByDesc(
function (stdClass $object) {
@@ -80,7 +80,7 @@ class Income
/**
* @return string
*/
- public function getTotal()
+ public function getTotal(): string
{
return strval(round($this->total, 2));
}
diff --git a/app/Helpers/Csv/Converter/AccountId.php b/app/Helpers/Csv/Converter/AccountId.php
index 85de9301d4..00912809bd 100644
--- a/app/Helpers/Csv/Converter/AccountId.php
+++ b/app/Helpers/Csv/Converter/AccountId.php
@@ -31,6 +31,9 @@ class AccountId extends BasicConverter implements ConverterInterface
if (!is_null($account)) {
Log::debug('Found ' . $account->accountType->type . ' named "******" with ID: ' . $this->value . ' (not mapped) ');
+ } else {
+ // new account to prevent TypeErrors.
+ $account = new Account;
}
}
diff --git a/app/Helpers/Csv/Converter/Amount.php b/app/Helpers/Csv/Converter/Amount.php
index c7ff345085..6aade561ab 100644
--- a/app/Helpers/Csv/Converter/Amount.php
+++ b/app/Helpers/Csv/Converter/Amount.php
@@ -11,12 +11,12 @@ class Amount extends BasicConverter implements ConverterInterface
{
/**
- * @return string|int
+ * @return string
*/
- public function convert()
+ public function convert(): string
{
if (is_numeric($this->value)) {
- return $this->value;
+ return strval($this->value);
}
return '0';
diff --git a/app/Helpers/Csv/Converter/AmountComma.php b/app/Helpers/Csv/Converter/AmountComma.php
index 46b6ebd606..ca3937e074 100644
--- a/app/Helpers/Csv/Converter/AmountComma.php
+++ b/app/Helpers/Csv/Converter/AmountComma.php
@@ -17,10 +17,10 @@ class AmountComma extends BasicConverter implements ConverterInterface
*/
public function convert()
{
- $value = str_replace(',', '.', $this->value);
+ $value = str_replace(',', '.', str_val($this->value));
if (is_numeric($value)) {
- return $value;
+ return strval($value);
}
return '0';
diff --git a/app/Helpers/Csv/Converter/AssetAccountIban.php b/app/Helpers/Csv/Converter/AssetAccountIban.php
index 8a98e37593..d506b2d052 100644
--- a/app/Helpers/Csv/Converter/AssetAccountIban.php
+++ b/app/Helpers/Csv/Converter/AssetAccountIban.php
@@ -15,10 +15,11 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
{
/**
- * @return Account|null
+ * @return Account
*/
- public function convert()
+ public function convert(): Account
{
+
// is mapped? Then it's easy!
if (isset($this->mapped[$this->index][$this->value])) {
$account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
@@ -29,7 +30,7 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
// find or create new account:
$account = $this->findAccount();
- if (is_null($account)) {
+ if (is_null($account->id)) {
// create it if doesn't exist.
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
@@ -55,13 +56,13 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
return $account;
}
- return null;
+ return new Account;
}
/**
- * @return Account|null
+ * @return Account
*/
- protected function findAccount()
+ protected function findAccount(): Account
{
$set = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->get(['accounts.*']);
/** @var Account $entry */
@@ -72,6 +73,6 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
}
}
- return null;
+ return new Account;
}
}