Some code cleanup. Fixes the tests.

This commit is contained in:
James Cole 2016-04-25 18:43:09 +02:00
parent 53c80aaef8
commit eb5e55a272
32 changed files with 64 additions and 54 deletions

View File

@ -9,9 +9,9 @@
namespace FireflyIII\Bootstrap; namespace FireflyIII\Bootstrap;
use Illuminate\Log\Writer;
use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Bootstrap\ConfigureLogging as IlluminateConfigureLogging; use Illuminate\Foundation\Bootstrap\ConfigureLogging as IlluminateConfigureLogging;
use Illuminate\Log\Writer;
/** /**
* Class ConfigureLogging * Class ConfigureLogging
@ -26,7 +26,7 @@ class ConfigureLogging extends IlluminateConfigureLogging
*/ */
protected function configureSingleHandler(Application $app, Writer $log) protected function configureSingleHandler(Application $app, Writer $log)
{ {
$log->useFiles($app->storagePath().'/logs/firefly-iii.log'); $log->useFiles($app->storagePath() . '/logs/firefly-iii.log');
} }
/** /**
@ -36,7 +36,7 @@ class ConfigureLogging extends IlluminateConfigureLogging
protected function configureDailyHandler(Application $app, Writer $log) protected function configureDailyHandler(Application $app, Writer $log)
{ {
$log->useDailyFiles( $log->useDailyFiles(
$app->storagePath().'/logs/firefly-iii.log', $app->storagePath() . '/logs/firefly-iii.log',
$app->make('config')->get('app.log_max_files', 5) $app->make('config')->get('app.log_max_files', 5)
); );
} }

View File

@ -70,6 +70,7 @@ class AttachmentCollector extends BasicCollector implements CollectorInterface
$this->exportDisk->put($file, $this->explanationString); $this->exportDisk->put($file, $this->explanationString);
Log::debug('Also put explanation file "' . $file . '" in the zip.'); Log::debug('Also put explanation file "' . $file . '" in the zip.');
$this->getFiles()->push($file); $this->getFiles()->push($file);
return true; return true;
} }

View File

@ -58,6 +58,7 @@ class UploadCollector extends BasicCollector implements CollectorInterface
foreach ($files as $entry) { foreach ($files as $entry) {
$this->processOldUpload($entry); $this->processOldUpload($entry);
} }
return true; return true;
} }

View File

@ -72,6 +72,7 @@ class CsvExporter extends BasicExporter implements ExporterInterface
} }
$writer->insertAll($rows); $writer->insertAll($rows);
return true; return true;
} }

View File

@ -81,6 +81,7 @@ class Processor
$attachmentCollector = app('FireflyIII\Export\Collector\AttachmentCollector', [$this->job]); $attachmentCollector = app('FireflyIII\Export\Collector\AttachmentCollector', [$this->job]);
$attachmentCollector->run(); $attachmentCollector->run();
$this->files = $this->files->merge($attachmentCollector->getFiles()); $this->files = $this->files->merge($attachmentCollector->getFiles());
return true; return true;
} }
@ -89,7 +90,7 @@ class Processor
*/ */
public function collectJournals(): bool public function collectJournals(): bool
{ {
$args = [$this->accounts, Auth::user(), $this->settings['startDate'], $this->settings['endDate']]; $args = [$this->accounts, Auth::user(), $this->settings['startDate'], $this->settings['endDate']];
/** @var JournalCollector $journalCollector */ /** @var JournalCollector $journalCollector */
$journalCollector = app('FireflyIII\Repositories\Journal\JournalCollector', $args); $journalCollector = app('FireflyIII\Repositories\Journal\JournalCollector', $args);
$this->journals = $journalCollector->collect(); $this->journals = $journalCollector->collect();
@ -100,6 +101,7 @@ class Processor
$this->settings['endDate']->format('Y-m-d') $this->settings['endDate']->format('Y-m-d')
. ').' . ').'
); );
return true; return true;
} }
@ -112,6 +114,7 @@ class Processor
$uploadCollector->run(); $uploadCollector->run();
$this->files = $this->files->merge($uploadCollector->getFiles()); $this->files = $this->files->merge($uploadCollector->getFiles());
return true; return true;
} }
@ -127,6 +130,7 @@ class Processor
$count++; $count++;
} }
Log::debug('Converted ' . $count . ' journals to "Entry" objects.'); Log::debug('Converted ' . $count . ' journals to "Entry" objects.');
return true; return true;
} }
@ -137,6 +141,7 @@ class Processor
{ {
$this->configurationMaker = app('FireflyIII\Export\ConfigurationFile', [$this->job]); $this->configurationMaker = app('FireflyIII\Export\ConfigurationFile', [$this->job]);
$this->files->push($this->configurationMaker->make()); $this->files->push($this->configurationMaker->make());
return true; return true;
} }
@ -173,6 +178,7 @@ class Processor
$disk->delete($file); $disk->delete($file);
} }
Log::debug('Done!'); Log::debug('Done!');
return true; return true;
} }
@ -188,6 +194,7 @@ class Processor
$exporter->run(); $exporter->run();
$this->files->push($exporter->getFileName()); $this->files->push($exporter->getFileName());
Log::debug('Added "' . $exporter->getFileName() . '" to the list of files to include in the zip.'); Log::debug('Added "' . $exporter->getFileName() . '" to the list of files to include in the zip.');
return true; return true;
} }

