A set of small fixes, courtesy of scrutinizer-ci

This commit is contained in:
James Cole 2016-01-27 18:31:44 +01:00
parent e8776d44c5
commit 9155c13e08
16 changed files with 261 additions and 256 deletions

View File

@ -28,7 +28,6 @@ class UpgradeFireflyInstructions extends Command
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{

View File

@ -6,7 +6,6 @@ use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Foundation\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\HttpException;
/**
@ -26,9 +25,21 @@ class Handler extends ExceptionHandler
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
];
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
*
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
/**
* Report or log an exception.
*
@ -42,17 +53,4 @@ class Handler extends ExceptionHandler
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
*
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}

View File

@ -72,7 +72,7 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
public function frontpage(Collection $accounts, Carbon $start, Carbon $end)
{
// language:
$format = trans('config.month_and_day');
$format = (string)trans('config.month_and_day');
$data = ['count' => 0, 'labels' => [], 'datasets' => [],];
$current = clone $start;
while ($current <= $end) {

View File

@ -23,7 +23,7 @@ class ChartJsPiggyBankChartGenerator implements PiggyBankChartGenerator
{
// language:
$format = trans('config.month_and_day');
$format = (string)trans('config.month_and_day');
$data = [
'count' => 1,

View File

@ -105,7 +105,7 @@ class AttachmentHelper implements AttachmentHelperInterface
$count = Auth::user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
if ($count > 0) {
$msg = trans('validation.file_already_attached', ['name' => $name]);
$msg = (string)trans('validation.file_already_attached', ['name' => $name]);
$this->errors->add('attachments', $msg);
return true;
@ -151,7 +151,7 @@ class AttachmentHelper implements AttachmentHelperInterface
$attachment->save();
$name = e($file->getClientOriginalName()); // add message:
$msg = trans('validation.file_attached', ['name' => $name]);
$msg = (string)trans('validation.file_attached', ['name' => $name]);
$this->messages->add('attachments', $msg);
// return it.
@ -171,7 +171,7 @@ class AttachmentHelper implements AttachmentHelperInterface
$name = e($file->getClientOriginalName());
if (!in_array($mime, $this->allowedMimes)) {
$msg = trans('validation.file_invalid_mime', ['name' => $name, 'mime' => $mime]);
$msg = (string)trans('validation.file_invalid_mime', ['name' => $name, 'mime' => $mime]);
$this->errors->add('attachments', $msg);
return false;
@ -190,7 +190,7 @@ class AttachmentHelper implements AttachmentHelperInterface
$size = $file->getSize();
$name = e($file->getClientOriginalName());
if ($size > $this->maxUploadSize) {
$msg = trans('validation.file_too_large', ['name' => $name]);
$msg = (string)trans('validation.file_too_large', ['name' => $name]);
$this->errors->add('attachments', $msg);
return false;

View File

@ -73,7 +73,7 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface
if (preg_match('/ABN AMRO.{24} (.*)/', $this->data['description'], $matches)) {
Log::debug('AbnAmroSpecifix: Description is structured as costs from ABN AMRO itself.');
$this->data['opposing-account-name'] = "ABN AMRO";
$this->data['opposing-account-name'] = 'ABN AMRO';
$this->data['description'] = $matches[1];
return true;
@ -117,22 +117,24 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface
// SEPA plain descriptions contain several key-value pairs, split by a colon
preg_match_all('/([A-Za-z]+(?=:\s)):\s([A-Za-z 0-9._#-]+(?=\s))/', $this->data['description'], $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$key = $match[1];
$value = trim($match[2]);
if (is_array($matches)) {
foreach ($matches as $match) {
$key = $match[1];
$value = trim($match[2]);
switch (strtoupper($key)) {
case 'OMSCHRIJVING':
$this->data['description'] = $value;
break;
case 'NAAM':
$this->data['opposing-account-name'] = $value;
break;
case 'IBAN':
$this->data['opposing-account-iban'] = $value;
break;
default:
// Ignore the rest
switch (strtoupper($key)) {
case 'OMSCHRIJVING':
$this->data['description'] = $value;
break;
case 'NAAM':
$this->data['opposing-account-name'] = $value;
break;
case 'IBAN':
$this->data['opposing-account-iban'] = $value;
break;
default:
// Ignore the rest
}
}
}
@ -153,26 +155,24 @@ class AbnAmroDescription extends Specifix implements SpecifixInterface
if (preg_match_all('!\/([A-Z]{3,4})\/([^/]*)!', $this->data['description'], $matches, PREG_SET_ORDER)) {
Log::debug('AbnAmroSpecifix: Description is structured as TRTP format.');
foreach ($matches as $match) {
$key = $match[1];
$value = trim($match[2]);
if (is_array($matches)) {
foreach ($matches as $match) {
$key = $match[1];
$value = trim($match[2]);
switch (strtoupper($key)) {
// is not being used.
// case 'TRTP':
// $type = $value;
// break;
case 'NAME':
$this->data['opposing-account-name'] = $value;
break;
case 'REMI':
$this->data['description'] = $value;
break;
case 'IBAN':
$this->data['opposing-account-iban'] = $value;
break;
default:
// Ignore the rest
switch (strtoupper($key)) {
case 'NAME':
$this->data['opposing-account-name'] = $value;
break;
case 'REMI':
$this->data['description'] = $value;
break;
case 'IBAN':
$this->data['opposing-account-iban'] = $value;
break;
default:
// Ignore the rest
}
}
}

View File

@ -16,7 +16,7 @@ interface FiscalHelperInterface
* This method produces a clone of the Carbon date object passed, checks preferences
* and calculates the first day of the fiscal year.
*
* @param Carbon $start
* @param Carbon $date
*
* @return Carbon date object
*/
@ -30,6 +30,6 @@ interface FiscalHelperInterface
*
* @return Carbon date object
*/
public function endOfFiscalYear(Carbon $start);
public function endOfFiscalYear(Carbon $date);
}

