Skip to content

Commit

Permalink
Improved parsed banking transaction mails/parsed mail logs.
Browse files Browse the repository at this point in the history
- Added ability to change parsed mail's state.
- Added ability to change parsed mail's note.
- Added ability to track source bank account (updated `CsobMailParser` & `TatraBankaMailParser` + logging through `MailProcessor`)
- Refactored `ParsedMailLog`'s State constants/enum
- Added `EnumHelper` to simplify work with enum especially with Nette forms (enum values listing)

remp/respekt#189
  • Loading branch information
burithetech committed May 20, 2024
1 parent 85183a0 commit 1a37c7b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Helpers/EnumHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Crm\ApplicationModule\Helpers;

/**
* @method static array cases() IDE helper because there can't be defined self::cases() as an abstract static method.
*/
trait EnumHelper
{
public static function names(): array
{
return array_column(self::cases(), 'name');
}

public static function values(): array
{
return array_column(self::cases(), 'value');
}

/**
* List of enum values as 'enum value'=>'friendly name'. Initially intended for use in a Nette forms.
* Without overriding the method returns the 'friendly name' the same as the 'enum value' or
* in case of non-backed enum it returns a pair of 'enum keys'.
*/
public static function getFriendlyList(): array
{
$values = self::values();

$isNonBackedEnum = count($values) === 0;
if ($isNonBackedEnum) {
$names = self::names();
return array_combine($names, $names);
}

return array_combine($values, $values);
}
}

0 comments on commit 1a37c7b

Please sign in to comment.