mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 06:01:21 +00:00
Clean up code, remove unused methods.
This commit is contained in:
@@ -37,6 +37,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property bool $active
|
||||
* @property int $user_id
|
||||
* @property-read string $email
|
||||
* @property bool encrypted
|
||||
*/
|
||||
class Budget extends Model
|
||||
{
|
||||
@@ -60,34 +61,6 @@ class Budget extends Model
|
||||
/** @var array */
|
||||
protected $hidden = ['encrypted'];
|
||||
|
||||
/**
|
||||
* @param array $fields
|
||||
*
|
||||
* @deprecated
|
||||
* @return Budget
|
||||
*/
|
||||
public static function firstOrCreateEncrypted(array $fields)
|
||||
{
|
||||
// everything but the name:
|
||||
$query = self::orderBy('id');
|
||||
$search = $fields;
|
||||
unset($search['name']);
|
||||
foreach ($search as $name => $value) {
|
||||
$query->where($name, $value);
|
||||
}
|
||||
$set = $query->get(['budgets.*']);
|
||||
/** @var Budget $budget */
|
||||
foreach ($set as $budget) {
|
||||
if ($budget->name === $fields['name']) {
|
||||
return $budget;
|
||||
}
|
||||
}
|
||||
// create it!
|
||||
$budget = self::create($fields);
|
||||
|
||||
return $budget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
@@ -98,7 +71,10 @@ class Budget extends Model
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$budgetId = (int)$value;
|
||||
$budget = auth()->user()->budgets()->find($budgetId);
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
/** @var Budget $budget */
|
||||
$budget = $user->budgets()->find($budgetId);
|
||||
if (null !== $budget) {
|
||||
return $budget;
|
||||
}
|
||||
@@ -110,7 +86,7 @@ class Budget extends Model
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function budgetlimits()
|
||||
public function budgetlimits(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(BudgetLimit::class);
|
||||
}
|
||||
@@ -123,7 +99,7 @@ class Budget extends Model
|
||||
* @return string
|
||||
* @throws \Illuminate\Contracts\Encryption\DecryptException
|
||||
*/
|
||||
public function getNameAttribute($value)
|
||||
public function getNameAttribute($value): string
|
||||
{
|
||||
if ($this->encrypted) {
|
||||
return Crypt::decrypt($value);
|
||||
@@ -139,7 +115,7 @@ class Budget extends Model
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Encryption\EncryptException
|
||||
*/
|
||||
public function setNameAttribute($value)
|
||||
public function setNameAttribute($value): void
|
||||
{
|
||||
$encrypt = config('firefly.encryption');
|
||||
$this->attributes['name'] = $encrypt ? Crypt::encrypt($value) : $value;
|
||||
@@ -150,7 +126,7 @@ class Budget extends Model
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function transactionJournals()
|
||||
public function transactionJournals(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(TransactionJournal::class, 'budget_transaction_journal', 'budget_id');
|
||||
}
|
||||
@@ -159,7 +135,7 @@ class Budget extends Model
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function transactions()
|
||||
public function transactions(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Transaction::class, 'budget_transaction', 'budget_id');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user