View File

@ -91,7 +91,7 @@ class ReportHelper implements ReportHelperInterface
->groupBy('accounts.id')
->get(['accounts.id', DB::Raw('SUM(`transactions`.`amount`) as `balance`')]);
// and for end:
// and end:
$endSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->whereIn('accounts.id', $ids)

View File

@ -111,7 +111,7 @@ class AuthController extends Controller
// is user email domain blocked?
if ($this->isBlockedDomain($data['email'])) {
$validator->getMessageBag()->add('email', trans('validation.invalid_domain'));
$validator->getMessageBag()->add('email', (string)trans('validation.invalid_domain'));
$this->throwValidationException(
$request, $validator
);

View File

@ -68,7 +68,7 @@ class BudgetController extends Controller
Session::forget('budgets.create.fromStore');
Session::flash('gaEventCategory', 'budgets');
Session::flash('gaEventAction', 'create');
$subTitle = trans('firefly.create_new_budget');
$subTitle = (string)trans('firefly.create_new_budget');
return view('budgets.create', compact('subTitle'));
}

View File

@ -354,8 +354,8 @@ Breadcrumbs::register(
'reports.report', function (BreadCrumbGenerator $breadcrumbs, Carbon $start, Carbon $end, $reportType, $accountIds) {
$breadcrumbs->parent('reports.index');
$monthFormat = trans('config.month_and_day');
$title = trans('firefly.report_' . $reportType, ['start' => $start->formatLocalized($monthFormat), 'end' => $end->formatLocalized($monthFormat)]);
$monthFormat = (string)trans('config.month_and_day');
$title = (string)trans('firefly.report_' . $reportType, ['start' => $start->formatLocalized($monthFormat), 'end' => $end->formatLocalized($monthFormat)]);
$breadcrumbs->push($title, route('reports.report', [$reportType, $start->format('Ymd'), $end->format('Ymd'), $accountIds]));
}

View File

@ -1,6 +1,7 @@
<?php namespace FireflyIII\Models;
use Auth;
use Carbon\Carbon;
use Crypt;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model;
@ -34,14 +35,16 @@ use Watson\Validating\ValidatingTrait;
* @method static Builder|\FireflyIII\Models\Account hasMetaValue($name, $value)
* @property string $startBalance
* @property string $endBalance
* @property float $difference
* @property Carbon $lastActivityDate
*/
class Account extends Model
{
use SoftDeletes, ValidatingTrait;
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $fillable = ['user_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban'];
protected $hidden = ['virtual_balance_encrypted', 'encrypted'];
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $rules
= [
'user_id' => 'required|exists:users,id',
@ -109,6 +112,22 @@ class Account extends Model
return null;
}
/**
* @param Account $value
*
* @return Account
*/
public static function routeBinder(Account $value)
{
if (Auth::check()) {
if ($value->user_id == Auth::user()->id) {
return $value;
}
}
throw new NotFoundHttpException;
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
@ -284,20 +303,4 @@ class Account extends Model
{
return $this->belongsTo('FireflyIII\User');
}
/**
* @param Account $value
*
* @return Account
*/
public static function routeBinder(Account $value)
{
if (Auth::check()) {
if ($value->user_id == Auth::user()->id) {
return $value;
}
}
throw new NotFoundHttpException;
}
}

View File

@ -25,15 +25,16 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property-read User $user
* @property string $dateFormatted
* @property string $budgeted
* @property float $amount
*/
class Budget extends Model
{
use SoftDeletes;
protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'enddate'];
protected $fillable = ['user_id', 'name', 'active'];
protected $hidden = ['encrypted'];
protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'enddate'];
/**
* @param array $fields
@ -63,6 +64,21 @@ class Budget extends Model
}
/**
* @param Budget $value
*
* @return Budget
*/
public static function routeBinder(Budget $value)
{
if (Auth::check()) {
if ($value->user_id == Auth::user()->id) {
return $value;
}
}
throw new NotFoundHttpException;
}
/**
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
@ -120,20 +136,5 @@ class Budget extends Model
return $this->belongsTo('FireflyIII\User');
}
/**
* @param Budget $value
*
* @return Budget
*/
public static function routeBinder(Budget $value)
{
if (Auth::check()) {
if ($value->user_id == Auth::user()->id) {
return $value;
}
}
throw new NotFoundHttpException;
}
}

