Code cleanup

This commit is contained in:
James Cole 2019-08-17 10:47:29 +02:00
parent 23479790fe
commit c2296c3ad5
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
95 changed files with 463 additions and 507 deletions

View File

@ -33,9 +33,9 @@ class Amount implements ConverterInterface
* Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
* - Jamie Zawinski.
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*
*
* @param $value
*
* @return string

View File

@ -46,7 +46,7 @@ class FakeJobConfiguration implements JobConfigurationInterface
* if stage is not "new", then album must be 'station to station'
*
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function configurationComplete(): bool
{
@ -70,7 +70,7 @@ class FakeJobConfiguration implements JobConfigurationInterface
*
* @return MessageBag
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function configureJob(array $data): MessageBag
{
@ -128,7 +128,7 @@ class FakeJobConfiguration implements JobConfigurationInterface
*
* @return string
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function getNextView(): string
{

View File

@ -89,10 +89,10 @@ class FileJobConfiguration implements JobConfigurationInterface
/**
* Returns the view of the next step in the job configuration.
*
* @throws FireflyException
* @return string
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*@throws FireflyException
*/
public function getNextView(): string
{
@ -132,7 +132,7 @@ class FileJobConfiguration implements JobConfigurationInterface
* @return FileConfigurationInterface
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
private function getConfigurationObject(): FileConfigurationInterface
{

View File

@ -111,7 +111,7 @@ class SpectreJobConfiguration implements JobConfigurationInterface
* @return SpectreJobConfigurationInterface
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
private function getHandler(): SpectreJobConfigurationInterface
{

View File

@ -109,7 +109,7 @@ class YnabJobConfiguration implements JobConfigurationInterface
* @return YnabJobConfigurationInterface
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
private function getHandler(): YnabJobConfigurationInterface
{

View File

@ -52,8 +52,8 @@ class FakeRoutine implements RoutineInterface
* @return void
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
public function run(): void
{

View File

@ -49,8 +49,8 @@ class SpectreRoutine implements RoutineInterface
*
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
public function run(): void
{

View File

@ -64,7 +64,7 @@ class AbnAmroDescription implements SpecificInterface
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function run(array $row): array
{
@ -132,8 +132,8 @@ class AbnAmroDescription implements SpecificInterface
*
* @return bool true if the description is SEPA format, false otherwise
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
protected function parseSepaDescription(): bool
{
@ -189,8 +189,8 @@ class AbnAmroDescription implements SpecificInterface
*
* @return bool true if the description is TRTP format, false otherwise
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
protected function parseTRTPDescription(): bool
{

View File

@ -61,7 +61,7 @@ class Belfius implements SpecificInterface
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function run(array $row): array
{

View File

@ -59,7 +59,7 @@ class IngBelgium implements SpecificInterface
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function run(array $row): array
{

View File

@ -66,7 +66,7 @@ class IngDescription implements SpecificInterface
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function run(array $row): array
{

View File

@ -59,7 +59,7 @@ class RabobankDescription implements SpecificInterface
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function run(array $row): array
{

View File

@ -51,7 +51,7 @@ use Log;
*
* Class ImportArrayStorage
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class ImportArrayStorage
{
@ -201,8 +201,8 @@ class ImportArrayStorage
* @return Collection
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
private function storeGroupArray(): Collection
{
@ -388,9 +388,9 @@ class ImportArrayStorage
*
* @return bool
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*
*
*
*/
private function transferExists(array $transaction): bool
{

View File

@ -67,7 +67,7 @@ use Log;
/**
* Class CreateRecurringTransactions.
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*
*/
class CreateRecurringTransactions implements ShouldQueue
@ -228,7 +228,7 @@ class CreateRecurringTransactions implements ShouldQueue
* @param Carbon $date
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*/
private function getTransactionData(Recurrence $recurrence, Carbon $date): array
{
@ -441,8 +441,8 @@ class CreateRecurringTransactions implements ShouldQueue
* @param Recurrence $recurrence
*
* @return bool
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*
*/
private function validRecurrence(Recurrence $recurrence): bool
{

View File

@ -30,6 +30,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class AccessTokenCreatedMail
*
* @codeCoverageIgnore
*/
class AccessTokenCreatedMail extends Mailable

View File

@ -30,6 +30,7 @@ use Illuminate\Queue\SerializesModels;
* Class AdminTestMail.
*
* Sends a test mail to administrators.
*
* @codeCoverageIgnore
*/
class AdminTestMail extends Mailable

View File

@ -30,6 +30,7 @@ use Illuminate\Queue\SerializesModels;
* Class ConfirmEmailChangeMail
*
* Sends message to new address to confirm change.
*
* @codeCoverageIgnore
*/
class ConfirmEmailChangeMail extends Mailable

View File

@ -31,6 +31,7 @@ use Laravel\Passport\Client;
/**
* Class OAuthTokenCreatedMail
*
* @codeCoverageIgnore
*/
class OAuthTokenCreatedMail extends Mailable

View File

@ -31,6 +31,7 @@ use Illuminate\Queue\SerializesModels;
* Sends newly registered user an email message.
*
* Class RegisteredUser
*
* @codeCoverageIgnore
*/
class RegisteredUser extends Mailable

View File

@ -31,6 +31,7 @@ use Illuminate\Support\Collection;
* Class ReportNewJournalsMail.
*
* Sends a list of newly created journals to the user.
*
* @codeCoverageIgnore
*/
class ReportNewJournalsMail extends Mailable

View File

@ -30,6 +30,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Sends user link for new password.
* Class RequestedNewPassword
*
* @codeCoverageIgnore
*/
class RequestedNewPassword extends Mailable

View File

@ -28,6 +28,7 @@ use Illuminate\Queue\SerializesModels;
/**
* Class UndoEmailChangeMail
*
* @codeCoverageIgnore
*/
class UndoEmailChangeMail extends Mailable

View File

@ -23,13 +23,11 @@ declare(strict_types=1);
namespace FireflyIII\Models;
use Carbon\Carbon;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class Transaction.
@ -159,8 +157,6 @@ class Transaction extends Model
/**
* Check if a table is joined.
*
*
*
* @param Builder $query
* @param string $table
*

View File

@ -112,7 +112,7 @@ class EventServiceProvider extends ServiceProvider
}
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*/
protected function registerCreateEvents(): void
{

View File

@ -53,8 +53,8 @@ use FireflyIII\Services\IP\IPRetrievalInterface;
use FireflyIII\Services\Password\PwndVerifierV3;
use FireflyIII\Services\Password\Verifier;
use FireflyIII\Support\Amount;
use FireflyIII\Support\FireflyConfig;
use FireflyIII\Support\ExpandedForm;
use FireflyIII\Support\FireflyConfig;
use FireflyIII\Support\Form\AccountForm;
use FireflyIII\Support\Form\CurrencyForm;
use FireflyIII\Support\Form\PiggyBankForm;
@ -63,9 +63,9 @@ use FireflyIII\Support\Navigation;
use FireflyIII\Support\Preferences;
use FireflyIII\Support\Steam;
use FireflyIII\Support\Twig\AmountFormat;
use FireflyIII\Support\Twig\TransactionGroupTwig;
use FireflyIII\Support\Twig\General;
use FireflyIII\Support\Twig\Rule;
use FireflyIII\Support\Twig\TransactionGroupTwig;
use FireflyIII\Support\Twig\Translation;
use FireflyIII\Validation\FireflyValidator;
use Illuminate\Foundation\Application;
@ -80,7 +80,7 @@ use Validator;
* Class FireflyServiceProvider.
*
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class FireflyServiceProvider extends ServiceProvider
{
@ -108,7 +108,7 @@ class FireflyServiceProvider extends ServiceProvider
/**
* Register stuff.
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*/
public function register(): void
{

View File

@ -40,7 +40,7 @@ use Log;
/**
* Class AccountRepository.
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class AccountRepository implements AccountRepositoryInterface
{

View File

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Attachment;
use Carbon\Carbon;
use Crypt;
use Exception;
use FireflyIII\Exceptions\FireflyException;
@ -38,7 +37,7 @@ use Log;
/**
* Class AttachmentRepository.
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class AttachmentRepository implements AttachmentRepositoryInterface
{

View File

@ -41,7 +41,7 @@ use Log;
/**
* Class BillRepository.
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class BillRepository implements BillRepositoryInterface
{

View File

@ -46,9 +46,9 @@ use Navigation;
/**
* Class BudgetRepository.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*
*
*
*/
class BudgetRepository implements BudgetRepositoryInterface
{
@ -105,7 +105,7 @@ class BudgetRepository implements BudgetRepositoryInterface
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array
{
@ -173,8 +173,8 @@ class BudgetRepository implements BudgetRepositoryInterface
* @param Carbon $end
*
* @return Collection
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
public function getBudgetLimits(Budget $budget, Carbon $start = null, Carbon $end = null): Collection
{
@ -335,8 +335,8 @@ class BudgetRepository implements BudgetRepositoryInterface
* @param Budget $budget
*
* @return Carbon
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
public function firstUseDate(Budget $budget): ?Carbon
{
@ -377,8 +377,8 @@ class BudgetRepository implements BudgetRepositoryInterface
* @param Carbon $end
*
* @return Collection
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
public function getAllBudgetLimits(Carbon $start = null, Carbon $end = null): Collection
{
@ -870,7 +870,7 @@ class BudgetRepository implements BudgetRepositoryInterface
/**
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's 5.
* // it's 5.
*/
public function cleanupBudgets(): bool
{
@ -992,8 +992,8 @@ class BudgetRepository implements BudgetRepositoryInterface
* @param string $amount
*
* @return BudgetLimit|null
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, string $amount): ?BudgetLimit
{

View File

@ -37,9 +37,9 @@ use Navigation;
/**
* Class CategoryRepository.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*
*
*
*/
class CategoryRepository implements CategoryRepositoryInterface
{
@ -323,7 +323,7 @@ class CategoryRepository implements CategoryRepositoryInterface
* @param Category $category
*
* @return Carbon|null
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function firstUseDate(Category $category): ?Carbon
{
@ -365,7 +365,7 @@ class CategoryRepository implements CategoryRepositoryInterface
*
* @return Carbon|null
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function lastUseDate(Category $category, Collection $accounts): ?Carbon
{

View File

@ -38,7 +38,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Class ImportJobRepository.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
*/
class ImportJobRepository implements ImportJobRepositoryInterface
{

View File

@ -34,7 +34,7 @@ use Log;
/**
* Class LinkTypeRepository.
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*
*/
class LinkTypeRepository implements LinkTypeRepositoryInterface
{
@ -252,7 +252,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
* @param TransactionJournal $outward
*
* @return TransactionJournalLink|null
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function storeLink(array $information, TransactionJournal $inward, TransactionJournal $outward): ?TransactionJournalLink
{
@ -347,7 +347,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
* @param TransactionJournalLink $link
* @param string $text
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @throws \Exception
*/
private function setNoteText(TransactionJournalLink $link, string $text): void

View File

@ -37,8 +37,8 @@ use Log;
/**
* Class PiggyBankRepository.
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*
*
*/
class PiggyBankRepository implements PiggyBankRepositoryInterface
{
@ -293,7 +293,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
* @param TransactionJournal $journal
*
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function getExactAmount(PiggyBank $piggyBank, PiggyBankRepetition $repetition, TransactionJournal $journal): string
{
@ -406,7 +406,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
* @param PiggyBank $piggyBank
*
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function getSuggestedMonthlyAmount(PiggyBank $piggyBank): string
{

View File

@ -234,9 +234,8 @@ class RecurringRepository implements RecurringRepositoryInterface
* @param Carbon $start
* @param Carbon $end
*
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function getOccurrencesInRange(RecurrenceRepetition $repetition, Carbon $start, Carbon $end): array
{
@ -366,7 +365,7 @@ class RecurringRepository implements RecurringRepositoryInterface
* @param int $count
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function getXOccurrences(RecurrenceRepetition $repetition, Carbon $date, int $count): array
{
@ -400,7 +399,7 @@ class RecurringRepository implements RecurringRepositoryInterface
* @param RecurrenceRepetition $repetition
*
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function repetitionDescription(RecurrenceRepetition $repetition): string
{

View File

@ -34,7 +34,7 @@ use Log;
/**
* Class RuleRepository.
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*
*/
class RuleRepository implements RuleRepositoryInterface
{

View File

@ -36,7 +36,7 @@ use Log;
/**
* Class TagRepository.
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*
*/
class TagRepository implements TagRepositoryInterface
{
@ -272,7 +272,7 @@ class TagRepository implements TagRepositoryInterface
* @param Carbon|null $end
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function sumsOfTag(Tag $tag, ?Carbon $start, ?Carbon $end): array
{
@ -410,7 +410,7 @@ class TagRepository implements TagRepositoryInterface
* @param Collection $tags
*
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
private function getMinAmount(Collection $tags): string
{

View File

@ -32,7 +32,7 @@ use Log;
/**
* Class UserRepository.
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*
*/
class UserRepository implements UserRepositoryInterface
{

View File

@ -69,8 +69,8 @@ class BelongsUser implements Rule
* @return bool
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
public function passes($attribute, $value): bool
{
@ -110,7 +110,7 @@ class BelongsUser implements Rule
*
* @return int
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function countField(string $class, string $field, string $value): int
{

View File

@ -50,8 +50,6 @@ class IsAssetAccountId implements Rule
* @param mixed $value
*
* @return bool
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function passes($attribute, $value): bool
{

View File

@ -74,8 +74,6 @@ class IsValidAttachmentModel implements Rule
* @param mixed $value
*
* @return bool
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function passes($attribute, $value): bool
{

View File

@ -72,8 +72,8 @@ class UniqueIban implements Rule
* @param mixed $value
*
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
*
*/
public function passes($attribute, $value): bool
{
@ -127,7 +127,7 @@ class UniqueIban implements Rule
/**
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
private function getMaxOccurrences(): array
{

View File

@ -52,7 +52,7 @@ class ValidJournals implements Rule
* @param mixed $value
*
* @return bool
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
*/
public function passes($attribute, $value): bool
{

View File

@ -49,8 +49,8 @@ class ValidRecurrenceRepetitionType implements Rule
* @param mixed $value
*
* @return bool
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*
*/
public function passes($attribute, $value): bool
{

View File

@ -53,8 +53,8 @@ class ValidRecurrenceRepetitionValue implements Rule
* @param mixed $value
*
* @return bool
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*
*/
public function passes($attribute, $value): bool
{
@ -104,7 +104,7 @@ class ValidRecurrenceRepetitionValue implements Rule
*
* @return bool
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
private function validateNdom(string $value): bool
{

View File

@ -47,9 +47,9 @@ class ApiContext
* @param array $permittedIps
* @param string|null $proxyUrl
*
* @throws FireflyException
* @return BunqApiContext|FakeApiContext
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*
*@throws FireflyException
*/
public function create(BunqEnumApiEnvironmentType $environmentType, string $apiKey, string $description, array $permittedIps, string $proxyUrl = null
) {

View File

@ -48,7 +48,7 @@ class RecurrenceDestroyService
* Delete recurrence.
*
* @param Recurrence $recurrence
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function destroy(Recurrence $recurrence): void
{

View File

@ -86,7 +86,7 @@ trait AccountServiceTrait
*
* @param Account $account
* @param array $data
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function updateMetaData(Account $account, array $data): void
{

View File

@ -263,7 +263,7 @@ trait JournalServiceTrait
*
* @param TransactionJournal $journal
* @param array $tags
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*
* @codeCoverageIgnore
*/

View File

@ -34,7 +34,7 @@ class Holder extends SpectreObject
* Holder constructor.
*
* @param array $data
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
*/
public function __construct(array $data)
{

View File

@ -175,7 +175,7 @@ class Transaction extends SpectreObject
* Get opposing account data.
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function getOpposingAccountData(): array
{

View File

@ -41,7 +41,7 @@ class ListAccountsRequest extends SpectreRequest
/**
* @throws FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function call(): void
{

View File

@ -39,7 +39,7 @@ class ListCustomersRequest extends SpectreRequest
/**
*
* @throws \FireflyIII\Exceptions\FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function call(): void
{

View File

@ -43,7 +43,7 @@ class ListLoginsRequest extends SpectreRequest
/**
* @throws FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function call(): void
{

View File

@ -41,7 +41,7 @@ class ListTransactionsRequest extends SpectreRequest
/**
* @throws FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function call(): void
{

View File

@ -50,8 +50,6 @@ class Amount
*
* @return string
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public static function getAmountJsConfig(bool $sepBySpace, int $signPosn, string $sign, bool $csPrecedes): string
{
@ -122,7 +120,7 @@ class Amount
* @param bool $coloured
*
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function formatAnything(TransactionCurrency $format, string $amount, bool $coloured = null): string
{
@ -164,7 +162,7 @@ class Amount
* @param bool $coloured
*
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @noinspection MoreThanThreeArgumentsInspection
*/
public function formatFlat(string $symbol, int $decimalPlaces, string $amount, bool $coloured = null): string

View File

@ -40,7 +40,7 @@ class AccountList implements BinderInterface
*
* @return Collection
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public static function routeBinder(string $value, Route $route): Collection
{

View File

@ -39,7 +39,7 @@ class BudgetList implements BinderInterface
*
* @return Collection
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public static function routeBinder(string $value, Route $route): Collection
{

View File

@ -38,7 +38,7 @@ class CategoryList implements BinderInterface
*
* @return Collection
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public static function routeBinder(string $value, Route $route): Collection
{

View File

@ -27,7 +27,6 @@ use FireflyIII\Import\Prerequisites\PrerequisitesInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Routing\Route;
use Log;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
@ -37,8 +36,8 @@ class ImportProvider implements BinderInterface
{
/**
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
public static function getProviders(): array
{

View File

@ -23,32 +23,17 @@ declare(strict_types=1);
namespace FireflyIII\Support;
use Amount as Amt;
use Carbon\Carbon;
use Eloquent;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Support\Form\FormSupport;
use Form;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Support\MessageBag;
use Log;
use RuntimeException;
use Throwable;
/**
* Class ExpandedForm.
*
* @SuppressWarnings(PHPMD.TooManyMethods)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*
* @codeCoverageIgnore
*/
class ExpandedForm
@ -225,7 +210,7 @@ class ExpandedForm
* @param \Illuminate\Support\Collection $set
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function makeSelectListWithEmpty(Collection $set): array
{

View File

@ -117,7 +117,7 @@ class CurrencyForm
* @param array $options
*
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function allCurrencyField(string $name, string $view, $value = null, array $options = null): string
{
@ -168,7 +168,7 @@ class CurrencyForm
* @param array $options
*
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function currencyField(string $name, string $view, $value = null, array $options = null): string
{

View File

@ -79,8 +79,8 @@ trait AugumentData
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
protected function earnedByCategory(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
{
@ -352,7 +352,7 @@ trait AugumentData
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function getExpensesForBudget(Collection $limits, Budget $budget, Carbon $start, Carbon $end): array // get data + augment with info
{
@ -397,7 +397,7 @@ trait AugumentData
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*
*/
protected function spentInPeriodMulti(Budget $budget, Collection $limits): array // get data + augment with info
@ -586,8 +586,8 @@ trait AugumentData
* @param Carbon $end
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
protected function spentByBudget(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
{
@ -647,8 +647,8 @@ trait AugumentData
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
protected function spentByCategory(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
{

View File

@ -47,8 +47,8 @@ trait ChartGeneration
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
protected function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array // chart helper method.
{

View File

@ -88,7 +88,7 @@ trait GetConfigurationData
* Get config for date range.
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*/
protected function getDateRangeConfig(): array // get configuration + get preferences.
{
@ -177,7 +177,7 @@ trait GetConfigurationData
* @param string $specificPage
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function getSpecificSteps(string $route, string $specificPage): array // get config values
{

View File

@ -28,7 +28,6 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
@ -281,7 +280,7 @@ trait PeriodOverview
* @param Carbon $theDate
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*/
protected function getNoCategoryPeriodOverview(Carbon $theDate): array
{

View File

@ -83,7 +83,7 @@ trait RenderPartialViews
*
* @return string
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function balanceAmount(array $attributes): string // generate view for report.
{

View File

@ -65,8 +65,8 @@ trait RequestInformation
* @param string $language
*
* @return string
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*
*/
protected function getHelpText(string $route, string $language): string // get from internet.
{
@ -213,7 +213,7 @@ trait RequestInformation
* @param Carbon $date
*
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function notInSessionRange(Carbon $date): bool // Validate a preference
{

View File

@ -109,8 +109,6 @@ trait TransactionCalculation
* @param Carbon $end
*
* @return array
*
*
*/
protected function getExpensesInCategories(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): array
{
@ -175,8 +173,6 @@ trait TransactionCalculation
* @param Carbon $end
*
* @return Collection
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
protected function getIncomeForTags(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): array
{

View File

@ -272,7 +272,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
*
* @return array
* @throws FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function getValuesForMapping(Reader $reader, array $config, array $columnConfig): array
{

View File

@ -58,7 +58,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
* @param array $config
*
* @return MessageBag
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function configurationComplete(array $config): MessageBag
{

View File

@ -110,7 +110,7 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterface
*
* @return array
* @throws FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function getNextData(): array
{

View File

@ -132,7 +132,7 @@ class ImportTransaction
* @param ColumnValue $columnValue
*
* @throws FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function addColumnValue(ColumnValue $columnValue): void
{

View File

@ -60,7 +60,7 @@ class AssetAccountMapper
* @param array $data
*
* @return Account
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function map(?int $accountId, array $data): Account
{

View File

@ -81,7 +81,7 @@ class MappedValuesValidator
*
* @return array
* @throws FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function validate(array $mappings): array
{

View File

@ -45,7 +45,7 @@ class OpposingAccountMapper
* @param array $data
*
* @return Account
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function map(?int $accountId, string $amount, array $data): Account
{

View File

@ -108,7 +108,7 @@ class StageImportDataHandler
* @param LocalAccount $originalSource
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
private function convertToArray(array $transactions, SpectreAccount $spectreAccount, LocalAccount $originalSource): array
{

View File

@ -104,7 +104,7 @@ class Navigation
*
* @return array
* @throws \FireflyIII\Exceptions\FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
public function blockPeriods(\Carbon\Carbon $start, \Carbon\Carbon $end, string $range): array
{

View File

@ -70,7 +70,7 @@ trait CalculateRangeOccurrences
* @param string $moment
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function getMonthlyInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
{
@ -150,7 +150,7 @@ trait CalculateRangeOccurrences
* @param string $moment
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function getWeeklyInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
{
@ -194,7 +194,7 @@ trait CalculateRangeOccurrences
* @param string $moment
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
protected function getYearlyInRange(Carbon $start, Carbon $end, int $skipMod, string $moment): array
{

View File

@ -42,8 +42,8 @@ trait FiltersWeekends
* @param array $dates
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
*
*/
protected function filterWeekends(RecurrenceRepetition $repetition, array $dates): array
{

View File

@ -181,7 +181,7 @@ class Search implements SearchInterface
* @param GroupCollectorInterface $collector
*
* @return GroupCollectorInterface
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
private function applyModifiers(GroupCollectorInterface $collector): GroupCollectorInterface
{

View File

@ -22,6 +22,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use Exception;
use FireflyIII\Models\Note;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
@ -47,7 +48,7 @@ class ClearNotes implements ActionInterface
* @param TransactionJournal $journal
*
* @return bool
* @throws \Exception
* @throws Exception
*/
public function act(TransactionJournal $journal): bool
{

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@ -57,7 +58,7 @@ class ConvertToDeposit implements ActionInterface
* @param TransactionJournal $journal
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
* @throws FireflyException
*/
public function act(TransactionJournal $journal): bool
{
@ -121,7 +122,7 @@ class ConvertToDeposit implements ActionInterface
* @param TransactionJournal $journal
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
* @throws FireflyException
*/
private function convertTransfer(TransactionJournal $journal): bool
{
@ -163,7 +164,7 @@ class ConvertToDeposit implements ActionInterface
* @param TransactionJournal $journal
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
* @throws FireflyException
*/
private function convertWithdrawal(TransactionJournal $journal): bool
{

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@ -58,7 +59,7 @@ class ConvertToWithdrawal implements ActionInterface
* @param TransactionJournal $journal
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
* @throws FireflyException
*/
public function act(TransactionJournal $journal): bool
{
@ -122,7 +123,7 @@ class ConvertToWithdrawal implements ActionInterface
* @param TransactionJournal $journal
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
* @throws FireflyException
*/
private function convertDeposit(TransactionJournal $journal): bool
{
@ -175,7 +176,7 @@ class ConvertToWithdrawal implements ActionInterface
* @param TransactionJournal $journal
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
* @throws FireflyException
*/
private function convertTransfer(TransactionJournal $journal): bool
{

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionJournal;
use Log;
@ -47,6 +46,7 @@ class RemoveTag implements ActionInterface
/**
* Remove tag X
*
* @param TransactionJournal $journal
*
* @return bool
@ -55,7 +55,7 @@ class RemoveTag implements ActionInterface
{
// if tag does not exist, no need to continue:
$name = $this->action->action_value;
$tag = $journal->user->tags()->where('tag', $name)->first();
$tag = $journal->user->tags()->where('tag', $name)->first();
if (null !== $tag) {
Log::debug(sprintf('RuleAction RemoveTag removed tag #%d ("%s") from journal #%d.', $tag->id, $tag->tag, $journal->id));

View File

@ -47,13 +47,14 @@ class SetBudget implements ActionInterface
/**
* Set budget.
*
* @param TransactionJournal $journal
*
* @return bool
*/
public function act(TransactionJournal $journal): bool
{
$search = $this->action->action_value;
$search = $this->action->action_value;
$budget = $journal->user->budgets()->where('name', $search)->first();
if (null === $budget) {

View File

@ -24,7 +24,6 @@ namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Log;

View File

@ -133,9 +133,9 @@ class SetDestinationAccount implements ActionInterface
if (null === $account) {
$data = [
'name' => $this->action->action_value,
'account_type' => 'expense',
'account_type' => 'expense',
'account_type_id' => null,
'virtual_balance' => 0,
'virtual_balance' => 0,
'active' => true,
'iban' => null,
];

View File

@ -137,9 +137,9 @@ class SetSourceAccount implements ActionInterface
// create new revenue account with this name:
$data = [
'name' => $this->action->action_value,
'account_type' => 'revenue',
'account_type' => 'revenue',
'account_type_id' => null,
'virtual_balance' => 0,
'virtual_balance' => 0,
'active' => true,
'iban' => null,
];

View File

@ -45,19 +45,18 @@ class RuleEngine
public const TRIGGER_STORE = 1;
/** @var int */
public const TRIGGER_UPDATE = 2;
/** @var bool */
private $allRules;
/** @var RuleGroupRepository */
private $ruleGroupRepository;
/** @var Collection */
private $ruleGroups;
/** @var array */
private $rulesToApply;
/** @var bool */
private $allRules;
/** @var User */
private $user;
/** @var RuleGroupRepository */
private $ruleGroupRepository;
/** @var int */
private $triggerMode;
/** @var User */
private $user;
/**
* RuleEngine constructor.
@ -72,94 +71,6 @@ class RuleEngine
$this->triggerMode = self::TRIGGER_STORE;
}
/**
* @param int $triggerMode
*/
public function setTriggerMode(int $triggerMode): void
{
$this->triggerMode = $triggerMode;
}
/**
* @param bool $allRules
*/
public function setAllRules(bool $allRules): void
{
Log::debug('RuleEngine will apply ALL rules.');
$this->allRules = $allRules;
}
/**
* @param array $rulesToApply
*/
public function setRulesToApply(array $rulesToApply): void
{
Log::debug('RuleEngine will try rules', $rulesToApply);
$this->rulesToApply = $rulesToApply;
}
/**
* @param User $user
*/
public function setUser(User $user): void
{
$this->user = $user;
$this->ruleGroupRepository->setUser($user);
$this->ruleGroups = $this->ruleGroupRepository->getActiveGroups();
}
/**
* @param TransactionJournal $transactionJournal
*/
public function processTransactionJournal(TransactionJournal $transactionJournal): void
{
Log::debug(sprintf('Will process transaction journal #%d ("%s")', $transactionJournal->id, $transactionJournal->description));
/** @var RuleGroup $group */
foreach ($this->ruleGroups as $group) {
Log::debug(sprintf('Now at rule group #%d', $group->id));
$groupTriggered = false;
/** @var Rule $rule */
foreach ($group->rules as $rule) {
Log::debug(sprintf('Now at rule #%d from rule group #%d', $rule->id, $group->id));
$ruleTriggered = false;
// if in rule selection, or group in selection or all rules, it's included.
if ($this->includeRule($rule)) {
Log::debug(sprintf('Rule #%d is included.', $rule->id));
/** @var Processor $processor */
$processor = app(Processor::class);
$ruleTriggered = false;
try {
$processor->make($rule, true);
$ruleTriggered = $processor->handleTransactionJournal($transactionJournal);
} catch (FireflyException $e) {
Log::error($e->getMessage());
}
if ($ruleTriggered) {
Log::debug('The rule was triggered, so the group is as well!');
$groupTriggered = true;
}
}
if (!$this->includeRule($rule)) {
Log::debug(sprintf('Rule #%d is not included.', $rule->id));
}
// if the rule is triggered and stop processing is true, cancel the entire group.
if ($ruleTriggered && $rule->stop_processing) {
Log::info(sprintf('Break out group #%d because rule #%d was triggered.', $group->id, $rule->id));
break;
}
}
// if group is triggered and stop processing is true, cancel the whole thing.
if ($groupTriggered && $group->stop_processing) {
Log::info(sprintf('Break out ALL because group #%d was triggered.', $group->id));
break;
}
}
Log::debug('Done processing this transaction journal.');
}
/**
* @param array $journal
*/
@ -212,8 +123,96 @@ class RuleEngine
Log::debug('Done processing this transaction journal.');
}
/**
* @param TransactionJournal $transactionJournal
*/
public function processTransactionJournal(TransactionJournal $transactionJournal): void
{
Log::debug(sprintf('Will process transaction journal #%d ("%s")', $transactionJournal->id, $transactionJournal->description));
/** @var RuleGroup $group */
foreach ($this->ruleGroups as $group) {
Log::debug(sprintf('Now at rule group #%d', $group->id));
$groupTriggered = false;
/** @var Rule $rule */
foreach ($group->rules as $rule) {
Log::debug(sprintf('Now at rule #%d from rule group #%d', $rule->id, $group->id));
$ruleTriggered = false;
// if in rule selection, or group in selection or all rules, it's included.
if ($this->includeRule($rule)) {
Log::debug(sprintf('Rule #%d is included.', $rule->id));
/** @var Processor $processor */
$processor = app(Processor::class);
$ruleTriggered = false;
try {
$processor->make($rule, true);
$ruleTriggered = $processor->handleTransactionJournal($transactionJournal);
} catch (FireflyException $e) {
Log::error($e->getMessage());
}
if ($ruleTriggered) {
Log::debug('The rule was triggered, so the group is as well!');
$groupTriggered = true;
}
}
if (!$this->includeRule($rule)) {
Log::debug(sprintf('Rule #%d is not included.', $rule->id));
}
// if the rule is triggered and stop processing is true, cancel the entire group.
if ($ruleTriggered && $rule->stop_processing) {
Log::info(sprintf('Break out group #%d because rule #%d was triggered.', $group->id, $rule->id));
break;
}
}
// if group is triggered and stop processing is true, cancel the whole thing.
if ($groupTriggered && $group->stop_processing) {
Log::info(sprintf('Break out ALL because group #%d was triggered.', $group->id));
break;
}
}
Log::debug('Done processing this transaction journal.');
}
/**
* @param bool $allRules
*/
public function setAllRules(bool $allRules): void
{
Log::debug('RuleEngine will apply ALL rules.');
$this->allRules = $allRules;
}
/**
* @param array $rulesToApply
*/
public function setRulesToApply(array $rulesToApply): void
{
Log::debug('RuleEngine will try rules', $rulesToApply);
$this->rulesToApply = $rulesToApply;
}
/**
* @param int $triggerMode
*/
public function setTriggerMode(int $triggerMode): void
{
$this->triggerMode = $triggerMode;
}
/**
* @param User $user
*/
public function setUser(User $user): void
{
$this->user = $user;
$this->ruleGroupRepository->setUser($user);
$this->ruleGroups = $this->ruleGroupRepository->getActiveGroups();
}
/**
* @param Rule $rule
*
* @return bool
*/
private function includeRule(Rule $rule): bool
@ -224,8 +223,8 @@ class RuleEngine
return false;
}
$validTrigger = ('store-journal' === $trigger->trigger_value && self::TRIGGER_STORE === $this->triggerMode) ||
('update-journal' === $trigger->trigger_value && self::TRIGGER_UPDATE === $this->triggerMode);
$validTrigger = ('store-journal' === $trigger->trigger_value && self::TRIGGER_STORE === $this->triggerMode)
|| ('update-journal' === $trigger->trigger_value && self::TRIGGER_UPDATE === $this->triggerMode);
return $validTrigger && ($this->allRules || in_array($rule->id, $this->rulesToApply, true));
}

View File

@ -78,11 +78,11 @@ class TriggerFactory
* @param string $triggerValue
* @param bool $stopProcessing
*
* @see TriggerFactory::getTrigger
*
* @return AbstractTrigger
*
* @throws FireflyException
* @see TriggerFactory::getTrigger
*
*/
public static function makeTriggerFromStrings(string $triggerType, string $triggerValue, bool $stopProcessing): AbstractTrigger
{

View File

@ -22,6 +22,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\RuleTrigger;
@ -62,16 +63,71 @@ class Processor
$this->actions = new Collection;
}
/**
* Return found triggers
*
* @return int
*/
public function getFoundTriggers(): int
{
return $this->foundTriggers;
}
/**
* Set found triggers
*
* @param int $foundTriggers
*/
public function setFoundTriggers(int $foundTriggers): void
{
$this->foundTriggers = $foundTriggers;
}
/**
* Returns the rule
*
* @return \FireflyIII\Models\Rule
* @return Rule
*/
public function getRule(): Rule
{
return $this->rule;
}
/**
* This method will scan the given transaction journal and check if it matches the triggers found in the Processor
* If so, it will also attempt to run the given actions on the journal. It returns a bool indicating if the transaction journal
* matches all of the triggers (regardless of whether the Processor could act on it).
*
* @param array $journal
*
* @return bool
* @throws FireflyException
*/
public function handleJournalArray(array $journal): bool
{
Log::debug(sprintf('handleJournalArray for journal #%d (group #%d)', $journal['transaction_journal_id'], $journal['transaction_group_id']));
// grab the actual journal.
$this->journal = TransactionJournal::find($journal['transaction_journal_id']);
// get all triggers:
$triggered = $this->triggered();
if ($triggered) {
Log::debug('Rule is triggered, go to actions.');
if ($this->actions->count() > 0) {
Log::debug('Has more than zero actions.');
$this->actions();
}
if (0 === $this->actions->count()) {
Log::info('Rule has no actions!');
}
return true;
}
return false;
}
/**
* This method will scan the given transaction journal and check if it matches the triggers found in the Processor
* If so, it will also attempt to run the given actions on the journal. It returns a bool indicating if the transaction journal
@ -80,7 +136,7 @@ class Processor
* @param Transaction $transaction
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
* @throws FireflyException
*/
public function handleTransaction(Transaction $transaction): bool
{
@ -107,6 +163,140 @@ class Processor
return false;
}
/**
* This method will scan the given transaction journal and check if it matches the triggers found in the Processor
* If so, it will also attempt to run the given actions on the journal. It returns a bool indicating if the transaction journal
* matches all of the triggers (regardless of whether the Processor could act on it).
*
* @param TransactionJournal $journal
*
* @return bool
* @throws FireflyException
*/
public function handleTransactionJournal(TransactionJournal $journal): bool
{
Log::debug(sprintf('handleTransactionJournal for journal %d', $journal->id));
$this->journal = $journal;
// get all triggers:
$triggered = $this->triggered();
if ($triggered) {
if ($this->actions->count() > 0) {
$this->actions();
}
return true;
}
return false;
}
/**
* @return bool
*/
public function isStrict(): bool
{
return $this->strict;
}
/**
* @param bool $strict
*/
public function setStrict(bool $strict): void
{
$this->strict = $strict;
}
/**
* This method will make a Processor that will process each transaction journal using the triggers
* and actions found in the given Rule.
*
* @param Rule $rule
* @param bool $includeActions
*
* @throws FireflyException
*/
public function make(Rule $rule, bool $includeActions = null): void
{
$includeActions = $includeActions ?? true;
Log::debug(sprintf('Making new rule from Rule %d', $rule->id));
Log::debug(sprintf('Rule is strict: %s', var_export($rule->strict, true)));
$this->rule = $rule;
$this->strict = $rule->strict;
$triggerSet = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
/** @var RuleTrigger $trigger */
foreach ($triggerSet as $trigger) {
Log::debug(sprintf('Push trigger %d', $trigger->id));
$this->triggers->push(TriggerFactory::getTrigger($trigger));
}
if (true === $includeActions) {
$this->actions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
}
}
/**
* This method will make a Processor that will process each transaction journal using the given
* trigger (singular!). It can only report if the transaction journal was hit by the given trigger
* and will not be able to act on it using actions.
*
* @param string $triggerName
* @param string $triggerValue
*
* @throws FireflyException
*/
public function makeFromString(string $triggerName, string $triggerValue): void
{
Log::debug(sprintf('Processor::makeFromString("%s", "%s")', $triggerName, $triggerValue));
$trigger = TriggerFactory::makeTriggerFromStrings($triggerName, $triggerValue, false);
$this->triggers->push($trigger);
}
/**
* This method will make a Processor that will process each transaction journal using the given
* triggers. It can only report if the transaction journal was hit by the given triggers
* and will not be able to act on it using actions.
*
* The given triggers must be in the following format:
*
* [type => xx, value => yy, stop_processing => bool], [type => xx, value => yy, stop_processing => bool],
*
* @param array $triggers
*
* @throws FireflyException
*/
public function makeFromStringArray(array $triggers): void
{
foreach ($triggers as $entry) {
$entry['value'] = $entry['value'] ?? '';
$trigger = TriggerFactory::makeTriggerFromStrings($entry['type'], $entry['value'], $entry['stop_processing']);
$this->triggers->push($trigger);
}
}
/**
* Run the actions
*
* @return void
* @throws FireflyException
*/
private function actions(): void
{
/**
* @var int
* @var RuleAction $action
*/
foreach ($this->actions as $action) {
/** @var ActionInterface $actionClass */
$actionClass = ActionFactory::getAction($action);
Log::debug(sprintf('Fire action %s on journal #%d', get_class($actionClass), $this->journal->id));
$actionClass->act($this->journal);
if ($action->stop_processing) {
Log::debug('Stop processing now and break.');
break;
}
}
}
/**
* Method to check whether the current transaction would be triggered
* by the given list of triggers.
@ -147,193 +337,4 @@ class Processor
return $result;
}
/**
* Return found triggers
*
* @return int
*/
public function getFoundTriggers(): int
{
return $this->foundTriggers;
}
/**
* Set found triggers
*
* @param int $foundTriggers
*/
public function setFoundTriggers(int $foundTriggers): void
{
$this->foundTriggers = $foundTriggers;
}
/**
* Run the actions
*
* @return void
* @throws \FireflyIII\Exceptions\FireflyException
*/
private function actions(): void
{
/**
* @var int
* @var RuleAction $action
*/
foreach ($this->actions as $action) {
/** @var ActionInterface $actionClass */
$actionClass = ActionFactory::getAction($action);
Log::debug(sprintf('Fire action %s on journal #%d', get_class($actionClass), $this->journal->id));
$actionClass->act($this->journal);
if ($action->stop_processing) {
Log::debug('Stop processing now and break.');
break;
}
}
}
/**
* This method will scan the given transaction journal and check if it matches the triggers found in the Processor
* If so, it will also attempt to run the given actions on the journal. It returns a bool indicating if the transaction journal
* matches all of the triggers (regardless of whether the Processor could act on it).
*
* @param array $journal
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function handleJournalArray(array $journal): bool
{
Log::debug(sprintf('handleJournalArray for journal #%d (group #%d)', $journal['transaction_journal_id'], $journal['transaction_group_id']));
// grab the actual journal.
$this->journal = TransactionJournal::find($journal['transaction_journal_id']);
// get all triggers:
$triggered = $this->triggered();
if ($triggered) {
Log::debug('Rule is triggered, go to actions.');
if ($this->actions->count() > 0) {
Log::debug('Has more than zero actions.');
$this->actions();
}
if (0 === $this->actions->count()) {
Log::info('Rule has no actions!');
}
return true;
}
return false;
}
/**
* This method will scan the given transaction journal and check if it matches the triggers found in the Processor
* If so, it will also attempt to run the given actions on the journal. It returns a bool indicating if the transaction journal
* matches all of the triggers (regardless of whether the Processor could act on it).
*
* @param TransactionJournal $journal
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function handleTransactionJournal(TransactionJournal $journal): bool
{
Log::debug(sprintf('handleTransactionJournal for journal %d', $journal->id));
$this->journal = $journal;
// get all triggers:
$triggered = $this->triggered();
if ($triggered) {
if ($this->actions->count() > 0) {
$this->actions();
}
return true;
}
return false;
}
/**
* @return bool
*/
public function isStrict(): bool
{
return $this->strict;
}
/**
* @param bool $strict
*/
public function setStrict(bool $strict): void
{
$this->strict = $strict;
}
/**
* This method will make a Processor that will process each transaction journal using the triggers
* and actions found in the given Rule.
*
* @param Rule $rule
* @param bool $includeActions
*
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function make(Rule $rule, bool $includeActions = null): void
{
$includeActions = $includeActions ?? true;
Log::debug(sprintf('Making new rule from Rule %d', $rule->id));
Log::debug(sprintf('Rule is strict: %s', var_export($rule->strict, true)));
$this->rule = $rule;
$this->strict = $rule->strict;
$triggerSet = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
/** @var RuleTrigger $trigger */
foreach ($triggerSet as $trigger) {
Log::debug(sprintf('Push trigger %d', $trigger->id));
$this->triggers->push(TriggerFactory::getTrigger($trigger));
}
if (true === $includeActions) {
$this->actions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
}
}
/**
* This method will make a Processor that will process each transaction journal using the given
* trigger (singular!). It can only report if the transaction journal was hit by the given trigger
* and will not be able to act on it using actions.
*
* @param string $triggerName
* @param string $triggerValue
*
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function makeFromString(string $triggerName, string $triggerValue): void
{
Log::debug(sprintf('Processor::makeFromString("%s", "%s")', $triggerName, $triggerValue));
$trigger = TriggerFactory::makeTriggerFromStrings($triggerName, $triggerValue, false);
$this->triggers->push($trigger);
}
/**
* This method will make a Processor that will process each transaction journal using the given
* triggers. It can only report if the transaction journal was hit by the given triggers
* and will not be able to act on it using actions.
*
* The given triggers must be in the following format:
*
* [type => xx, value => yy, stop_processing => bool], [type => xx, value => yy, stop_processing => bool],
*
* @param array $triggers
*
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function makeFromStringArray(array $triggers): void
{
foreach ($triggers as $entry) {
$entry['value'] = $entry['value'] ?? '';
$trigger = TriggerFactory::makeTriggerFromStrings($entry['type'], $entry['value'], $entry['stop_processing']);
$this->triggers->push($trigger);
}
}
}

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleTrigger;
@ -78,7 +79,7 @@ class TransactionMatcher
* triggers onto each transaction journal until enough matches are found ($limit).
*
* @return array
* @throws \FireflyIII\Exceptions\FireflyException
* @throws FireflyException
*/
public function findTransactionsByRule(): array
{
@ -108,7 +109,7 @@ class TransactionMatcher
* triggers onto each transaction journal until enough matches are found ($limit).
*
* @return array
* @throws \FireflyIII\Exceptions\FireflyException
* @throws FireflyException
*/
public function findTransactionsByTriggers(): array
{

View File

@ -127,7 +127,7 @@ class BillTransformer extends AbstractTransformer
* @param Bill $bill
* @param Carbon $date
*
* @return \Carbon\Carbon
* @return Carbon
*/
protected function nextDateMatch(Bill $bill, Carbon $date): Carbon
{

View File

@ -24,10 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Transformers;
use Carbon\Carbon;
use FireflyIII\Models\Category;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Log;

View File

@ -46,8 +46,6 @@ use Illuminate\Validation\Validator;
class FireflyValidator extends Validator
{
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param $attribute
* @param $value
*
@ -65,8 +63,6 @@ class FireflyValidator extends Validator
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param $attribute
* @param $value
* @param $parameters
@ -86,8 +82,6 @@ class FireflyValidator extends Validator
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param $attribute
* @param $value
*
@ -108,8 +102,6 @@ class FireflyValidator extends Validator
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param $attribute
* @param $value
*
@ -191,8 +183,6 @@ class FireflyValidator extends Validator
* @param $attribute
* @param $value
* @param $parameters
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
*/
public function validateLess($attribute, $value, $parameters): bool
@ -207,8 +197,6 @@ class FireflyValidator extends Validator
* @param $attribute
* @param $value
* @param $parameters
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return bool
*/
public function validateMore($attribute, $value, $parameters): bool
@ -220,8 +208,6 @@ class FireflyValidator extends Validator
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param $attribute
* @param $value
* @param $parameters
@ -381,8 +367,6 @@ class FireflyValidator extends Validator
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param $attribute
* @param $value
* @param $parameters
@ -415,8 +399,6 @@ class FireflyValidator extends Validator
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param $attribute
* @param $value
* @param $parameters
@ -452,7 +434,7 @@ class FireflyValidator extends Validator
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* Validate an object and its unicity. Checks for encryption / encrypted values as well.
*
* parameter 0: the table
@ -496,8 +478,6 @@ class FireflyValidator extends Validator
}
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param $attribute
* @param $value
* @param $parameters