Small code cleanup.

This commit is contained in:
James Cole
2021-04-27 06:23:16 +02:00
parent cf2c99d986
commit fab0c5bfd9
19 changed files with 26 additions and 73 deletions

View File

@@ -39,9 +39,7 @@ use Log;
*/
class LinkController extends Controller
{
/** @var LinkTypeRepositoryInterface */
private $repository;
private LinkTypeRepositoryInterface $repository;
/**
* LinkController constructor.

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Admin;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Update\UpdateTrait;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Middleware\IsDemoUser;
@@ -62,8 +63,7 @@ class UpdateController extends Controller
* Show page with update options.
*
* @return Factory|View
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws FireflyException
*/
public function index()
{

View File

@@ -159,7 +159,6 @@ class IndexController extends Controller
continue;
}
/** @var TransactionCurrency $currency */
$currencyId = $bill['currency_id'];
$sums[$groupOrder][$currencyId] = $sums[$groupOrder][$currencyId] ?? [
'currency_id' => $currencyId,

View File

@@ -144,7 +144,7 @@ class ShowController extends Controller
*/
public function show(Request $request, Budget $budget)
{
/** @var Carbon $start */
/** @var Carbon $allStart */
$allStart = session('first', Carbon::now()->startOfYear());
$allEnd = today();
$page = (int)$request->get('page');

View File

@@ -108,7 +108,7 @@ class BudgetController extends Controller
$currencies = [];
$defaultEntries = [];
while ($end >= $loopStart) {
/** @var Carbon $currentEnd */
/** @var Carbon $loopEnd */
$loopEnd = app('navigation')->endOfPeriod($loopStart, $step);
$spent = $this->opsRepository->sumExpenses($loopStart, $loopEnd, null, $collection);
$label = trim(app('navigation')->periodShow($loopStart, $step));

View File

@@ -76,7 +76,7 @@ class CategoryController extends Controller
$cache->addProperty('chart.category.all');
$cache->addProperty($category->id);
if ($cache->has()) {
return response()->json($cache->get());
return response()->json($cache->get());
}
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
@@ -125,7 +125,7 @@ class CategoryController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.category.frontpage');
if ($cache->has()) {
return response()->json($cache->get());
return response()->json($cache->get());
}
$frontPageGenerator = new FrontpageChartGenerator($start, $end);
@@ -270,7 +270,7 @@ class CategoryController extends Controller
$cache->addProperty('chart.category.period.no-cat');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
return response()->json($cache->get());
return response()->json($cache->get());
}
$data = $this->reportPeriodChart($accounts, $start, $end, null);
@@ -283,8 +283,8 @@ class CategoryController extends Controller
* Chart for a specific period.
* TODO test method, for category refactor.
*
* @param Category $category
* @param $date
* @param Category $category
* @param Carbon $date
*
* @return JsonResponse
*/
@@ -294,7 +294,7 @@ class CategoryController extends Controller
$start = app('navigation')->startOfPeriod($date, $range);
$end = session()->get('end');
if ($end < $start) {
[$end, $start] = [$start, $end];
[$end, $start] = [$start, $end];
}
$cache = new CacheProperties;
@@ -303,7 +303,7 @@ class CategoryController extends Controller
$cache->addProperty($category->id);
$cache->addProperty('chart.category.period-chart');
if ($cache->has()) {
return response()->json($cache->get());
return response()->json($cache->get());
}
/** @var WholePeriodChartGenerator $chartGenerator */

View File

@@ -140,10 +140,8 @@ class CategoryReportController extends Controller
* @param Collection $categories
* @param Carbon $start
* @param Carbon $end
* @param string $others
*
* @return JsonResponse
*
*/
public function categoryIncome(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): JsonResponse
{

View File

@@ -80,7 +80,7 @@ class PiggyBankController extends Controller
$locale = app('steam')->getLocale();
// get first event or start date of piggy bank or today
$startDate = $piggyBank->start_date ?? today(config('app.timezone'));
$startDate = $piggyBank->startdate ?? today(config('app.timezone'));
/** @var PiggyBankEvent $first */
$firstEvent = $set->first();

View File

@@ -52,12 +52,10 @@ class TransactionController extends Controller
}
/**
* @param string $objectType
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
* @throws FireflyException
*/
public function budgets(Carbon $start, Carbon $end)
{

View File

@@ -32,7 +32,7 @@ class HelpController extends Controller
/**
* Show help for a route.
*
* @param $route
* @param string $route
*
* @return JsonResponse
*/

View File

@@ -30,54 +30,9 @@ use Illuminate\Http\Request;
/**
* Class AutoCompleteController.
*
* TODO autocomplete for transaction types.
*
*/
class AutoCompleteController extends Controller
{
/**
* Searches in the titles of all transaction journals.
* The result is limited to the top 15 unique results.
*
* If the query is numeric, it will append the journal with that particular ID.
*
* @param Request $request
*
* @return JsonResponse
*/
public function allJournalsWithID(Request $request): JsonResponse
{
$search = (string)$request->get('search');
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
/** @var TransactionGroupRepositoryInterface $groupRepos */
$groupRepos = app(TransactionGroupRepositoryInterface::class);
$result = $repository->searchJournalDescriptions($search);
$array = [];
if (is_numeric($search)) {
// search for group, not journal.
$firstResult = $groupRepos->find((int)$search);
if (null !== $firstResult) {
// group may contain multiple journals, each a result:
foreach ($firstResult->transactionJournals as $journal) {
$array[] = $journal->toArray();
}
}
}
// if not numeric, search ahead!
// limit and unique
$limited = $result->slice(0, 15);
$array = array_merge($array, $limited->toArray());
foreach ($array as $index => $item) {
// give another key for consistency
$array[$index]['name'] = sprintf('#%d: %s', $item['transaction_group_id'], $item['description']);
}
return response()->json($array);
}
}

View File

@@ -191,7 +191,7 @@ class PreferencesController extends Controller
// same for locale:
if (!auth()->user()->hasRole('demo')) {
/** @var Preference $currentLocale */
/** @var Preference $locale */
$locale = $request->get('locale');
app('preferences')->set('locale', $locale);
}

View File

@@ -148,13 +148,13 @@ class CreateController extends Controller
RecurrenceRepetition::WEEKEND_TO_MONDAY => (string)trans('firefly.jump_to_monday'),
];
/** @var Transaction $source */
/** @var Transaction $dest */
// fill prefilled with journal info
$type = strtolower($journal->transactionType->type);
/** @var Transaction $source */
$source = $journal->transactions()->where('amount', '<', 0)->first();
/** @var Transaction $dest */
$dest = $journal->transactions()->where('amount', '>', 0)->first();
$category = $journal->categories()->first() ? $journal->categories()->first()->name : '';
$budget = $journal->budgets()->first() ? $journal->budgets()->first()->id : 0;

View File

@@ -122,7 +122,7 @@ class TagController extends Controller
foreach ($earned as $currency) {
$currencyId = $currency['currency_id'];
/** @var array $category */
/** @var array $tag */
foreach ($currency['tags'] as $tag) {
foreach ($tag['transaction_journals'] as $journal) {
$destinationId = $journal['destination_account_id'];

View File

@@ -34,7 +34,7 @@ use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/** @var int The headers to check. */
protected $headers = Request::HEADER_X_FORWARDED_ALL;
//protected $headers = Request::HEADER_X_FORWARDED_ALL;
/**
* TrustProxies constructor.

View File

@@ -22,6 +22,7 @@ declare(strict_types=1);
namespace FireflyIII\Models;
use Carbon\Carbon;
use Eloquent;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
@@ -87,6 +88,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static Builder|Account withTrashed()
* @method static Builder|Account withoutTrashed()
* @mixin Eloquent
* @property Carbon $lastActivityDate
*
*/
class Account extends Model
{

View File

@@ -44,6 +44,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property int $user_id
* @property string $name
* @property Carbon $lastActivity
* @property bool $encrypted
* @property-read Collection|\FireflyIII\Models\Attachment[] $attachments
* @property-read int|null $attachments_count

View File

@@ -40,6 +40,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property string $name
* @property string $outward
* @property string $inward
* @property int $journalCount
* @property bool $editable
* @property-read Collection|\FireflyIII\Models\TransactionJournalLink[] $transactionJournalLinks
* @property-read int|null $transaction_journal_links_count

View File

@@ -174,10 +174,10 @@ trait JournalServiceTrait
if (null === $account && null !== $data['number']) {
Log::debug(sprintf('Searching for account number "%s".', $data['number']));
// find by preferred type.
$source = $this->accountRepository->findByAccountNumber($data['number'], [$types[0]]);
$source = $this->accountRepository->findByAccountNumber((string) $data['number'], [$types[0]]);
// or any expected type.
$source = $source ?? $this->accountRepository->findByAccountNumber($data['iban'], $types);
$source = $source ?? $this->accountRepository->findByAccountNumber((string) $data['number'], $types);
if (null !== $source) {
Log::debug(sprintf('Found account: #%d, %s', $source->id, $source->name));