View File

@ -60,6 +60,7 @@ class SendRegistrationMail
} catch (Swift_TransportException $e) { } catch (Swift_TransportException $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
} }
return true; return true;
} }
} }

View File

@ -47,6 +47,7 @@ class UserConfirmation
$user = $event->user; $user = $event->user;
$ipAddress = $event->ipAddress; $ipAddress = $event->ipAddress;
$this->doConfirm($user, $ipAddress); $this->doConfirm($user, $ipAddress);
return true; return true;
} }
@ -62,6 +63,7 @@ class UserConfirmation
$user = $event->user; $user = $event->user;
$ipAddress = $event->ipAddress; $ipAddress = $event->ipAddress;
$this->doConfirm($user, $ipAddress); $this->doConfirm($user, $ipAddress);
return true; return true;
} }

View File

@ -21,7 +21,7 @@ class UserEventListener
{ {
/** /**
* Handle user logout events. * Handle user logout events.
* *
* @return bool * @return bool
*/ */
public function onUserLogout(): bool public function onUserLogout(): bool

View File

@ -73,6 +73,7 @@ class Data
/** /**
* FIXME may return null * FIXME may return null
*
* @return string * @return string
*/ */
public function getCsvFileLocation(): string public function getCsvFileLocation(): string
@ -92,6 +93,7 @@ class Data
/** /**
* FIXME may return null * FIXME may return null
*
* @return string * @return string
*/ */
public function getDateFormat(): string public function getDateFormat(): string
@ -111,6 +113,7 @@ class Data
/** /**
* FIXME may return null * FIXME may return null
*
* @return string * @return string
*/ */
public function getDelimiter(): string public function getDelimiter(): string

View File

@ -95,8 +95,8 @@ class BalanceReportHelper implements BalanceReportHelperInterface
{ {
$line = new BalanceLine; $line = new BalanceLine;
$line->setBudget($budget); $line->setBudget($budget);
$line->setStartDate($budget->startdate); // returned by getBudgetsAndLimitsInRange $line->setStartDate($budget->startdate); // returned by getBudgetsAndLimitsInRange()
$line->setEndDate($budget->enddate); // returned by getBudgetsAndLimitsInRange $line->setEndDate($budget->enddate); // returned by getBudgetsAndLimitsInRange()
// loop accounts: // loop accounts:
foreach ($accounts as $account) { foreach ($accounts as $account) {

View File

@ -120,7 +120,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface
$repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); $repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$budgets = $repository->getActiveBudgets(); $budgets = $repository->getActiveBudgets();
$set = new Collection; $set = new Collection;
/** @var Budget $budget */ /** @var Budget $budget */
foreach ($budgets as $budget) { foreach ($budgets as $budget) {
$expenses = $repository->getExpensesPerDay($budget, $start, $end, $accounts); $expenses = $repository->getExpensesPerDay($budget, $start, $end, $accounts);

View File

@ -174,9 +174,9 @@ class BillController extends Controller
*/ */
public function show(BillRepositoryInterface $repository, Bill $bill) public function show(BillRepositoryInterface $repository, Bill $bill)
{ {
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page')); $page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
$pageSize = Preferences::get('transactionPageSize', 50)->data; $pageSize = Preferences::get('transactionPageSize', 50)->data;
$journals = $repository->getJournals($bill, $page, $pageSize); $journals = $repository->getJournals($bill, $page, $pageSize);
$journals->setPath('/bills/show/' . $bill->id); $journals->setPath('/bills/show/' . $bill->id);
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill); $bill->nextExpectedMatch = $repository->nextExpectedMatch($bill);
$hideBill = true; $hideBill = true;

View File

@ -149,7 +149,6 @@ class BudgetController extends Controller
$budgeted = '0'; $budgeted = '0';
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$repeatFreq = Config::get('firefly.range_to_repeat_freq.' . $range); $repeatFreq = Config::get('firefly.range_to_repeat_freq.' . $range);
/** @var Carbon $date */
/** @var Carbon $start */ /** @var Carbon $start */
$start = session('start', new Carbon); $start = session('start', new Carbon);
/** @var Carbon $end */ /** @var Carbon $end */

View File

@ -7,7 +7,6 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
use Response; use Response;

View File

@ -100,9 +100,9 @@ class ReportController extends Controller
break; break;
case ($role === BalanceLine::ROLE_DIFFROLE): case ($role === BalanceLine::ROLE_DIFFROLE):
// journals no budget, not corrected by a tag. // journals no budget, not corrected by a tag.
$journals = $budgetRepository->getAllWithoutBudget($account, $attributes['accounts'], $attributes['startDate'], $attributes['endDate']); $journals = $budgetRepository->getAllWithoutBudget($account, $attributes['accounts'], $attributes['startDate'], $attributes['endDate']);
$budget->name = strval(trans('firefly.leftUnbalanced')); $budget->name = strval(trans('firefly.leftUnbalanced'));
$journals = $journals->filter( $journals = $journals->filter(
function (TransactionJournal $journal) { function (TransactionJournal $journal) {
$tags = $journal->tags()->where('tagMode', 'balancingAct')->count(); $tags = $journal->tags()->where('tagMode', 'balancingAct')->count();
if ($tags === 0) { if ($tags === 0) {

View File

@ -138,7 +138,7 @@ class PreferencesController extends Controller
// save page size: // save page size:
$transactionPageSize = intval(Input::get('transactionPageSize')); $transactionPageSize = intval(Input::get('transactionPageSize'));
if($transactionPageSize > 0 && $transactionPageSize < 1337) { if ($transactionPageSize > 0 && $transactionPageSize < 1337) {
Preferences::set('transactionPageSize', $transactionPageSize); Preferences::set('transactionPageSize', $transactionPageSize);
} else { } else {
Preferences::set('transactionPageSize', 50); Preferences::set('transactionPageSize', 50);

View File

@ -36,15 +36,16 @@ class Kernel extends HttpKernel
* *
* @var array * @var array
*/ */
protected $bootstrappers = [ protected $bootstrappers
'Illuminate\Foundation\Bootstrap\DetectEnvironment', = [
'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\DetectEnvironment',
'FireflyIII\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\LoadConfiguration',
'Illuminate\Foundation\Bootstrap\HandleExceptions', 'FireflyIII\Bootstrap\ConfigureLogging',
'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\HandleExceptions',
'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\RegisterFacades',
'Illuminate\Foundation\Bootstrap\BootProviders', 'Illuminate\Foundation\Bootstrap\RegisterProviders',
]; 'Illuminate\Foundation\Bootstrap\BootProviders',
];
/** /**
* The application's global HTTP middleware stack. * The application's global HTTP middleware stack.
@ -144,7 +145,7 @@ class Kernel extends HttpKernel
// MUST be confirmed. // MUST be confirmed.
// MUST have owner role // MUST have owner role
// (this group includes the other Firefly middleware) // (this group includes the other Firefly middleware)
'admin' => [ 'admin' => [
EncryptCookies::class, EncryptCookies::class,
AddQueuedCookiesToResponse::class, AddQueuedCookiesToResponse::class,
StartSession::class, StartSession::class,

View File

@ -31,14 +31,14 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournalMeta whereName($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournalMeta whereName($value)
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournalMeta whereData($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournalMeta whereData($value)
* @mixin \Eloquent * @mixin \Eloquent
* @property string $hash * @property string $hash
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournalMeta whereHash($value) * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournalMeta whereHash($value)
*/ */
class TransactionJournalMeta extends Model class TransactionJournalMeta extends Model
{ {
protected $dates = ['created_at', 'updated_at']; protected $dates = ['created_at', 'updated_at'];
protected $fillable = ['transaction_journal_id', 'name', 'data','hash']; protected $fillable = ['transaction_journal_id', 'name', 'data', 'hash'];
protected $table = 'journal_meta'; protected $table = 'journal_meta';
/** /**

View File

@ -3,9 +3,10 @@ declare(strict_types = 1);
namespace FireflyIII\Providers; namespace FireflyIII\Providers;
use Config;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Log; use Log;
use Config;
/** /**
* Class AppServiceProvider * Class AppServiceProvider
* *

View File

@ -81,7 +81,7 @@ class FireflyServiceProvider extends ServiceProvider
} }
); );
$this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository'); $this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository');
$this->app->bind('FireflyIII\Support\Search\SearchInterface', 'FireflyIII\Support\Search\Search'); $this->app->bind('FireflyIII\Support\Search\SearchInterface', 'FireflyIII\Support\Search\Search');
$this->app->bind('FireflyIII\Repositories\User\UserRepositoryInterface', 'FireflyIII\Repositories\User\UserRepository'); $this->app->bind('FireflyIII\Repositories\User\UserRepositoryInterface', 'FireflyIII\Repositories\User\UserRepository');

View File

@ -124,7 +124,8 @@ interface AccountRepositoryInterface
/** /**
* @param Account $account * @param Account $account
* @param int $page * @param int $page
* @param int $pageSize * @param int $pageSize
*
* @return LengthAwarePaginator * @return LengthAwarePaginator
*/ */
public function getJournals(Account $account, int $page, int $pageSize = 50): LengthAwarePaginator; public function getJournals(Account $account, int $page, int $pageSize = 50): LengthAwarePaginator;

View File

@ -327,6 +327,7 @@ class BillRepository implements BillRepositoryInterface
/** /**
* Get all journals that were recorded on this bill between these dates. * Get all journals that were recorded on this bill between these dates.
*
* @param Bill $bill * @param Bill $bill
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end

View File

@ -83,7 +83,7 @@ class ExportJobRepository implements ExportJobRepositoryInterface
/** /**
* *
* FIXME this may return null * FIXME this may return null
* *
* @param string $key * @param string $key
* *
* @return ExportJob|null * @return ExportJob|null

View File

@ -119,6 +119,7 @@ class RuleRepository implements RuleRepositoryInterface
$rule->order = ($rule->order + 1); $rule->order = ($rule->order + 1);
$rule->save(); $rule->save();
$this->resetRulesInGroupOrder($rule->ruleGroup); $this->resetRulesInGroupOrder($rule->ruleGroup);
return true; return true;
} }
@ -141,6 +142,7 @@ class RuleRepository implements RuleRepositoryInterface
$rule->order = ($rule->order - 1); $rule->order = ($rule->order - 1);
$rule->save(); $rule->save();
$this->resetRulesInGroupOrder($rule->ruleGroup); $this->resetRulesInGroupOrder($rule->ruleGroup);
return true; return true;
} }
@ -342,6 +344,7 @@ class RuleRepository implements RuleRepositoryInterface
$this->storeAction($rule, $actionValues); $this->storeAction($rule, $actionValues);
} }
return true; return true;
} }
@ -349,6 +352,7 @@ class RuleRepository implements RuleRepositoryInterface
/** /**
* @param Rule $rule * @param Rule $rule
* @param array $data * @param array $data
*
* @return bool * @return bool
*/ */
private function storeTriggers(Rule $rule, array $data): bool private function storeTriggers(Rule $rule, array $data): bool
@ -378,6 +382,7 @@ class RuleRepository implements RuleRepositoryInterface
$this->storeTrigger($rule, $triggerValues); $this->storeTrigger($rule, $triggerValues);
$order++; $order++;
} }
return true; return true;
} }
} }

View File

@ -133,6 +133,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
$ruleGroup->order = ($ruleGroup->order + 1); $ruleGroup->order = ($ruleGroup->order + 1);
$ruleGroup->save(); $ruleGroup->save();
$this->resetRuleGroupOrder(); $this->resetRuleGroupOrder();
return true; return true;
} }
@ -155,6 +156,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
$ruleGroup->order = ($ruleGroup->order - 1); $ruleGroup->order = ($ruleGroup->order - 1);
$ruleGroup->save(); $ruleGroup->save();
$this->resetRuleGroupOrder(); $this->resetRuleGroupOrder();
return true; return true;
} }

View File

@ -6,7 +6,6 @@ namespace FireflyIII\Repositories\Tag;
use Carbon\Carbon; use Carbon\Carbon;
use DB; use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;

View File

@ -4,7 +4,6 @@ declare(strict_types = 1);
namespace FireflyIII\Repositories\Tag; namespace FireflyIII\Repositories\Tag;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;

View File

@ -286,7 +286,7 @@ class ExpandedForm
return $html; return $html;
} }
/** /**
* @param $name * @param $name

View File

@ -111,9 +111,10 @@ class Preferences
$user = Auth::user(); $user = Auth::user();
if (is_null($user)) { if (is_null($user)) {
// make new preference, return it: // make new preference, return it:
$pref = new Preference; $pref = new Preference;
$pref->name = $name; $pref->name = $name;
$pref->data = $value; $pref->data = $value;
return $pref; return $pref;
} }

View File

@ -19,9 +19,9 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
* @property string $password * @property string $password
* @property string $remember_token * @property string $remember_token
* @property string $reset * @property string $reset
* @property bool $activated * @property bool $activated
* @property bool $isAdmin * @property bool $isAdmin
* @property bool $has2FA * @property bool $has2FA
* @property boolean $blocked * @property boolean $blocked
* @property string $blocked_code * @property string $blocked_code
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Account[] $accounts * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Account[] $accounts

View File

@ -63,6 +63,7 @@ return [
'1M' => 'monthly', '1M' => 'monthly',
'3M' => 'quarterly', '3M' => 'quarterly',
'6M' => 'half-year', '6M' => 'half-year',
'1Y' => 'yearly',
'custom' => 'monthly', 'custom' => 'monthly',
], ],
'subTitlesByIdentifier' => 'subTitlesByIdentifier' =>

View File

@ -74,19 +74,4 @@ class ChartBudgetControllerTest extends TestCase
$this->assertResponseStatus(200); $this->assertResponseStatus(200);
} }
/**
* @covers FireflyIII\Http\Controllers\Chart\BudgetController::year
*/
public function testYear()
{
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
$repository->shouldReceive('getBudgetsAndExpensesPerMonth')->once()->andReturn([]);
$repository->shouldReceive('getWithoutBudgetSum')->times(12)->andReturn('0');
$this->be($this->user());
$this->call('GET', '/chart/budget/year/default/20150101/20151231/1');
$this->assertResponseStatus(200);
}
} }