Made the magic strings of EventCommentHelper into an array

This commit is contained in:
Jan Böhmer
2024-06-25 22:29:04 +02:00
parent a0a7ca3c9c
commit 6df7bc5f2a
6 changed files with 62 additions and 33 deletions

View File

@@ -29,30 +29,16 @@ namespace App\Services\LogSystem;
*/
class EventCommentNeededHelper
{
final public const VALID_OPERATION_TYPES = [
'part_edit',
'part_create',
'part_delete',
'part_stock_operation',
'datastructure_edit',
'datastructure_create',
'datastructure_delete',
];
public function __construct(protected array $enforce_change_comments_for)
{
}
/**
* Checks if a log change comment is needed for the given operation type
*/
public function isCommentNeeded(string $comment_type): bool
public function isCommentNeeded(EventCommentType $comment_type): bool
{
//Check if the comment type is valid
if (! in_array($comment_type, self::VALID_OPERATION_TYPES, true)) {
throw new \InvalidArgumentException('The comment type "'.$comment_type.'" is not valid!');
}
return in_array($comment_type, $this->enforce_change_comments_for, true);
}
}