A set of small fixes, courtesy of scrutinizer-ci

This commit is contained in:
James Cole
2016-01-27 19:35:00 +01:00
parent 9155c13e08
commit 28fdad9426
12 changed files with 69 additions and 51 deletions

View File

@@ -42,8 +42,11 @@ class Account extends Model
{
use SoftDeletes, ValidatingTrait;
/** @var array */
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
/** @var array */
protected $fillable = ['user_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban'];
/** @var array */
protected $hidden = ['virtual_balance_encrypted', 'encrypted'];
protected $rules
= [
@@ -52,6 +55,8 @@ class Account extends Model
'name' => 'required',
'active' => 'required|boolean',
];
/** @var bool */
private $joinedAccountTypes;
/**
* @param array $fields

View File

@@ -26,6 +26,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property string $dateFormatted
* @property string $budgeted
* @property float $amount
* @property Carbon $date
*/
class Budget extends Model
{

View File

@@ -23,6 +23,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property-read User $user
* @property string $dateFormatted
* @property float $spent
* @property Carbon $lastActivity
*/
class Category extends Model
{

View File

@@ -27,11 +27,12 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property integer $zoomLevel
* @property-read Collection|TransactionJournal[] $transactionjournals
* @property-read User $user
* @property int $account_id
*/
class Tag extends Model
{
protected $fillable = ['user_id', 'tag', 'date', 'description', 'longitude', 'latitude', 'zoomLevel', 'tagMode'];
protected $dates = ['created_at', 'updated_at', 'date'];
protected $fillable = ['user_id', 'tag', 'date', 'description', 'longitude', 'latitude', 'zoomLevel', 'tagMode'];
/**
* @param array $fields
@@ -66,30 +67,18 @@ class Tag extends Model
}
/**
* Save the model to the database.
* @param Tag $value
*
* @param array $options
*
* @return bool
* @return Tag
*/
public function save(array $options = [])
public static function routeBinder(Tag $value)
{
foreach ($this->transactionjournals()->get() as $journal) {
$count = $journal->tags()->count();
$journal->tag_count = $count;
$journal->save();
if (Auth::check()) {
if ($value->user_id == Auth::user()->id) {
return $value;
}
}
return parent::save($options);
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function transactionjournals()
{
return $this->belongsToMany('FireflyIII\Models\TransactionJournal');
throw new NotFoundHttpException;
}
/**
@@ -120,6 +109,24 @@ class Tag extends Model
return Crypt::decrypt($value);
}
/**
* Save the model to the database.
*
* @param array $options
*
* @return bool
*/
public function save(array $options = [])
{
foreach ($this->transactionjournals()->get() as $journal) {
$count = $journal->tags()->count();
$journal->tag_count = $count;
$journal->save();
}
return parent::save($options);
}
/**
* @codeCoverageIgnore
*
@@ -140,6 +147,15 @@ class Tag extends Model
$this->attributes['tag'] = Crypt::encrypt($value);
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function transactionjournals()
{
return $this->belongsToMany('FireflyIII\Models\TransactionJournal');
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
@@ -150,20 +166,4 @@ class Tag extends Model
}
/**
* @param Tag $value
*
* @return Tag
*/
public static function routeBinder(Tag $value)
{
if (Auth::check()) {
if ($value->user_id == Auth::user()->id) {
return $value;
}
}
throw new NotFoundHttpException;
}
}

View File

@@ -49,6 +49,7 @@ use Watson\Validating\ValidatingTrait;
* @property float $journalAmount
* @property int $account_id
* @property int $budget_id
* @property string $account_name
* @method static Builder|TransactionJournal accountIs($account)
* @method static Builder|TransactionJournal after($date)
* @method static Builder|TransactionJournal before($date)
@@ -61,12 +62,16 @@ class TransactionJournal extends Model
use SoftDeletes, ValidatingTrait;
protected $dates = ['created_at', 'updated_at', 'date', 'deleted_at'];
/** @var array */
protected $dates = ['created_at', 'updated_at', 'date', 'deleted_at'];
/** @var array */
protected $fillable
= ['user_id', 'transaction_type_id', 'bill_id', 'transaction_currency_id', 'description', 'completed', 'date', 'encrypted', 'tag_count'];
= ['user_id', 'transaction_type_id', 'bill_id', 'transaction_currency_id', 'description', 'completed', 'date', 'encrypted', 'tag_count'];
/** @var array */
protected $hidden = ['encrypted'];
/** @var array */
protected $rules
= [
= [
'user_id' => 'required|exists:users,id',
'transaction_type_id' => 'required|exists:transaction_types,id',
'bill_id' => 'exists:bills,id',
@@ -77,6 +82,9 @@ class TransactionJournal extends Model
'encrypted' => 'required|boolean',
];
/** @var bool */
private $joinedTransactionTypes;
/**
* @param $value
*