Added PHP7 return type statements.

This commit is contained in:
James Cole 2016-02-06 16:22:12 +01:00
parent b8c7876454
commit 4424e48926
4 changed files with 59 additions and 51 deletions

View File

@ -122,7 +122,7 @@ class Entry
/**
* @return array
*/
public static function getTypes()
public static function getTypes(): array
{
// key = field name (see top of class)
// value = field type (see csv.php under 'roles')
@ -139,7 +139,7 @@ class Entry
'fromAccountId' => 'account-id',
'fromAccountName' => 'account-name',
'fromAccountIban' => 'account-iban',
'fromAccountType' => '_ignore',
'fromAccountType' => '_ignore', // no, Firefly cannot import what it exports. I know :D
'toAccountId' => 'opposing-id',
'toAccountName' => 'opposing-name',
'toAccountIban' => 'opposing-iban',
@ -150,7 +150,7 @@ class Entry
/**
* @return string
*/
public function getAmount()
public function getAmount(): string
{
return $this->amount;
}

View File

@ -122,7 +122,7 @@ class AccountController extends Controller
// the opening balance is tricky:
$openingBalanceAmount = null;
if ($openingBalance) {
if ($openingBalance->id) {
$transaction = $repository->getFirstTransaction($openingBalance, $account);
$openingBalanceAmount = $transaction->amount;
}

View File

@ -36,7 +36,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return int
*/
public function countAccounts(array $types)
public function countAccounts(array $types): int
{
$count = Auth::user()->accounts()->accountTypeIn($types)->count();
@ -47,9 +47,9 @@ class AccountRepository implements AccountRepositoryInterface
* @param Account $account
* @param Account $moveTo
*
* @return boolean
* @return bool
*/
public function destroy(Account $account, Account $moveTo = null)
public function destroy(Account $account, Account $moveTo = null): bool
{
if (!is_null($moveTo)) {
// update all transactions:
@ -68,7 +68,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Account
*/
public function find(int $accountId)
public function find(int $accountId): Account
{
return Auth::user()->accounts()->findOrNew($accountId);
}
@ -80,7 +80,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Collection
*/
public function get(array $ids)
public function get(array $ids): Collection
{
return Auth::user()->accounts()->whereIn('id', $ids)->get(['accounts.*']);
}
@ -90,7 +90,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Collection
*/
public function getAccounts(array $types)
public function getAccounts(array $types): Collection
{
/** @var Collection $result */
$result = Auth::user()->accounts()->with(
@ -119,7 +119,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Collection
*/
public function getCreditCards(Carbon $date)
public function getCreditCards(Carbon $date): Collection
{
$set = Auth::user()->accounts()
->hasMetaValue('accountRole', 'ccAsset')
@ -147,7 +147,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Transaction
*/
public function getFirstTransaction(TransactionJournal $journal, Account $account)
public function getFirstTransaction(TransactionJournal $journal, Account $account): Transaction
{
$transaction = $journal->transactions()->where('account_id', $account->id)->first();
@ -159,7 +159,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Collection
*/
public function getFrontpageAccounts(Preference $preference)
public function getFrontpageAccounts(Preference $preference): Collection
{
$query = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account']);
@ -181,9 +181,9 @@ class AccountRepository implements AccountRepositoryInterface
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
* @return Collection
*/
public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end)
public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end): Collection
{
$set = Auth::user()
->transactionjournals()
@ -209,7 +209,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return LengthAwarePaginator
*/
public function getJournals(Account $account, $page)
public function getJournals(Account $account, $page): LengthAwarePaginator
{
$offset = ($page - 1) * 50;
$query = Auth::user()
@ -235,7 +235,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Collection
*/
public function getPiggyBankAccounts()
public function getPiggyBankAccounts(): Collection
{
$start = clone session('start', new Carbon);
$end = clone session('end', new Carbon);
@ -277,7 +277,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Collection
*/
public function getSavingsAccounts()
public function getSavingsAccounts(): Collection
{
$accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
@ -322,9 +322,9 @@ class AccountRepository implements AccountRepositoryInterface
* @param Account $account
* @param Carbon $date
*
* @return float
* @return string
*/
public function leftOnAccount(Account $account, Carbon $date)
public function leftOnAccount(Account $account, Carbon $date): string
{
$balance = Steam::balance($account, $date, true);
@ -342,7 +342,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return TransactionJournal|null
*/
public function openingBalanceTransaction(Account $account)
public function openingBalanceTransaction(Account $account): TransactionJournal
{
$journal = TransactionJournal
::orderBy('transaction_journals.date', 'ASC')
@ -351,6 +351,9 @@ class AccountRepository implements AccountRepositoryInterface
->transactionTypes([TransactionType::OPENING_BALANCE])
->orderBy('created_at', 'ASC')
->first(['transaction_journals.*']);
if(is_null($journal)) {
return new TransactionJournal;
}
return $journal;
}
@ -360,7 +363,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Account
*/
public function store(array $data)
public function store(array $data): Account
{
$newAccount = $this->storeAccount($data);
if (!is_null($newAccount)) {
@ -392,7 +395,7 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @return string
*/
public function sumOfEverything()
public function sumOfEverything(): string
{
return Auth::user()->transactions()->sum('amount');
}
@ -405,7 +408,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Account
*/
public function update(Account $account, array $data)
public function update(Account $account, array $data): Account
{
// update the account:
$account->name = $data['name'];
@ -449,7 +452,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Account
*/
protected function storeAccount(array $data)
private function storeAccount(array $data): Account
{
$type = Config::get('firefly.accountTypeByIdentifier.' . $data['accountType']);
$accountType = AccountType::whereType($type)->first();
@ -493,7 +496,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return TransactionJournal
*/
protected function storeInitialBalance(Account $account, Account $opposing, array $data)
private function storeInitialBalance(Account $account, Account $opposing, array $data): TransactionJournal
{
$transactionType = TransactionType::whereType(TransactionType::OPENING_BALANCE)->first();
$journal = TransactionJournal::create(
@ -534,8 +537,10 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @param Account $account
* @param array $data
*
* @return bool
*/
protected function storeMetadata(Account $account, array $data)
private function storeMetadata(Account $account, array $data): bool
{
$validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType'];
foreach ($validFields as $field) {
@ -549,9 +554,9 @@ class AccountRepository implements AccountRepositoryInterface
);
$metaData->save();
}
}
return true;
}
/**
@ -561,7 +566,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return TransactionJournal
*/
protected function updateInitialBalance(Account $account, TransactionJournal $journal, array $data)
private function updateInitialBalance(Account $account, TransactionJournal $journal, array $data): TransactionJournal
{
$journal->date = $data['openingBalanceDate'];
$journal->save();
@ -585,8 +590,9 @@ class AccountRepository implements AccountRepositoryInterface
* @param Account $account
* @param array $data
*
* @return bool
*/
protected function updateMetadata(Account $account, array $data)
private function updateMetadata(Account $account, array $data): bool
{
$validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType'];
@ -611,5 +617,7 @@ class AccountRepository implements AccountRepositoryInterface
}
}
return true;
}
}

View File

@ -24,7 +24,7 @@ interface AccountRepositoryInterface
*
* @return int
*/
public function countAccounts(array $types);
public function countAccounts(array $types): int;
/**
* @param Account $account
@ -32,7 +32,7 @@ interface AccountRepositoryInterface
*
* @return boolean
*/
public function destroy(Account $account, Account $moveTo = null);
public function destroy(Account $account, Account $moveTo = null): bool;
/**
* @param int $accountId
@ -41,7 +41,7 @@ interface AccountRepositoryInterface
*
* @return Account
*/
public function find(int $accountId);
public function find(int $accountId): Account;
/**
* Gets all the accounts by ID, for a given set.
@ -50,14 +50,14 @@ interface AccountRepositoryInterface
*
* @return Collection
*/
public function get(array $ids);
public function get(array $ids): Collection;
/**
* @param array $types
*
* @return Collection
*/
public function getAccounts(array $types);
public function getAccounts(array $types): Collection;
/**
* This method returns the users credit cards, along with some basic information about the
@ -70,7 +70,7 @@ interface AccountRepositoryInterface
*
* @return Collection
*/
public function getCreditCards(Carbon $date);
public function getCreditCards(Carbon $date): Collection;
/**
* @param TransactionJournal $journal
@ -78,23 +78,23 @@ interface AccountRepositoryInterface
*
* @return Transaction
*/
public function getFirstTransaction(TransactionJournal $journal, Account $account);
public function getFirstTransaction(TransactionJournal $journal, Account $account): Transaction;
/**
* @param Preference $preference
*
* @return Collection
*/
public function getFrontpageAccounts(Preference $preference);
public function getFrontpageAccounts(Preference $preference): Collection;
/**
* @param Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
* @return Collection
*/
public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end);
public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end): Collection;
/**
* @param Account $account
@ -102,48 +102,48 @@ interface AccountRepositoryInterface
*
* @return LengthAwarePaginator
*/
public function getJournals(Account $account, $page);
public function getJournals(Account $account, $page): LengthAwarePaginator;
/**
* Get the accounts of a user that have piggy banks connected to them.
*
* @return Collection
*/
public function getPiggyBankAccounts();
public function getPiggyBankAccounts(): Collection;
/**
* Get savings accounts and the balance difference in the period.
*
* @return Collection
*/
public function getSavingsAccounts();
public function getSavingsAccounts() : Collection;
/**
* @param Account $account
* @param Carbon $date
*
* @return float
* @return string
*/
public function leftOnAccount(Account $account, Carbon $date);
public function leftOnAccount(Account $account, Carbon $date): string;
/**
* @param Account $account
*
* @return TransactionJournal|null
* @return TransactionJournal
*/
public function openingBalanceTransaction(Account $account);
public function openingBalanceTransaction(Account $account) : TransactionJournal;
/**
* @param array $data
*
* @return Account
*/
public function store(array $data);
public function store(array $data) : Account;
/**
* @return string
*/
public function sumOfEverything();
public function sumOfEverything() : string;
/**
* @param Account $account
@ -151,5 +151,5 @@ interface AccountRepositoryInterface
*
* @return Account
*/
public function update(Account $account, array $data);
public function update(Account $account, array $data): Account;
}