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)
{

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;
@@ -27,13 +26,10 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* Class AccountMeta
*
* @package FireflyIII\Models
* Class AccountMeta.
*/
class AccountMeta extends Model
{
/**
* The attributes that should be casted to native types.
*
@@ -49,7 +45,6 @@ class AccountMeta extends Model
protected $table = 'account_meta';
/**
*
* @return BelongsTo
*/
public function account(): BelongsTo
@@ -57,7 +52,6 @@ class AccountMeta extends Model
return $this->belongsTo('FireflyIII\Models\Account');
}
/**
* @param $value
*

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;
@@ -27,9 +26,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Class AccountType
*
* @package FireflyIII\Models
* Class AccountType.
*/
class AccountType extends Model
{
@@ -42,7 +39,6 @@ class AccountType extends Model
const BENEFICIARY = 'Beneficiary account';
const IMPORT = 'Import account';
/**
* The attributes that should be casted to native types.
*

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;
@@ -31,9 +30,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class Attachment
*
* @package FireflyIII\Models
* Class Attachment.
*/
class Attachment extends Model
{
@@ -59,7 +56,7 @@ class Attachment extends Model
*
* @return Attachment
*/
public static function routeBinder(Attachment $value)
public static function routeBinder(self $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {
@@ -96,7 +93,7 @@ class Attachment extends Model
*/
public function getDescriptionAttribute($value)
{
if (is_null($value) || strlen($value) === 0) {
if (null === $value || 0 === strlen($value)) {
return null;
}
@@ -110,7 +107,7 @@ class Attachment extends Model
*/
public function getFilenameAttribute($value)
{
if (is_null($value) || strlen($value) === 0) {
if (null === $value || 0 === strlen($value)) {
return null;
}
@@ -124,7 +121,7 @@ class Attachment extends Model
*/
public function getMimeAttribute($value)
{
if (is_null($value) || strlen($value) === 0) {
if (null === $value || 0 === strlen($value)) {
return null;
}
@@ -132,14 +129,13 @@ class Attachment extends Model
}
/**
*
* @param $value
*
* @return null|string
*/
public function getNotesAttribute($value)
{
if (is_null($value) || strlen($value) === 0) {
if (null === $value || 0 === strlen($value)) {
return null;
}
@@ -147,14 +143,13 @@ class Attachment extends Model
}
/**
*
* @param $value
*
* @return null|string
*/
public function getTitleAttribute($value)
{
if (is_null($value) || strlen($value) === 0) {
if (null === $value || 0 === strlen($value)) {
return null;
}

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;
@@ -28,9 +27,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class AvailableBudget
*
* @package FireflyIII\Models
* Class AvailableBudget.
*/
class AvailableBudget extends Model
{

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;
@@ -32,9 +31,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Watson\Validating\ValidatingTrait;
/**
* Class Bill
*
* @package FireflyIII\Models
* Class Bill.
*/
class Bill extends Model
{
@@ -60,14 +57,14 @@ class Bill extends Model
= ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip',
'automatch', 'active',];
protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted'];
protected $rules = ['name' => 'required|between:1,200',];
protected $rules = ['name' => 'required|between:1,200'];
/**
* @param Bill $value
*
* @return Bill
*/
public static function routeBinder(Bill $value)
public static function routeBinder(self $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {
@@ -84,7 +81,7 @@ class Bill extends Model
*/
public function getMatchAttribute($value)
{
if (intval($this->match_encrypted) === 1) {
if (1 === intval($this->match_encrypted)) {
return Crypt::decrypt($value);
}
@@ -98,7 +95,7 @@ class Bill extends Model
*/
public function getNameAttribute($value)
{
if (intval($this->name_encrypted) === 1) {
if (1 === intval($this->name_encrypted)) {
return Crypt::decrypt($value);
}

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;
@@ -31,9 +30,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Watson\Validating\ValidatingTrait;
/**
* Class Budget
*
* @package FireflyIII\Models
* Class Budget.
*/
class Budget extends Model
{
@@ -57,7 +54,7 @@ class Budget extends Model
/** @var array */
protected $hidden = ['encrypted'];
/** @var array */
protected $rules = ['name' => 'required|between:1,200',];
protected $rules = ['name' => 'required|between:1,200'];
/**
* @param array $fields
@@ -91,7 +88,7 @@ class Budget extends Model
*
* @return Budget
*/
public static function routeBinder(Budget $value)
public static function routeBinder(self $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {
@@ -102,7 +99,6 @@ class Budget extends Model
}
/**
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function budgetlimits()

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;
@@ -27,13 +26,10 @@ use Illuminate\Database\Eloquent\Model;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class BudgetLimit
*
* @package FireflyIII\Models
* Class BudgetLimit.
*/
class BudgetLimit extends Model
{
/**
* The attributes that should be casted to native types.
*
@@ -85,7 +81,6 @@ class BudgetLimit extends Model
return $this->hasMany('FireflyIII\Models\LimitRepetition');
}
/**
* @param $value
*/

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;
@@ -31,9 +30,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Watson\Validating\ValidatingTrait;
/**
* Class Category
*
* @package FireflyIII\Models
* Class Category.
*/
class Category extends Model
{
@@ -56,7 +53,7 @@ class Category extends Model
/** @var array */
protected $hidden = ['encrypted'];
/** @var array */
protected $rules = ['name' => 'required|between:1,200',];
protected $rules = ['name' => 'required|between:1,200'];
/**
* @param array $fields
@@ -90,7 +87,7 @@ class Category extends Model
*
* @return Category
*/
public static function routeBinder(Category $value)
public static function routeBinder(self $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {
@@ -101,7 +98,6 @@ class Category extends Model
}
/**
*
* @param $value
*
* @return string
@@ -116,7 +112,6 @@ class Category extends Model
}
/**
*
* @param $value
*/
public function setNameAttribute($value)

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;
@@ -27,9 +26,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Configuration
*
* @package FireflyIII\Models
* Class Configuration.
*/
class Configuration extends Model
{

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;
@@ -28,13 +27,10 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* Class CurrencyExchange
*
* @package FireflyIII\Models
* Class CurrencyExchange.
*/
class CurrencyExchangeRate extends Model
{
/** @var array */
protected $dates = ['date'];

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;
@@ -28,11 +27,9 @@ use Illuminate\Database\Eloquent\Model;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class ExportJob
* Class ExportJob.
*
* @property User $user
*
* @package FireflyIII\Models
*/
class ExportJob extends Model
{
@@ -47,13 +44,14 @@ class ExportJob extends Model
* @param $value
*
* @return mixed
*
* @throws NotFoundHttpException
*/
public static function routeBinder($value)
{
if (auth()->check()) {
$model = self::where('key', $value)->where('user_id', auth()->user()->id)->first();
if (!is_null($model)) {
if (null !== $model) {
return $model;
}
}

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;
@@ -30,13 +29,10 @@ use Storage;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class ImportJob
*
* @package FireflyIII\Models
* Class ImportJob.
*/
class ImportJob extends Model
{
/**
* The attributes that should be casted to native types.
*
@@ -61,13 +57,14 @@ class ImportJob extends Model
* @param $value
*
* @return mixed
*
* @throws NotFoundHttpException
*/
public static function routeBinder($value)
{
if (auth()->check()) {
$model = self::where('key', $value)->where('user_id', auth()->user()->id)->first();
if (!is_null($model)) {
if (null !== $model) {
return $model;
}
}
@@ -127,10 +124,10 @@ class ImportJob extends Model
*/
public function getConfigurationAttribute($value)
{
if (is_null($value)) {
if (null === $value) {
return [];
}
if (strlen($value) === 0) {
if (0 === strlen($value)) {
return [];
}
@@ -144,7 +141,7 @@ class ImportJob extends Model
*/
public function getExtendedStatusAttribute($value)
{
if (strlen($value) === 0) {
if (0 === strlen($value)) {
return [];
}

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;
@@ -28,14 +27,12 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
/**
* Class LimitRepetition
* Class LimitRepetition.
*
* @deprecated
* @package FireflyIII\Models
*/
class LimitRepetition extends Model
{
/**
* The attributes that should be casted to native types.
*
@@ -62,10 +59,8 @@ class LimitRepetition extends Model
}
/**
*
* @param Builder $query
* @param Carbon $date
*
*/
public function scopeAfter(Builder $query, Carbon $date)
{
@@ -73,10 +68,8 @@ class LimitRepetition extends Model
}
/**
*
* @param Builder $query
* @param Carbon $date
*
*/
public function scopeBefore(Builder $query, Carbon $date)
{

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;
@@ -29,8 +28,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* @property int $journalCount
* Class LinkType
*
* @package FireflyIII\Models
*/
class LinkType extends Model
{
@@ -54,13 +51,14 @@ class LinkType extends Model
* @param $value
*
* @return mixed
*
* @throws NotFoundHttpException
*/
public static function routeBinder($value)
{
if (auth()->check()) {
$model = self::where('id', $value)->first();
if (!is_null($model)) {
if (null !== $model) {
return $model;
}
}

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;
@@ -27,9 +26,7 @@ use Illuminate\Database\Eloquent\Model;
use League\CommonMark\CommonMarkConverter;
/**
* Class Note
*
* @package FireflyIII\Models
* Class Note.
*/
class Note extends Model
{
@@ -59,7 +56,7 @@ class Note extends Model
/**
* Get all of the owning noteable models. Currently piggy bank and
* transaction journal
* transaction journal.
*/
public function noteable()
{

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;
@@ -32,9 +31,7 @@ use Steam;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class PiggyBank
*
* @package FireflyIII\Models
* Class PiggyBank.
*/
class PiggyBank extends Model
{
@@ -68,7 +65,7 @@ class PiggyBank extends Model
*
* @return PiggyBank
*/
public static function routeBinder(PiggyBank $value)
public static function routeBinder(self $value)
{
if (auth()->check()) {
if (intval($value->account->user_id) === auth()->user()->id) {
@@ -87,19 +84,19 @@ class PiggyBank extends Model
}
/**
* Grabs the PiggyBankRepetition that's currently relevant / active
* Grabs the PiggyBankRepetition that's currently relevant / active.
*
* @returns PiggyBankRepetition
*/
public function currentRelevantRep(): PiggyBankRepetition
{
if (!is_null($this->currentRep)) {
if (null !== $this->currentRep) {
return $this->currentRep;
}
// repeating piggy banks are no longer supported.
/** @var PiggyBankRepetition $rep */
$rep = $this->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']);
if (is_null($rep)) {
if (null === $rep) {
return new PiggyBankRepetition();
}
$this->currentRep = $rep;
@@ -108,7 +105,6 @@ class PiggyBank extends Model
}
/**
*
* @param $value
*
* @return string
@@ -134,12 +130,12 @@ class PiggyBank extends Model
$remainingAmount = bcsub($this->targetamount, $this->currentRelevantRep()->currentamount);
// more than 1 month to go and still need money to save:
if ($diffInMonths > 0 && bccomp($remainingAmount, '0') === 1) {
if ($diffInMonths > 0 && 1 === bccomp($remainingAmount, '0')) {
$savePerMonth = bcdiv($remainingAmount, strval($diffInMonths));
}
// less than 1 month to go but still need money to save:
if ($diffInMonths === 0 && bccomp($remainingAmount, '0') === 1) {
if (0 === $diffInMonths && 1 === bccomp($remainingAmount, '0')) {
$savePerMonth = $remainingAmount;
}
}
@@ -148,7 +144,6 @@ class PiggyBank extends Model
}
/**
*
* @param Carbon $date
*
* @return string
@@ -156,7 +151,7 @@ class PiggyBank extends Model
public function leftOnAccount(Carbon $date): string
{
$balance = Steam::balanceIgnoreVirtual($this->account, $date);
/** @var PiggyBank $p */
// @var PiggyBank $p
foreach ($this->account->piggyBanks as $piggyBank) {
$currentAmount = $piggyBank->currentRelevantRep()->currentamount ?? '0';
@@ -191,7 +186,6 @@ class PiggyBank extends Model
}
/**
*
* @param $value
*/
public function setNameAttribute($value)

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;
@@ -26,13 +25,10 @@ namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Class PiggyBankEvent
*
* @package FireflyIII\Models
* Class PiggyBankEvent.
*/
class PiggyBankEvent extends Model
{
/**
* The attributes that should be casted to native types.
*

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;
@@ -28,13 +27,10 @@ use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model;
/**
* Class PiggyBankRepetition
*
* @package FireflyIII\Models
* Class PiggyBankRepetition.
*/
class PiggyBankRepetition extends Model
{
/**
* The attributes that should be casted to native types.
*

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;
@@ -31,13 +30,10 @@ use Illuminate\Database\Eloquent\Model;
use Log;
/**
* Class Preference
*
* @package FireflyIII\Models
* Class Preference.
*/
class Preference extends Model
{
/**
* The attributes that should be casted to native types.
*
@@ -56,6 +52,7 @@ class Preference extends Model
* @param $value
*
* @return mixed
*
* @throws FireflyException
*/
public function getDataAttribute($value)
@@ -74,7 +71,7 @@ class Preference extends Model
} catch (Exception $e) {
// don't care, assume is false.
}
if (!($unserialized === false)) {
if (!(false === $unserialized)) {
return $unserialized;
}

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;
@@ -27,9 +26,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
/**
* Class Role
*
* @package FireflyIII\Models
* Class Role.
*/
class Role extends Model
{
@@ -44,7 +41,6 @@ class Role extends Model
'updated_at' => 'datetime',
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/

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;
@@ -28,9 +27,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class Rule
*
* @package FireflyIII\Models
* Class Rule.
*/
class Rule extends Model
{
@@ -56,7 +53,7 @@ class Rule extends Model
*
* @return Rule
*/
public static function routeBinder(Rule $value)
public static function routeBinder(self $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {

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;
@@ -26,9 +25,7 @@ namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Class RuleAction
*
* @package FireflyIII\Models
* Class RuleAction.
*/
class RuleAction extends Model
{

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;
@@ -28,9 +27,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class RuleGroup
*
* @package FireflyIII\Models
* Class RuleGroup.
*/
class RuleGroup extends Model
{
@@ -56,7 +53,7 @@ class RuleGroup extends Model
*
* @return RuleGroup
*/
public static function routeBinder(RuleGroup $value)
public static function routeBinder(self $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {

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;
@@ -26,9 +25,7 @@ namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
/**
* Class RuleTrigger
*
* @package FireflyIII\Models
* Class RuleTrigger.
*/
class RuleTrigger extends Model
{

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;
@@ -30,9 +29,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Watson\Validating\ValidatingTrait;
/**
* Class Tag
*
* @package FireflyIII\Models
* Class Tag.
*/
class Tag extends Model
{
@@ -50,15 +47,13 @@ class Tag extends Model
'deleted_at' => 'datetime',
'date' => 'date',
'zoomLevel' => 'int',
];
/** @var array */
protected $dates = ['date'];
/** @var array */
protected $fillable = ['user_id', 'tag', 'date', 'description', 'longitude', 'latitude', 'zoomLevel', 'tagMode'];
/** @var array */
protected $rules = ['tag' => 'required|between:1,200',];
protected $rules = ['tag' => 'required|between:1,200'];
/**
* @param array $fields
@@ -96,7 +91,7 @@ class Tag extends Model
*
* @return Tag
*/
public static function routeBinder(Tag $value)
public static function routeBinder(self $value)
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {
@@ -111,7 +106,7 @@ class Tag extends Model
*
* @return string
*/
public static function tagSum(Tag $tag): string
public static function tagSum(self $tag): string
{
$sum = '0';
/** @var TransactionJournal $journal */
@@ -123,14 +118,13 @@ class Tag extends Model
}
/**
*
* @param $value
*
* @return string
*/
public function getDescriptionAttribute($value)
{
if (is_null($value)) {
if (null === $value) {
return $value;
}
@@ -138,14 +132,13 @@ class Tag extends Model
}
/**
*
* @param $value
*
* @return string
*/
public function getTagAttribute($value)
{
if (is_null($value)) {
if (null === $value) {
return null;
}
@@ -155,7 +148,7 @@ class Tag extends Model
/**
* Save the model to the database.
*
* @param array $options
* @param array $options
*
* @return bool
*/
@@ -171,7 +164,6 @@ class Tag extends Model
}
/**
*
* @param $value
*/
public function setDescriptionAttribute($value)
@@ -180,7 +172,6 @@ class Tag extends Model
}
/**
*
* @param $value
*/
public function setTagAttribute($value)

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;
@@ -30,53 +29,43 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Watson\Validating\ValidatingTrait;
/**
* Class Transaction
* Class Transaction.
*
* @property-read int $journal_id
* @property Carbon $date
* @property-read string $transaction_description
* @property string $transaction_amount
* @property string $transaction_foreign_amount
* @property string $transaction_type_type
* @property string $foreign_currency_symbol
* @property int $foreign_currency_dp
*
* @property int $account_id
* @property string $account_name
* @property string $account_iban
* @property string $account_number
* @property string $account_bic
* @property string $account_currency_code
*
* @property int $opposing_account_id
* @property string $opposing_account_name
* @property string $opposing_account_iban
* @property string $opposing_account_number
* @property string $opposing_account_bic
* @property string $opposing_currency_code
*
*
* @property int $transaction_budget_id
* @property string $transaction_budget_name
* @property int $transaction_journal_budget_id
* @property string $transaction_journal_budget_name
*
* @property-read int $transaction_category_id
* @property-read string $transaction_category_name
* @property-read int $transaction_journal_category_id
* @property-read string $transaction_journal_category_name
*
* @property-read int $bill_id
* @property string $bill_name
*
* @property string $notes
* @property string $tags
*
* @property string $transaction_currency_symbol
* @property int $transaction_currency_dp
* @property string $transaction_currency_code
*
* @package FireflyIII\Models
* @property int $journal_id
* @property Carbon $date
* @property string $transaction_description
* @property string $transaction_amount
* @property string $transaction_foreign_amount
* @property string $transaction_type_type
* @property string $foreign_currency_symbol
* @property int $foreign_currency_dp
* @property int $account_id
* @property string $account_name
* @property string $account_iban
* @property string $account_number
* @property string $account_bic
* @property string $account_currency_code
* @property int $opposing_account_id
* @property string $opposing_account_name
* @property string $opposing_account_iban
* @property string $opposing_account_number
* @property string $opposing_account_bic
* @property string $opposing_currency_code
* @property int $transaction_budget_id
* @property string $transaction_budget_name
* @property int $transaction_journal_budget_id
* @property string $transaction_journal_budget_name
* @property int $transaction_category_id
* @property string $transaction_category_name
* @property int $transaction_journal_category_id
* @property string $transaction_journal_category_name
* @property int $bill_id
* @property string $bill_name
* @property string $notes
* @property string $tags
* @property string $transaction_currency_symbol
* @property int $transaction_currency_dp
* @property string $transaction_currency_code
*/
class Transaction extends Model
{
@@ -97,7 +86,7 @@ class Transaction extends Model
];
protected $fillable
= ['account_id', 'transaction_journal_id', 'description', 'amount', 'identifier', 'transaction_currency_id', 'foreign_currency_id',
'foreign_amount'];
'foreign_amount',];
protected $hidden = ['encrypted'];
protected $rules
= [
@@ -117,7 +106,7 @@ class Transaction extends Model
public static function isJoined(Builder $query, string $table): bool
{
$joins = $query->getQuery()->joins;
if (is_null($joins)) {
if (null === $joins) {
return false;
}
foreach ($joins as $join) {
@@ -174,7 +163,6 @@ class Transaction extends Model
}
/**
*
* @param Builder $query
* @param Carbon $date
*/
@@ -187,10 +175,8 @@ class Transaction extends Model
}
/**
*
* @param Builder $query
* @param Carbon $date
*
*/
public function scopeBefore(Builder $query, Carbon $date)
{
@@ -201,7 +187,6 @@ class Transaction extends Model
}
/**
*
* @param Builder $query
* @param array $types
*/

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;
@@ -28,9 +27,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class TransactionCurrency
*
* @package FireflyIII\Models
* Class TransactionCurrency.
*/
class TransactionCurrency extends Model
{
@@ -58,7 +55,7 @@ class TransactionCurrency extends Model
*
* @return TransactionCurrency
*/
public static function routeBinder(TransactionCurrency $currency)
public static function routeBinder(self $currency)
{
if (auth()->check()) {
return $currency;

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;
@@ -38,9 +37,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Watson\Validating\ValidatingTrait;
/**
* Class TransactionJournal
*
* @package FireflyIII\Models
* Class TransactionJournal.
*/
class TransactionJournal extends Model
{
@@ -71,7 +68,7 @@ class TransactionJournal extends Model
protected $fillable
= ['user_id', 'transaction_type_id', 'bill_id', 'interest_date', 'book_date', 'process_date',
'transaction_currency_id', 'description', 'completed',
'date', 'rent_date', 'encrypted', 'tag_count'];
'date', 'rent_date', 'encrypted', 'tag_count',];
/** @var array */
protected $hidden = ['encrypted'];
/** @var array */
@@ -89,6 +86,7 @@ class TransactionJournal extends Model
* @param $value
*
* @return mixed
*
* @throws NotFoundHttpException
*/
public static function routeBinder($value)
@@ -98,7 +96,7 @@ class TransactionJournal extends Model
->with('transactionType')
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);
if (!is_null($object)) {
if (null !== $object) {
return $object;
}
}
@@ -159,7 +157,6 @@ class TransactionJournal extends Model
}
/**
*
* @param $value
*
* @return string
@@ -174,7 +171,6 @@ class TransactionJournal extends Model
}
/**
*
* @param string $name
*
* @return string
@@ -193,14 +189,14 @@ class TransactionJournal extends Model
Log::debug(sprintf('Looking for journal #%d meta field "%s".', $this->id, $name));
$entry = $this->transactionJournalMeta()->where('name', $name)->first();
if (!is_null($entry)) {
if (null !== $entry) {
$value = $entry->data;
// cache:
$cache->store($value);
}
// convert to Carbon if name is _date
if (!is_null($value) && substr($name, -5) === '_date') {
if (null !== $value && '_date' === substr($name, -5)) {
$value = new Carbon($value);
// cache:
$cache->store($value);
@@ -216,7 +212,7 @@ class TransactionJournal extends Model
*/
public function hasMeta(string $name): bool
{
return !is_null($this->getMeta($name));
return null !== $this->getMeta($name);
}
/**
@@ -224,47 +220,44 @@ class TransactionJournal extends Model
*/
public function isDeposit(): bool
{
if (!is_null($this->transaction_type_type)) {
return $this->transaction_type_type === TransactionType::DEPOSIT;
if (null !== $this->transaction_type_type) {
return TransactionType::DEPOSIT === $this->transaction_type_type;
}
return $this->transactionType->isDeposit();
}
/**
*
* @return bool
*/
public function isOpeningBalance(): bool
{
if (!is_null($this->transaction_type_type)) {
return $this->transaction_type_type === TransactionType::OPENING_BALANCE;
if (null !== $this->transaction_type_type) {
return TransactionType::OPENING_BALANCE === $this->transaction_type_type;
}
return $this->transactionType->isOpeningBalance();
}
/**
*
* @return bool
*/
public function isTransfer(): bool
{
if (!is_null($this->transaction_type_type)) {
return $this->transaction_type_type === TransactionType::TRANSFER;
if (null !== $this->transaction_type_type) {
return TransactionType::TRANSFER === $this->transaction_type_type;
}
return $this->transactionType->isTransfer();
}
/**
*
* @return bool
*/
public function isWithdrawal(): bool
{
if (!is_null($this->transaction_type_type)) {
return $this->transaction_type_type === TransactionType::WITHDRAWAL;
if (null !== $this->transaction_type_type) {
return TransactionType::WITHDRAWAL === $this->transaction_type_type;
}
return $this->transactionType->isWithdrawal();
@@ -289,7 +282,7 @@ class TransactionJournal extends Model
/**
* Save the model to the database.
*
* @param array $options
* @param array $options
*
* @return bool
*/
@@ -302,7 +295,6 @@ class TransactionJournal extends Model
}
/**
*
* @param EloquentBuilder $query
* @param Carbon $date
*
@@ -314,7 +306,6 @@ class TransactionJournal extends Model
}
/**
*
* @param EloquentBuilder $query
* @param Carbon $date
*
@@ -336,7 +327,6 @@ class TransactionJournal extends Model
}
/**
*
* @param EloquentBuilder $query
* @param array $types
*/
@@ -351,7 +341,6 @@ class TransactionJournal extends Model
}
/**
*
* @param $value
*/
public function setDescriptionAttribute($value)
@@ -369,12 +358,12 @@ class TransactionJournal extends Model
*/
public function setMeta(string $name, $value): TransactionJournalMeta
{
if (is_null($value)) {
if (null === $value) {
$this->deleteMeta($name);
return new TransactionJournalMeta();
}
if (is_string($value) && strlen($value) === 0) {
if (is_string($value) && 0 === strlen($value)) {
return new TransactionJournalMeta();
}
@@ -384,7 +373,7 @@ class TransactionJournal extends Model
Log::debug(sprintf('Going to set "%s" with value "%s"', $name, json_encode($value)));
$entry = $this->transactionJournalMeta()->where('name', $name)->first();
if (is_null($entry)) {
if (null === $entry) {
$entry = new TransactionJournalMeta();
$entry->transactionJournal()->associate($this);
$entry->name = $name;

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;
@@ -29,9 +28,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class TransactionJournalLink
*
* @package FireflyIII\Models
* Class TransactionJournalLink.
*/
class TransactionJournalLink extends Model
{
@@ -41,6 +38,7 @@ class TransactionJournalLink extends Model
* @param $value
*
* @return mixed
*
* @throws NotFoundHttpException
*/
public static function routeBinder($value)
@@ -52,7 +50,7 @@ class TransactionJournalLink extends Model
->where('t_a.user_id', auth()->user()->id)
->where('t_b.user_id', auth()->user()->id)
->first(['journal_links.*']);
if (!is_null($model)) {
if (null !== $model) {
return $model;
}
}
@@ -74,7 +72,7 @@ class TransactionJournalLink extends Model
*/
public function getCommentAttribute($value): ?string
{
if (!is_null($value)) {
if (null !== $value) {
return Crypt::decrypt($value);
}
@@ -90,12 +88,11 @@ class TransactionJournalLink extends Model
}
/**
*
* @param $value
*/
public function setCommentAttribute($value): void
{
if (!is_null($value) && strlen($value) > 0) {
if (null !== $value && strlen($value) > 0) {
$this->attributes['comment'] = Crypt::encrypt($value);
return;

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;
@@ -28,9 +27,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class TransactionJournalMeta
*
* @package FireflyIII\Models
* Class TransactionJournalMeta.
*/
class TransactionJournalMeta extends Model
{
@@ -72,7 +69,6 @@ class TransactionJournalMeta extends Model
}
/**
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function transactionJournal(): BelongsTo

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;
@@ -28,9 +27,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class TransactionType
*
* @package FireflyIII\Models
* Class TransactionType.
*/
class TransactionType extends Model
{
@@ -64,19 +61,18 @@ class TransactionType extends Model
throw new NotFoundHttpException;
}
$transactionType = self::where('type', ucfirst($type))->first();
if (!is_null($transactionType)) {
if (null !== $transactionType) {
return $transactionType;
}
throw new NotFoundHttpException;
}
/**
* @return bool
*/
public function isDeposit()
{
return $this->type === self::DEPOSIT;
return self::DEPOSIT === $this->type;
}
/**
@@ -84,7 +80,7 @@ class TransactionType extends Model
*/
public function isOpeningBalance()
{
return $this->type === self::OPENING_BALANCE;
return self::OPENING_BALANCE === $this->type;
}
/**
@@ -92,7 +88,7 @@ class TransactionType extends Model
*/
public function isTransfer()
{
return $this->type === self::TRANSFER;
return self::TRANSFER === $this->type;
}
/**
@@ -100,11 +96,10 @@ class TransactionType extends Model
*/
public function isWithdrawal()
{
return $this->type === self::WITHDRAWAL;
return self::WITHDRAWAL === $this->type;
}
/**
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function transactionJournals()