Code clean up.

This commit is contained in:
James Cole
2017-11-15 12:25:49 +01:00
parent 57dcdfa0c4
commit ffca858b8d
476 changed files with 2055 additions and 4181 deletions

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Models;
@@ -37,9 +36,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Watson\Validating\ValidatingTrait;
/**
* Class Account
*
* @package FireflyIII\Models
* Class Account.
*/
class Account extends Model
{
@@ -70,13 +67,14 @@ class Account extends Model
'active' => 'required|boolean',
'iban' => 'between:1,50|iban',
];
/** @var bool */
/** @var bool */
private $joinedAccountTypes;
/**
* @param array $fields
*
* @return Account
*
* @throws FireflyException
*/
public static function firstOrCreateEncrypted(array $fields)
@@ -99,7 +97,6 @@ class Account extends Model
$fields['name'] = $fields['iban'];
}
/** @var Account $account */
foreach ($set as $account) {
if ($account->name === $fields['name']) {
@@ -118,7 +115,7 @@ class Account extends Model
*
* @return Account
*/
public static function routeBinder(Account $value)
public static function routeBinder(self $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {
@@ -151,7 +148,7 @@ class Account extends Model
{
$name = $this->name;
if ($this->accountType->type === AccountType::CASH) {
if (AccountType::CASH === $this->accountType->type) {
return '';
}
@@ -159,16 +156,17 @@ class Account extends Model
}
/**
* FIxxME can return null
* FIxxME can return null.
*
* @param $value
*
* @return string
*
* @throws FireflyException
*/
public function getIbanAttribute($value): string
{
if (is_null($value) || strlen(strval($value)) === 0) {
if (null === $value || 0 === strlen(strval($value))) {
return '';
}
try {
@@ -176,7 +174,7 @@ class Account extends Model
} catch (DecryptException $e) {
throw new FireflyException('Cannot decrypt value "' . $value . '" for account #' . $this->id);
}
if (is_null($result)) {
if (null === $result) {
return '';
}
@@ -184,7 +182,6 @@ class Account extends Model
}
/**
*
* @param string $fieldName
*
* @return string
@@ -201,7 +198,6 @@ class Account extends Model
}
/**
*
* @param $value
*
* @return string
@@ -216,9 +212,10 @@ class Account extends Model
}
/**
* Returns the opening balance
* Returns the opening balance.
*
* @return TransactionJournal
*
* @throws FireflyException
*/
public function getOpeningBalance(): TransactionJournal
@@ -228,7 +225,7 @@ class Account extends Model
->where('transactions.account_id', $this->id)
->transactionTypes([TransactionType::OPENING_BALANCE])
->first(['transaction_journals.*']);
if (is_null($journal)) {
if (null === $journal) {
return new TransactionJournal;
}
@@ -239,6 +236,7 @@ class Account extends Model
* Returns the amount of the opening balance for this account.
*
* @return string
*
* @throws FireflyException
*/
public function getOpeningBalanceAmount(): string
@@ -248,16 +246,16 @@ class Account extends Model
->where('transactions.account_id', $this->id)
->transactionTypes([TransactionType::OPENING_BALANCE])
->first(['transaction_journals.*']);
if (is_null($journal)) {
if (null === $journal) {
return '0';
}
$count = $journal->transactions()->count();
if ($count !== 2) {
if (2 !== $count) {
throw new FireflyException(sprintf('Cannot use getFirstTransaction on journal #%d', $journal->id));
}
$transaction = $journal->transactions()->where('account_id', $this->id)->first();
if (is_null($transaction)) {
if (null === $transaction) {
return '0';
}
@@ -265,9 +263,10 @@ class Account extends Model
}
/**
* Returns the date of the opening balance for this account. If no date, will return 01-01-1900
* Returns the date of the opening balance for this account. If no date, will return 01-01-1900.
*
* @return Carbon
*
* @throws FireflyException
*/
public function getOpeningBalanceDate(): Carbon
@@ -278,7 +277,7 @@ class Account extends Model
->where('transactions.account_id', $this->id)
->transactionTypes([TransactionType::OPENING_BALANCE])
->first(['transaction_journals.*']);
if (is_null($journal)) {
if (null === $journal) {
return $date;
}
@@ -294,13 +293,12 @@ class Account extends Model
}
/**
*
* @param EloquentBuilder $query
* @param array $types
*/
public function scopeAccountTypeIn(EloquentBuilder $query, array $types)
{
if (is_null($this->joinedAccountTypes)) {
if (null === $this->joinedAccountTypes) {
$query->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id');
$this->joinedAccountTypes = true;
}
@@ -308,7 +306,6 @@ class Account extends Model
}
/**
*
* @param EloquentBuilder $query
* @param string $name
* @param string $value
@@ -326,7 +323,6 @@ class Account extends Model
}
/**
*
* @param $value
*/
public function setIbanAttribute($value)
@@ -335,7 +331,6 @@ class Account extends Model
}
/**
*
* @param $value
*/
public function setNameAttribute($value)
@@ -347,7 +342,6 @@ class Account extends Model
/**
* @param $value
*
*/
public function setVirtualBalanceAttribute($value)
{