diff --git a/app/Support/Binder/AccountList.php b/app/Support/Binder/AccountList.php index 3028d88f1c..29cfd8e7ea 100644 --- a/app/Support/Binder/AccountList.php +++ b/app/Support/Binder/AccountList.php @@ -31,7 +31,7 @@ class AccountList implements BinderInterface * * @return Collection */ - public static function routeBinder($value, $route) + public static function routeBinder($value, $route): Collection { if (Auth::check()) { diff --git a/app/Support/Binder/BudgetList.php b/app/Support/Binder/BudgetList.php index e957adad65..875d5e249b 100644 --- a/app/Support/Binder/BudgetList.php +++ b/app/Support/Binder/BudgetList.php @@ -12,6 +12,7 @@ namespace FireflyIII\Support\Binder; use Auth; use FireflyIII\Models\Budget; +use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -29,7 +30,7 @@ class BudgetList implements BinderInterface * * @return mixed */ - public static function routeBinder($value, $route) + public static function routeBinder($value, $route): Collection { if (Auth::check()) { $ids = explode(',', $value); diff --git a/app/Support/Binder/CategoryList.php b/app/Support/Binder/CategoryList.php index a212d302c0..de14aa583b 100644 --- a/app/Support/Binder/CategoryList.php +++ b/app/Support/Binder/CategoryList.php @@ -12,6 +12,7 @@ namespace FireflyIII\Support\Binder; use Auth; use FireflyIII\Models\Category; +use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** @@ -28,7 +29,7 @@ class CategoryList implements BinderInterface * * @return mixed */ - public static function routeBinder($value, $route) + public static function routeBinder($value, $route): Collection { if (Auth::check()) { $ids = explode(',', $value); diff --git a/app/Support/Binder/Date.php b/app/Support/Binder/Date.php index e910bc07d9..886c6090be 100644 --- a/app/Support/Binder/Date.php +++ b/app/Support/Binder/Date.php @@ -32,7 +32,7 @@ class Date implements BinderInterface * * @return mixed */ - public static function routeBinder($value, $route) + public static function routeBinder($value, $route): Carbon { $fiscalHelper = new FiscalHelper; diff --git a/app/Support/Facades/Amount.php b/app/Support/Facades/Amount.php index 2a9c0d01a0..c6d2b43250 100644 --- a/app/Support/Facades/Amount.php +++ b/app/Support/Facades/Amount.php @@ -18,7 +18,7 @@ class Amount extends Facade * * @return string */ - protected static function getFacadeAccessor() + protected static function getFacadeAccessor(): string { return 'amount'; } diff --git a/app/Support/Facades/ExpandedForm.php b/app/Support/Facades/ExpandedForm.php index 2fe33eedb1..006a88f2c3 100644 --- a/app/Support/Facades/ExpandedForm.php +++ b/app/Support/Facades/ExpandedForm.php @@ -18,7 +18,7 @@ class ExpandedForm extends Facade * * @return string */ - protected static function getFacadeAccessor() + protected static function getFacadeAccessor(): string { return 'expandedform'; } diff --git a/app/Support/Facades/Navigation.php b/app/Support/Facades/Navigation.php index cfbc44188d..dba4ed838b 100644 --- a/app/Support/Facades/Navigation.php +++ b/app/Support/Facades/Navigation.php @@ -18,7 +18,7 @@ class Navigation extends Facade * * @return string */ - protected static function getFacadeAccessor() + protected static function getFacadeAccessor(): string { return 'navigation'; } diff --git a/app/Support/Facades/Preferences.php b/app/Support/Facades/Preferences.php index 9b406b97f7..06b7033813 100644 --- a/app/Support/Facades/Preferences.php +++ b/app/Support/Facades/Preferences.php @@ -18,7 +18,7 @@ class Preferences extends Facade * * @return string */ - protected static function getFacadeAccessor() + protected static function getFacadeAccessor(): string { return 'preferences'; } diff --git a/app/Support/Facades/Steam.php b/app/Support/Facades/Steam.php index 69655ac55b..5c93adcd8b 100644 --- a/app/Support/Facades/Steam.php +++ b/app/Support/Facades/Steam.php @@ -18,7 +18,7 @@ class Steam extends Facade * * @return string */ - protected static function getFacadeAccessor() + protected static function getFacadeAccessor(): string { return 'steam'; } diff --git a/app/Support/Migration/TestData.php b/app/Support/Migration/TestData.php index c488655083..8731dd1cac 100644 --- a/app/Support/Migration/TestData.php +++ b/app/Support/Migration/TestData.php @@ -43,8 +43,10 @@ class TestData /** * @param User $user + * + * @return bool */ - public static function createAssetAccounts(User $user) + public static function createAssetAccounts(User $user): bool { $assets = ['TestData Checking Account', 'TestData Savings', 'TestData Shared', 'TestData Creditcard', 'Emergencies', 'STE']; // first two ibans match test-upload.csv @@ -75,13 +77,17 @@ class TestData } } + return true; + } /** * @param User $user * @param Carbon $start + * + * @return TransactionJournal */ - public static function createAttachments(User $user, Carbon $start) + public static function createAttachments(User $user, Carbon $start): TransactionJournal { $toAccount = TestData::findAccount($user, 'TestData Checking Account'); @@ -138,12 +144,15 @@ class TestData file_put_contents(storage_path('upload/at-' . $one->id . '.data'), $encrypted); file_put_contents(storage_path('upload/at-' . $two->id . '.data'), $encrypted); + return $journal; } /** * @param User $user + * + * @return bool */ - public static function createBills(User $user) + public static function createBills(User $user): bool { Bill::create( [ @@ -174,15 +183,19 @@ class TestData ] ); + return true; + } /** * @param User $user * @param Carbon $current - * @param $name - * @param $amount + * @param string $name + * @param string $amount + * + * @return BudgetLimit */ - public static function createBudgetLimit(User $user, Carbon $current, string $name, string $amount) + public static function createBudgetLimit(User $user, Carbon $current, string $name, string $amount): BudgetLimit { $start = clone $current; $end = clone $current; @@ -190,7 +203,7 @@ class TestData $start->startOfMonth(); $end->endOfMonth(); - BudgetLimit::create( + $limit = BudgetLimit::create( [ 'budget_id' => $budget->id, 'startdate' => $start->format('Y-m-d'), @@ -199,12 +212,16 @@ class TestData 'repeat_freq' => 'monthly', ] ); + + return $limit; } /** * @param User $user + * + * @return bool */ - public static function createBudgets(User $user) + public static function createBudgets(User $user): bool { Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]); Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]); @@ -214,16 +231,18 @@ class TestData foreach (['A', 'B', 'C', 'D', "E"] as $letter) { Budget::firstOrCreateEncrypted(['name' => 'Empty budget ' . $letter, 'user_id' => $user->id]); } + + return true; } /** * @param User $user * @param Carbon $date * - * @return static + * @return TransactionJournal * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public static function createCar(User $user, Carbon $date) + public static function createCar(User $user, Carbon $date): TransactionJournal { // twice: $date = new Carbon($date->format('Y-m') . '-10'); // paid on 10th @@ -262,7 +281,7 @@ class TestData 'date' => $date, ] ); - self::createTransactions($journal, $fromAccount, $toAccount, '100'); + self::createTransactions($journal, $fromAccount, $toAccount, strval($amount)); // and again! @@ -271,19 +290,26 @@ class TestData /** * @param User $user + * + * @return bool */ - public static function createCategories(User $user) + public static function createCategories(User $user): bool { Category::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]); Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]); + + return true; } /** * @param User $user * @param Carbon $date + * + * @return bool + * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public static function createDrinksAndOthers(User $user, Carbon $date) + public static function createDrinksAndOthers(User $user, Carbon $date): bool { $start = clone $date; $end = clone $date; @@ -321,15 +347,19 @@ class TestData $current->addWeek(); } + + return true; } /** * @param User $user + * + * @return bool */ - public static function createExpenseAccounts(User $user) + public static function createExpenseAccounts(User $user): bool { $expenses = ['Adobe', 'Google', 'Vitens', 'Albert Heijn', 'PLUS', 'Apple', 'Bakker', 'Belastingdienst', 'bol.com', 'Cafe Central', 'conrad.nl', - 'coolblue', 'Shell', + 'Coolblue', 'Shell', 'DUO', 'Etos', 'FEBO', 'Greenchoice', 'Halfords', 'XS4All', 'iCentre', 'Jumper', 'Land lord']; foreach ($expenses as $name) { // create account: @@ -344,14 +374,19 @@ class TestData ); } + return true; + } /** * @param User $user * @param Carbon $date + * + * @return bool + * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public static function createGroceries(User $user, Carbon $date) + public static function createGroceries(User $user, Carbon $date): bool { bcscale(2); $start = clone $date; @@ -392,6 +427,8 @@ class TestData $current->addDay(); } + + return true; } /** @@ -432,10 +469,13 @@ class TestData } /** - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @param User $user + * + * @return bool + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public static function createPiggybanks(User $user) + public static function createPiggybanks(User $user): bool { $account = self::findAccount($user, 'TestData Savings'); @@ -567,6 +607,7 @@ class TestData ] ); + return true; } /** @@ -577,7 +618,7 @@ class TestData * * @return TransactionJournal */ - public static function createPower(User $user, string $description, Carbon $date, string $amount) + public static function createPower(User $user, string $description, Carbon $date, string $amount): TransactionJournal { $date = new Carbon($date->format('Y-m') . '-06'); // paid on 10th $fromAccount = TestData::findAccount($user, 'TestData Checking Account'); @@ -638,8 +679,10 @@ class TestData /** * @param User $user + * + * @return bool */ - public static function createRevenueAccounts(User $user) + public static function createRevenueAccounts(User $user): bool { $revenues = ['Job', 'Belastingdienst', 'Bank', 'KPN', 'Google']; foreach ($revenues as $name) { @@ -654,12 +697,16 @@ class TestData ] ); } + + return true; } /** * @param User $user + * + * @return RuleGroup */ - public static function createRules(User $user) + public static function createRules(User $user): RuleGroup { $group = RuleGroup::create( [ @@ -733,6 +780,8 @@ class TestData 'action_value' => trans('firefly.default_rule_action_set_category'), ] ); + + return $group; } /** @@ -772,9 +821,9 @@ class TestData * @param Carbon $date * @param string $amount * - * @return static + * @return TransactionJournal */ - public static function createTV(User $user, string $description, Carbon $date, string $amount) + public static function createTV(User $user, string $description, Carbon $date, string $amount): TransactionJournal { $date = new Carbon($date->format('Y-m') . '-15'); // paid on 10th $fromAccount = TestData::findAccount($user, 'TestData Checking Account'); @@ -801,26 +850,27 @@ class TestData } /** - * @param User $user - * @param Carbon|null $date + * @param User $user + * @param Carbon $date + * + * @return Tag */ - public static function createTags(User $user, Carbon $date = null) + public static function createTags(User $user, Carbon $date): Tag { - $title = 'SomeTag nr. ' . rand(1, 1234); - if (!is_null($date)) { - $title = 'SomeTag' . $date->month . '.' . $date->year . '.nothing'; - } + $title = 'SomeTag' . $date->month . '.' . $date->year . '.nothing'; - Tag::create( + $tag = Tag::create( [ 'user_id' => $user->id, 'tag' => $title, 'tagMode' => 'nothing', - 'date' => is_null($date) ? null : $date->format('Y-m-d'), + 'date' => $date->format('Y-m-d'), ] ); + + return $tag; } /** @@ -828,8 +878,10 @@ class TestData * @param Account $from * @param Account $to * @param string $amount + * + * @return bool */ - public static function createTransactions(TransactionJournal $journal, Account $from, Account $to, string $amount) + public static function createTransactions(TransactionJournal $journal, Account $from, Account $to, string $amount): bool { Log::debug('---- Transaction From: ' . bcmul($amount, '-1')); Log::debug('---- Transaction To : ' . $amount); @@ -849,6 +901,8 @@ class TestData ] ); + + return true; } /** @@ -873,7 +927,7 @@ class TestData * @param Carbon $date * @param string $amount * - * @return TransactionJournal|static + * @return TransactionJournal */ public static function createWater(User $user, string $description, Carbon $date, string $amount): TransactionJournal { @@ -922,9 +976,9 @@ class TestData * @param User $user * @param $name * - * @return Budget|null + * @return Budget */ - public static function findBudget(User $user, string $name) + public static function findBudget(User $user, string $name): Budget { /** @var Budget $budget */ foreach (Budget::get() as $budget) { @@ -934,14 +988,16 @@ class TestData } } - return null; + return new Budget; } /** * @param User $user * @param Carbon $date + * + * @return TransactionJournal */ - public static function openingBalanceSavings(User $user, Carbon $date) + public static function openingBalanceSavings(User $user, Carbon $date): TransactionJournal { // opposing account for opening balance: $opposing = Account::create( @@ -968,6 +1024,7 @@ class TestData ] ); self::createTransactions($journal, $opposing, $savings, '10000'); + return $journal; } diff --git a/app/User.php b/app/User.php index 917ea694a0..3f0b86d787 100644 --- a/app/User.php +++ b/app/User.php @@ -3,6 +3,8 @@ declare(strict_types = 1); namespace FireflyIII; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Foundation\Auth\User as Authenticatable; use Zizaco\Entrust\Traits\EntrustUserTrait; @@ -60,105 +62,105 @@ class User extends Authenticatable protected $table = 'users'; /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function accounts() + public function accounts(): HasMany { return $this->hasMany('FireflyIII\Models\Account'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function attachments() + public function attachments(): HasMany { return $this->hasMany('FireflyIII\Models\Attachment'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function bills() + public function bills(): HasMany { return $this->hasMany('FireflyIII\Models\Bill'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function budgets() + public function budgets(): HasMany { return $this->hasMany('FireflyIII\Models\Budget'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function categories() + public function categories(): HasMany { return $this->hasMany('FireflyIII\Models\Category'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function exportjobs() + public function exportjobs(): HasMany { return $this->hasMany('FireflyIII\Models\ExportJob'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough + * @return HasManyThrough */ - public function piggyBanks() + public function piggyBanks(): HasManyThrough { return $this->hasManyThrough('FireflyIII\Models\PiggyBank', 'FireflyIII\Models\Account'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function preferences() + public function preferences(): HasMany { return $this->hasMany('FireflyIII\Models\Preference'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function ruleGroups() + public function ruleGroups(): HasMany { return $this->hasMany('FireflyIII\Models\RuleGroup'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function rules() + public function rules(): HasMany { return $this->hasMany('FireflyIII\Models\Rule'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function tags() + public function tags(): HasMany { return $this->hasMany('FireflyIII\Models\Tag'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function transactionjournals() + public function transactionjournals(): HasMany { return $this->hasMany('FireflyIII\Models\TransactionJournal'); } /** - * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough + * @return HasManyThrough */ - public function transactions() + public function transactions(): HasManyThrough { return $this->hasManyThrough('FireflyIII\Models\Transaction', 'FireflyIII\Models\TransactionJournal'); } diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index b640d8a6fc..b0517f8bd2 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -48,7 +48,7 @@ class FireflyValidator extends Validator * * @return bool */ - public function validateBelongsToUser($attribute, $value, $parameters) + public function validateBelongsToUser($attribute, $value, $parameters): bool { $field = $parameters[1] ?? 'id'; @@ -70,7 +70,7 @@ class FireflyValidator extends Validator * * @return bool */ - public function validateIban($attribute, $value) + public function validateIban($attribute, $value): bool { if (!is_string($value) || is_null($value) || strlen($value) < 6) { return false; @@ -97,7 +97,7 @@ class FireflyValidator extends Validator * * @return bool */ - public function validateRuleActionValue($attribute) + public function validateRuleActionValue($attribute): bool { // get the index from a string like "rule-action-value.2". $parts = explode('.', $attribute); @@ -139,7 +139,7 @@ class FireflyValidator extends Validator * * @return bool */ - public function validateRuleTriggerValue($attribute) + public function validateRuleTriggerValue($attribute): bool { // get the index from a string like "rule-trigger-value.2". $parts = explode('.', $attribute); @@ -176,7 +176,7 @@ class FireflyValidator extends Validator * * @return bool */ - public function validateUniqueAccountForUser($attribute, $value, $parameters) + public function validateUniqueAccountForUser($attribute, $value, $parameters): bool { // because a user does not have to be logged in (tests and what-not). if (!Auth::check()) { @@ -207,7 +207,7 @@ class FireflyValidator extends Validator * * @return bool */ - public function validateUniqueForUser($attribute, $value, $parameters) + public function validateUniqueForUser($attribute, $value, $parameters): bool { $query = DB::table($parameters[0])->where($parameters[1], $value); $query->where('user_id', Auth::user()->id); @@ -238,7 +238,7 @@ class FireflyValidator extends Validator * * @return bool */ - public function validateUniqueObjectForUser($attribute, $value, $parameters) + public function validateUniqueObjectForUser($attribute, $value, $parameters): bool { $value = $this->tryDecrypt($value); // exclude? @@ -271,9 +271,9 @@ class FireflyValidator extends Validator * * @return bool */ - public function validateUniquePiggyBankForUser($attribute, $value, $parameters) + public function validateUniquePiggyBankForUser($attribute, $value, $parameters): bool { - $exclude = $parameters[0] ?? null; + $exclude = $parameters[0] ?? null; $query = DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at') ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id); if (!is_null($exclude)) { @@ -292,12 +292,33 @@ class FireflyValidator extends Validator return true; } + /** + * @param int $index + * + * @return string + */ + private function getRuleTriggerName($index): string + { + return $this->data['rule-trigger'][$index] ?? 'invalid'; + + } + + /** + * @param int $index + * + * @return string + */ + private function getRuleTriggerValue($index): string + { + return $this->data['rule-trigger-value'][$index] ?? ''; + } + /** * @param $value * * @return mixed */ - protected function tryDecrypt($value) + private function tryDecrypt($value) { try { $value = Crypt::decrypt($value); @@ -311,7 +332,7 @@ class FireflyValidator extends Validator /** * @return bool */ - protected function validateAccountAnonymously() + private function validateAccountAnonymously(): bool { if (!isset($this->data['user_id'])) { return false; @@ -340,7 +361,7 @@ class FireflyValidator extends Validator * @internal param $parameters * */ - protected function validateByAccountId($value) + private function validateByAccountId($value): bool { /** @var Account $existingAccount */ $existingAccount = Account::find($this->data['id']); @@ -367,7 +388,7 @@ class FireflyValidator extends Validator * * @return bool */ - protected function validateByAccountTypeId($value, $parameters) + private function validateByAccountTypeId($value, $parameters): bool { $type = AccountType::find($this->data['account_type_id'])->first(); $ignore = $parameters[0] ?? 0; @@ -391,7 +412,7 @@ class FireflyValidator extends Validator * * @return bool */ - protected function validateByAccountTypeString($value, $parameters) + private function validateByAccountTypeString($value, $parameters): bool { $search = Config::get('firefly.accountTypeByIdentifier.' . $this->data['what']); $type = AccountType::whereType($search)->first(); @@ -407,26 +428,5 @@ class FireflyValidator extends Validator return true; } - - /** - * @param int $index - * - * @return string - */ - private function getRuleTriggerName($index) - { - return $this->data['rule-trigger'][$index] ?? 'invalid'; - - } - - /** - * @param int $index - * - * @return string - */ - private function getRuleTriggerValue($index) - { - return $this->data['rule-trigger-value'][$index] ?? ''; - } }