View File

@ -22,14 +22,15 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property-read Collection|TransactionJournal[] $transactionjournals
* @property-read User $user
* @property string $dateFormatted
* @property float $spent
*/
class Category extends Model
{
use SoftDeletes;
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
protected $fillable = ['user_id', 'name'];
protected $hidden = ['encrypted'];
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
/**
* @param array $fields
@ -59,6 +60,21 @@ class Category extends Model
}
/**
* @param Category $value
*
* @return Category
*/
public static function routeBinder(Category $value)
{
if (Auth::check()) {
if ($value->user_id == Auth::user()->id) {
return $value;
}
}
throw new NotFoundHttpException;
}
/**
* @codeCoverageIgnore
*
@ -105,19 +121,4 @@ class Category extends Model
return $this->belongsTo('FireflyIII\User');
}
/**
* @param Category $value
*
* @return Category
*/
public static function routeBinder(Category $value)
{
if (Auth::check()) {
if ($value->user_id == Auth::user()->id) {
return $value;
}
}
throw new NotFoundHttpException;
}
}

View File

@ -16,29 +16,13 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property Carbon $enddate
* @property float $amount
* @property-read BudgetLimit $budgetLimit
* @property int $budget_id
*/
class LimitRepetition extends Model
{
protected $hidden = ['amount_encrypted'];
protected $dates = ['created_at', 'updated_at', 'startdate', 'enddate'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function budgetLimit()
{
return $this->belongsTo('FireflyIII\Models\BudgetLimit');
}
/**
* @param $value
*/
public function setAmountAttribute($value)
{
$this->attributes['amount'] = strval(round($value, 2));
}
protected $hidden = ['amount_encrypted'];
/**
* @param $value
@ -60,4 +44,20 @@ class LimitRepetition extends Model
throw new NotFoundHttpException;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function budgetLimit()
{
return $this->belongsTo('FireflyIII\Models\BudgetLimit');
}
/**
* @param $value
*/
public function setAmountAttribute($value)
{
$this->attributes['amount'] = strval(round($value, 2));
}
}

View File

@ -46,6 +46,9 @@ use Watson\Validating\ValidatingTrait;
* @property-read TransactionType $transactionType
* @property-read Collection|TransactionGroup[] $transactiongroups
* @property-read User $user
* @property float $journalAmount
* @property int $account_id
* @property int $budget_id
* @method static Builder|TransactionJournal accountIs($account)
* @method static Builder|TransactionJournal after($date)
* @method static Builder|TransactionJournal before($date)
@ -58,10 +61,10 @@ class TransactionJournal extends Model
use SoftDeletes, ValidatingTrait;
protected $dates = ['created_at', 'updated_at', 'date', 'deleted_at'];
protected $fillable
= ['user_id', 'transaction_type_id', 'bill_id', 'transaction_currency_id', 'description', 'completed', 'date', 'encrypted', 'tag_count'];
protected $hidden = ['encrypted'];
protected $dates = ['created_at', 'updated_at', 'date', 'deleted_at'];
protected $rules
= [
'user_id' => 'required|exists:users,id',
@ -74,6 +77,36 @@ class TransactionJournal extends Model
'encrypted' => 'required|boolean',
];
/**
* @param $value
*
* @return mixed
* @throws NotFoundHttpException
*/
public static function routeBinder($value)
{
if (Auth::check()) {
$validTypes = [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER];
$object = TransactionJournal::where('transaction_journals.id', $value)
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->whereIn('transaction_types.type', $validTypes)
->where('user_id', Auth::user()->id)->first(['transaction_journals.*']);
if ($object) {
return $object;
}
}
throw new NotFoundHttpException;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function attachments()
{
return $this->morphMany('FireflyIII\Models\Attachment', 'attachable');
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
@ -101,22 +134,6 @@ class TransactionJournal extends Model
return $this->belongsToMany('FireflyIII\Models\Category');
}
/**
* @return string
*/
public function getAmountPositiveAttribute()
{
$amount = '0';
/** @var Transaction $t */
foreach ($this->transactions as $t) {
if ($t->amount > 0) {
$amount = $t->amount;
}
}
return $amount;
}
/**
* @return float
*/
@ -142,36 +159,19 @@ class TransactionJournal extends Model
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
* @return string
*/
public function tags()
public function getAmountPositiveAttribute()
{
return $this->belongsToMany('FireflyIII\Models\Tag');
}
$amount = '0';
/** @var Transaction $t */
foreach ($this->transactions as $t) {
if ($t->amount > 0) {
$amount = $t->amount;
}
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function transactions()
{
return $this->hasMany('FireflyIII\Models\Transaction');
}
/**
* Save the model to the database.
*
* @param array $options
*
* @return bool
*/
public function save(array $options = [])
{
$count = $this->tags()->count();
$this->tag_count = $count;
return parent::save($options);
return $amount;
}
/**
@ -210,6 +210,62 @@ class TransactionJournal extends Model
return $account;
}
/**
* @return string
*/
public function getTransactionType()
{
return $this->transactionType->type;
}
/**
* @return bool
*/
public function isDeposit()
{
if (!is_null($this->type)) {
return $this->type == TransactionType::DEPOSIT;
}
return $this->transactionType->isDeposit();
}
/**
* @return bool
*/
public function isOpeningBalance()
{
if (!is_null($this->type)) {
return $this->type == TransactionType::OPENING_BALANCE;
}
return $this->transactionType->isOpeningBalance();
}
/**
* @return bool
*/
public function isTransfer()
{
if (!is_null($this->type)) {
return $this->type == TransactionType::TRANSFER;
}
return $this->transactionType->isTransfer();
}
/**
* @return bool
*/
public function isWithdrawal()
{
if (!is_null($this->type)) {
return $this->type == TransactionType::WITHDRAWAL;
}
return $this->transactionType->isWithdrawal();
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
@ -219,6 +275,21 @@ class TransactionJournal extends Model
return $this->hasMany('FireflyIII\Models\PiggyBankEvent');
}
/**
* Save the model to the database.
*
* @param array $options
*
* @return bool
*/
public function save(array $options = [])
{
$count = $this->tags()->count();
$this->tag_count = $count;
return parent::save($options);
}
/**
* @codeCoverageIgnore
*
@ -290,11 +361,12 @@ class TransactionJournal extends Model
}
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function attachments()
public function tags()
{
return $this->morphMany('FireflyIII\Models\Attachment', 'attachable');
return $this->belongsToMany('FireflyIII\Models\Tag');
}
/**
@ -324,6 +396,15 @@ class TransactionJournal extends Model
return $this->belongsToMany('FireflyIII\Models\TransactionGroup');
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function transactions()
{
return $this->hasMany('FireflyIII\Models\Transaction');
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
@ -332,82 +413,4 @@ class TransactionJournal extends Model
{
return $this->belongsTo('FireflyIII\User');
}
/**
* @return string
*/
public function getTransactionType()
{
return $this->transactionType->type;
}
/**
* @return bool
*/
public function isWithdrawal()
{
if (!is_null($this->type)) {
return $this->type == TransactionType::WITHDRAWAL;
}
return $this->transactionType->isWithdrawal();
}
/**
* @return bool
*/
public function isDeposit()
{
if (!is_null($this->type)) {
return $this->type == TransactionType::DEPOSIT;
}
return $this->transactionType->isDeposit();
}
/**
* @return bool
*/
public function isTransfer()
{
if (!is_null($this->type)) {
return $this->type == TransactionType::TRANSFER;
}
return $this->transactionType->isTransfer();
}
/**
* @return bool
*/
public function isOpeningBalance()
{
if (!is_null($this->type)) {
return $this->type == TransactionType::OPENING_BALANCE;
}
return $this->transactionType->isOpeningBalance();
}
/**
* @param $value
*
* @return mixed
* @throws NotFoundHttpException
*/
public static function routeBinder($value)
{
if (Auth::check()) {
$validTypes = [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER];
$object = TransactionJournal::where('transaction_journals.id', $value)
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->whereIn('transaction_types.type', $validTypes)
->where('user_id', Auth::user()->id)->first(['transaction_journals.*']);
if ($object) {
return $object;
}
}
throw new NotFoundHttpException;
}
}