Code cleanup and documentation improvements.

This commit is contained in:
James Cole
2018-07-06 07:15:42 +02:00
parent bdc6678341
commit a76241c7ba
49 changed files with 342 additions and 82 deletions

View File

@@ -35,7 +35,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Returns basic information about this installation.
*
* Class AboutController
* Class AboutController.
*/
class AboutController extends Controller
{

View File

@@ -1,5 +1,4 @@
<?php
/**
* AccountController.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
@@ -41,14 +40,15 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class AccountController
* Class AccountController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AccountController extends Controller
{
/** @var CurrencyRepositoryInterface */
/** @var CurrencyRepositoryInterface The currency repository */
private $currencyRepository;
/** @var AccountRepositoryInterface */
/** @var AccountRepositoryInterface The account repository */
private $repository;
/**
@@ -126,6 +126,8 @@ class AccountController extends Controller
}
/**
* Show single instance.
*
* @param Request $request
* @param Account $account
*
@@ -147,6 +149,8 @@ class AccountController extends Controller
}
/**
* Store a new instance.
*
* @param AccountRequest $request
*
* @return \Illuminate\Http\JsonResponse
@@ -198,13 +202,15 @@ class AccountController extends Controller
}
/**
* All the available types.
*
* @param string $type
*
* @return array
*/
private function mapTypes(string $type): array
{
$types = [
$types = [
'all' => [AccountType::DEFAULT, AccountType::CASH, AccountType::ASSET, AccountType::EXPENSE, AccountType::REVENUE,
AccountType::INITIAL_BALANCE, AccountType::BENEFICIARY, AccountType::IMPORT, AccountType::RECONCILIATION,
AccountType::LOAN,],
@@ -226,10 +232,11 @@ class AccountController extends Controller
AccountType::RECONCILIATION => [AccountType::RECONCILIATION],
AccountType::LOAN => [AccountType::LOAN],
];
$return = $types['all'];
if (isset($types[$type])) {
return $types[$type];
$return = $types[$type];
}
return $types['all']; // @codeCoverageIgnore
return $return; // @codeCoverageIgnore
}
}

View File

@@ -41,12 +41,13 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class AttachmentController
* Class AttachmentController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AttachmentController extends Controller
{
/** @var AttachmentRepositoryInterface */
/** @var AttachmentRepositoryInterface The attachment repository */
private $repository;
/**
@@ -82,6 +83,8 @@ class AttachmentController extends Controller
}
/**
* Download an attachment.
*
* @param Attachment $attachment
*
* @return LaravelResponse
@@ -212,6 +215,8 @@ class AttachmentController extends Controller
}
/**
* Upload an attachment.
*
* @param Request $request
* @param Attachment $attachment
*

View File

@@ -40,14 +40,15 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class AvailableBudgetController
* Class AvailableBudgetController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class AvailableBudgetController extends Controller
{
/** @var CurrencyRepositoryInterface */
/** @var CurrencyRepositoryInterface The currency repository */
private $currencyRepository;
/** @var BudgetRepositoryInterface */
/** @var BudgetRepositoryInterface The budget repository */
private $repository;
/**

View File

@@ -40,11 +40,11 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class BillController
* Class BillController.
*/
class BillController extends Controller
{
/** @var BillRepositoryInterface */
/** @var BillRepositoryInterface The bill repository */
private $repository;
/**
@@ -107,6 +107,8 @@ class BillController extends Controller
/**
* Show the specified bill.
*
* @param Request $request
* @param Bill $bill
*
@@ -128,6 +130,8 @@ class BillController extends Controller
}
/**
* Store a bill.
*
* @param BillRequest $request
*
* @return JsonResponse
@@ -151,6 +155,8 @@ class BillController extends Controller
/**
* Update a bill.
*
* @param BillRequest $request
* @param Bill $bill
*

View File

@@ -39,12 +39,13 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class BudgetController
* Class BudgetController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class BudgetController extends Controller
{
/** @var BudgetRepositoryInterface */
/** @var BudgetRepositoryInterface The budget repository */
private $repository;
/**
@@ -116,6 +117,8 @@ class BudgetController extends Controller
/**
* Show a budget.
*
* @param Request $request
* @param Budget $budget
*
@@ -137,6 +140,8 @@ class BudgetController extends Controller
}
/**
* Store a budget.
*
* @param BudgetRequest $request
*
* @return JsonResponse
@@ -159,6 +164,8 @@ class BudgetController extends Controller
/**
* Update a budget.
*
* @param BudgetRequest $request
* @param Budget $budget
*

View File

@@ -43,12 +43,13 @@ use League\Fractal\Serializer\JsonApiSerializer;
use Log;
/**
* Class BudgetLimitController
* Class BudgetLimitController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class BudgetLimitController extends Controller
{
/** @var BudgetRepositoryInterface */
/** @var BudgetRepositoryInterface The budget repository */
private $repository;
/**

View File

@@ -39,12 +39,13 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class CategoryController
* Class CategoryController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CategoryController extends Controller
{
/** @var CategoryRepositoryInterface */
/** @var CategoryRepositoryInterface The category repository */
private $repository;
/**
@@ -116,6 +117,8 @@ class CategoryController extends Controller
/**
* Show the category.
*
* @param Request $request
* @param Category $category
*
@@ -137,6 +140,8 @@ class CategoryController extends Controller
}
/**
* Store new category.
*
* @param CategoryRequest $request
*
* @return JsonResponse
@@ -159,6 +164,8 @@ class CategoryController extends Controller
/**
* Update the category.
*
* @param CategoryRequest $request
* @param Category $category
*

View File

@@ -31,13 +31,13 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* Class ConfigurationController
* Class ConfigurationController.
*/
class ConfigurationController extends Controller
{
/** @var UserRepositoryInterface */
/** @var UserRepositoryInterface The user repository */
private $repository;
/**
@@ -63,6 +63,8 @@ class ConfigurationController extends Controller
}
/**
* Show all configuration.
*
* @return JsonResponse
*/
public function index(): JsonResponse
@@ -73,6 +75,8 @@ class ConfigurationController extends Controller
}
/**
* Update the configuration.
*
* @param Request $request
*
* @return JsonResponse
@@ -104,6 +108,8 @@ class ConfigurationController extends Controller
}
/**
* Get all config values.
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/

View File

@@ -43,7 +43,7 @@ class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
/** @var ParameterBag */
/** @var ParameterBag Parameters from the URI are stored here. */
protected $parameters;
/**
@@ -57,6 +57,8 @@ class Controller extends BaseController
}
/**
* Method to help build URI's.
*
* @return string
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -81,6 +83,8 @@ class Controller extends BaseController
}
/**
* Method to grab all parameters from the URI.
*
* @return ParameterBag
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/

View File

@@ -41,14 +41,15 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class CurrencyController
* Class CurrencyController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CurrencyController extends Controller
{
/** @var CurrencyRepositoryInterface */
/** @var CurrencyRepositoryInterface The currency repository */
private $repository;
/** @var UserRepositoryInterface */
/** @var UserRepositoryInterface The user repository */
private $userRepository;
/**
@@ -129,6 +130,8 @@ class CurrencyController extends Controller
/**
* Show a currency.
*
* @param Request $request
* @param TransactionCurrency $currency
*
@@ -152,6 +155,8 @@ class CurrencyController extends Controller
}
/**
* Store new currency.
*
* @param CurrencyRequest $request
*
* @return JsonResponse
@@ -182,6 +187,8 @@ class CurrencyController extends Controller
/**
* Update a currency.
*
* @param CurrencyRequest $request
* @param TransactionCurrency $currency
*

View File

@@ -36,12 +36,11 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
*
* Class CurrencyExchangeRateController
*/
class CurrencyExchangeRateController extends Controller
{
/** @var CurrencyRepositoryInterface */
/** @var CurrencyRepositoryInterface The currency repository */
private $repository;
/**
@@ -65,6 +64,8 @@ class CurrencyExchangeRateController extends Controller
}
/**
* Show an exchange rate.
*
* @param Request $request
*
* @return JsonResponse

View File

@@ -40,17 +40,20 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class JournalLinkController.
*
* Class JournalLinkController
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class JournalLinkController extends Controller
{
/** @var JournalRepositoryInterface */
/** @var JournalRepositoryInterface The journal repository */
private $journalRepository;
/** @var LinkTypeRepositoryInterface */
/** @var LinkTypeRepositoryInterface The link type repository */
private $repository;
/**
* JournalLinkController constructor.
*/
public function __construct()
{
parent::__construct();
@@ -180,6 +183,8 @@ class JournalLinkController extends Controller
}
/**
* Update object.
*
* @param JournalLinkRequest $request
* @param TransactionJournalLink $journalLink
*

View File

@@ -40,18 +40,21 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class LinkTypeController.
*
* Class LinkTypeController
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class LinkTypeController extends Controller
{
/** @var LinkTypeRepositoryInterface */
/** @var LinkTypeRepositoryInterface The link type repository */
private $repository;
/** @var UserRepositoryInterface */
/** @var UserRepositoryInterface The user repository */
private $userRepository;
/**
* LinkTypeController constructor.
*/
public function __construct()
{
parent::__construct();
@@ -172,6 +175,8 @@ class LinkTypeController extends Controller
}
/**
* Update object.
*
* @param LinkTypeRequest $request
* @param LinkType $linkType
*

View File

@@ -39,16 +39,19 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* TODO order up and down.
* Class PiggyBankController
* Class PiggyBankController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PiggyBankController extends Controller
{
/** @var PiggyBankRepositoryInterface */
/** @var PiggyBankRepositoryInterface The piggy bank repository */
private $repository;
/**
* PiggyBankController constructor.
*/
public function __construct()
{
parent::__construct();
@@ -163,6 +166,8 @@ class PiggyBankController extends Controller
}
/**
* Update piggy bank.
*
* @param PiggyBankRequest $request
* @param PiggyBank $piggyBank
*

View File

@@ -102,6 +102,8 @@ class PreferenceController extends Controller
}
/**
* Update a preference.
*
* @param PreferenceRequest $request
* @param Preference $preference
*

View File

@@ -38,14 +38,16 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
*
* Class RecurrenceController
*/
class RecurrenceController extends Controller
{
/** @var RecurringRepositoryInterface */
/** @var RecurringRepositoryInterface The recurring transaction repository */
private $repository;
/**
* RecurrenceController constructor.
*/
public function __construct()
{
parent::__construct();
@@ -155,6 +157,8 @@ class RecurrenceController extends Controller
}
/**
* Update single recurrence.
*
* @param RecurrenceRequest $request
* @param Recurrence $recurrence
*

View File

@@ -42,9 +42,12 @@ use League\Fractal\Serializer\JsonApiSerializer;
*/
class RuleController extends Controller
{
/** @var RuleRepositoryInterface */
/** @var RuleRepositoryInterface The rule repository */
private $ruleRepository;
/**
* RuleController constructor.
*/
public function __construct()
{
parent::__construct();
@@ -153,6 +156,8 @@ class RuleController extends Controller
}
/**
* Update a rule.
*
* @param RuleRequest $request
* @param Rule $rule
*

View File

@@ -38,11 +38,17 @@ use League\Fractal\Resource\Item;
use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class RuleGroupController
*/
class RuleGroupController extends Controller
{
/** @var RuleGroupRepositoryInterface */
/** @var RuleGroupRepositoryInterface The rule group repository */
private $ruleGroupRepository;
/**
* RuleGroupController constructor.
*/
public function __construct()
{
parent::__construct();
@@ -151,6 +157,8 @@ class RuleGroupController extends Controller
}
/**
* Update a rule group.
*
* @param RuleGroupRequest $request
* @param RuleGroup $ruleGroup
*

View File

@@ -50,7 +50,7 @@ use League\Fractal\Serializer\JsonApiSerializer;
class TransactionController extends Controller
{
/** @var JournalRepositoryInterface */
/** @var JournalRepositoryInterface The journal repository */
private $repository;
/**
@@ -89,6 +89,8 @@ class TransactionController extends Controller
}
/**
* Show all transactions.
*
* @param Request $request
*
* @return JsonResponse
@@ -133,6 +135,8 @@ class TransactionController extends Controller
/**
* Show a single transaction.
*
* @param Request $request
* @param Transaction $transaction
* @param string $include
@@ -173,6 +177,8 @@ class TransactionController extends Controller
}
/**
* Store a new transaction.
*
* @param TransactionRequest $request
*
* @param JournalRepositoryInterface $repository
@@ -218,6 +224,8 @@ class TransactionController extends Controller
/**
* Update a transaction.
*
* @param TransactionRequest $request
* @param JournalRepositoryInterface $repository
* @param Transaction $transaction
@@ -262,13 +270,15 @@ class TransactionController extends Controller
}
/**
* All the types you can request.
*
* @param string $type
*
* @return array
*/
private function mapTypes(string $type): array
{
$types = [
$types = [
'all' => [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER, TransactionType::OPENING_BALANCE,
TransactionType::RECONCILIATION,],
'withdrawal' => [TransactionType::WITHDRAWAL,],
@@ -286,11 +296,12 @@ class TransactionController extends Controller
'specials' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,],
'default' => [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER,],
];
$return = $types['default'];
if (isset($types[$type])) {
return $types[$type];
$return = $types[$type];
}
return $types['default']; // @codeCoverageIgnore
return $return;
}
}

View File

@@ -40,13 +40,14 @@ use League\Fractal\Serializer\JsonApiSerializer;
/**
* Class UserController
* Class UserController.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class UserController extends Controller
{
/** @var UserRepositoryInterface */
/** @var UserRepositoryInterface The user repository */
private $repository;
/**
@@ -119,6 +120,8 @@ class UserController extends Controller
}
/**
* Show a single user.
*
* @param Request $request
* @param User $user
*
@@ -142,6 +145,8 @@ class UserController extends Controller
}
/**
* Store a new user.
*
* @param UserRequest $request
*
* @return JsonResponse
@@ -167,6 +172,8 @@ class UserController extends Controller
}
/**
* Update a user.
*
* @param UserRequest $request
* @param User $user
*

View File

@@ -30,6 +30,8 @@ class AccountRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -39,6 +41,8 @@ class AccountRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -66,6 +70,8 @@ class AccountRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -34,6 +34,8 @@ use FireflyIII\Rules\IsValidAttachmentModel;
class AttachmentRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -43,6 +45,8 @@ class AttachmentRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -57,6 +61,8 @@ class AttachmentRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -29,6 +29,8 @@ namespace FireflyIII\Api\V1\Requests;
class AvailableBudgetRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -38,6 +40,8 @@ class AvailableBudgetRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -51,6 +55,8 @@ class AvailableBudgetRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -33,6 +33,8 @@ class BillRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -42,6 +44,8 @@ class BillRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -64,6 +68,8 @@ class BillRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -30,6 +30,8 @@ namespace FireflyIII\Api\V1\Requests;
class BudgetLimitRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -39,6 +41,8 @@ class BudgetLimitRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -52,6 +56,8 @@ class BudgetLimitRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -31,6 +31,8 @@ use FireflyIII\Models\Budget;
class BudgetRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -40,6 +42,8 @@ class BudgetRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -52,6 +56,8 @@ class BudgetRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -31,6 +31,8 @@ use FireflyIII\Models\Category;
class CategoryRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -40,6 +42,8 @@ class CategoryRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -51,6 +55,8 @@ class CategoryRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -30,6 +30,8 @@ namespace FireflyIII\Api\V1\Requests;
class CurrencyRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -39,6 +41,8 @@ class CurrencyRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -53,6 +57,8 @@ class CurrencyRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -31,6 +31,8 @@ namespace FireflyIII\Api\V1\Requests;
class JournalLinkRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -40,6 +42,8 @@ class JournalLinkRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -53,6 +57,8 @@ class JournalLinkRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -33,6 +33,8 @@ use Illuminate\Validation\Rule;
class LinkTypeRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -42,6 +44,8 @@ class LinkTypeRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -56,6 +60,8 @@ class LinkTypeRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -33,6 +33,8 @@ use FireflyIII\Rules\IsAssetAccountId;
class PiggyBankRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -42,6 +44,8 @@ class PiggyBankRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -58,6 +62,8 @@ class PiggyBankRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -32,6 +32,8 @@ class PreferenceRequest extends Request
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -40,6 +42,11 @@ class PreferenceRequest extends Request
return auth()->check();
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
{
return [
@@ -47,6 +54,11 @@ class PreferenceRequest extends Request
];
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array
{
return [

View File

@@ -37,6 +37,8 @@ class RecurrenceRequest extends Request
use RecurrenceValidation, TransactionValidation;
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -46,6 +48,8 @@ class RecurrenceRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -74,6 +78,8 @@ class RecurrenceRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -33,6 +33,8 @@ use FireflyIII\Models\RuleGroup;
class RuleGroupRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -42,6 +44,8 @@ class RuleGroupRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -54,6 +58,8 @@ class RuleGroupRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -32,6 +32,8 @@ use Illuminate\Validation\Validator;
class RuleRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -41,6 +43,8 @@ class RuleRequest extends Request
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -77,6 +81,8 @@ class RuleRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -37,6 +37,8 @@ class TransactionRequest extends Request
use TransactionValidation;
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
@@ -78,6 +80,8 @@ class TransactionRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
@@ -156,6 +160,8 @@ class TransactionRequest extends Request
}
/**
* Get transaction data.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @return array

View File

@@ -34,28 +34,32 @@ use FireflyIII\User;
class UserRequest extends Request
{
/**
* Authorize logged in users.
*
* @return bool
*/
public function authorize(): bool
{
$result = false;
// Only allow authenticated users
if (!auth()->check()) {
return false; // @codeCoverageIgnore
}
/** @var User $user */
$user = auth()->user();
if (auth()->check()) {
/** @var User $user */
$user = auth()->user();
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
if (!$repository->hasRole($user, 'owner')) {
return false; // @codeCoverageIgnore
if ($repository->hasRole($user, 'owner')) {
$result = true; // @codeCoverageIgnore
}
}
return true;
return $result;
}
/**
* Get all data from the request.
*
* @return array
*/
public function getAll(): array
@@ -70,6 +74,8 @@ class UserRequest extends Request
}
/**
* The rules that the incoming request must be matched against.
*
* @return array
*/
public function rules(): array

View File

@@ -1,5 +1,4 @@
<?php
/**
* CreateExport.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
@@ -20,6 +19,8 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MultipleReturnStatementsInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands;

View File

@@ -1,5 +1,4 @@
<?php
/**
* CreateImport.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
@@ -20,6 +19,8 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MultipleReturnStatementsInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands;

View File

@@ -1,5 +1,4 @@
<?php
/**
* DecryptAttachment.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
@@ -20,6 +19,8 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MultipleReturnStatementsInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands;

View File

@@ -1,5 +1,4 @@
<?php
/**
* EncryptFile.php
* Copyright (c) 2018 thegrumpydictator@gmail.com

View File

@@ -1,5 +1,4 @@
<?php /** @noinspection PhpDynamicAsStaticMethodCallInspection */
<?php
/**
* Import.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
@@ -20,6 +19,9 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MultipleReturnStatementsInspection */
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands;
@@ -52,6 +54,8 @@ class Import extends Command
/**
* Run the import routine.
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @throws FireflyException
*/
@@ -102,10 +106,11 @@ class Import extends Command
}
$this->infoLine(sprintf('The import has finished. %d transactions have been imported.', $count));
}
/**
* Displays an error.
*
* @param string $message
* @param array|null $data
*/
@@ -117,6 +122,8 @@ class Import extends Command
}
/**
* Displays an informational message.
*
* @param string $message
* @param array $data
*/

View File

@@ -1,5 +1,4 @@
<?php /** @noinspection PhpDynamicAsStaticMethodCallInspection */
<?php
/**
* ScanAttachments.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
@@ -20,6 +19,8 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands;
@@ -63,13 +64,13 @@ class ScanAttachments extends Command
try {
$content = $disk->get($fileName);
} catch (FileNotFoundException $e) {
$this->error(sprintf('Could not find data for attachment #%d', $attachment->id));
$this->error(sprintf('Could not find data for attachment #%d: %s', $attachment->id, $e->getMessage()));
continue;
}
try {
$decrypted = Crypt::decrypt($content);
} catch (DecryptException $e) {
$this->error(sprintf('Could not decrypt data of attachment #%d', $attachment->id));
$this->error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage()));
continue;
}
$tmpfname = tempnam(sys_get_temp_dir(), 'FireflyIII');

View File

@@ -1,5 +1,4 @@
<?php /** @noinspection PhpStaticAsDynamicMethodCallInspection */
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
<?php
/**
* UpgradeDatabase.php
@@ -21,6 +20,10 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection MultipleReturnStatementsInspection */
/** @noinspection PhpStaticAsDynamicMethodCallInspection */
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands;
@@ -59,6 +62,8 @@ use UnexpectedValueException;
* Class UpgradeDatabase.
*
* Upgrade user database.
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class UpgradeDatabase extends Command
{
@@ -94,6 +99,13 @@ class UpgradeDatabase extends Command
$this->info('Firefly III database is up to date.');
}
/**
* Since it is one routine these warnings make sense and should be supressed.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function migrateBillsToRules(): void
{
foreach (User::get() as $user) {
@@ -104,11 +116,14 @@ class UpgradeDatabase extends Command
$currencyPreference = Preferences::getForUser($user, 'currencyPreference', config('firefly.default_currency', 'EUR'));
if (null === $currencyPreference) {
$this->error('User has no currency preference. Impossible.');
return;
}
$currency = TransactionCurrency::where('code', $currencyPreference->data)->first();
if (null === $currency) {
$this->line('Fall back to default currency in migrateBillsToRules().');
$currency = app('amount')->getDefaultCurrency();
}
@@ -265,6 +280,9 @@ class UpgradeDatabase extends Command
/**
* Each (asset) account must have a reference to a preferred currency. If the account does not have one, it's forced upon the account.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function updateAccountCurrencies(): void
{
@@ -325,6 +343,9 @@ class UpgradeDatabase extends Command
*
* Both source and destination must match the respective currency preference of the related asset account.
* So FF3 must verify all transactions.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function updateOtherCurrencies(): void
{
@@ -570,7 +591,11 @@ class UpgradeDatabase extends Command
*
* The transaction that is sent to this function MUST be the source transaction (amount negative).
*
* Method is long and complex bit I'm taking it for granted.
* Method is long and complex but I'll allow it. https://imgur.com/gallery/dVDJiez
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* @param Transaction $transaction
*/

View File

@@ -1,5 +1,4 @@
<?php
/**
* UpgradeFireflyInstructions.php
* Copyright (c) 2018 thegrumpydictator@gmail.com

View File

@@ -1,5 +1,4 @@
<?php
/**
* UseEncryption.php
* Copyright (c) 2018 thegrumpydictator@gmail.com

View File

@@ -1,5 +1,4 @@
<?php
/**
* VerifiesAccessToken.php
* Copyright (c) 2018 thegrumpydictator@gmail.com

View File

@@ -1,5 +1,4 @@
<?php /** @noinspection PhpDynamicAsStaticMethodCallInspection */
<?php
/**
* VerifyDatabase.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
@@ -20,6 +19,8 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
declare(strict_types=1);
namespace FireflyIII\Console\Commands;
@@ -40,12 +41,16 @@ use FireflyIII\User;
use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Database\Eloquent\Builder;
use Log;
use Preferences;
use Schema;
use stdClass;
/**
* Class VerifyDatabase.
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class VerifyDatabase extends Command
{
@@ -144,9 +149,10 @@ class VerifyDatabase extends Command
}
/**
* Fix the situation where the matching transactions
* of a journal somehow have non-matching categories
* or budgets
* Fix the situation where the matching transactions of a journal somehow have non-matching categories or budgets.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function fixBadMeta(): void
{
@@ -207,6 +213,12 @@ class VerifyDatabase extends Command
}
}
/**
* Makes sure amounts are stored correctly.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function fixDoubleAmounts(): void
{
$count = 0;
@@ -256,7 +268,7 @@ class VerifyDatabase extends Command
}
/**
*
* Removes bills from journals that should not have bills.
*/
private function removeBills(): void
{
@@ -396,6 +408,7 @@ class VerifyDatabase extends Command
$objName = Crypt::decrypt($objName);
} catch (DecryptException $e) {
// it probably was not encrypted.
Log::debug(sprintf('Not a problem: %s', $e->getMessage()));
}
// also count the transactions:
@@ -433,6 +446,7 @@ class VerifyDatabase extends Command
$objName = Crypt::decrypt($objName);
} catch (DecryptException $e) {
// it probably was not encrypted.
Log::debug(sprintf('Not a problem: %s', $e->getMessage()));
}
// also count the transactions:
@@ -571,6 +585,7 @@ class VerifyDatabase extends Command
$objName = Crypt::decrypt($objName);
} catch (DecryptException $e) {
// it probably was not encrypted.
Log::debug(sprintf('Not a problem: %s', $e->getMessage()));
}
$line = sprintf(
@@ -598,7 +613,8 @@ class VerifyDatabase extends Command
$sum = (string)$user->transactions()->sum('amount');
if (0 !== bccomp($sum, '0')) {
$this->error('Error: Transactions for user #' . $user->id . ' (' . $user->email . ') are off by ' . $sum . '!');
} else {
}
if (0 === bccomp($sum, '0')) {
$this->info(sprintf('Amount integrity OK for user #%d', $user->id));
}
}