Code cleanup.

This commit is contained in:
James Cole
2021-03-28 11:46:23 +02:00
parent 2c575f3ca5
commit b5eeacc128
124 changed files with 1568 additions and 1384 deletions

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\CategoryFormRequest;
@@ -37,8 +38,8 @@ use Illuminate\View\View;
*/
class CreateController extends Controller
{
private CategoryRepositoryInterface $repository;
private AttachmentHelperInterface $attachments;
private CategoryRepositoryInterface $repository;
/**
* CategoryController constructor.
@@ -51,7 +52,7 @@ class CreateController extends Controller
$this->middleware(
function ($request, $next) {
app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('title', (string)trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->repository = app(CategoryRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
@@ -60,6 +61,7 @@ class CreateController extends Controller
}
);
}
/**
* Create category.
*
@@ -73,10 +75,11 @@ class CreateController extends Controller
$this->rememberPreviousUri('categories.create.uri');
}
$request->session()->forget('categories.create.fromStore');
$subTitle = (string) trans('firefly.create_new_category');
$subTitle = (string)trans('firefly.create_new_category');
return prefixView('categories.create', compact('subTitle'));
}
/**
* Store new category.
*
@@ -89,7 +92,7 @@ class CreateController extends Controller
$data = $request->getCategoryData();
$category = $this->repository->store($data);
$request->session()->flash('success', (string) trans('firefly.stored_category', ['name' => $category->name]));
$request->session()->flash('success', (string)trans('firefly.stored_category', ['name' => $category->name]));
app('preferences')->mark();
// store attachment(s):
@@ -98,7 +101,7 @@ class CreateController extends Controller
$this->attachments->saveAttachmentsForModel($category, $files);
}
if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
}
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@@ -106,7 +109,7 @@ class CreateController extends Controller
}
$redirect = redirect(route('categories.index'));
if (1 === (int) $request->get('create_another')) {
if (1 === (int)$request->get('create_another')) {
// @codeCoverageIgnoreStart
$request->session()->put('categories.create.fromStore', true);

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
@@ -50,7 +51,7 @@ class DeleteController extends Controller
$this->middleware(
function ($request, $next) {
app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('title', (string)trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->repository = app(CategoryRepositoryInterface::class);
@@ -68,7 +69,7 @@ class DeleteController extends Controller
*/
public function delete(Category $category)
{
$subTitle = (string) trans('firefly.delete_category', ['name' => $category->name]);
$subTitle = (string)trans('firefly.delete_category', ['name' => $category->name]);
// put previous url in session
$this->rememberPreviousUri('categories.delete.uri');
@@ -89,7 +90,7 @@ class DeleteController extends Controller
$name = $category->name;
$this->repository->destroy($category);
$request->session()->flash('success', (string) trans('firefly.deleted_category', ['name' => $name]));
$request->session()->flash('success', (string)trans('firefly.deleted_category', ['name' => $name]));
app('preferences')->mark();
return redirect($this->getPreviousUri('categories.delete.uri'));

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\CategoryFormRequest;
@@ -39,8 +40,8 @@ use Illuminate\View\View;
class EditController extends Controller
{
private CategoryRepositoryInterface $repository;
private AttachmentHelperInterface $attachments;
private CategoryRepositoryInterface $repository;
/**
* CategoryController constructor.
@@ -62,6 +63,7 @@ class EditController extends Controller
}
);
}
/**
* Edit a category.
*

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
@@ -50,7 +51,7 @@ class IndexController extends Controller
$this->middleware(
function ($request, $next) {
app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('title', (string)trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->repository = app(CategoryRepositoryInterface::class);
@@ -58,6 +59,7 @@ class IndexController extends Controller
}
);
}
/**
* Show all categories.
*
@@ -67,8 +69,8 @@ class IndexController extends Controller
*/
public function index(Request $request)
{
$page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$collection = $this->repository->getCategories();
$total = $collection->count();
$collection = $collection->slice(($page - 1) * $pageSize, $pageSize);

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Category;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Http\Controllers\Controller;
@@ -41,6 +42,7 @@ use Log;
class NoCategoryController extends Controller
{
use PeriodOverview;
/** @var JournalRepositoryInterface Journals and transactions overview */
private $journalRepos;
@@ -56,7 +58,7 @@ class NoCategoryController extends Controller
$this->middleware(
function ($request, $next) {
app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('title', (string)trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->journalRepos = app(JournalRepositoryInterface::class);
@@ -81,8 +83,8 @@ class NoCategoryController extends Controller
$start = $start ?? session('start');
/** @var Carbon $end */
$end = $end ?? session('end');
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$subTitle = trans(
'firefly.without_category_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@@ -103,6 +105,7 @@ class NoCategoryController extends Controller
return prefixView('categories.no-category', compact('groups', 'subTitle', 'periods', 'start', 'end'));
}
/**
* Show all transactions without a category.
*
@@ -116,10 +119,10 @@ class NoCategoryController extends Controller
$start = null;
$end = null;
$periods = new Collection;
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
Log::debug('Start of noCategory()');
$subTitle = (string) trans('firefly.all_journals_without_category');
$subTitle = (string)trans('firefly.all_journals_without_category');
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon : $first->date;
$end = today(config('app.timezone'));

View File

@@ -42,6 +42,7 @@ use Illuminate\View\View;
class ShowController extends Controller
{
use PeriodOverview;
/** @var CategoryRepositoryInterface The category repository */
private $repository;
@@ -57,7 +58,7 @@ class ShowController extends Controller
$this->middleware(
function ($request, $next) {
app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('title', (string)trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->repository = app(CategoryRepositoryInterface::class);
@@ -65,6 +66,7 @@ class ShowController extends Controller
}
);
}
/**
* Show a single category.
*
@@ -82,9 +84,9 @@ class ShowController extends Controller
/** @var Carbon $end */
$end = $end ?? session('end', Carbon::now()->endOfMonth());
$subTitleIcon = 'fa-bookmark';
$page = (int) $request->get('page');
$page = (int)$request->get('page');
$attachments = $this->repository->getAttachments($category);
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$oldest = $this->repository->firstUseDate($category) ?? Carbon::now()->startOfYear();
$periods = $this->getCategoryPeriodOverview($category, $oldest, $end);
$path = route('categories.show', [$category->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
@@ -103,7 +105,7 @@ class ShowController extends Controller
$groups = $collector->getPaginatedGroups();
$groups->setPath($path);
return prefixView('categories.show', compact('category','attachments', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
return prefixView('categories.show', compact('category', 'attachments', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
}
/**
@@ -118,19 +120,19 @@ class ShowController extends Controller
{
// default values:
$subTitleIcon = 'fa-bookmark';
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$start = null;
$end = null;
$periods = new Collection;
$subTitle = (string) trans('firefly.all_journals_for_category', ['name' => $category->name]);
$subTitle = (string)trans('firefly.all_journals_for_category', ['name' => $category->name]);
$first = $this->repository->firstUseDate($category);
/** @var Carbon $start */
$start = $first ?? today(config('app.timezone'));
$end = today(config('app.timezone'));
$path = route('categories.show.all', [$category->id]);
$attachments = $this->repository->getAttachments($category);
$start = $first ?? today(config('app.timezone'));
$end = today(config('app.timezone'));
$path = route('categories.show.all', [$category->id]);
$attachments = $this->repository->getAttachments($category);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@@ -141,6 +143,6 @@ class ShowController extends Controller
$groups = $collector->getPaginatedGroups();
$groups->setPath($path);
return prefixView('categories.show', compact('category','attachments', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
return prefixView('categories.show', compact('category', 'attachments', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
}
}